diff --git a/.papi/descriptors/package.json b/.papi/descriptors/package.json index 9094dc2..3b415b5 100644 --- a/.papi/descriptors/package.json +++ b/.papi/descriptors/package.json @@ -1,5 +1,5 @@ { - "version": "0.1.0-autogenerated.18306352226980812337", + "version": "0.1.0-autogenerated.18031542027992032156", "name": "@polkadot-api/descriptors", "files": [ "dist" diff --git a/src/api/common.ts b/src/api/common.ts index ca1bcf1..c89f5eb 100644 --- a/src/api/common.ts +++ b/src/api/common.ts @@ -10,7 +10,7 @@ import { dotAh, } from "@polkadot-api/descriptors" import { Binary, Enum, SS58String } from "polkadot-api" -import { map } from "rxjs" +import { combineLatest, from, map } from "rxjs" const encodeAccount = AccountId().enc @@ -90,20 +90,34 @@ export const fromAssetHubToForeign = ( type GenericApi = TypedApi -export const watchAccoutFreeBalance = - (api: { - query: { - System: { - Account: { - watchValue: GenericApi["query"]["System"]["Account"]["watchValue"] - } +export const watchAccoutFreeBalance = (api: { + constants: { + Balances: { + ExistentialDeposit: () => Promise + } + } + query: { + System: { + Account: { + watchValue: GenericApi["query"]["System"]["Account"]["watchValue"] } } - }) => - (account: SS58String) => - api.query.System.Account.watchValue(account, "best").pipe( - map(({ data }) => data.free - data.frozen), + } +}) => { + const edPromise = api.constants.Balances.ExistentialDeposit() + return (account: SS58String) => + combineLatest([ + from(edPromise), + api.query.System.Account.watchValue(account, "best"), + ]).pipe( + map(([ed, { data }]) => { + const spendableBalance = + data.free - + (data.frozen - data.reserved > ed ? data.frozen - data.reserved : ed) + return spendableBalance > 0n ? spendableBalance : 0n + }), ) +} export const watchForeingAssetAccoutFreeBalance = ( diff --git a/whitelist.ts b/whitelist.ts index b35b510..18a9de1 100644 --- a/whitelist.ts +++ b/whitelist.ts @@ -7,12 +7,14 @@ const dotWhitelist: DotWhitelistEntry[] = [ "tx.XcmPallet.limited_teleport_assets", "tx.XcmPallet.limited_reserve_transfer_assets", "query.System.Account", + "const.Balances.ExistentialDeposit", ] const ahWhitelist: DotAhWhitelistEntry[] = [ "tx.PolkadotXcm.limited_teleport_assets", "tx.PolkadotXcm.limited_reserve_transfer_assets", "query.ForeignAssets.Account", + "const.Balances.ExistentialDeposit", ] export const whitelist = [...dotWhitelist, ...ahWhitelist]