diff options
author | Sebastian <sebasjm@gmail.com> | 2023-12-01 10:09:38 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-12-01 10:09:54 -0300 |
commit | 1e5abb5b2aa9545e194f6db879e7480162f6d481 (patch) | |
tree | d5e31d4cfe595aeb20c6e0dce2719e2a5ebc352c /packages/taler-wallet-webextension/src/cta/Withdraw/state.ts | |
parent | ce2e58962cb0a61725fe0fe3dd8535965f482b95 (diff) | |
download | wallet-core-1e5abb5b2aa9545e194f6db879e7480162f6d481.tar.xz |
exchange account info
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw/state.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/cta/Withdraw/state.ts | 23 |
1 files changed, 18 insertions, 5 deletions
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<string>(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<boolean>(false); - + async function doWithdrawAndCheckError(): Promise<void> { 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, |