taler-typescript-core

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

commit be43e472fe6b2022bcc9878ef6f11045f61ad053
parent 6d8125c4eedccf37f43cd45aa15f81bc52b7cf50
Author: Sebastian <sebasjm@gmail.com>
Date:   Mon, 12 Aug 2024 09:23:46 -0300

no select amount in withdrawal since there is an amount input now

Diffstat:
Mpackages/taler-wallet-webextension/src/cta/Withdraw/index.ts | 26+++++++++++++-------------
Mpackages/taler-wallet-webextension/src/cta/Withdraw/state.ts | 122++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mpackages/taler-wallet-webextension/src/cta/Withdraw/views.tsx | 41-----------------------------------------
Mpackages/taler-wallet-webextension/src/wallet/Application.tsx | 8+-------
4 files changed, 75 insertions(+), 122 deletions(-)

diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts @@ -16,9 +16,9 @@ import { AmountJson, - AmountString, CurrencySpecification, ExchangeListItem, + ScopeInfo } from "@gnu-taler/taler-util"; import { Loading } from "../../components/Loading.js"; import { State as SelectExchangeState } from "../../hooks/useSelectedExchange.js"; @@ -37,7 +37,7 @@ 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 { FinalStateOperation, SelectAmountView, SuccessView } from "./views.js"; +import { FinalStateOperation, SuccessView } from "./views.js"; export interface PropsFromURI { talerWithdrawUri: string | undefined; @@ -47,10 +47,10 @@ export interface PropsFromURI { export interface PropsFromParams { talerExchangeWithdrawUri: string | undefined; + scope: ScopeInfo; amount: string | undefined; cancel: () => Promise<void>; onSuccess: (txid: string) => Promise<void>; - onAmountChanged: (amount: AmountString) => Promise<void>; } export type State = @@ -58,7 +58,7 @@ export type State = | State.LoadingUriError | SelectExchangeState.NoExchangeFound | SelectExchangeState.Selecting - | State.SelectAmount + // | State.SelectAmount | State.AlreadyCompleted | State.Success; @@ -72,14 +72,14 @@ export namespace State { error: ErrorAlert; } - export interface SelectAmount { - status: "select-amount"; - error: undefined; - exchangeBaseUrl: string; - confirm: ButtonHandler; - amount: AmountFieldHandler; - currency: string; - } + // export interface SelectAmount { + // status: "select-amount"; + // error: undefined; + // exchangeBaseUrl: string; + // confirm: ButtonHandler; + // amount: AmountFieldHandler; + // currency: string; + // } export interface AlreadyCompleted { status: "already-completed"; operationState: "confirmed" | "aborted" | "selected"; @@ -126,7 +126,7 @@ export namespace State { const viewMapping: StateViewMap<State> = { loading: Loading, error: ErrorAlertView, - "select-amount": SelectAmountView, + // "select-amount": SelectAmountView, "no-exchange-found": NoExchangesView, "selecting-exchange": ExchangeSelectionPage, success: SuccessView, diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -38,8 +38,8 @@ import { PropsFromParams, PropsFromURI, State } from "./index.js"; export function useComponentStateFromParams({ talerExchangeWithdrawUri: maybeTalerUri, amount, + scope, cancel, - onAmountChanged, onSuccess, }: PropsFromParams): RecursiveState<State> { const api = useBackendContext(); @@ -97,66 +97,66 @@ export function useComponentStateFromParams({ const maybeAmount = uriInfoHook.response.amount ?? paramsAmount; - 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; + // 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(scope.currency); async function doManualWithdraw( exchange: string, diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx @@ -280,44 +280,3 @@ function WithdrawWithMobile({ ); } -export function SelectAmountView({ - amount, - exchangeBaseUrl, - confirm, -}: State.SelectAmount): VNode { - const { i18n } = useTranslationContext(); - return ( - <Fragment> - <section style={{ textAlign: "left" }}> - <Part - title={ - <div - style={{ - display: "flex", - alignItems: "center", - }} - > - <i18n.Translate>Exchange</i18n.Translate> - </div> - } - text={<ExchangeDetails exchange={exchangeBaseUrl} />} - kind="neutral" - big - /> - <Grid container columns={2} justifyContent="space-between"> - <AmountField label={i18n.str`Amount`} required handler={amount} /> - </Grid> - </section> - <section> - <Button - variant="contained" - color="info" - disabled={!confirm.onClick} - onClick={confirm.onClick} - > - <i18n.Translate>See details</i18n.Translate> - </Button> - </section> - </Fragment> - ); -} diff --git a/packages/taler-wallet-webextension/src/wallet/Application.tsx b/packages/taler-wallet-webextension/src/wallet/Application.tsx @@ -584,13 +584,7 @@ export function Application(): VNode { return ( <CallToActionTemplate title={i18n.str`Digital cash withdrawal`}> <WithdrawPageFromParams - onAmountChanged={async (newamount) => { - const page = `${Pages.ctaWithdrawManual({ - scope: encodeCrockForURI(stringifyScopeInfoShort(s)), - amount: newamount, - })}?talerUri=${encodeCrockForURI(talerUri)}`; - redirectTo(page); - }} + scope={s} talerExchangeWithdrawUri={talerUri} amount={amount} cancel={() => redirectTo(Pages.balance)}