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/TransferCreate | |
parent | 6ddb2de84245ae3914c92b2b2eb7399e7f04500e (diff) | |
download | wallet-core-59d235e8d29159bc8caccf8bee6a2bca8b0b90dc.tar.xz |
redirect after success #7357
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/TransferCreate')
4 files changed, 7 insertions, 67 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts b/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts index 1794b837b..5097380f6 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts @@ -21,17 +21,17 @@ import { ButtonHandler, TextFieldHandler } from "../../mui/handlers.js"; import { compose, StateViewMap } from "../../utils/index.js"; import * as wxApi from "../../wxApi.js"; import { useComponentState } from "./state.js"; -import { LoadingUriView, ReadyView, CreatedView } from "./views.js"; +import { LoadingUriView, ReadyView } from "./views.js"; export interface Props { amount: string; onClose: () => Promise<void>; + onSuccess: (tx: string) => Promise<void>; } export type State = | State.Loading | State.LoadingUriError - | State.Created | State.Ready; export namespace State { @@ -49,11 +49,6 @@ export namespace State { error: undefined; cancel: ButtonHandler; } - export interface Created extends BaseInfo { - status: "created"; - talerUri: string; - copyToClipboard: ButtonHandler; - } export interface Ready extends BaseInfo { status: "ready"; invalid: boolean; @@ -69,7 +64,6 @@ export namespace State { const viewMapping: StateViewMap<State> = { loading: Loading, "loading-uri": LoadingUriView, - created: CreatedView, ready: ReadyView, }; diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts b/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts index e6397f2e9..03dfc8b18 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts @@ -21,34 +21,18 @@ import * as wxApi from "../../wxApi.js"; import { Props, State } from "./index.js"; export function useComponentState( - { amount: amountStr, onClose }: Props, + { amount: amountStr, onClose, onSuccess }: Props, api: typeof wxApi, ): State { const amount = Amounts.parseOrThrow(amountStr); const [subject, setSubject] = useState(""); - const [talerUri, setTalerUri] = useState(""); const [operationError, setOperationError] = useState< TalerErrorDetail | undefined >(undefined); - if (talerUri) { - return { - status: "created", - talerUri, - error: undefined, - cancel: { - onClick: onClose, - }, - copyToClipboard: { - onClick: async () => { - navigator.clipboard.writeText(talerUri); - }, - }, - }; - } - async function accept(): Promise<string> { + async function accept(): Promise<void> { try { const resp = await api.initiatePeerPushPayment({ amount: Amounts.stringify(amount), @@ -56,7 +40,7 @@ export function useComponentState( summary: subject, }, }); - return resp.talerUri; + onSuccess(resp.transactionId); } catch (e) { if (e instanceof TalerError) { setOperationError(e.errorDetail); @@ -77,10 +61,7 @@ export function useComponentState( onInput: async (e) => setSubject(e), }, create: { - onClick: async () => { - const uri = await accept(); - setTalerUri(uri); - }, + onClick: accept }, chosenAmount: amount, toBeReceived: amount, diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/stories.tsx b/packages/taler-wallet-webextension/src/cta/TransferCreate/stories.tsx index c6ce301a9..2746cc153 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/stories.tsx @@ -20,19 +20,12 @@ */ import { createExample } from "../../test-utils.js"; -import { ReadyView, CreatedView } from "./views.js"; +import { ReadyView } from "./views.js"; export default { title: "wallet/transfer create", }; -export const ShowQr = createExample(CreatedView, { - talerUri: - "taler://pay-push/exchange.taler.ar/HS585JK0QCXHJ8Z8QWZA3EBAY5WY7XNC1RR2MHJXSH2Z4WP0YPJ0", - cancel: {}, - copyToClipboard: {}, -}); - export const Ready = createExample(ReadyView, { chosenAmount: { currency: "ARS", diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/views.tsx b/packages/taler-wallet-webextension/src/cta/TransferCreate/views.tsx index 433980621..297ae4837 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/views.tsx @@ -38,34 +38,6 @@ export function LoadingUriView({ error }: State.LoadingUriError): VNode { ); } -export function CreatedView({ - talerUri, - copyToClipboard, - cancel, -}: State.Created): VNode { - const { i18n } = useTranslationContext(); - return ( - <WalletAction> - <LogoHeader /> - <SubTitle> - <i18n.Translate>Digital cash transfer</i18n.Translate> - </SubTitle> - <section> - <p>Show this QR to receive the transfer</p> - <QR text={talerUri} /> - </section> - <section> - or - <Button onClick={copyToClipboard.onClick}>Copy the transfer URI</Button> - </section> - <section> - <Link upperCased onClick={cancel.onClick}> - <i18n.Translate>Close</i18n.Translate> - </Link> - </section> - </WalletAction> - ); -} export function ReadyView({ subject, |