From 75fa6cef1266e9c1f0ac88ae6ffee5674eade80e Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Fri, 7 Jan 2022 15:02:06 +0000 Subject: [PATCH] add derives for transfer Signed-off-by: Gregory Hill --- packages/apps-config/src/api/spec/interbtc.ts | 26 ++++++++++++++++--- .../page-accounts/src/Accounts/Account.tsx | 4 +-- .../src/Sidebar/AccountMenuButtons.tsx | 2 +- .../page-accounts/src/modals/Transfer.tsx | 8 +++--- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/packages/apps-config/src/api/spec/interbtc.ts b/packages/apps-config/src/api/spec/interbtc.ts index 126b5ca67862..0687eb7c0747 100644 --- a/packages/apps-config/src/api/spec/interbtc.ts +++ b/packages/apps-config/src/api/spec/interbtc.ts @@ -3,16 +3,16 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment */ -import type { Observable } from 'rxjs'; -import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { ApiInterfaceRx, SubmittableExtrinsicFunction } from '@polkadot/api/types'; import type { OverrideBundleDefinition } from '@polkadot/types/types'; import interbtc from '@interlay/interbtc-types'; -import { combineLatest, map } from 'rxjs'; +import { combineLatest, from, map, Observable } from 'rxjs'; import { DeriveBalancesAll } from '@polkadot/api-derive/types'; import { memo } from '@polkadot/api-derive/util'; import { TypeRegistry, U128 } from '@polkadot/types'; +import { AnyTuple } from '@polkadot/types-codec/types'; import { BN, formatBalance } from '@polkadot/util'; function balanceOf (number: number | string): U128 { @@ -45,6 +45,8 @@ export function getBalance ( map(([data]: [any]): DeriveBalancesAll => { return { ...defaultAccountBalance(), + accountId: api.registry.createType('AccountId', account), + availableBalance: data.free, freeBalance: data.free, lockedBalance: data.frozen, reservedBalance: data.reserved @@ -54,10 +56,26 @@ export function getBalance ( ); } +export function transferBalance ( + instanceId: string, + api: ApiInterfaceRx +): Observable> { + const nativeToken = api.registry.chainTokens[0] || formatBalance.getDefaults().unit; + + return memo( + instanceId, + (account: string, amount: number) => + api.tx.tokens.transfer(account, { Token: nativeToken }, amount) + ); +} + const definitions: OverrideBundleDefinition = { derives: { balances: { - all: getBalance + all: getBalance, + transfer: transferBalance, + transferAll: transferBalance, + transferKeepAlive: transferBalance } }, diff --git a/packages/page-accounts/src/Accounts/Account.tsx b/packages/page-accounts/src/Accounts/Account.tsx index 30fce8563479..2a8457f1fb8b 100644 --- a/packages/page-accounts/src/Accounts/Account.tsx +++ b/packages/page-accounts/src/Accounts/Account.tsx @@ -653,11 +653,11 @@ function Account ({ account: { address, meta }, className = '', delegation, filt isLogo type='address' /> - {isFunction(api.api.tx.balances?.transfer) && ( + {isFunction(api.api.tx.balances?.transfer) || isFunction(api.api.derive.balances?.transfer) && (