From 5a7269b20db0371535669c0faa7f1814d967b5ca Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 31 Aug 2019 11:49:36 +0200 Subject: cli refunds --- src/headless/taler-wallet-cli.ts | 14 +++++++++++ src/taleruri.ts | 53 ++++++++++++++++++++++++++++++++++++++++ src/wallet.ts | 17 +++++++++---- src/webex/pages/pay.tsx | 13 +++++----- src/webex/pages/refund.tsx | 8 ++++-- src/webex/pages/tip.tsx | 29 +++------------------- src/webex/renderHtml.tsx | 25 +++++++++++++++++++ src/webex/wxBackend.ts | 2 +- 8 files changed, 121 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts index 86eaec64c..bfa1ac4b9 100644 --- a/src/headless/taler-wallet-cli.ts +++ b/src/headless/taler-wallet-cli.ts @@ -179,6 +179,20 @@ program wallet.stop(); }); + + + program + .command("refund-uri ") + .action(async (refundUri, cmdObj) => { + applyVerbose(program.verbose); + console.log("getting refund", refundUri); + const wallet = await getDefaultNodeWallet({ + persistentStoragePath: walletDbPath, + }); + await wallet.applyRefund(refundUri); + wallet.stop(); + }); + program .command("pay-uri { const refundPermissions = refundResponse.refund_permissions; @@ -3149,8 +3149,7 @@ export class Wallet { .finish(); this.notifier.notify(); - // Start submitting it but don't wait for it here. - this.submitRefunds(hc); + await this.submitRefunds(hc); return hc; } @@ -3159,7 +3158,15 @@ export class Wallet { * Accept a refund, return the contract hash for the contract * that was involved in the refund. */ - async acceptRefund(refundUrl: string): Promise { + async applyRefund(talerRefundUri: string): Promise { + const parseResult = parseRefundUri(talerRefundUri); + + if (!parseResult) { + throw Error("invalid refund URI"); + } + + const refundUrl = parseResult.refundUrl; + Wallet.enableTracing && console.log("processing refund"); let resp; try { diff --git a/src/webex/pages/pay.tsx b/src/webex/pages/pay.tsx index d929426c4..1561dd95f 100644 --- a/src/webex/pages/pay.tsx +++ b/src/webex/pages/pay.tsx @@ -30,7 +30,7 @@ import { ExchangeRecord, ProposalDownloadRecord } from "../../dbTypes"; import { ContractTerms } from "../../talerTypes"; import { CheckPayResult, PreparePayResult } from "../../walletTypes"; -import { renderAmount } from "../renderHtml"; +import { renderAmount, ProgressButton } from "../renderHtml"; import * as wxApi from "../wxApi"; import React, { useState, useEffect } from "react"; @@ -44,6 +44,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) { const [payStatus, setPayStatus] = useState(); const [payErrMsg, setPayErrMsg] = useState(""); const [numTries, setNumTries] = useState(0); + const [loading, setLoading] = useState(false); let totalFees: Amounts.AmountJson | undefined = undefined; useEffect(() => { @@ -99,6 +100,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) { const doPayment = async () => { setNumTries(numTries + 1); try { + setLoading(true); const res = await wxApi.confirmPay(payStatus!.proposalId!, undefined); document.location.href = res.nextUrl; } catch (e) { @@ -140,12 +142,11 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) { ) : (
- +
)} diff --git a/src/webex/pages/refund.tsx b/src/webex/pages/refund.tsx index 6bc1a136e..57d740486 100644 --- a/src/webex/pages/refund.tsx +++ b/src/webex/pages/refund.tsx @@ -188,8 +188,12 @@ async function main() { return; } - const contractTermsHash = query.contractTermsHash; - const refundUrl = query.refundUrl; + const talerRefundUri = query.talerRefundUri; + if (!talerRefundUri) { + console.error("taler refund URI requred"); + return; + } + ReactDOM.render(, container); } diff --git a/src/webex/pages/tip.tsx b/src/webex/pages/tip.tsx index a3f5c38c3..0a066053b 100644 --- a/src/webex/pages/tip.tsx +++ b/src/webex/pages/tip.tsx @@ -29,35 +29,12 @@ import * as i18n from "../../i18n"; import { acceptTip, getReserveCreationInfo, getTipStatus } from "../wxApi"; -import { WithdrawDetailView, renderAmount } from "../renderHtml"; +import { WithdrawDetailView, renderAmount, ProgressButton } from "../renderHtml"; import * as Amounts from "../../amounts"; import { useState, useEffect } from "react"; import { TipStatus } from "../../walletTypes"; -interface LoadingButtonProps { - loading: boolean; -} - -function LoadingButton( - props: - & React.PropsWithChildren - & React.DetailedHTMLProps< - React.ButtonHTMLAttributes, - HTMLButtonElement - >, -) { - return ( -