Skip to content

Commit

Permalink
fix: add some validations
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Apr 14, 2020
1 parent edff37f commit 29ac1c0
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/api/procedures/setIssuanceData.ts
@@ -1,7 +1,7 @@
import { SecurityToken } from '~/api/entities';
import { PolymeshError, Procedure } from '~/base';
import { ErrorCode, IssuanceData, Role, RoleType } from '~/types';
import { stringToTicker } from '~/utils';
import { numberToBalance, stringToIdentityId, stringToTicker } from '~/utils';

export interface SetIssuanceDataParams {
issuances: IssuanceData[];
Expand All @@ -20,14 +20,35 @@ export async function prepareSetIssuanceData(
): Promise<SecurityToken> {
const {
context: {
polymeshApi: { query, tx },
polymeshApi: {
query,
tx: { asset },
},
},
context,
} = this;
const { ticker, issuances } = args;

const investors = issuances.map(issuance => stringToIdentityId(issuance.did, context));
const values = issuances.map(issuance => numberToBalance(issuance.balance, context));

if (investors.length !== values.length) {
throw new PolymeshError({
code: ErrorCode.ValidationError,
message: 'You must set the same number of investors as values',
});
}

const securityToken = new SecurityToken({ ticker }, context);
const { isDivisible, totalSupply } = await securityToken.details();
// check granularity

debugger;

const rawTicker = stringToTicker(ticker, context);

// this.addTransaction(asset.batchIssue, {}, rawTicker, [], []);

return new SecurityToken({ ticker }, context);
}

Expand Down

0 comments on commit 29ac1c0

Please sign in to comment.