@@ -25,45 +25,48 @@ export const fetchSystemParachainForeignAssetInfo = async (
2525 if ( api . query . foreignAssets !== undefined ) {
2626 const assetEntries = await api . query . foreignAssets . asset . entries ( ) ;
2727
28- for ( const [ assetStorageKeyData ] of assetEntries ) {
29- const foreignAssetData = assetStorageKeyData . toHuman ( ) ;
30-
31- if ( foreignAssetData ) {
32- // remove any commas from multilocation key values e.g. Parachain: 2,125 -> Parachain: 2125
33- const foreignAssetMultiLocationStr = JSON . stringify (
34- foreignAssetData [ 0 ] ,
35- ) . replace ( / ( \d ) , / g, '$1' ) ;
28+ let foreignAssetMultiLocationStr : string | undefined = undefined ;
29+ for ( const asset of assetEntries ) {
30+ const storageKey = asset [ 0 ] . toHuman ( ) ;
31+ if ( storageKey && Array . isArray ( storageKey ) && storageKey . length > 0 ) {
32+ foreignAssetMultiLocationStr = JSON . stringify ( storageKey [ 0 ] ) . replace (
33+ / ( \d ) , / g,
34+ '$1' ,
35+ ) ;
36+ }
37+ if ( ! foreignAssetMultiLocationStr ) {
38+ throw new Error ( 'Unable to determine asset location' ) ;
39+ }
3640
37- const foreignAssetMultiLocation = JSON . parse (
38- foreignAssetMultiLocationStr ,
39- ) as UnionXcmMultiLocation ;
41+ const foreignAssetMultiLocation = JSON . parse (
42+ foreignAssetMultiLocationStr ,
43+ ) as UnionXcmMultiLocation ;
4044
41- const hexId = stringToHex ( JSON . stringify ( foreignAssetMultiLocation ) ) ;
45+ const hexId = stringToHex ( JSON . stringify ( foreignAssetMultiLocation ) ) ;
4246
43- const assetMetadata = (
44- await api . query . foreignAssets . metadata ( foreignAssetMultiLocation )
45- ) . toHuman ( ) ;
47+ const assetMetadata = (
48+ await api . query . foreignAssets . metadata ( foreignAssetMultiLocation )
49+ ) . toHuman ( ) ;
4650
47- if ( assetMetadata ) {
48- const metadata = assetMetadata as ForeignAssetMetadata ;
49- const assetSymbol = metadata . symbol ;
50- const assetName = metadata . name ;
51+ if ( assetMetadata ) {
52+ const metadata = assetMetadata as ForeignAssetMetadata ;
53+ const assetSymbol = metadata . symbol ;
54+ const assetName = metadata . name ;
5155
52- // if the symbol exists in metadata use it, otherwise uses the hex of the multilocation as the key
53- const foreignAssetInfoKey = assetSymbol ? assetSymbol : hexId ;
54- const assetLocation = JSON . stringify ( foreignAssetMultiLocation ) ;
56+ // if the symbol exists in metadata use it, otherwise uses the hex of the multilocation as the key
57+ const foreignAssetInfoKey = assetSymbol ? assetSymbol : hexId ;
58+ const assetLocation = JSON . stringify ( foreignAssetMultiLocation ) ;
5559
56- const [ assetHubReserveLocation , originChainReserveLocation ] =
57- getAssetReserveLocations ( assetLocation , chainId ) ;
60+ const [ assetHubReserveLocation , originChainReserveLocation ] =
61+ getAssetReserveLocations ( assetLocation , chainId ) ;
5862
59- foreignAssetsInfo [ foreignAssetInfoKey ] = {
60- symbol : assetSymbol ,
61- name : assetName ,
62- multiLocation : assetLocation ,
63- assetHubReserveLocation,
64- originChainReserveLocation,
65- } ;
66- }
63+ foreignAssetsInfo [ foreignAssetInfoKey ] = {
64+ symbol : assetSymbol ,
65+ name : assetName ,
66+ multiLocation : assetLocation ,
67+ assetHubReserveLocation,
68+ originChainReserveLocation,
69+ } ;
6770 }
6871 }
6972 }
0 commit comments