diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw/state.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/cta/Withdraw/state.ts | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts index 717d3ba6b..f19f32ec0 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -18,9 +18,12 @@ import { AmountJson, Amounts, + ExchangeFullDetails, ExchangeListItem, ExchangeTosStatus, TalerError, + parseWithdrawExchangeUri, + stringifyWithdrawUri, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useState } from "preact/hooks"; @@ -33,6 +36,7 @@ import { RecursiveState } from "../../utils/index.js"; import { PropsFromParams, PropsFromURI, State } from "./index.js"; export function useComponentStateFromParams({ + talerExchangeWithdrawUri: maybeTalerUri, amount, cancel, onSuccess, @@ -44,7 +48,29 @@ export function useComponentStateFromParams({ WalletApiOperation.ListExchanges, {}, ); - return { amount: Amounts.parseOrThrow(amount), exchanges }; + const uri = parseWithdrawExchangeUri(maybeTalerUri); + const exchangeByTalerUri = uri?.exchangeBaseUrl; + let ex: ExchangeFullDetails | undefined; + if (exchangeByTalerUri && uri.exchangePub) { + await api.wallet.call(WalletApiOperation.AddExchange, { + exchangeBaseUrl: exchangeByTalerUri, + masterPub: uri.exchangePub, + }); + const info = await api.wallet.call( + WalletApiOperation.GetExchangeDetailedInfo, + { + exchangeBaseUrl: exchangeByTalerUri, + }, + ); + + ex = info.exchange; + } + const chosenAmount = uri + ? uri.amount + ? Amounts.parseOrThrow(uri.amount) + : Amounts.parseOrThrow(`${ex ? ex.currency : "KUDOS"}:66`) + : Amounts.parseOrThrow(amount); + return { amount: chosenAmount, exchanges, exchange: ex }; }); if (!uriInfoHook) return { status: "loading", error: undefined }; @@ -60,6 +86,7 @@ export function useComponentStateFromParams({ } const chosenAmount = uriInfoHook.response.amount; + const exchangeByTalerUri = uriInfoHook.response.exchange?.exchangeBaseUrl; const exchangeList = uriInfoHook.response.exchanges.exchanges; async function doManualWithdraw( @@ -92,7 +119,7 @@ export function useComponentStateFromParams({ undefined, chosenAmount, exchangeList, - undefined, + exchangeByTalerUri, ); } |