summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-09-16 16:03:58 -0300
committerSebastian <sebasjm@gmail.com>2022-09-16 16:03:58 -0300
commit59d235e8d29159bc8caccf8bee6a2bca8b0b90dc (patch)
tree551261c860b1989dc0b1a05ddcfd53d20e561626 /packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts
parent6ddb2de84245ae3914c92b2b2eb7399e7f04500e (diff)
downloadwallet-core-59d235e8d29159bc8caccf8bee6a2bca8b0b90dc.tar.gz
wallet-core-59d235e8d29159bc8caccf8bee6a2bca8b0b90dc.tar.bz2
wallet-core-59d235e8d29159bc8caccf8bee6a2bca8b0b90dc.zip
redirect after success #7357
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts')
-rw-r--r--packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts29
1 files changed, 5 insertions, 24 deletions
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,