aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw/index.ts21
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw/state.ts31
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx9
3 files changed, 53 insertions, 8 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts
index 45c37ba5c..ae4b3c436 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts
@@ -16,20 +16,19 @@
import { AmountJson, ExchangeListItem } from "@gnu-taler/taler-util";
import { Loading } from "../../components/Loading.js";
-import { HookError } from "../../hooks/useAsyncAsHook.js";
import { State as SelectExchangeState } from "../../hooks/useSelectedExchange.js";
import { ButtonHandler, SelectFieldHandler } from "../../mui/handlers.js";
-import { compose, StateViewMap } from "../../utils/index.js";
+import { StateViewMap, compose } from "../../utils/index.js";
import {
useComponentStateFromParams,
useComponentStateFromURI,
} from "./state.js";
+import { ErrorAlertView } from "../../components/CurrentAlerts.js";
+import { ErrorAlert } from "../../context/alert.js";
import { ExchangeSelectionPage } from "../../wallet/ExchangeSelection/index.js";
import { NoExchangesView } from "../../wallet/ExchangeSelection/views.js";
-import { SuccessView } from "./views.js";
-import { ErrorAlert } from "../../context/alert.js";
-import { ErrorAlertView } from "../../components/CurrentAlerts.js";
+import { SelectAmountView, SuccessView } from "./views.js";
export interface PropsFromURI {
talerWithdrawUri: string | undefined;
@@ -38,6 +37,7 @@ export interface PropsFromURI {
}
export interface PropsFromParams {
+ talerExchangeWithdrawUri: string;
amount: string;
cancel: () => Promise<void>;
onSuccess: (txid: string) => Promise<void>;
@@ -48,6 +48,7 @@ export type State =
| State.LoadingUriError
| SelectExchangeState.NoExchangeFound
| SelectExchangeState.Selecting
+ | State.SelectAmount
| State.Success;
export namespace State {
@@ -60,6 +61,13 @@ export namespace State {
error: ErrorAlert;
}
+ export interface SelectAmount {
+ status: "select-amount";
+ error: undefined;
+ currentExchange: ExchangeListItem;
+ currency: string;
+ }
+
export type Success = {
status: "success";
error: undefined;
@@ -84,13 +92,14 @@ export namespace State {
const viewMapping: StateViewMap<State> = {
loading: Loading,
error: ErrorAlertView,
+ "select-amount": SelectAmountView,
"no-exchange-found": NoExchangesView,
"selecting-exchange": ExchangeSelectionPage,
success: SuccessView,
};
export const WithdrawPageFromURI = compose(
- "WithdrawPageFromURI",
+ "WithdrawPageFromURI_Withdraw",
(p: PropsFromURI) => useComponentStateFromURI(p),
viewMapping,
);
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,
);
}
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx
index 50bf99a0c..57d6238b2 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx
@@ -142,3 +142,12 @@ function WithdrawWithMobile({
</section>
);
}
+
+export function SelectAmountView({ currency }: State.SelectAmount): VNode {
+ const { i18n } = useTranslationContext();
+ return (
+ <Fragment>
+ <p>select the amount for ${currency}</p>
+ </Fragment>
+ );
+}