Skip to content

Commit

Permalink
fix: feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Aug 7, 2020
1 parent e28a80b commit b0850cd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 47 deletions.
26 changes: 8 additions & 18 deletions src/Polymesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,21 @@ import {
MiddlewareConfig,
NetworkProperties,
ResultSet,
Signer as MeshSigner,
SignerType,
SigningItem,
SubCallback,
TickerReservationStatus,
UiKeyring,
UnsubCallback,
} from '~/types';
import { ClaimOperation } from '~/types/internal';
import {
accountKeyToString,
booleanToBool,
calculateNextKey,
createClaim,
identityIdToString,
linkTypeToMeshLinkType,
moduleAddressToString,
signatoryToSigner,
signerToSignatory,
stringToTicker,
textToString,
Expand Down Expand Up @@ -739,13 +738,13 @@ export class Polymesh {
*
* @note can be subscribed to
*/
public async getMySigningKeys(): Promise<SigningItem[]>;
public async getMySigningKeys(callback: SubCallback<SigningItem[]>): Promise<UnsubCallback>;
public async getMySigningKeys(): Promise<MeshSigner[]>;
public async getMySigningKeys(callback: SubCallback<MeshSigner[]>): Promise<UnsubCallback>;

// eslint-disable-next-line require-jsdoc
public async getMySigningKeys(
callback?: SubCallback<SigningItem[]>
): Promise<SigningItem[] | UnsubCallback> {
callback?: SubCallback<MeshSigner[]>
): Promise<MeshSigner[] | UnsubCallback> {
const {
context: {
polymeshApi: {
Expand All @@ -757,17 +756,8 @@ export class Polymesh {

const { did } = context.getCurrentIdentity();

const assembleResult = ({ signing_items: signingItems }: DidRecord): SigningItem[] => {
return signingItems.map(({ signer: rawSigner }) => {
return {
signer: {
value: rawSigner.isAccountKey
? accountKeyToString(rawSigner.asAccountKey)
: identityIdToString(rawSigner.asIdentity),
type: rawSigner.isAccountKey ? SignerType.AccountKey : SignerType.Identity,
},
};
});
const assembleResult = ({ signing_items: signingItems }: DidRecord): MeshSigner[] => {
return signingItems.map(({ signer: rawSigner }) => signatoryToSigner(rawSigner));
};

if (callback) {
Expand Down
33 changes: 17 additions & 16 deletions src/__tests__/Polymesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Signer } from '@polkadot/api/types';
import { ApolloLink, GraphQLRequest } from 'apollo-link';
import * as apolloLinkContextModule from 'apollo-link-context';
import BigNumber from 'bignumber.js';
import { AccountKey, DidRecord, IdentityId, TxTags } from 'polymesh-types/types';
import { DidRecord, Signatory, TxTags } from 'polymesh-types/types';
import sinon from 'sinon';

import { Identity, TickerReservation } from '~/api/entities';
Expand Down Expand Up @@ -1151,20 +1151,25 @@ describe('Polymesh Class', () => {
const did = 'someDid';
const accountKey = 'someAccountKey';
const fakeResult = [
{ signer: { value: did, type: SignerType.Identity } },
{ signer: { value: accountKey, type: SignerType.AccountKey } },
{ value: did, type: SignerType.Identity },
{ value: accountKey, type: SignerType.AccountKey },
];
const signerIdentityId = dsMockUtils.createMockSignatory({
Identity: dsMockUtils.createMockIdentityId(did),
});
const signerAccountKey = dsMockUtils.createMockSignatory({
AccountKey: dsMockUtils.createMockAccountKey(accountKey),
});

let accountKeyToStringStub: sinon.SinonStub<[AccountKey], string>;
let identityIdToStringStub: sinon.SinonStub<[IdentityId], string>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let signatoryToSignerStub: sinon.SinonStub<[Signatory], any>;
let didRecordsStub: sinon.SinonStub;
let rawDidRecord: DidRecord;

beforeAll(() => {
accountKeyToStringStub = sinon.stub(utilsModule, 'accountKeyToString');
identityIdToStringStub = sinon.stub(utilsModule, 'identityIdToString');
accountKeyToStringStub.returns(accountKey);
identityIdToStringStub.returns(did);
signatoryToSignerStub = sinon.stub(utilsModule, 'signatoryToSigner');
signatoryToSignerStub.withArgs(signerIdentityId).returns(fakeResult[0]);
signatoryToSignerStub.withArgs(signerAccountKey).returns(fakeResult[1]);
});

beforeEach(() => {
Expand All @@ -1175,16 +1180,12 @@ describe('Polymesh Class', () => {
master_key: dsMockUtils.createMockAccountKey(),
signing_items: [
dsMockUtils.createMockSigningItem({
signer: dsMockUtils.createMockSignatory({
Identity: dsMockUtils.createMockIdentityId(did),
}),
signer: signerIdentityId,
signer_type: dsMockUtils.createMockSignatoryType(),
permissions: [],
}),
dsMockUtils.createMockSigningItem({
signer: dsMockUtils.createMockSignatory({
AccountKey: dsMockUtils.createMockAccountKey(accountKey),
}),
signer: signerAccountKey,
signer_type: dsMockUtils.createMockSignatoryType(),
permissions: [],
}),
Expand All @@ -1193,7 +1194,7 @@ describe('Polymesh Class', () => {
/* eslint-enabled @typescript-eslint/camelcase */
});

test('should return a list of SigningItem', async () => {
test('should return a list of Signers', async () => {
const polymesh = await Polymesh.connect({
nodeUrl: 'wss://some.url',
});
Expand Down
3 changes: 2 additions & 1 deletion src/api/procedures/__tests__/transferTokenOwnership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import {
Authorization,
AuthorizationType,
RoleType,
Signer,
SignerType,
TickerReservationStatus,
} from '~/types';
import { PolymeshTx, Signer } from '~/types/internal';
import { PolymeshTx } from '~/types/internal';
import * as utilsModule from '~/utils';

describe('transferTokenOwnership procedure', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { IKeyringPair, TypeDef } from '@polkadot/types/types';
import BigNumber from 'bignumber.js';

import { Identity } from '~/api/entities';
import { Signer } from '~/types/internal';

export enum TransactionStatus {
/**
Expand Down Expand Up @@ -380,10 +379,6 @@ export enum SignerType {
AccountKey = 'AccountKey',
}

export interface SigningItem {
signer: Signer;
}

export enum TransactionArgumentType {
Did = 'Did',
Address = 'Address',
Expand Down Expand Up @@ -441,6 +436,11 @@ export type TransactionArgument = {
| ComplexTransactionArgument
);

export interface Signer {
type: SignerType;
value: string;
}

export { TxTags } from 'polymesh-types/types';
export * from '~/api/entities/types';
export * from '~/base/types';
Expand Down
6 changes: 0 additions & 6 deletions src/types/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import BigNumber from 'bignumber.js';
import { DocumentNode } from 'graphql';

import { PostTransactionValue } from '~/base';
import { SignerType } from '~/types';

/**
* Polkadot's `tx` submodule
Expand Down Expand Up @@ -100,11 +99,6 @@ export interface TransactionSpec<
batchSize: number | null;
}

export interface Signer {
type: SignerType;
value: string;
}

export interface AuthTarget {
did: string;
authId: BigNumber;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
NextKey,
PaginationOptions,
Rule,
Signer,
SignerType,
SingleClaimCondition,
TokenDocument,
Expand All @@ -76,7 +77,6 @@ import {
Extrinsics,
MapMaybePostTransactionValue,
MaybePostTransactionValue,
Signer,
} from '~/types/internal';
import { tuple } from '~/types/utils';
import {
Expand Down

0 comments on commit b0850cd

Please sign in to comment.