Skip to content

Commit 86d868f

Browse files
committed
chore(new-issuer): fix merge conflicts
2 parents 4e4aea0 + 650e11a commit 86d868f

20 files changed

Lines changed: 280 additions & 112 deletions

File tree

packages/new-polymath-issuer/src/components/DividendCard/DividendCard.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
ButtonFluid,
1818
} from '@polymathnetwork/new-ui';
1919
import { DIVIDEND_PAYMENT_INVESTOR_BATCH_SIZE } from '~/constants';
20+
import * as sc from './styles';
2021

2122
interface Props {
2223
dividend: types.DividendEntity;
@@ -88,9 +89,9 @@ export const DividendCard: FC<Props> = ({
8889
{formatters.toTokens(dividend.amount)} {currencyLabel}
8990
</Paragraph>
9091
</CardPrimary>
91-
<Heading mt="m" mb={1}>
92+
<sc.DividendHeading mt="m" mb={1}>
9293
{dividend.name}
93-
</Heading>
94+
</sc.DividendHeading>
9495
<Label color={currencyColor} bg={currencyBgColor}>
9596
Issued in {currencyType}
9697
</Label>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { styled, Heading, ThemeInterface } from '@polymathnetwork/new-ui';
2+
import { StyledComponent } from 'styled-components';
3+
4+
export const DividendHeading: StyledComponent<
5+
typeof Heading,
6+
ThemeInterface,
7+
any,
8+
'variant'
9+
> = styled(Heading)`
10+
width: 100%;
11+
word-wrap: break-word;
12+
`;

packages/new-polymath-issuer/src/pages/DividendDetails/Presenter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export const Presenter = ({
243243
<Box ml="m">
244244
<Text color="highlightText" fontSize={6} fontWeight={0}>
245245
{formatters.toPercent(
246-
1 - pendingTransactions / totalTransactions
246+
1 - pendingTransactions / (totalTransactions || 1)
247247
)}
248248
</Text>
249249
<Paragraph>Transactions are completed</Paragraph>

packages/new-polymath-issuer/src/pages/DividendsWizard/Container.tsx

Lines changed: 101 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { DataFetcher } from '~/components/enhancers/DataFetcher';
66
import {
77
createTaxWithholdingListBySymbolAndCheckpointFetcher,
88
createCheckpointBySymbolAndIdFetcher,
9+
createCheckpointsBySymbolFetcher,
10+
createDividendsByCheckpointFetcher,
911
} from '~/state/fetchers';
1012
import { types, formatters, utils } from '@polymathnetwork/new-shared';
1113
import { DateTime } from 'luxon';
@@ -17,13 +19,15 @@ import { ActionType } from 'typesafe-actions';
1719
import { DividendModuleTypes } from '@polymathnetwork/sdk';
1820
import { BigNumber } from 'bignumber.js';
1921
import { Page } from '@polymathnetwork/new-ui';
20-
import { range, padStart } from 'lodash';
22+
import { range, padStart, flatten, map, every, values } from 'lodash';
2123
import { polyClient } from '~/lib/polyClient';
2224
import { GetErc20BalanceByAddressAndWalletArgs } from '~/types';
25+
import { push } from 'redux-little-router';
2326

2427
const actions = {
2528
updateTaxWithholdingListStart,
2629
createErc20DividendDistributionStart,
30+
push,
2731
};
2832

2933
export interface Props {
@@ -203,48 +207,109 @@ export class ContainerBase extends Component<Props, State> {
203207

204208
public render() {
205209
const { securityTokenSymbol, checkpointIndex } = this.props;
210+
const fetcher = createCheckpointsBySymbolFetcher({
211+
securityTokenSymbol,
212+
});
213+
206214
const { step } = this.state;
207215
const parsedCheckpointIndex = parseInt(checkpointIndex, 10);
208216
return (
209217
<Page title="Create New Dividend Distribution">
210218
<DataFetcher
211219
watchProps={this.state}
212-
fetchers={[
213-
createTaxWithholdingListBySymbolAndCheckpointFetcher({
214-
securityTokenSymbol,
215-
checkpointIndex: parsedCheckpointIndex,
216-
dividendType: DividendModuleTypes.Erc20,
217-
}),
218-
createCheckpointBySymbolAndIdFetcher({
219-
securityTokenSymbol,
220-
checkpointIndex: parsedCheckpointIndex,
221-
}),
222-
]}
223-
render={(
224-
{
225-
taxWithholdings,
226-
checkpoints: [checkpoint],
227-
}: {
228-
taxWithholdings: types.TaxWithholdingEntity[];
229-
checkpoints: types.CheckpointEntity[];
230-
},
231-
loading: boolean
232-
) => {
220+
fetchers={[fetcher]}
221+
render={(data: { checkpoints: types.CheckpointEntity[] }) => {
222+
const { checkpoints } = data;
223+
const fetchers = checkpoints.map(({ index }) =>
224+
createDividendsByCheckpointFetcher(
225+
{
226+
securityTokenSymbol,
227+
checkpointIndex: index,
228+
},
229+
{ propKey: `${index}` }
230+
)
231+
);
233232
return (
234-
<Presenter
235-
createDividendDistribution={this.createDividendDistribution}
236-
updateTaxWithholdingList={this.updateTaxWithholdingList}
237-
stepIndex={step}
238-
securityTokenSymbol={securityTokenSymbol}
239-
checkpoint={checkpoint}
240-
onNextStep={this.nextStep}
241-
onPreviousStep={this.previousStep}
242-
taxWithholdings={taxWithholdings}
243-
downloadTaxWithholdingList={this.downloadTaxWithholdingList}
244-
downloadSampleExclusionList={this.downloadSampleExclusionList}
245-
fetchBalance={this.fetchBalance}
246-
fetchIsValidToken={this.fetchIsValidToken}
247-
isLoadingData={loading}
233+
<DataFetcher
234+
watchProps={this.state}
235+
fetchers={fetchers}
236+
render={(dividendsData: {
237+
[key: string]: types.DividendEntity[];
238+
}) => {
239+
const dividends = flatten(values(dividendsData));
240+
const isCompleted = map(dividends, dividend => {
241+
const { expiry, investors } = dividend;
242+
const remainingPayments = investors.filter(
243+
(investor: any) =>
244+
!investor.paymentReceived && !investor.excluded
245+
).length;
246+
247+
return expiry <= new Date() || remainingPayments === 0;
248+
});
249+
const allDividendsCompleted = every(
250+
isCompleted,
251+
(complete: boolean) => complete
252+
);
253+
254+
if (!allDividendsCompleted) {
255+
// There are dividends with pending distribution
256+
const { dispatch } = this.props;
257+
const dividendsListUrl = `/securityTokens/${securityTokenSymbol}/dividends`;
258+
dispatch(push(dividendsListUrl));
259+
}
260+
return (
261+
<DataFetcher
262+
watchProps={this.state}
263+
fetchers={[
264+
createTaxWithholdingListBySymbolAndCheckpointFetcher({
265+
securityTokenSymbol,
266+
checkpointIndex: parsedCheckpointIndex,
267+
dividendType: DividendModuleTypes.Erc20,
268+
}),
269+
createCheckpointBySymbolAndIdFetcher({
270+
securityTokenSymbol,
271+
checkpointIndex: parsedCheckpointIndex,
272+
}),
273+
]}
274+
render={(
275+
{
276+
taxWithholdings,
277+
checkpoints: [checkpoint],
278+
}: {
279+
taxWithholdings: types.TaxWithholdingEntity[];
280+
checkpoints: types.CheckpointEntity[];
281+
},
282+
loading: boolean
283+
) => {
284+
return (
285+
<Presenter
286+
createDividendDistribution={
287+
this.createDividendDistribution
288+
}
289+
updateTaxWithholdingList={
290+
this.updateTaxWithholdingList
291+
}
292+
stepIndex={step}
293+
securityTokenSymbol={securityTokenSymbol}
294+
checkpoint={checkpoint}
295+
onNextStep={this.nextStep}
296+
onPreviousStep={this.previousStep}
297+
taxWithholdings={taxWithholdings}
298+
downloadTaxWithholdingList={
299+
this.downloadTaxWithholdingList
300+
}
301+
downloadSampleExclusionList={
302+
this.downloadSampleExclusionList
303+
}
304+
fetchBalance={this.fetchBalance}
305+
fetchIsValidToken={this.fetchIsValidToken}
306+
isLoadingData={loading}
307+
/>
308+
);
309+
}}
310+
/>
311+
);
312+
}}
248313
/>
249314
);
250315
}}

packages/new-polymath-issuer/src/pages/DividendsWizard/Step-1/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const Step1: FC<Step1Props> = ({
8282
via a CSV which includes one wallet (ETH) address per line.
8383
</Paragraph>
8484
<Paragraph>
85-
You can download
85+
You can download{' '}
8686
<LinkButton onClick={downloadSampleExclusionList}>
8787
<Icon Asset={icons.SvgDownload} /> Sample-Exclusion-List.csv
8888
</LinkButton>{' '}
@@ -148,6 +148,7 @@ export const Step1: FC<Step1Props> = ({
148148
],
149149
header: true,
150150
maxRows: 100,
151+
strict: true,
151152
validateFile,
152153
customValidationErrorMessage: {
153154
header: 'Duplicate Entries',

packages/new-polymath-issuer/src/pages/DividendsWizard/Step-2/TaxWithholdingModal.tsx

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ interface Props {
2222
onClose: () => void;
2323
taxWithholdingData?: TaxWithholdingsItem;
2424
fieldProps: FieldProps<any>;
25+
exclusionList: string[];
2526
}
2627

2728
export const TaxWithholdingModal: FC<Props> = ({
2829
isOpen,
2930
onClose,
3031
isEditing,
3132
fieldProps,
33+
exclusionList,
3234
}) => {
3335
const { field, form } = fieldProps;
3436
const isValid = !get(form.errors, field.name);
@@ -52,34 +54,46 @@ export const TaxWithholdingModal: FC<Props> = ({
5254

5355
const valueAddress = value[csvEthAddressKey].toUpperCase();
5456

55-
const matchingIndex = findIndex(
56-
formTaxWithholdings,
57-
taxWithholding =>
58-
taxWithholding[csvEthAddressKey].toUpperCase() === valueAddress
59-
);
57+
// Check if excluded
58+
const excluded = exclusionList.find(address => {
59+
return address.toUpperCase() === valueAddress;
60+
});
6061

61-
const alreadyExists = matchingIndex !== -1;
62+
if (!excluded) {
63+
// Check if the address already exists in the tax withholding list
64+
// if it is a new address, add it to list, otherwise if the address
65+
// exists or if the user is editing an existing address, replace the
66+
// item from the array with the new item.
67+
const matchingIndex = findIndex(
68+
formTaxWithholdings,
69+
taxWithholding =>
70+
taxWithholding[csvEthAddressKey].toUpperCase() === valueAddress
71+
);
6272

63-
if (isEditing || alreadyExists) {
64-
const finalValue = { ...value };
73+
const alreadyExists = matchingIndex !== -1;
6574

66-
formTaxWithholdings.splice(matchingIndex, 1, finalValue);
67-
form.setFieldValue('taxWithholdings', formTaxWithholdings);
68-
} else {
6975
const finalValue = { ...value };
70-
71-
form.setFieldValue('taxWithholdings', [
72-
...formTaxWithholdings,
73-
finalValue,
74-
]);
76+
if (isEditing || alreadyExists) {
77+
formTaxWithholdings.splice(matchingIndex, 1, finalValue);
78+
form.setFieldValue('taxWithholdings', formTaxWithholdings);
79+
} else {
80+
form.setFieldValue('taxWithholdings', [
81+
...formTaxWithholdings,
82+
finalValue,
83+
]);
84+
}
85+
form.setFieldValue(field.name, {
86+
[csvTaxWithholdingKey]: null,
87+
[csvEthAddressKey]: '',
88+
});
89+
form.setFieldTouched(field.name, false);
90+
onClose();
91+
} else {
92+
form.setFieldError(
93+
'currentTaxWithholding.Investor ETH Address',
94+
'This address was excluded in the previous step'
95+
);
7596
}
76-
77-
form.setFieldValue(field.name, {
78-
[csvTaxWithholdingKey]: null,
79-
[csvEthAddressKey]: '',
80-
});
81-
form.setFieldTouched(field.name, false);
82-
onClose();
8397
};
8498

8599
// NOTE @RafaelVidaurre: Workaround to avoid broken dirty-checking
@@ -100,7 +114,6 @@ export const TaxWithholdingModal: FC<Props> = ({
100114
},
101115
[isOpen]
102116
);
103-
104117
return (
105118
<ModalConfirm
106119
isOpen={isOpen}

0 commit comments

Comments
 (0)