Skip to content

Commit 2ba08cc

Browse files
Merge pull request #552 from PolymathNetwork/fix/step2-confirm-navigation
fix(new-issuer): confirm unposted transactions
2 parents 6f0d65e + 86d868f commit 2ba08cc

2 files changed

Lines changed: 71 additions & 2 deletions

File tree

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 (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
};

0 commit comments

Comments
 (0)