From 7ea8321ddd2d56f43dceaa18340f1d1c39a83e76 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 20 Jan 2023 15:41:08 -0300 Subject: introducing getBalanceDetail for getting all depositable/transferable amount for a currency --- .../src/wallet/DestinationSelection/state.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts') diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts index d5015ae1d..a921d32cb 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts @@ -27,10 +27,21 @@ import { Contact, Props, State } from "./index.js"; export function useComponentState(props: Props): RecursiveState { const api = useBackendContext(); const { pushAlertOnError } = useAlertContext(); + const parsedInitialAmount = !props.amount ? undefined : Amounts.parse(props.amount); + const hook = useAsyncAsHook(async () => { + if (!parsedInitialAmount) return undefined; + const resp = await api.wallet.call(WalletApiOperation.GetBalanceDetail, { + currency: parsedInitialAmount.currency, + }); + return resp; + }); + + const total = hook && !hook.hasError ? hook.response : undefined; + // const initialCurrency = parsedInitialAmount?.currency; const [amount, setAmount] = useState( @@ -120,6 +131,14 @@ export function useComponentState(props: Props): RecursiveState { props.goToWalletBankDeposit(currencyAndAmount); }), }, + sendAll: { + onClick: + total === undefined + ? undefined + : pushAlertOnError(async () => { + setAmount(total.balanceMerchantDepositable); + }), + }, goToWallet: { onClick: invalid ? undefined @@ -143,6 +162,7 @@ export function useComponentState(props: Props): RecursiveState { setAmount(undefined); }), }, + sendAll: {}, goToBank: { onClick: invalid ? undefined -- cgit v1.2.3