Skip to content

Commit

Permalink
Merge branch 'beta' into test/reclaim-funds-procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Wiebe committed Nov 25, 2019
2 parents f967e85 + 7f38dc2 commit 347234a
Show file tree
Hide file tree
Showing 6 changed files with 630 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polymathnetwork/sdk",
"version": "2.0.1-beta.58",
"version": "2.0.1-beta.60",
"description": "A Javascript SDK for interacting with the Polymath network for the browser and Node.js",
"bugs": {
"url": "https://github.com/PolymathNetwork/polymath-sdk/issues"
Expand Down
28 changes: 18 additions & 10 deletions src/procedures/PushDividendPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,27 @@ import {
PolyTransactionTag,
ErrorCode,
} from '../types';
import { Factories } from '../Context';
import { PolymathError } from '../PolymathError';
import { DividendDistribution, SecurityToken } from '../entities';

const CHUNK_SIZE = 100;

export const createPushDividendPaymentResolver = (
factories: Factories,
symbol: string,
dividendType: DividendType,
index: number
) => async () => {
return factories.dividendDistributionFactory.refresh(
DividendDistribution.generateId({
securityTokenId: SecurityToken.generateId({ symbol }),
dividendType,
index,
})
);
};

export class PushDividendPayment extends Procedure<PushDividendPaymentProcedureArgs> {
public type = ProcedureType.PushDividendPayment;

Expand Down Expand Up @@ -74,7 +90,7 @@ export class PushDividendPayment extends Procedure<PushDividendPaymentProcedureA
}

const unpaidShareholders = shareholderStatuses
.filter(status => status.paymentReceived)
.filter(status => !status.paymentReceived)
.map(status => status.address);

const shareholderAddressChunks = chunk(unpaidShareholders, CHUNK_SIZE);
Expand All @@ -86,15 +102,7 @@ export class PushDividendPayment extends Procedure<PushDividendPaymentProcedureA
resolver:
index < shareholderAddressChunks.length - 1
? undefined
: async () => {
return factories.dividendDistributionFactory.refresh(
DividendDistribution.generateId({
securityTokenId: SecurityToken.generateId({ symbol }),
dividendType,
index,
})
);
},
: createPushDividendPaymentResolver(factories, symbol, dividendType, index),
})({
dividendIndex,
payees: addresses,
Expand Down
23 changes: 17 additions & 6 deletions src/procedures/TransferErc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Procedure } from './Procedure';
import { TransferErc20ProcedureArgs, ErrorCode, ProcedureType, PolyTransactionTag } from '../types';
import { PolymathError } from '../PolymathError';
import { Erc20TokenBalance } from '../entities';
import { Factories } from '~/Context';

/**
* Procedure to transfer funds of an ERC20 token. If no token address is specified, it defaults to POLY
Expand Down Expand Up @@ -34,7 +35,9 @@ export class TransferErc20 extends Procedure<TransferErc20ProcedureArgs> {
}

try {
token = await contractWrappers.getERC20TokenWrapper({ address: tokenAddress });
token = await contractWrappers.getERC20TokenWrapper({
address: tokenAddress,
});
} catch (err) {
throw new PolymathError({
code: ErrorCode.ProcedureValidationError,
Expand Down Expand Up @@ -70,11 +73,19 @@ export class TransferErc20 extends Procedure<TransferErc20ProcedureArgs> {

await this.addTransaction(token.transfer, {
tag: PolyTransactionTag.TransferErc20,
resolver: async _receipt => {
return factories.erc20TokenBalanceFactory.refresh(
Erc20TokenBalance.generateId({ tokenAddress: address, walletAddress: receiver })
);
},
resolver: createTransferErc20Resolver(factories, address, receiver),
})({ to: receiver, value: amount });
}
}
export const createTransferErc20Resolver = (
factories: Factories,
tokenAddress: string,
receiver: string
) => async () => {
return factories.erc20TokenBalanceFactory.refresh(
Erc20TokenBalance.generateId({
tokenAddress,
walletAddress: receiver,
})
);
};
1 change: 1 addition & 0 deletions src/procedures/__tests__/AssignSecurityTokenRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('AssignSecurityTokenRole', () => {
// Mock the context, wrappers, and tokenFactory to test AssignSecurityTokenRole
contextMock = ImportMock.mockClass(contextModule, 'Context');
wrappersMock = ImportMock.mockClass(wrappersModule, 'PolymathBase');

tokenFactoryMock = ImportMock.mockClass(tokenFactoryModule, 'MockedTokenFactoryModule');

contextMock.set('contractWrappers', wrappersMock.getMockInstance());
Expand Down
Loading

0 comments on commit 347234a

Please sign in to comment.