diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw')
5 files changed, 48 insertions, 84 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts index d777489ab..2d9aaf828 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts @@ -26,7 +26,6 @@ import { useComponentStateFromURI, } from "./state.js"; import { - CompletedView, LoadingExchangeView, LoadingInfoView, LoadingUriView, @@ -36,11 +35,13 @@ import { export interface PropsFromURI { talerWithdrawUri: string | undefined; cancel: () => Promise<void>; + onSuccess: (txid: string) => Promise<void>; } export interface PropsFromParams { amount: string; cancel: () => Promise<void>; + onSuccess: (txid: string) => Promise<void>; } export type State = @@ -48,8 +49,7 @@ export type State = | State.LoadingUriError | State.LoadingExchangeError | State.LoadingInfoError - | State.Success - | State.Completed; + | State.Success; export namespace State { export interface Loading { @@ -69,11 +69,6 @@ export namespace State { error: HookError; } - export type Completed = { - status: "completed"; - error: undefined; - }; - export type Success = { status: "success"; error: undefined; @@ -100,7 +95,6 @@ const viewMapping: StateViewMap<State> = { "loading-uri": LoadingUriView, "loading-exchange": LoadingExchangeView, "loading-info": LoadingInfoView, - completed: CompletedView, success: SuccessView, }; diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts index 0b174d34c..fca69a669 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -23,7 +23,7 @@ import * as wxApi from "../../wxApi.js"; import { PropsFromURI, PropsFromParams, State } from "./index.js"; export function useComponentStateFromParams( - { amount, cancel }: PropsFromParams, + { amount, cancel, onSuccess }: PropsFromParams, api: typeof wxApi, ): State { const [ageRestricted, setAgeRestricted] = useState(0); @@ -40,8 +40,8 @@ export function useComponentStateFromParams( // get the first exchange with the currency as the default one const exchange = exchangeHookDep ? exchangeHookDep.exchanges.find( - (e) => e.currency === chosenAmount.currency, - ) + (e) => e.currency === chosenAmount.currency, + ) : undefined; /** * For the exchange selected, bring the status of the terms of service @@ -90,7 +90,6 @@ export function useComponentStateFromParams( undefined, ); const [doingWithdraw, setDoingWithdraw] = useState<boolean>(false); - const [withdrawCompleted, setWithdrawCompleted] = useState<boolean>(false); if (!exchangeHook) return { status: "loading", error: undefined }; if (exchangeHook.hasError) { @@ -122,7 +121,7 @@ export function useComponentStateFromParams( Amounts.stringify(amount), ); - setWithdrawCompleted(true); + onSuccess(response.transactionId); } catch (e) { if (e instanceof TalerError) { setWithdrawError(e); @@ -143,9 +142,6 @@ export function useComponentStateFromParams( if (!amountHook.response) { return { status: "loading", error: undefined }; } - if (withdrawCompleted) { - return { status: "completed", error: undefined }; - } const withdrawalFee = Amounts.sub( amountHook.response.amount.raw, @@ -156,8 +152,8 @@ export function useComponentStateFromParams( const { state: termsState } = (!terms ? undefined : terms.hasError - ? undefined - : terms.response) || { state: undefined }; + ? undefined + : terms.response) || { state: undefined }; async function onAccept(accepted: boolean): Promise<void> { if (!termsState || !exchange) return; @@ -194,10 +190,10 @@ export function useComponentStateFromParams( //TODO: calculate based on exchange info const ageRestriction = ageRestrictionEnabled ? { - list: ageRestrictionOptions, - value: String(ageRestricted), - onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)), - } + list: ageRestrictionOptions, + value: String(ageRestricted), + onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)), + } : undefined; return { @@ -218,19 +214,19 @@ export function useComponentStateFromParams( tosProps: !termsState ? undefined : { - onAccept, - onReview: setReviewing, - reviewed: reviewed, - reviewing: reviewing, - terms: termsState, - }, + onAccept, + onReview: setReviewing, + reviewed: reviewed, + reviewing: reviewing, + terms: termsState, + }, mustAcceptFirst, cancel, }; } export function useComponentStateFromURI( - { talerWithdrawUri, cancel }: PropsFromURI, + { talerWithdrawUri, cancel, onSuccess }: PropsFromURI, api: typeof wxApi, ): State { const [ageRestricted, setAgeRestricted] = useState(0); @@ -303,7 +299,6 @@ export function useComponentStateFromURI( undefined, ); const [doingWithdraw, setDoingWithdraw] = useState<boolean>(false); - const [withdrawCompleted, setWithdrawCompleted] = useState<boolean>(false); if (!uriInfoHook) return { status: "loading", error: undefined }; if (uriInfoHook.hasError) { @@ -343,8 +338,10 @@ export function useComponentStateFromURI( ); if (res.confirmTransferUrl) { document.location.href = res.confirmTransferUrl; + } else { + onSuccess(res.transactionId) } - setWithdrawCompleted(true); + } catch (e) { if (e instanceof TalerError) { setWithdrawError(e); @@ -365,9 +362,6 @@ export function useComponentStateFromURI( if (!amountHook.response) { return { status: "loading", error: undefined }; } - if (withdrawCompleted) { - return { status: "completed", error: undefined }; - } const withdrawalFee = Amounts.sub( amountHook.response.amount.raw, @@ -378,8 +372,8 @@ export function useComponentStateFromURI( const { state: termsState } = (!terms ? undefined : terms.hasError - ? undefined - : terms.response) || { state: undefined }; + ? undefined + : terms.response) || { state: undefined }; async function onAccept(accepted: boolean): Promise<void> { if (!termsState || !thisExchange) return; @@ -416,10 +410,10 @@ export function useComponentStateFromURI( //TODO: calculate based on exchange info const ageRestriction = ageRestrictionEnabled ? { - list: ageRestrictionOptions, - value: String(ageRestricted), - onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)), - } + list: ageRestrictionOptions, + value: String(ageRestricted), + onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)), + } : undefined; return { @@ -441,12 +435,12 @@ export function useComponentStateFromURI( tosProps: !termsState ? undefined : { - onAccept, - onReview: setReviewing, - reviewed: reviewed, - reviewing: reviewing, - terms: termsState, - }, + onAccept, + onReview: setReviewing, + reviewed: reviewed, + reviewing: reviewing, + terms: termsState, + }, mustAcceptFirst, cancel, }; diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/stories.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw/stories.tsx index 9c4faaf4a..2be4437cc 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/stories.tsx @@ -21,7 +21,7 @@ import { createExample } from "../../test-utils.js"; import { TermsState } from "../../utils/index.js"; -import { CompletedView, SuccessView } from "./views.js"; +import { SuccessView } from "./views.js"; export default { title: "cta/withdraw", @@ -179,11 +179,6 @@ export const EditExchangeModified = createExample(SuccessView, { tosProps: normalTosState, }); -export const CompletedWithoutBankURL = createExample(CompletedView, { - status: "completed", - error: undefined, -}); - export const WithAgeRestriction = createExample(SuccessView, { error: undefined, status: "success", diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts index 3a49f2a71..a0c24a6bb 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts @@ -68,6 +68,7 @@ describe("Withdraw CTA states", () => { cancel: async () => { null; }, + onSuccess: async () => { null }, }, { listExchanges: async () => ({ exchanges }), @@ -108,6 +109,7 @@ describe("Withdraw CTA states", () => { cancel: async () => { null; }, + onSuccess: async () => { null }, }, { listExchanges: async () => ({ exchanges }), @@ -150,6 +152,7 @@ describe("Withdraw CTA states", () => { cancel: async () => { null; }, + onSuccess: async () => { null }, }, { listExchanges: async () => ({ exchanges }), @@ -160,10 +163,10 @@ describe("Withdraw CTA states", () => { }), getExchangeWithdrawalInfo: async (): Promise<ExchangeWithdrawDetails> => - ({ - withdrawalAmountRaw: "ARS:2", - withdrawalAmountEffective: "ARS:2", - } as any), + ({ + withdrawalAmountRaw: "ARS:2", + withdrawalAmountEffective: "ARS:2", + } as any), getExchangeTos: async (): Promise<GetExchangeTosResult> => ({ contentType: "text", content: "just accept", @@ -224,6 +227,7 @@ describe("Withdraw CTA states", () => { cancel: async () => { null; }, + onSuccess: async () => { null }, }, { listExchanges: async () => ({ exchanges }), @@ -234,10 +238,10 @@ describe("Withdraw CTA states", () => { }), getExchangeWithdrawalInfo: async (): Promise<ExchangeWithdrawDetails> => - ({ - withdrawalAmountRaw: "ARS:2", - withdrawalAmountEffective: "ARS:2", - } as any), + ({ + withdrawalAmountRaw: "ARS:2", + withdrawalAmountEffective: "ARS:2", + } as any), getExchangeTos: async (): Promise<GetExchangeTosResult> => ({ contentType: "text", content: "just accept", diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx index 440586343..60157d289 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx @@ -76,29 +76,6 @@ export function LoadingInfoView({ error }: State.LoadingInfoError): VNode { ); } -export function CompletedView(state: State.Completed): VNode { - const { i18n } = useTranslationContext(); - return ( - <WalletAction> - <LogoHeader /> - <SubTitle> - <i18n.Translate>Digital cash withdrawal</i18n.Translate> - </SubTitle> - <SuccessBox> - <h3> - <i18n.Translate>Withdrawal in process...</i18n.Translate> - </h3> - <p> - <i18n.Translate> - You can close the page now. Check your bank if the transaction need - a confirmation step to be completed - </i18n.Translate> - </p> - </SuccessBox> - </WalletAction> - ); -} - export function SuccessView(state: State.Success): VNode { const { i18n } = useTranslationContext(); return ( |