From 1e5abb5b2aa9545e194f6db879e7480162f6d481 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 1 Dec 2023 10:09:38 -0300 Subject: exchange account info --- .../src/cta/Withdraw/state.ts | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw/state.ts') diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts index 46d221766..c10572d1a 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -297,7 +297,7 @@ function exchangeSelectionState( return selectedExchange; } - return () => { + return (): State.Success | State.LoadingUriError | State.Loading => { const { i18n } = useTranslationContext(); const { pushAlertOnError } = useAlertContext(); const [ageRestricted, setAgeRestricted] = useState(0); @@ -306,6 +306,7 @@ function exchangeSelectionState( currentExchange.tosStatus == ExchangeTosStatus.Pending || currentExchange.tosStatus == ExchangeTosStatus.Proposed; + const [selectedCurrency, setSelectedCurrency] = useState(chosenAmount.currency) /** * With the exchange and amount, ask the wallet the information * about the withdrawal @@ -324,7 +325,7 @@ function exchangeSelectionState( raw: Amounts.parseOrThrow(info.amountRaw), effective: Amounts.parseOrThrow(info.amountEffective), }; - + return { amount: withdrawAmount, ageRestrictionOptions: info.ageRestrictionOptions, @@ -336,7 +337,7 @@ function exchangeSelectionState( undefined, ); const [doingWithdraw, setDoingWithdraw] = useState(false); - + async function doWithdrawAndCheckError(): Promise { try { setDoingWithdraw(true); @@ -401,13 +402,26 @@ function exchangeSelectionState( } : undefined; + const altCurrencies = amountHook.response.accounts.filter(a => !!a.currencySpecification).map(a => a.currencySpecification!.name) + const chooseCurrencies = altCurrencies.length === 0 ? [] : [toBeReceived.currency, ...altCurrencies] + const convAccount = amountHook.response.accounts.find(c => { + return c.currencySpecification && c.currencySpecification.name === selectedCurrency + }) + const conversionInfo = !convAccount ? undefined : ({ + spec: convAccount.currencySpecification!, + amount: Amounts.parseOrThrow(convAccount.transferAmount!) + }) + return { status: "success", error: undefined, doSelectExchange: selectedExchange.doSelect, currentExchange, toBeReceived, - accounts: amountHook.response.accounts, + chooseCurrencies, + selectedCurrency, + changeCurrency: (s) => { setSelectedCurrency(s) }, + conversionInfo, withdrawalFee, chosenAmount, talerWithdrawUri, @@ -417,7 +431,6 @@ function exchangeSelectionState( doingWithdraw || tosNeedToBeAccepted ? undefined : pushAlertOnError(doWithdrawAndCheckError), - error: withdrawError, }, onTosUpdate, cancel, -- cgit v1.2.3