Skip to content

refactor: 💡 use polkadot types from polymesh-types #1484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
modulePathIgnorePatterns: ['dist'],
moduleNameMapper: {
'~/(.*)': '<rootDir>/src/$1',
'polymesh-types/(.*)': '<rootDir>/src/polkadot/$1',
'polymesh-types/(.*)':
'<rootDir>/node_modules/@polymeshassociation/polymesh-types/generated-types/$1',
},
};
10 changes: 2 additions & 8 deletions src/api/client/Claims.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Vec } from '@polkadot/types';
import BigNumber from 'bignumber.js';
import { filter, flatten, isEqual, uniqBy, uniqWith } from 'lodash';
import { IdentityClaim } from 'polymesh-types/polymesh';

Check failure on line 4 in src/api/client/Claims.ts

View workflow job for this annotation

GitHub Actions / Validate API snapshot

Cannot find module 'polymesh-types/polymesh' or its corresponding type declarations.

import {
Context,
Expand All @@ -15,7 +16,6 @@
customClaimTypeQuery,
} from '~/middleware/queries/claims';
import { ClaimsOrderBy, ClaimTypeEnum, Query } from '~/middleware/types';
import { IdentityClaim } from '~/polkadot/polymesh';
import {
CddClaim,
ClaimData,
Expand Down Expand Up @@ -431,13 +431,7 @@
const data: ClaimData<CddClaim>[] = [];

result.forEach(optClaim => {
const {
claim_issuer: claimIssuer,
issuance_date: issuanceDate,
last_update_date: lastUpdateDate,
expiry: rawExpiry,
claim,
} = optClaim;
const { claimIssuer, issuanceDate, lastUpdateDate, expiry: rawExpiry, claim } = optClaim;

const expiry = !rawExpiry.isEmpty ? momentToDate(rawExpiry.unwrap()) : null;

Expand Down
2 changes: 1 addition & 1 deletion src/api/client/Polymesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
} from '@apollo/client/core';
import { ApiPromise, HttpProvider, WsProvider } from '@polkadot/api';
import { DefinitionsCall } from '@polkadot/types/types';
import schema from '@polymeshassociation/polymesh-types/generated-types/schema';
import { SigningManager } from '@polymeshassociation/signing-manager-types';
import fetch from 'cross-fetch';
import schema from 'polymesh-types/schema';

import { Staking } from '~/api/client/Staking';
import { Account, Context, createTransactionBatch, Identity, PolymeshError } from '~/internal';
Expand Down
2 changes: 1 addition & 1 deletion src/api/entities/Asset/Base/Settlements/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DispatchError } from '@polkadot/types/interfaces/system';
import { Result, Vec } from '@polkadot/types-codec';
import BigNumber from 'bignumber.js';
import { ComplianceReport, TransferCondition } from 'polymesh-types/polymesh';

import { assertPortfolioExists } from '~/api/procedures/utils';
import {
Expand All @@ -11,7 +12,6 @@ import {
Nft,
toggleAssetPreApproval,
} from '~/internal';
import { ComplianceReport, TransferCondition } from '~/polkadot/polymesh';
import { NftCollection, NoArgsProcedureMethod, PortfolioLike, TransferBreakdown } from '~/types';
import { isFungibleAsset } from '~/utils';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import BigNumber from 'bignumber.js';
import { when } from 'jest-when';
import { PolymeshMoment } from 'polymesh-types/polymesh';

import { Schedules } from '~/api/entities/Asset/Fungible/Checkpoints/Schedules';
import {
Expand All @@ -9,7 +10,6 @@ import {
Namespace,
PolymeshTransaction,
} from '~/internal';
import { Moment } from '~/polkadot';
import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mocks';
import { tuple } from '~/types/utils';
import * as utilsConversionModule from '~/utils/conversion';
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('Schedules class', () => {
[dsMockUtils.createMockAssetId(rawAssetId), rawId],
dsMockUtils.createMockOption(
dsMockUtils.createMockCheckpointSchedule({
pending: dsMockUtils.createMockBTreeSet<Moment>([
pending: dsMockUtils.createMockBTreeSet<PolymeshMoment>([
dsMockUtils.createMockMoment(new BigNumber(start.getTime())),
dsMockUtils.createMockMoment(new BigNumber(nextCheckpointDate.getTime())),
]),
Expand Down
2 changes: 1 addition & 1 deletion src/api/entities/Asset/__tests__/Base/Settlements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
import { Result, Vec } from '@polkadot/types-codec';
import BigNumber from 'bignumber.js';
import { when } from 'jest-when';
import { ComplianceReport, TransferCondition } from 'polymesh-types/polymesh';

import { FungibleSettlements, NonFungibleSettlements } from '~/api/entities/Asset/Base/Settlements';
import { Context, Namespace, PolymeshTransaction } from '~/internal';
import { ComplianceReport, TransferCondition } from '~/polkadot/polymesh';
import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mocks';
import { Mocked } from '~/testUtils/types';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/api/entities/Identity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import BigNumber from 'bignumber.js';
import P from 'bluebird';
import { chunk, differenceWith, flatten, intersectionWith, uniqBy } from 'lodash';
import { CddStatus } from 'polymesh-types/polymesh';

import { unlinkChildIdentity } from '~/api/procedures/unlinkChildIdentity';
import { assertPortfolioExists } from '~/api/procedures/utils';
Expand All @@ -29,7 +30,6 @@ import { assetHoldersQuery, nftHoldersQuery } from '~/middleware/queries/assets'
import { trustingAssetsQuery } from '~/middleware/queries/claims';
import { historicalInstructionsQuery } from '~/middleware/queries/settlements';
import { AssetHoldersOrderBy, NftHoldersOrderBy, Query } from '~/middleware/types';
import { CddStatus } from '~/polkadot/polymesh';
import {
Asset,
CheckRolesResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { bool } from '@polkadot/types';
import { PolymeshPrimitivesSecondaryKeySignatory } from '@polkadot/types/lookup';
import BigNumber from 'bignumber.js';
import { when } from 'jest-when';
import { AuthorizationType as MeshAuthorizationType } from 'polymesh-types/polymesh';

import { Context, Namespace } from '~/internal';
import { authorizationsQuery } from '~/middleware/queries/authorizations';
import { AuthorizationStatusEnum, AuthTypeEnum } from '~/middleware/types';
import { AuthorizationType as MeshAuthorizationType } from '~/polkadot/polymesh';
import { dsMockUtils, entityMockUtils } from '~/testUtils/mocks';
import { AuthorizationType, Identity, SignerValue } from '~/types';
import { hexToUuid } from '~/utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@polkadot/types/lookup';
import BigNumber from 'bignumber.js';
import { when } from 'jest-when';
import { AffirmationCount, ExecuteInstructionInfo } from 'polymesh-types/polymesh';

import {
getAuthorization,
Expand All @@ -15,7 +16,6 @@ import {
} from '~/api/procedures/modifyInstructionAffirmation';
import * as procedureUtilsModule from '~/api/procedures/utils';
import { Context, DefaultPortfolio, Instruction, PolymeshError } from '~/internal';
import { AffirmationCount, ExecuteInstructionInfo } from '~/polkadot/polymesh';
import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mocks';
import {
createMockAssetCount,
Expand Down
4 changes: 2 additions & 2 deletions src/api/procedures/__tests__/registerIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { PolymeshPrimitivesSecondaryKey } from '@polkadot/types/lookup';
import { ISubmittableResult } from '@polkadot/types/types';
import BigNumber from 'bignumber.js';
import { when } from 'jest-when';
import { PolymeshMoment } from 'polymesh-types/polymesh';

import {
createRegisterIdentityResolver,
prepareRegisterIdentity,
} from '~/api/procedures/registerIdentity';
import { Context, Identity, PolymeshError, Procedure } from '~/internal';
import { Moment } from '~/polkadot';
import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mocks';
import { Mocked } from '~/testUtils/types';
import { ErrorCode, PermissionedAccount, RegisterIdentityParams } from '~/types';
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('registerIdentity procedure', () => {
PolymeshPrimitivesSecondaryKey,
[PermissionedAccount, Context]
>;
let dateToMomentSpy: jest.SpyInstance<Moment, [Date, Context]>;
let dateToMomentSpy: jest.SpyInstance<PolymeshMoment, [Date, Context]>;
let registerIdentityTransaction: PolymeshTx<unknown[]>;
let proc: Procedure<RegisterIdentityParams, Identity, Record<string, unknown>>;

Expand Down
8 changes: 2 additions & 6 deletions src/api/procedures/executeManualInstruction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PolymeshPrimitivesIdentityIdPortfolioId } from '@polkadot/types/lookup';
import { Option } from '@polkadot/types-codec';
import BigNumber from 'bignumber.js';
import P from 'bluebird';

Expand All @@ -11,7 +10,6 @@ import {
PolymeshError,
Procedure,
} from '~/internal';
import { ExecuteInstructionInfo } from '~/polkadot/polymesh';
import {
ErrorCode,
ExecuteManualInstructionParams,
Expand Down Expand Up @@ -57,7 +55,7 @@ export async function prepareExecuteManualInstruction(
polymeshApi: {
tx: { settlement: settlementTx },
query: { settlement },
call,
call: { settlementApi },
},
},
context,
Expand Down Expand Up @@ -99,9 +97,7 @@ export async function prepareExecuteManualInstruction(
}
}

const rawInfo = await call.settlementApi.getExecuteInstructionInfo<
Option<ExecuteInstructionInfo>
>(rawInstructionId);
const rawInfo = await settlementApi.getExecuteInstructionInfo(rawInstructionId);

const { fungibleTokens, nonFungibleTokens, offChainAssets, consumedWeight } =
rawInfo.unwrapOrDefault();
Expand Down
12 changes: 8 additions & 4 deletions src/api/procedures/modifyInstructionAffirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
} from '@polkadot/types/lookup';
import BigNumber from 'bignumber.js';
import P from 'bluebird';
import { AffirmationCount, ExecuteInstructionInfo, PolymeshMoment } from 'polymesh-types/polymesh';

import { assertInstructionValid } from '~/api/procedures/utils';
import { Context, Identity, Instruction, PolymeshError, Procedure } from '~/internal';
import { AffirmationCount, ExecuteInstructionInfo, Moment } from '~/polkadot/polymesh';
import {
AffirmationStatus,
AffirmInstructionParams,
Expand Down Expand Up @@ -348,7 +348,7 @@ export async function prepareModifyInstructionAffirmation(
PolymeshPrimitivesSettlementAffirmationCount
]
>
| PolymeshTx<[u64, Option<Moment>]>
| PolymeshTx<[u64, Option<PolymeshMoment>]>
| PolymeshTx<[u64]>
| PolymeshTx<
[
Expand Down Expand Up @@ -640,7 +640,11 @@ export async function prepareStorage(
): Promise<Storage> {
const {
context,
context: { polymeshApi },
context: {
polymeshApi: {
call: { settlementApi },
},
},
} = this;
const { id } = params;
const rawId = bigNumberToU64(id, context);
Expand All @@ -654,7 +658,7 @@ export async function prepareStorage(
const [{ data: legs }, signer, executeInstructionInfo] = await Promise.all([
instruction.getLegsFromChain(),
context.getSigningIdentity(),
polymeshApi.call.settlementApi.getExecuteInstructionInfo(rawId),
settlementApi.getExecuteInstructionInfo(rawId),
]);

const [portfolios, senderLegAmount, offChainLegIndices] = await P.reduce<
Expand Down
2 changes: 1 addition & 1 deletion src/base/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { getTypeDef, u32 } from '@polkadot/types';
import { Hash, SignedBlock } from '@polkadot/types/interfaces';
import { SpRuntimeDispatchError } from '@polkadot/types/lookup';
import { RegistryError, TypeDef, TypeDefInfo } from '@polkadot/types/types';
import { polymesh } from '@polymeshassociation/polymesh-types/generated-types/definitions';
import { BigNumber } from 'bignumber.js';
import { polymesh } from 'polymesh-types/definitions';

import { Context, PolymeshError } from '~/internal';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './polkadot/augment-api';
import '@polymeshassociation/polymesh-types/generated-types/augment-api';

import BigNumber from 'bignumber.js';

Expand Down
43 changes: 0 additions & 43 deletions src/polkadot/asset/definitions.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/polkadot/asset/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/polkadot/asset/types.ts

This file was deleted.

Loading
Loading