diff --git a/src/utils/__tests__/index.ts b/src/utils/__tests__/index.ts index 2d100fd924..7a4163b99d 100644 --- a/src/utils/__tests__/index.ts +++ b/src/utils/__tests__/index.ts @@ -1713,10 +1713,13 @@ describe('claimToMeshClaim and meshClaimToClaim', () => { scope: { type: ScopeType.Identity, value: 'someTickerDid' }, }; const fakeResult = ('meshClaim' as unknown) as MeshClaim; + const fakeScope = ('scope' as unknown) as MeshScope; - dsMockUtils - .getCreateTypeStub() - .withArgs('Claim', { [value.type]: [value.code, value.scope] }) + const createTypeStub = dsMockUtils.getCreateTypeStub(); + + createTypeStub.withArgs('Scope', sinon.match.any).returns(fakeScope); + createTypeStub + .withArgs('Claim', { [value.type]: [value.code, scopeToMeshScope(value.scope, context)] }) .returns(fakeResult); let result = claimToMeshClaim(value, context); @@ -1728,9 +1731,8 @@ describe('claimToMeshClaim and meshClaimToClaim', () => { scope: { type: ScopeType.Identity, value: 'someTickerDid' }, }; - dsMockUtils - .getCreateTypeStub() - .withArgs('Claim', { [value.type]: value.scope }) + createTypeStub + .withArgs('Claim', { [value.type]: scopeToMeshScope(value.scope, context) }) .returns(fakeResult); result = claimToMeshClaim(value, context); @@ -1741,10 +1743,7 @@ describe('claimToMeshClaim and meshClaimToClaim', () => { type: ClaimType.NoData, }; - dsMockUtils - .getCreateTypeStub() - .withArgs('Claim', { [value.type]: null }) - .returns(fakeResult); + createTypeStub.withArgs('Claim', { [value.type]: null }).returns(fakeResult); result = claimToMeshClaim(value, context); diff --git a/src/utils/index.ts b/src/utils/index.ts index a48bfe811b..b2a317a838 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -998,11 +998,46 @@ export function canTransferResultToTransferStatus( return u8ToTransferStatus(canTransferResult.asOk); } +/** + * @hidden + */ +export function scopeToMeshScope(scope: Scope, context: Context): MeshScope { + const { type, value } = scope; + + return context.polymeshApi.createType('Scope', { + [type]: value, + }); +} + +/** + * @hidden + */ +export function meshScopeToScope(scope: MeshScope): Scope { + if (scope.isTicker) { + return { + type: ScopeType.Ticker, + value: tickerToString(scope.asTicker), + }; + } + + if (scope.isIdentity) { + return { + type: ScopeType.Identity, + value: identityIdToString(scope.asIdentity), + }; + } + + return { + type: ScopeType.Custom, + value: u8aToString(scope.asCustom), + }; +} + /** * @hidden */ export function claimToMeshClaim(claim: Claim, context: Context): MeshClaim { - let value: unknown; + let value; switch (claim.type) { case ClaimType.NoData: @@ -1011,11 +1046,11 @@ export function claimToMeshClaim(claim: Claim, context: Context): MeshClaim { break; } case ClaimType.Jurisdiction: { - value = tuple(claim.code, claim.scope); + value = tuple(claim.code, scopeToMeshScope(claim.scope, context)); break; } default: { - value = claim.scope; + value = scopeToMeshScope(claim.scope, context); } } @@ -1064,41 +1099,6 @@ export function createClaim( return { type, scope }; } -/** - * @hidden - */ -export function scopeToMeshScope(scope: Scope, context: Context): MeshScope { - const { type, value } = scope; - - return context.polymeshApi.createType('Scope', { - [type]: value, - }); -} - -/** - * @hidden - */ -export function meshScopeToScope(scope: MeshScope): Scope { - if (scope.isTicker) { - return { - type: ScopeType.Ticker, - value: tickerToString(scope.asTicker), - }; - } - - if (scope.isIdentity) { - return { - type: ScopeType.Identity, - value: identityIdToString(scope.asIdentity), - }; - } - - return { - type: ScopeType.Custom, - value: u8aToString(scope.asCustom), - }; -} - /** * @hidden */