Skip to content

Commit

Permalink
feat(sto): add name to the Sto entity
Browse files Browse the repository at this point in the history
  • Loading branch information
monitz87 committed Feb 27, 2021
1 parent 35c4b1b commit d800303
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/api/entities/Sto/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,21 @@ describe('Sto class', () => {
expect(queue).toBe(expectedQueue);
});
});

describe('method: name', () => {
test("should return the offering's name", async () => {
const name = 'someName';
const ticker = 'SOMETICKER';
const id = new BigNumber(1);
const sto = new Sto({ id, ticker }, context);

dsMockUtils.createQueryStub('sto', 'fundraiserNames', {
returnValue: dsMockUtils.createMockFundraiserName(name),
});

const result = await sto.name();

expect(result).toBe(name);
});
});
});
21 changes: 20 additions & 1 deletion src/api/entities/Sto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import { Query } from '~/middleware/types';
import { Fundraiser } from '~/polkadot/polymesh/types';
import { Ensured, ErrorCode, ResultSet, SubCallback, UnsubCallback } from '~/types';
import { ProcedureMethod } from '~/types/internal';
import { fundraiserToStoDetails, numberToU64, stringToTicker } from '~/utils/conversion';
import {
fundraiserToStoDetails,
numberToU64,
stringToTicker,
textToString,
} from '~/utils/conversion';
import { calculateNextKey, createProcedureMethod } from '~/utils/internal';

import { Investment, StoDetails } from './types';
Expand Down Expand Up @@ -236,4 +241,18 @@ export class Sto extends Entity<UniqueIdentifiers> {
count,
};
}

/**
* Retrieve the Offering's name
*/
public async name(): Promise<string> {
const { context, id, ticker } = this;

const name = await context.polymeshApi.query.sto.fundraiserNames(
stringToTicker(ticker, context),
numberToU64(id, context)
);

return textToString(name);
}
}
8 changes: 8 additions & 0 deletions src/testUtils/mocks/dataSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
DocumentUri,
FundingRoundName,
Fundraiser,
FundraiserName,
FundraiserStatus,
FundraiserTier,
IdentityClaim,
Expand Down Expand Up @@ -1675,6 +1676,13 @@ export const createMockPalletName = (name?: string): PalletName =>
export const createMockDispatchableName = (name?: string): DispatchableName =>
createMockStringCodec(name) as DispatchableName;

/**
* @hidden
* NOTE: `isEmpty` will be set to true if no value is passed
*/
export const createMockFundraiserName = (name?: string): FundraiserName =>
createMockStringCodec(name) as FundraiserName;

/**
* @hidden
* NOTE: `isEmpty` will be set to true if no value is passed
Expand Down

0 comments on commit d800303

Please sign in to comment.