-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sdk): Add existential deposits for foreign assets ✨
- Loading branch information
1 parent
73622dd
commit ea38f8f
Showing
38 changed files
with
2,342 additions
and
1,272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
import type { ApiPromise } from '@polkadot/api' | ||
import type { TForeignAsset, TNativeAsset } from '../../src/types' | ||
|
||
const fetchAssets = async ( | ||
api: ApiPromise, | ||
query: string, | ||
isNative: boolean | ||
): Promise<TForeignAsset[]> => { | ||
const [module, section] = query.split('.') | ||
const res = await api.query[module][section].entries() | ||
|
||
return res | ||
.filter( | ||
([ | ||
{ | ||
args: [era] | ||
} | ||
]) => { | ||
const hasNativeAssetId = Object.prototype.hasOwnProperty.call( | ||
era.toHuman(), | ||
'NativeAssetId' | ||
) | ||
return isNative ? hasNativeAssetId : !hasNativeAssetId | ||
} | ||
) | ||
.map( | ||
([ | ||
{ | ||
args: [era] | ||
}, | ||
value | ||
]) => { | ||
const { symbol, decimals, existentialDeposit, minimalBalance } = value.toHuman() as any | ||
return { | ||
assetId: Object.values(era.toHuman() ?? {})[0], | ||
symbol, | ||
decimals: +decimals, | ||
existentialDeposit: minimalBalance ?? existentialDeposit | ||
} | ||
} | ||
) | ||
} | ||
|
||
export const fetchAcalaNativeAssets = async ( | ||
api: ApiPromise, | ||
query: string | ||
): Promise<TNativeAsset[]> => { | ||
return (await fetchAssets(api, query, true)).map(asset => ({ | ||
symbol: asset.symbol, | ||
decimals: asset.decimals, | ||
existentialDeposit: asset.existentialDeposit | ||
})) | ||
} | ||
|
||
export const fetchAcalaForeignAssets = async ( | ||
api: ApiPromise, | ||
query: string | ||
): Promise<TForeignAsset[]> => { | ||
return fetchAssets(api, query, false) | ||
} |
Oops, something went wrong.