From 34e2fd51e038d26c9ea1c0c6770148640669518f Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 20 Jun 2023 17:50:30 -0300 Subject: add select max amount --- .../src/components/AmountField.tsx | 5 +++- .../src/wallet/DestinationSelection/index.ts | 2 +- .../src/wallet/DestinationSelection/state.ts | 33 ++++++++++++++-------- .../src/wallet/DestinationSelection/views.tsx | 6 ++-- 4 files changed, 29 insertions(+), 17 deletions(-) (limited to 'packages/taler-wallet-webextension/src') diff --git a/packages/taler-wallet-webextension/src/components/AmountField.tsx b/packages/taler-wallet-webextension/src/components/AmountField.tsx index 432aa6af1..c330c72b5 100644 --- a/packages/taler-wallet-webextension/src/components/AmountField.tsx +++ b/packages/taler-wallet-webextension/src/components/AmountField.tsx @@ -24,7 +24,7 @@ import { TranslatedString, } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; -import { useState } from "preact/hooks"; +import { useEffect, useState } from "preact/hooks"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { AmountFieldHandler } from "../mui/handlers.js"; import { TextField } from "../mui/TextField.js"; @@ -56,6 +56,9 @@ export function AmountField({ const previousValue = Amounts.stringifyValue(normal); const [textValue, setTextValue] = useState(previousValue); + useEffect(() => { + setTextValue(previousValue); + }, [previousValue]); function updateUnit(newUnit: number) { setUnit(newUnit); diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts index 7724ec2be..b56fe5523 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts @@ -70,7 +70,7 @@ export namespace State { error: undefined; type: Props["type"]; selectCurrency: ButtonHandler; - sendAll: ButtonHandler; + selectMax: ButtonHandler; previous: Contact[]; goToBank: ButtonHandler; goToWallet: ButtonHandler; diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts index e42b1dbf9..a5d44e872 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts @@ -14,14 +14,14 @@ GNU Taler; see the file COPYING. If not, see */ -import { Amounts, TransactionType } from "@gnu-taler/taler-util"; +import { Amounts } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { useEffect, useState } from "preact/hooks"; +import { useTranslationContext } from "@gnu-taler/web-util/browser"; +import { useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; -import { assertUnreachable, RecursiveState } from "../../utils/index.js"; +import { RecursiveState, assertUnreachable } from "../../utils/index.js"; import { Contact, Props, State } from "./index.js"; export function useComponentState(props: Props): RecursiveState { @@ -130,13 +130,16 @@ export function useComponentState(props: Props): RecursiveState { props.goToWalletBankDeposit(currencyAndAmount); }), }, - sendAll: { - onClick: - info === undefined - ? undefined - : pushAlertOnError(async () => { - setAmount(info.balance.balanceMerchantDepositable); - }), + selectMax: { + onClick: pushAlertOnError(async () => { + const resp = await api.wallet.call( + WalletApiOperation.GetMaxDepositAmount, + { + currency: amount.currency, + }, + ); + setAmount(Amounts.parseOrThrow(resp.effectiveAmount)); + }), }, goToWallet: { onClick: invalid @@ -161,7 +164,13 @@ export function useComponentState(props: Props): RecursiveState { setAmount(undefined); }), }, - sendAll: {}, + selectMax: { + onClick: invalid + ? undefined + : pushAlertOnError(async () => { + props.goToWalletManualWithdraw(currencyAndAmount); + }), + }, goToBank: { onClick: invalid ? undefined diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx index c230c1490..f8e2c6707 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx @@ -203,7 +203,7 @@ export function ReadyGetView({ return (

- Specify the amount and the origin2 + Specify the amount and the origin

- -- cgit v1.2.3