add select max amount
This commit is contained in:
parent
5c5586df99
commit
34e2fd51e0
@ -24,7 +24,7 @@ import {
|
|||||||
TranslatedString,
|
TranslatedString,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import { Fragment, h, VNode } from "preact";
|
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 { useTranslationContext } from "@gnu-taler/web-util/browser";
|
||||||
import { AmountFieldHandler } from "../mui/handlers.js";
|
import { AmountFieldHandler } from "../mui/handlers.js";
|
||||||
import { TextField } from "../mui/TextField.js";
|
import { TextField } from "../mui/TextField.js";
|
||||||
@ -56,6 +56,9 @@ export function AmountField({
|
|||||||
const previousValue = Amounts.stringifyValue(normal);
|
const previousValue = Amounts.stringifyValue(normal);
|
||||||
|
|
||||||
const [textValue, setTextValue] = useState<string>(previousValue);
|
const [textValue, setTextValue] = useState<string>(previousValue);
|
||||||
|
useEffect(() => {
|
||||||
|
setTextValue(previousValue);
|
||||||
|
}, [previousValue]);
|
||||||
|
|
||||||
function updateUnit(newUnit: number) {
|
function updateUnit(newUnit: number) {
|
||||||
setUnit(newUnit);
|
setUnit(newUnit);
|
||||||
|
@ -70,7 +70,7 @@ export namespace State {
|
|||||||
error: undefined;
|
error: undefined;
|
||||||
type: Props["type"];
|
type: Props["type"];
|
||||||
selectCurrency: ButtonHandler;
|
selectCurrency: ButtonHandler;
|
||||||
sendAll: ButtonHandler;
|
selectMax: ButtonHandler;
|
||||||
previous: Contact[];
|
previous: Contact[];
|
||||||
goToBank: ButtonHandler;
|
goToBank: ButtonHandler;
|
||||||
goToWallet: ButtonHandler;
|
goToWallet: ButtonHandler;
|
||||||
|
@ -14,14 +14,14 @@
|
|||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Amounts, TransactionType } from "@gnu-taler/taler-util";
|
import { Amounts } from "@gnu-taler/taler-util";
|
||||||
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
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 { alertFromError, useAlertContext } from "../../context/alert.js";
|
||||||
import { useBackendContext } from "../../context/backend.js";
|
import { useBackendContext } from "../../context/backend.js";
|
||||||
import { useTranslationContext } from "@gnu-taler/web-util/browser";
|
|
||||||
import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js";
|
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";
|
import { Contact, Props, State } from "./index.js";
|
||||||
|
|
||||||
export function useComponentState(props: Props): RecursiveState<State> {
|
export function useComponentState(props: Props): RecursiveState<State> {
|
||||||
@ -130,13 +130,16 @@ export function useComponentState(props: Props): RecursiveState<State> {
|
|||||||
props.goToWalletBankDeposit(currencyAndAmount);
|
props.goToWalletBankDeposit(currencyAndAmount);
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
sendAll: {
|
selectMax: {
|
||||||
onClick:
|
onClick: pushAlertOnError(async () => {
|
||||||
info === undefined
|
const resp = await api.wallet.call(
|
||||||
? undefined
|
WalletApiOperation.GetMaxDepositAmount,
|
||||||
: pushAlertOnError(async () => {
|
{
|
||||||
setAmount(info.balance.balanceMerchantDepositable);
|
currency: amount.currency,
|
||||||
}),
|
},
|
||||||
|
);
|
||||||
|
setAmount(Amounts.parseOrThrow(resp.effectiveAmount));
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
goToWallet: {
|
goToWallet: {
|
||||||
onClick: invalid
|
onClick: invalid
|
||||||
@ -161,7 +164,13 @@ export function useComponentState(props: Props): RecursiveState<State> {
|
|||||||
setAmount(undefined);
|
setAmount(undefined);
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
sendAll: {},
|
selectMax: {
|
||||||
|
onClick: invalid
|
||||||
|
? undefined
|
||||||
|
: pushAlertOnError(async () => {
|
||||||
|
props.goToWalletManualWithdraw(currencyAndAmount);
|
||||||
|
}),
|
||||||
|
},
|
||||||
goToBank: {
|
goToBank: {
|
||||||
onClick: invalid
|
onClick: invalid
|
||||||
? undefined
|
? undefined
|
||||||
|
@ -203,7 +203,7 @@ export function ReadyGetView({
|
|||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<h1>
|
<h1>
|
||||||
<i18n.Translate>Specify the amount and the origin2</i18n.Translate>
|
<i18n.Translate>Specify the amount and the origin</i18n.Translate>
|
||||||
</h1>
|
</h1>
|
||||||
<Grid container columns={2} justifyContent="space-between">
|
<Grid container columns={2} justifyContent="space-between">
|
||||||
<AmountField
|
<AmountField
|
||||||
@ -287,7 +287,7 @@ export function ReadySendView({
|
|||||||
goToBank,
|
goToBank,
|
||||||
goToWallet,
|
goToWallet,
|
||||||
previous,
|
previous,
|
||||||
sendAll,
|
selectMax,
|
||||||
}: State.Ready): VNode {
|
}: State.Ready): VNode {
|
||||||
const { i18n } = useTranslationContext();
|
const { i18n } = useTranslationContext();
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ export function ReadySendView({
|
|||||||
handler={amountHandler}
|
handler={amountHandler}
|
||||||
/>
|
/>
|
||||||
<EnabledBySettings name="advanceMode">
|
<EnabledBySettings name="advanceMode">
|
||||||
<Button onClick={sendAll.onClick}>
|
<Button onClick={selectMax.onClick}>
|
||||||
<i18n.Translate>Send all</i18n.Translate>
|
<i18n.Translate>Send all</i18n.Translate>
|
||||||
</Button>
|
</Button>
|
||||||
</EnabledBySettings>
|
</EnabledBySettings>
|
||||||
|
Loading…
Reference in New Issue
Block a user