aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-01-20 15:41:08 -0300
committerSebastian <sebasjm@gmail.com>2023-01-20 15:41:55 -0300
commit7ea8321ddd2d56f43dceaa18340f1d1c39a83e76 (patch)
tree9873eeb8fa836778d9c7fce1c6a778e7e8b6acaf /packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts
parent81dda3b6b1500ed11b6ae539ce52a6c7e9a58951 (diff)
downloadwallet-core-7ea8321ddd2d56f43dceaa18340f1d1c39a83e76.tar.xz
introducing getBalanceDetail for getting all depositable/transferable amount for a currency
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts')
-rw-r--r--packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts20
1 files changed, 20 insertions, 0 deletions
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<State> {
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<State> {
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<State> {
setAmount(undefined);
}),
},
+ sendAll: {},
goToBank: {
onClick: invalid
? undefined