diff options
author | Sebastian <sebasjm@gmail.com> | 2022-09-16 16:03:58 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-09-16 16:03:58 -0300 |
commit | 59d235e8d29159bc8caccf8bee6a2bca8b0b90dc (patch) | |
tree | 551261c860b1989dc0b1a05ddcfd53d20e561626 /packages/taler-wallet-webextension/src/cta/Refund | |
parent | 6ddb2de84245ae3914c92b2b2eb7399e7f04500e (diff) | |
download | wallet-core-59d235e8d29159bc8caccf8bee6a2bca8b0b90dc.tar.xz |
redirect after success #7357
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Refund')
5 files changed, 57 insertions, 100 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Refund/index.ts b/packages/taler-wallet-webextension/src/cta/Refund/index.ts index f513ee3b7..be9e3499b 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/index.ts @@ -22,7 +22,6 @@ import { compose, StateViewMap } from "../../utils/index.js"; import * as wxApi from "../../wxApi.js"; import { useComponentState } from "./state.js"; import { - CompletedView, IgnoredView, InProgressView, LoadingUriView, @@ -32,6 +31,7 @@ import { export interface Props { talerRefundUri?: string; cancel: () => Promise<void>; + onSuccess: (tx: string) => Promise<void>; } export type State = @@ -39,8 +39,7 @@ export type State = | State.LoadingUriError | State.Ready | State.Ignored - | State.InProgress - | State.Completed; + | State.InProgress; export namespace State { export interface Loading { @@ -79,17 +78,12 @@ export namespace State { status: "in-progress"; error: undefined; } - export interface Completed extends BaseInfo { - status: "completed"; - error: undefined; - } } const viewMapping: StateViewMap<State> = { loading: Loading, "loading-uri": LoadingUriView, "in-progress": InProgressView, - completed: CompletedView, ignored: IgnoredView, ready: ReadyView, }; diff --git a/packages/taler-wallet-webextension/src/cta/Refund/state.ts b/packages/taler-wallet-webextension/src/cta/Refund/state.ts index 8d36b61ea..16dbbf70d 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/state.ts @@ -21,7 +21,7 @@ import * as wxApi from "../../wxApi.js"; import { Props, State } from "./index.js"; export function useComponentState( - { talerRefundUri, cancel }: Props, + { talerRefundUri, cancel, onSuccess }: Props, api: typeof wxApi, ): State { const [ignored, setIgnored] = useState(false); @@ -51,8 +51,9 @@ export function useComponentState( const { refund, uri } = info.response; const doAccept = async (): Promise<void> => { - await api.applyRefund(uri); - info.retry(); + const res = await api.applyRefund(uri); + + onSuccess(res.transactionId); }; const doIgnore = async (): Promise<void> => { @@ -75,13 +76,6 @@ export function useComponentState( }; } - if (Amounts.isZero(baseInfo.awaitingAmount)) { - return { - status: "completed", - ...baseInfo, - }; - } - if (refund.pending) { return { status: "in-progress", diff --git a/packages/taler-wallet-webextension/src/cta/Refund/stories.tsx b/packages/taler-wallet-webextension/src/cta/Refund/stories.tsx index d3a2302d9..d74120dff 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/Refund/stories.tsx @@ -23,7 +23,6 @@ import { Amounts } from "@gnu-taler/taler-util"; import beer from "../../../static-dev/beer.png"; import { createExample } from "../../test-utils.js"; import { - CompletedView, IgnoredView, InProgressView, ReadyView, @@ -32,15 +31,6 @@ export default { title: "cta/refund", }; -export const Complete = createExample(CompletedView, { - status: "completed", - amount: Amounts.parseOrThrow("USD:1"), - granted: Amounts.parseOrThrow("USD:1"), - error: undefined, - merchantName: "the merchant", - products: undefined, -}); - export const InProgress = createExample(InProgressView, { status: "in-progress", error: undefined, diff --git a/packages/taler-wallet-webextension/src/cta/Refund/test.ts b/packages/taler-wallet-webextension/src/cta/Refund/test.ts index 04d3e0d5f..09470b7f6 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/test.ts @@ -40,6 +40,7 @@ describe("Refund CTA states", () => { cancel: async () => { null; }, + onSuccess: async () => { null; }, }, { prepareRefund: async () => ({}), @@ -79,25 +80,26 @@ describe("Refund CTA states", () => { cancel: async () => { null; }, + onSuccess: async () => { null; }, }, { prepareRefund: async () => - ({ - effectivePaid: "EUR:2", - awaiting: "EUR:2", - gone: "EUR:0", - granted: "EUR:0", - pending: false, - proposalId: "1", - info: { - contractTermsHash: "123", - merchant: { - name: "the merchant name", - }, - orderId: "orderId1", - summary: "the summary", + ({ + effectivePaid: "EUR:2", + awaiting: "EUR:2", + gone: "EUR:0", + granted: "EUR:0", + pending: false, + proposalId: "1", + info: { + contractTermsHash: "123", + merchant: { + name: "the merchant name", }, - } as PrepareRefundResult as any), + orderId: "orderId1", + summary: "the summary", + }, + } as PrepareRefundResult as any), applyRefund: async () => ({}), onUpdateNotification: async () => ({}), } as any, @@ -136,25 +138,26 @@ describe("Refund CTA states", () => { cancel: async () => { null; }, + onSuccess: async () => { null; }, }, { prepareRefund: async () => - ({ - effectivePaid: "EUR:2", - awaiting: "EUR:2", - gone: "EUR:0", - granted: "EUR:0", - pending: false, - proposalId: "1", - info: { - contractTermsHash: "123", - merchant: { - name: "the merchant name", - }, - orderId: "orderId1", - summary: "the summary", + ({ + effectivePaid: "EUR:2", + awaiting: "EUR:2", + gone: "EUR:0", + granted: "EUR:0", + pending: false, + proposalId: "1", + info: { + contractTermsHash: "123", + merchant: { + name: "the merchant name", }, - } as PrepareRefundResult as any), + orderId: "orderId1", + summary: "the summary", + }, + } as PrepareRefundResult as any), applyRefund: async () => ({}), onUpdateNotification: async () => ({}), } as any, @@ -220,25 +223,27 @@ describe("Refund CTA states", () => { cancel: async () => { null; }, + onSuccess: async () => { null; }, + }, { prepareRefund: async () => - ({ - awaiting: Amounts.stringify(awaiting), - effectivePaid: "EUR:2", - gone: "EUR:0", - granted: Amounts.stringify(granted), - pending, - proposalId: "1", - info: { - contractTermsHash: "123", - merchant: { - name: "the merchant name", - }, - orderId: "orderId1", - summary: "the summary", + ({ + awaiting: Amounts.stringify(awaiting), + effectivePaid: "EUR:2", + gone: "EUR:0", + granted: Amounts.stringify(granted), + pending, + proposalId: "1", + info: { + contractTermsHash: "123", + merchant: { + name: "the merchant name", }, - } as PrepareRefundResult as any), + orderId: "orderId1", + summary: "the summary", + }, + } as PrepareRefundResult as any), applyRefund: async () => ({}), onUpdateNotification: subscriptions.saveSubscription, } as any, @@ -286,7 +291,7 @@ describe("Refund CTA states", () => { { const state = getLastResultOrThrow(); - if (state.status !== "completed") expect.fail("3"); + if (state.status !== "ready") expect.fail("3"); if (state.error) expect.fail(); expect(state.merchantName).eq("the merchant name"); expect(state.products).undefined; diff --git a/packages/taler-wallet-webextension/src/cta/Refund/views.tsx b/packages/taler-wallet-webextension/src/cta/Refund/views.tsx index d8c67334c..4b5ff70dd 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Refund/views.tsx @@ -92,32 +92,6 @@ export function InProgressView(state: State.InProgress): VNode { </WalletAction> ); } -export function CompletedView(state: State.Completed): VNode { - const { i18n } = useTranslationContext(); - - return ( - <WalletAction> - <LogoHeader /> - - <SubTitle> - <i18n.Translate>Digital cash refund</i18n.Translate> - </SubTitle> - <section> - <p> - <i18n.Translate>this refund is already accepted.</i18n.Translate> - </p> - </section> - <section> - <Part - big - title={<i18n.Translate>Total to refunded</i18n.Translate>} - text={<Amount value={state.granted} />} - kind="negative" - /> - </section> - </WalletAction> - ); -} export function ReadyView(state: State.Ready): VNode { const { i18n } = useTranslationContext(); return ( |