Skip to content

Commit e319927

Browse files
committed
Merge branch 'develop' of https://github.com/PolymathNetwork/polymath-apps into fix/dividends-details-page-update
2 parents 517def6 + ef62a7c commit e319927

29 files changed

Lines changed: 314 additions & 170 deletions

File tree

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ActionType } from 'typesafe-actions';
1919
import { DividendModuleTypes } from '@polymathnetwork/sdk';
2020
import { BigNumber } from 'bignumber.js';
2121
import { Page } from '@polymathnetwork/new-ui';
22-
import { range, padStart, flatten, map, every, values } from 'lodash';
22+
import { range, padStart, flatten, map, every, values, keys } from 'lodash';
2323
import { polyClient } from '~/lib/polyClient';
2424
import { GetErc20BalanceByAddressAndWalletArgs } from '~/types';
2525
import { push } from 'redux-little-router';
@@ -236,7 +236,21 @@ export class ContainerBase extends Component<Props, State> {
236236
render={(dividendsData: {
237237
[key: string]: types.DividendEntity[];
238238
}) => {
239-
const dividends = flatten(values(dividendsData));
239+
const { dispatch } = this.props;
240+
const dividendsListUrl = `/securityTokens/${securityTokenSymbol}/dividends`;
241+
242+
const checkpointsList = values(dividendsData);
243+
if (
244+
checkpointsList.length === 0 ||
245+
!keys(dividendsData).find(checkpointId => {
246+
return checkpointId === checkpointIndex;
247+
})
248+
) {
249+
// No checkpoints exist
250+
dispatch(push(dividendsListUrl));
251+
}
252+
253+
const dividends = flatten(checkpointsList);
240254
const isCompleted = map(dividends, dividend => {
241255
const { expiry, investors } = dividend;
242256
const remainingPayments = investors.filter(
@@ -253,8 +267,6 @@ export class ContainerBase extends Component<Props, State> {
253267

254268
if (!allDividendsCompleted) {
255269
// There are dividends with pending distribution
256-
const { dispatch } = this.props;
257-
const dividendsListUrl = `/securityTokens/${securityTokenSymbol}/dividends`;
258270
dispatch(push(dividendsListUrl));
259271
}
260272
return (

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { CreateDividendDistributionParams } from './Container';
1919
import * as sc from './styles';
2020
import { Step1 } from './Step-1';
2121
import { Step2 } from './Step-2';
22+
import { ConfirmModal } from './Step-2/ConfirmModal';
2223
import { Step3 } from './Step-3';
2324
import { types, formatters } from '@polymathnetwork/new-shared';
2425
import BigNumber from 'bignumber.js';
@@ -27,6 +28,7 @@ import {
2728
GetErc20BalanceByAddressAndWalletArgs,
2829
GetIsValidErc20ByAddressArgs,
2930
} from '~/types';
31+
import { block, unblock } from 'redux-little-router';
3032

3133
export interface ExclusionEntry {
3234
['Investor ETH Address']: string;
@@ -64,6 +66,8 @@ export interface State {
6466
dividendAmount: BigNumber;
6567
tokenSymbol: string;
6668
positiveWithholdingAmount: number;
69+
isDirty: boolean;
70+
confirmModalOpen: boolean;
6771
}
6872

6973
export class Presenter extends Component<Props, State> {
@@ -74,6 +78,8 @@ export class Presenter extends Component<Props, State> {
7478
positiveWithholdingAmount: this.props.taxWithholdings.filter(
7579
({ percentage }) => percentage > 0
7680
).length,
81+
isDirty: false,
82+
confirmModalOpen: false,
7783
};
7884

7985
public setExcludedWallets = (excludedWallets: null | ExclusionEntry[]) => {
@@ -92,6 +98,41 @@ export class Presenter extends Component<Props, State> {
9298
this.setState({ positiveWithholdingAmount });
9399
};
94100

101+
public setIsDirty = (isDirty: boolean) => {
102+
if (isDirty !== this.state.isDirty) {
103+
this.setState({ isDirty });
104+
if (isDirty) {
105+
// Block reload
106+
window.onbeforeunload = e => {
107+
e.preventDefault();
108+
return true;
109+
};
110+
block(() => {
111+
return (
112+
'To apply your new/modified tax withholding entries, simply hit "CANCEL" and click on "UPDATE" above the Tax Withholdings table.\n' +
113+
'To ignore the new/modified tax withholding entries, simply hit "PROCEED"'
114+
);
115+
});
116+
} else {
117+
window.onbeforeunload = null;
118+
unblock();
119+
}
120+
}
121+
};
122+
123+
public closeConfirmModal = () => {
124+
this.setState({ confirmModalOpen: false });
125+
};
126+
127+
public openConfirmModal = () => {
128+
this.setState({ confirmModalOpen: true });
129+
};
130+
131+
public onConfirmBack = () => {
132+
this.closeConfirmModal();
133+
this.props.onPreviousStep();
134+
};
135+
95136
public getExcludedAddresses = () => {
96137
const { excludedWallets } = this.state;
97138

@@ -145,6 +186,7 @@ export class Presenter extends Component<Props, State> {
145186
nonExcludedInvestors={nonExcludedInvestors}
146187
exclusionList={exclusionList}
147188
isLoadingData={isLoadingData}
189+
setIsDirty={this.setIsDirty}
148190
/>
149191
);
150192
}
@@ -187,6 +229,7 @@ export class Presenter extends Component<Props, State> {
187229
dividendAmount,
188230
tokenSymbol,
189231
positiveWithholdingAmount,
232+
confirmModalOpen,
190233
} = this.state;
191234
const { investorBalances } = checkpoint;
192235
const exclusionList = this.getExcludedAddresses();
@@ -208,9 +251,13 @@ export class Presenter extends Component<Props, State> {
208251
) => {
209252
// TODO @RafaelVidaurre: Fix this by using the right component
210253
if (stepIndex > 0) {
211-
onPreviousStep();
212254
event.preventDefault();
213255
event.stopPropagation();
256+
if (stepIndex === 1 && this.state.isDirty) {
257+
this.openConfirmModal();
258+
} else {
259+
onPreviousStep();
260+
}
214261
}
215262
}}
216263
>
@@ -300,6 +347,11 @@ export class Presenter extends Component<Props, State> {
300347
</CardPrimary>
301348
</GridRow.Col>
302349
</GridRow>
350+
<ConfirmModal
351+
isOpen={confirmModalOpen}
352+
onConfirm={this.onConfirmBack}
353+
onClose={this.closeConfirmModal}
354+
/>
303355
</div>
304356
);
305357
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
validateYupSchema,
55
yupToFormErrors,
66
} from 'formik';
7-
import React, { Fragment, useState, useMemo, FC } from 'react';
7+
import React, { Fragment, useState, useMemo, FC, useEffect } from 'react';
88
import { has, merge } from 'lodash';
99
import { types } from '@polymathnetwork/new-shared';
1010
import {
@@ -37,6 +37,7 @@ import {
3737
FormValues,
3838
TaxWithholdingStatuses,
3939
} from './shared';
40+
import { unblock } from 'redux-little-router';
4041

4142
interface Props {
4243
onNextStep: () => void;
@@ -54,6 +55,7 @@ interface Props {
5455
exclusionList: string[];
5556
onTaxWithholdingListChange: (amountOfInvestors: number) => void;
5657
isLoadingData: boolean;
58+
setIsDirty: (isDirty: boolean) => void;
5759
}
5860

5961
const schema = validator.object().shape({
@@ -86,6 +88,7 @@ export const Step2: FC<Props> = ({
8688
exclusionList,
8789
onTaxWithholdingListChange,
8890
isLoadingData,
91+
setIsDirty,
8992
}) => {
9093
const [csvModalOpen, setCsvModalOpen] = useState(false);
9194

@@ -312,6 +315,7 @@ export const Step2: FC<Props> = ({
312315
csvModalOpen={csvModalOpen}
313316
closeCsvModal={closeCsvModal}
314317
isLoadingData={isLoadingData}
318+
setIsDirty={setIsDirty}
315319
exclusionList={exclusionList}
316320
/>
317321
)}
@@ -329,6 +333,7 @@ interface FormProps {
329333
csvModalOpen: boolean;
330334
closeCsvModal: () => void;
331335
isLoadingData: boolean;
336+
setIsDirty: (isDirty: boolean) => void;
332337
exclusionList: string[];
333338
}
334339

@@ -341,13 +346,25 @@ const Form: FC<FormProps> = ({
341346
csvModalOpen,
342347
closeCsvModal,
343348
isLoadingData,
349+
setIsDirty,
344350
exclusionList,
345351
}) => {
346352
const [isEditing, setIsEditing] = useState(false);
347353
const [confirmModalOpen, setConfirmModalOpen] = useState(false);
348354
const [taxWithholdingModalOpen, setTaxWithholdingModalOpen] = useState(false);
349355
const [confirmDeleteModalOpen, setConfirmDeleteModalOpen] = useState(false);
350356
const [addressesToDelete, setAddressesToDelete] = useState<string[]>([]);
357+
useEffect(() => {
358+
setIsDirty(isDraft);
359+
});
360+
361+
useEffect(() => {
362+
return () => {
363+
window.onbeforeunload = null;
364+
unblock();
365+
};
366+
}, []);
367+
351368
const openTaxWithhholdingModal = () => {
352369
setTaxWithholdingModalOpen(true);
353370
};

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

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ const Step3Base: FC<Props> = ({
127127

128128
const [erc20TokenSymbol, setErc20TokenSymbol] = useState('');
129129

130+
const isTestNet = [
131+
constants.NetworkIds.Kovan,
132+
constants.NetworkIds.Local,
133+
constants.NetworkIds.LocalVm,
134+
].includes(networkId);
135+
130136
useEffect(
131137
() => {
132138
const { isSubmitting, submitEvent } = formSubmissionStatus;
@@ -218,12 +224,6 @@ const Step3Base: FC<Props> = ({
218224
});
219225

220226
const difference = dividendAmount.minus(balance);
221-
222-
const isTestNet = [
223-
constants.NetworkIds.Kovan,
224-
constants.NetworkIds.Local,
225-
constants.NetworkIds.LocalVm,
226-
].includes(networkId);
227227
const willUseFaucet = isTestNet && currency === types.Tokens.Poly;
228228

229229
if (!willUseFaucet && difference.gte(0)) {
@@ -330,9 +330,9 @@ const Step3Base: FC<Props> = ({
330330
<FormItem.Label>Dividend Distribution Name</FormItem.Label>
331331
<FormItem.Input
332332
component={TextInput}
333-
placeholder="Enter the name"
334333
inputProps={{
335334
maxLength: dividendsTitleLength,
335+
placeholder: 'Enter the name',
336336
}}
337337
/>
338338
<FormItem.Error />
@@ -343,14 +343,34 @@ const Step3Base: FC<Props> = ({
343343
component={CurrencySelect}
344344
inputProps={{
345345
options: [
346-
types.Tokens.Erc20,
347-
types.Tokens.Dai,
348-
types.Tokens.Gusd,
349-
types.Tokens.Pax,
350-
types.Tokens.Poly,
351-
types.Tokens.Usdc,
352-
types.Tokens.Usdt,
346+
{
347+
value: types.Tokens.Erc20,
348+
},
349+
{
350+
value: types.Tokens.Dai,
351+
},
352+
{
353+
value: types.Tokens.Gusd,
354+
isDisabled: isTestNet,
355+
},
356+
{
357+
value: types.Tokens.Pax,
358+
isDisabled: isTestNet,
359+
},
360+
{
361+
value: types.Tokens.Poly,
362+
},
363+
{
364+
value: types.Tokens.Usdc,
365+
isDisabled: isTestNet,
366+
},
367+
{
368+
value: types.Tokens.Usdt,
369+
isDisabled: isTestNet,
370+
},
353371
],
372+
placeholder: 'Choose currency',
373+
disabledOptionText: 'Not available on test network',
354374
}}
355375
onChange={(selectedCurrency: string) =>
356376
updateCurrencySymbol(
@@ -359,7 +379,6 @@ const Step3Base: FC<Props> = ({
359379
: selectedCurrency
360380
)
361381
}
362-
placeholder="Choose currency"
363382
/>
364383
<FormItem.Error />
365384
</FormItem>
@@ -409,7 +428,9 @@ const Step3Base: FC<Props> = ({
409428
// do nothing
410429
}
411430
}}
412-
placeholder={'Enter ERC20 token contract address'}
431+
inputProps={{
432+
placeholder: 'Enter ERC20 token contract address',
433+
}}
413434
/>
414435
<FormItem.Error />
415436
</FormItem>
@@ -419,16 +440,16 @@ const Step3Base: FC<Props> = ({
419440
<FormItem.Label>Dividend Amount</FormItem.Label>
420441
<FormItem.Input
421442
component={NumberInput}
422-
placeholder="Enter the value"
423443
inputProps={{
424444
min: new BigNumber(0),
425445
max: new BigNumber('1000000000000000000'),
426-
maxDecimals:2,
446+
maxDecimals: 2,
427447
unit:
428448
currency === types.Tokens.Erc20
429449
? erc20TokenSymbol
430450
: currency,
431451
useBigNumbers: true,
452+
placeholder: 'Enter the value',
432453
}}
433454
onChange={updateDividendAmount}
434455
/>

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,18 @@ export const Presenter: FC<Props> = ({
6666
[walletAddress]
6767
);
6868

69-
const handleAddressChange = useCallback(values => {
70-
if (dividendsModule) {
71-
onChangeWalletAddress(values.walletAddress);
72-
} else {
73-
setWalletAddress(values.walletAddress);
74-
}
69+
const handleAddressChange = useCallback(
70+
values => {
71+
if (dividendsModule) {
72+
onChangeWalletAddress(values.walletAddress);
73+
} else {
74+
setWalletAddress(values.walletAddress);
75+
}
7576

76-
setEditAddressState(false);
77-
}, []);
77+
setEditAddressState(false);
78+
},
79+
[dividendsModule]
80+
);
7881

7982
const handleAddressValidation = useCallback(async values => {
8083
const schema = validator.object().shape({
@@ -234,7 +237,9 @@ export const Presenter: FC<Props> = ({
234237
<FormItem.Label>Wallet Address</FormItem.Label>
235238
<FormItem.Input
236239
component={TextInput}
237-
placeholder="Wallet address"
240+
inputProps={{
241+
placeholder: 'Wallet address',
242+
}}
238243
/>
239244
<FormItem.Error />
240245
</FormItem>

0 commit comments

Comments
 (0)