diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/InvoiceCreate')
4 files changed, 8 insertions, 72 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts index fe0b0f5f7..f7d6fbe63 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts @@ -17,7 +17,7 @@ import { Loading } from "../../components/Loading.js"; import { HookError } from "../../hooks/useAsyncAsHook.js"; import { compose, StateViewMap } from "../../utils/index.js"; -import { LoadingUriView, ReadyView, CreatedView } from "./views.js"; +import { LoadingUriView, ReadyView } from "./views.js"; import * as wxApi from "../../wxApi.js"; import { useComponentState } from "./state.js"; import { AmountJson, TalerErrorDetail } from "@gnu-taler/taler-util"; @@ -26,12 +26,12 @@ import { ButtonHandler, TextFieldHandler } from "../../mui/handlers.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"; create: ButtonHandler; @@ -70,7 +65,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/InvoiceCreate/state.ts b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts index 8f57582d6..a338387de 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts @@ -22,13 +22,12 @@ 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 hook = useAsyncAsHook(api.listExchanges); const [exchangeIdx, setExchangeIdx] = useState("0"); @@ -49,22 +48,6 @@ export function useComponentState( }; } - if (talerUri) { - return { - status: "created", - talerUri, - error: undefined, - cancel: { - onClick: onClose, - }, - copyToClipboard: { - onClick: async () => { - navigator.clipboard.writeText(talerUri); - }, - }, - }; - } - const exchanges = hook.response.exchanges.filter( (e) => e.currency === amount.currency, ); @@ -74,7 +57,7 @@ export function useComponentState( ); const selected = exchanges[Number(exchangeIdx)]; - async function accept(): Promise<string> { + async function accept(): Promise<void> { try { const resp = await api.initiatePeerPullPayment({ amount: Amounts.stringify(amount), @@ -83,7 +66,8 @@ export function useComponentState( summary: subject, }, }); - return resp.talerUri; + + onSuccess(resp.transactionId); } catch (e) { if (e instanceof TalerError) { setOperationError(e.errorDetail); @@ -103,10 +87,7 @@ export function useComponentState( invalid: !subject || Amounts.isZero(amount), exchangeUrl: selected.exchangeBaseUrl, create: { - onClick: async () => { - const uri = await accept(); - setTalerUri(uri); - }, + onClick: accept }, cancel: { onClick: onClose, diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/stories.tsx b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/stories.tsx index 0adc29e78..b5a0a52e2 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/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/invoice create", }; -export const ShowQr = createExample(CreatedView, { - talerUri: - "taler://pay-pull/exchange.taler.ar/HS585JK0QCXHJ8Z8QWZA3EBAY5WY7XNC1RR2MHJXSH2Z4WP0YPJ0", - cancel: {}, - copyToClipboard: {}, -}); - export const Ready = createExample(ReadyView, { chosenAmount: { currency: "ARS", diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx index c5ed9a4cf..693c07713 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx @@ -45,38 +45,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 invoice</i18n.Translate> - </SubTitle> - <section> - <p> - <i18n.Translate>Show this QR to pay the invoice</i18n.Translate> - </p> - <QR text={talerUri} /> - </section> - <section> - or - <Button onClick={copyToClipboard.onClick}> - <i18n.Translate>Copy the invoice URI</i18n.Translate> - </Button> - </section> - <section> - <Link upperCased onClick={cancel.onClick}> - <i18n.Translate>Close</i18n.Translate> - </Link> - </section> - </WalletAction> - ); -} export function ReadyView({ invalid, |