summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-02-18 16:54:15 -0300
committerSebastian <sebasjm@gmail.com>2022-02-18 16:55:38 -0300
commit606be7577be2bd249f19204d0c80b3b48e3065ca (patch)
tree1d3d72940cf590e1a643692046b43e2ac41354b3 /packages/taler-wallet-webextension/src/cta/Withdraw.tsx
parent2b2b8c160870d0c7e8fbcebca8b1ac157d93033b (diff)
downloadwallet-core-606be7577be2bd249f19204d0c80b3b48e3065ca.tar.gz
wallet-core-606be7577be2bd249f19204d0c80b3b48e3065ca.tar.bz2
wallet-core-606be7577be2bd249f19204d0c80b3b48e3065ca.zip
some fixes
-fix fulfillment messages -fix product list pricing and image on payment -filter exchange by currency on withdrawal -error message on operation error on withdrawal -add taler url on balance page (just for dev) -add no balance help -better text when doing manual withdraw for the firt time -removed balance from wallet (just history) -removed pending page
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw.tsx')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw.tsx60
1 files changed, 40 insertions, 20 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
index a4ee640ca..8f45a047c 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
@@ -28,10 +28,12 @@ import {
i18n,
WithdrawUriInfoResponse,
} from "@gnu-taler/taler-util";
+import { OperationFailedError } from "@gnu-taler/taler-wallet-core";
import { Fragment, h, VNode } from "preact";
import { useState } from "preact/hooks";
import { Loading } from "../components/Loading";
import { LoadingError } from "../components/LoadingError";
+import { ErrorTalerOperation } from "../components/ErrorTalerOperation";
import { LogoHeader } from "../components/LogoHeader";
import { Part } from "../components/Part";
import { SelectList } from "../components/SelectList";
@@ -64,7 +66,6 @@ export interface ViewProps {
onAccept: (b: boolean) => void;
reviewing: boolean;
reviewed: boolean;
- confirmed: boolean;
terms: TermsState;
knownExchanges: ExchangeListItem[];
}
@@ -81,8 +82,12 @@ export function View({
onReview,
onAccept,
reviewed,
- confirmed,
}: ViewProps): VNode {
+ const [withdrawError, setWithdrawError] = useState<
+ OperationFailedError | undefined
+ >(undefined);
+ const [confirmDisabled, setConfirmDisabled] = useState<boolean>(false);
+
const needsReview = terms.status === "changed" || terms.status === "new";
const [switchingExchange, setSwitchingExchange] = useState(false);
@@ -90,15 +95,37 @@ export function View({
undefined,
);
- const exchanges = knownExchanges.reduce(
- (prev, ex) => ({ ...prev, [ex.exchangeBaseUrl]: ex.exchangeBaseUrl }),
- {},
- );
+ const exchanges = knownExchanges
+ .filter((e) => e.currency === amount.currency)
+ .reduce(
+ (prev, ex) => ({ ...prev, [ex.exchangeBaseUrl]: ex.exchangeBaseUrl }),
+ {},
+ );
+
+ async function doWithdrawAndCheckError() {
+ try {
+ setConfirmDisabled(true);
+ await onWithdraw();
+ } catch (e) {
+ if (e instanceof OperationFailedError) {
+ setWithdrawError(e);
+ }
+ setConfirmDisabled(false);
+ }
+ }
return (
<WalletAction>
<LogoHeader />
<h2>{i18n.str`Digital cash withdrawal`}</h2>
+
+ {withdrawError && (
+ <ErrorTalerOperation
+ title="Could not finish the withdrawal operation"
+ error={withdrawError.operationError}
+ />
+ )}
+
<section>
<Part
title="Total to withdraw"
@@ -168,8 +195,8 @@ export function View({
{(terms.status === "accepted" || (needsReview && reviewed)) && (
<ButtonSuccess
upperCased
- disabled={!exchangeBaseUrl || confirmed}
- onClick={onWithdraw}
+ disabled={!exchangeBaseUrl || confirmDisabled}
+ onClick={doWithdrawAndCheckError}
>
{i18n.str`Confirm withdrawal`}
</ButtonSuccess>
@@ -178,7 +205,7 @@ export function View({
<ButtonWarning
upperCased
disabled={!exchangeBaseUrl}
- onClick={onWithdraw}
+ onClick={doWithdrawAndCheckError}
>
{i18n.str`Withdraw anyway`}
</ButtonWarning>
@@ -204,7 +231,6 @@ export function WithdrawPageWithParsedURI({
const [reviewing, setReviewing] = useState<boolean>(false);
const [reviewed, setReviewed] = useState<boolean>(false);
- const [confirmed, setConfirmed] = useState<boolean>(false);
const knownExchangesHook = useAsyncAsHook(() => wxApi.listExchanges());
@@ -267,16 +293,11 @@ export function WithdrawPageWithParsedURI({
const onWithdraw = async (): Promise<void> => {
if (!exchange) return;
- setConfirmed(true);
console.log("accepting exchange", exchange);
- try {
- const res = await wxApi.acceptWithdrawal(uri, exchange);
- console.log("accept withdrawal response", res);
- if (res.confirmTransferUrl) {
- document.location.href = res.confirmTransferUrl;
- }
- } catch (e) {
- setConfirmed(false);
+ const res = await wxApi.acceptWithdrawal(uri, exchange);
+ console.log("accept withdrawal response", res);
+ if (res.confirmTransferUrl) {
+ document.location.href = res.confirmTransferUrl;
}
};
@@ -289,7 +310,6 @@ export function WithdrawPageWithParsedURI({
terms={detailsHook.response.tos}
onSwitchExchange={setCustomExchange}
knownExchanges={knownExchanges}
- confirmed={confirmed}
reviewed={reviewed}
onAccept={onAccept}
reviewing={reviewing}