From 606be7577be2bd249f19204d0c80b3b48e3065ca Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 18 Feb 2022 16:54:15 -0300 Subject: 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 --- .../taler-wallet-webextension/src/cta/Withdraw.tsx | 60 ++++++++++++++-------- 1 file changed, 40 insertions(+), 20 deletions(-) (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw.tsx') 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(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 (

{i18n.str`Digital cash withdrawal`}

+ + {withdrawError && ( + + )} +
{i18n.str`Confirm withdrawal`} @@ -178,7 +205,7 @@ export function View({ {i18n.str`Withdraw anyway`} @@ -204,7 +231,6 @@ export function WithdrawPageWithParsedURI({ const [reviewing, setReviewing] = useState(false); const [reviewed, setReviewed] = useState(false); - const [confirmed, setConfirmed] = useState(false); const knownExchangesHook = useAsyncAsHook(() => wxApi.listExchanges()); @@ -267,16 +293,11 @@ export function WithdrawPageWithParsedURI({ const onWithdraw = async (): Promise => { 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} -- cgit v1.2.3