Skip to content

Commit

Permalink
feat: allow issuer change funding round name
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Mar 19, 2020
1 parent 3e27186 commit 3beb566
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/api/procedures/modifyToken.ts
@@ -1,11 +1,17 @@
import { SecurityToken } from '~/api/entities';
import { PolymeshError, Procedure } from '~/base';
import { ErrorCode } from '~/types';
import { stringToTicker, stringToTokenName } from '~/utils';
import {
fundingRoundNameToString,
stringToFundingRoundName,
stringToTicker,
stringToTokenName,
} from '~/utils';

export type ModifyTokenParams =
| { makeDivisible?: true; name: string }
| { makeDivisible: true; name?: string };
| { makeDivisible?: true; name: string; fundingRound?: string }
| { makeDivisible: true; name?: string; fundingRound?: string }
| { makeDivisible?: true; name?: string; fundingRound: string };

export type Params = { ticker: string } & ModifyTokenParams;

Expand All @@ -18,13 +24,13 @@ export async function prepareModifyToken(
): Promise<SecurityToken> {
const {
context: {
polymeshApi: { tx },
polymeshApi: { query, tx },
},
context,
} = this;
const { ticker, makeDivisible, name: newName } = args;
const { ticker, makeDivisible, name: newName, fundingRound: newFundingRound } = args;

if (makeDivisible === undefined && newName === undefined) {
if (makeDivisible === undefined && newName === undefined && newFundingRound === undefined) {
throw new PolymeshError({
code: ErrorCode.ValidationError,
message: 'Nothing to modify',
Expand All @@ -35,7 +41,10 @@ export async function prepareModifyToken(

const securityToken = new SecurityToken({ ticker }, context);

const { isDivisible, owner, name } = await securityToken.details();
const [{ isDivisible, owner, name }, fundingRound] = await Promise.all([
securityToken.details(),
query.asset.fundingRound(ticker),
]);

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (owner.did !== context.getCurrentIdentity().did) {
Expand Down Expand Up @@ -72,6 +81,22 @@ export async function prepareModifyToken(
this.addTransaction(tx.asset.renameToken, {}, rawTicker, stringToTokenName(newName, context));
}

if (newFundingRound) {
if (newFundingRound === fundingRoundNameToString(fundingRound)) {
throw new PolymeshError({
code: ErrorCode.ValidationError,
message: 'New funding round name is the same as current funding round',
});
}

this.addTransaction(
tx.asset.setFundingRound,
{},
rawTicker,
stringToFundingRoundName(newFundingRound, context)
);
}

return securityToken;
}

Expand Down

0 comments on commit 3beb566

Please sign in to comment.