Skip to content

Commit

Permalink
fix: multilocation type in pallets/foreign-assets (#1408)
Browse files Browse the repository at this point in the history
* fix: multilocation type in pallets/foreign-assets

* remove createType & update tests
  • Loading branch information
Imod7 committed Mar 6, 2024
1 parent 96c9f11 commit b7136d0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/services/pallets/PalletsForeignAssetsService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2023 Parity Technologies (UK) Ltd.
// Copyright 2017-2024 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -65,9 +65,9 @@ describe('PalletsForeignAssetsService', () => {
},
foreignAssetMetadata: {
deposit: '0',
name: '0x',
symbol: '0x',
decimals: '0',
name: '0x506f6c6b61646f74',
symbol: '0x444f54',
decimals: '10',
isFrozen: false,
},
},
Expand Down
8 changes: 3 additions & 5 deletions src/services/pallets/PalletsForeignAssetsService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2023 Parity Technologies (UK) Ltd.
// Copyright 2017-2024 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -56,13 +56,11 @@ export class PalletsForeignAssetsService extends AbstractService {
if (foreignAssetData) {
// remove any commas from multilocation key values e.g. Parachain: 2,125 -> Parachain: 2125
const foreignAssetMultiLocationStr = JSON.stringify(foreignAssetData[0]).replace(/(\d),/g, '$1');
const foreignAssetMultiLocation = api.registry.createType(
'XcmV3MultiLocation',

const assetMetadata = await api.query.foreignAssets.metadata<AssetMetadata>(
JSON.parse(foreignAssetMultiLocationStr),
);

const assetMetadata = await api.query.foreignAssets.metadata<AssetMetadata>(foreignAssetMultiLocation);

if (assetInfo.isSome) {
items.push({
foreignAssetInfo: assetInfo.unwrap(),
Expand Down
10 changes: 5 additions & 5 deletions src/services/test-helpers/mock/assets/mockAssetHubKusamaData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2023 Parity Technologies (UK) Ltd.
// Copyright 2017-2024 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -86,9 +86,9 @@ export const foreignAssetsInfo = [foreignAssetInfoDot, foreignAssetInfoTknr];
const foreignAssetMetadataDot = (): AssetMetadata => {
const responseObj = {
deposit: balanceOfDot,
name: assetHubKusamaRegistryV9430.createType('Bytes', ''),
symbol: assetHubKusamaRegistryV9430.createType('Bytes', ''),
decimals: assetHubKusamaRegistryV9430.createType('u8', 0),
name: assetHubKusamaRegistryV9430.createType('Bytes', 'Polkadot'),
symbol: assetHubKusamaRegistryV9430.createType('Bytes', 'DOT'),
decimals: assetHubKusamaRegistryV9430.createType('u8', 10),
isFrozen: falseBool,
};

Expand All @@ -110,7 +110,7 @@ const foreignAssetMetadataTknr = (): AssetMetadata => {
export const foreignAssetsMetadata = (location: string): AssetMetadata => {
const foreignAssetMultiLocationStr = JSON.stringify(location).replace(/(\d),/g, '$1');

if (foreignAssetMultiLocationStr == '{"parents":2"interior":{"x1":{"globalConsensus":{"polkadot":null}}}}')
if (foreignAssetMultiLocationStr == '{"parents":"2","interior":{"X1":{"GlobalConsensus":"Polkadot"}}}')
return foreignAssetMetadataDot();
else {
return foreignAssetMetadataTknr();
Expand Down

0 comments on commit b7136d0

Please sign in to comment.