Shortcut balance instances check (#5099)

This commit is contained in:
Jaco
2022-07-22 07:06:55 +03:00
committed by GitHub
parent 2121a1eea0
commit ec76f2cefd
2 changed files with 3 additions and 1 deletions
+1
View File
@@ -12,6 +12,7 @@ Changes:
- Add `toPrimitive()` to all base `Codec` interfaces (string/boolean/number)
- Adjust metadata conversion with `objectSpread` (where missing)
- Support for `TransactionPaymentCallApi` runtime interface
- Check `registry.getModuleInstances` against metadata paths (fallback)
- Update to `@polkadot/util` 10.1.1
- Update to latest Kusama metadata (Substrate & Polkadot are current)
+2 -1
View File
@@ -151,6 +151,7 @@ function querySystemAccount (api: DeriveApi, accountId: AccountId): Observable<R
*/
export function account (instanceId: string, api: DeriveApi): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAccount> {
const balanceInstances = api.registry.getModuleInstances(api.runtimeVersion.specName, 'balances');
const nonDefaultBalances = balanceInstances && (balanceInstances.length !== 1 || balanceInstances[0] !== 'balances');
return memo(instanceId, (address: AccountIndex | AccountId | Address | string): Observable<DeriveBalancesAccount> =>
api.derive.accounts.accountId(address).pipe(
@@ -158,7 +159,7 @@ export function account (instanceId: string, api: DeriveApi): (address: AccountI
(accountId
? combineLatest([
of(accountId),
balanceInstances && (balanceInstances.length !== 1 || balanceInstances[0] !== 'balances')
nonDefaultBalances
? queryBalancesAccount(api, accountId, balanceInstances)
: isFunction(api.query.system?.account)
? querySystemAccount(api, accountId)