summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-06-26 14:23:32 -0300
committerSebastian <sebasjm@gmail.com>2023-06-26 14:23:32 -0300
commit2779086a32a62d6d16b7813c2ca4944dc02c4d93 (patch)
tree25b367b09ca4d83375e4d24daa4402959d748b1c /packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
parent87fc6ebf48afc297ed1e2a0fd503a8401c0deb08 (diff)
downloadwallet-core-2779086a32a62d6d16b7813c2ca4944dc02c4d93.tar.gz
wallet-core-2779086a32a62d6d16b7813c2ca4944dc02c4d93.tar.bz2
wallet-core-2779086a32a62d6d16b7813c2ca4944dc02c4d93.zip
support for exchange-withdraw call to action, pending use case when the user need to specify the amount
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw/state.ts')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw/state.ts31
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,
);
}