Skip to content

Commit c3b66a2

Browse files
committed
chore(new-issuer): refactor complete check logic
1 parent bf561e3 commit c3b66a2

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

  • packages/new-polymath-issuer/src/pages/DividendsWizard

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

Lines changed: 13 additions & 17 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 } from 'lodash';
22+
import { range, padStart, flatten, map, every, values } from 'lodash';
2323
import { polyClient } from '~/lib/polyClient';
2424
import { GetErc20BalanceByAddressAndWalletArgs } from '~/types';
2525
import { push } from 'redux-little-router';
@@ -236,25 +236,21 @@ export class ContainerBase extends Component<Props, State> {
236236
render={(dividendsData: {
237237
[key: string]: types.DividendEntity[];
238238
}) => {
239-
const allDividendsCompleted = every(
240-
flatten(
241-
map(dividendsData, dividends =>
242-
map(dividends, dividend => {
243-
const { expiry, investors } = dividend;
244-
245-
const remainingPayments = investors.filter(
246-
(investor: any) =>
247-
!investor.paymentReceived && !investor.excluded
248-
).length;
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;
249246

250-
return (
251-
expiry <= new Date() || remainingPayments === 0
252-
);
253-
})
254-
)
255-
),
247+
return expiry <= new Date() || remainingPayments === 0;
248+
});
249+
const allDividendsCompleted = every(
250+
isCompleted,
256251
(complete: boolean) => complete
257252
);
253+
258254
if (!allDividendsCompleted) {
259255
// There are dividends with pending distribution
260256
const { dispatch } = this.props;

0 commit comments

Comments
 (0)