taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 75209143aace1fb78caedee35bcabf7eee8814c8
parent 1f8fccb0a2eacb28cfcc957c5b384d882cb2f523
Author: Sebastian <sebasjm@gmail.com>
Date:   Fri, 14 Feb 2025 14:23:34 -0300

fix #9537

Diffstat:
Mpackages/taler-wallet-webextension/src/cta/Withdraw/state.ts | 77+++++++++++------------------------------------------------------------------
1 file changed, 11 insertions(+), 66 deletions(-)

diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -21,6 +21,7 @@ import { ExchangeFullDetails, ExchangeListItem, NotificationType, + ScopeType, TransactionMajorState, TransactionMinorState, parseWithdrawExchangeUri, @@ -54,17 +55,21 @@ export function useComponentStateFromParams({ const uri = maybeTalerUri ? parseWithdrawExchangeUri(maybeTalerUri) : undefined; - const exchangeByTalerUri = updatedExchangeByUser ?? uri?.exchangeBaseUrl; + + const exchangeUrlByScope = + scope?.type === ScopeType.Exchange ? scope.url : undefined; + const exchangeByScopeOrTalerUri = + updatedExchangeByUser ?? exchangeUrlByScope ?? uri?.exchangeBaseUrl; let ex: ExchangeFullDetails | undefined; - if (exchangeByTalerUri) { + if (exchangeByScopeOrTalerUri) { await api.wallet.call(WalletApiOperation.AddExchange, { - exchangeBaseUrl: exchangeByTalerUri, + exchangeBaseUrl: exchangeByScopeOrTalerUri, }); const info = await api.wallet.call( WalletApiOperation.GetExchangeDetailedInfo, { - exchangeBaseUrl: exchangeByTalerUri, + exchangeBaseUrl: exchangeByScopeOrTalerUri, }, ); @@ -92,9 +97,8 @@ export function useComponentStateFromParams({ }; } - const currency = uriInfoHook.response.exchange?.currency ?? scope?.currency; - const exchangeByTalerUri = uriInfoHook.response.exchange?.exchangeBaseUrl; + const exchangeByUrl = uriInfoHook.response.exchange?.exchangeBaseUrl; const exchangeList = uriInfoHook.response.exchanges.exchanges; const maybeAmount = uriInfoHook.response.amount ?? paramsAmount; @@ -109,65 +113,6 @@ export function useComponentStateFromParams({ }; } - // if (!maybeAmount) { - // const exchangeBaseUrl = - // uriInfoHook.response.exchange?.exchangeBaseUrl ?? - // (exchangeList.length > 0 ? exchangeList[0].exchangeBaseUrl : undefined); - // const currency = - // uriInfoHook.response.exchange?.currency ?? - // (exchangeList.length > 0 ? exchangeList[0].currency : undefined); - - // if (!exchangeBaseUrl) { - // return { - // status: "error", - // error: { - // message: i18n.str`Can't withdraw from exchange`, - // description: i18n.str`Missing base URL`, - // cause: undefined, - // context: {}, - // type: "error", - // }, - // }; - // } - // if (!currency) { - // return { - // status: "error", - // error: { - // message: i18n.str`Can't withdraw from exchange`, - // description: i18n.str`Missing unknown currency`, - // cause: undefined, - // context: {}, - // type: "error", - // }, - // }; - // } - // return () => { - // const { pushAlertOnError } = useAlertContext(); - // const [amount, setAmount] = useState<AmountJson>( - // Amounts.zeroOfCurrency(currency), - // ); - // const isValid = Amounts.isNonZero(amount); - // return { - // status: "select-amount", - // currency, - // exchangeBaseUrl, - // error: undefined, - // confirm: { - // onClick: isValid - // ? pushAlertOnError(async () => { - // onAmountChanged(Amounts.stringify(amount)); - // }) - // : undefined, - // }, - // amount: { - // value: amount, - // onInput: pushAlertOnError(async (e) => { - // setAmount(e); - // }), - // }, - // }; - // }; - // } const chosenAmount = maybeAmount ?? Amounts.zeroOfCurrency(currency); async function doManualWithdraw( @@ -205,7 +150,7 @@ export function useComponentStateFromParams({ bankFee: Amounts.zeroOfCurrency(chosenAmount.currency), editableAmount: true, editableExchange: true, - exchange: exchangeByTalerUri, + exchange: exchangeByUrl, exchangeList: exchangeList, }, setUpdatedExchangeByUser,