diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/DestinationSelection')
5 files changed, 42 insertions, 2 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts index bd6b32e78..9a0ba1d88 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts @@ -66,6 +66,7 @@ export namespace State { error: undefined; type: Props["type"]; selectCurrency: ButtonHandler; + sendAll: 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 d5015ae1d..a921d32cb 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts @@ -27,10 +27,21 @@ import { Contact, Props, State } from "./index.js"; export function useComponentState(props: Props): RecursiveState<State> { const api = useBackendContext(); const { pushAlertOnError } = useAlertContext(); + const parsedInitialAmount = !props.amount ? undefined : Amounts.parse(props.amount); + const hook = useAsyncAsHook(async () => { + if (!parsedInitialAmount) return undefined; + const resp = await api.wallet.call(WalletApiOperation.GetBalanceDetail, { + currency: parsedInitialAmount.currency, + }); + return resp; + }); + + const total = hook && !hook.hasError ? hook.response : undefined; + // const initialCurrency = parsedInitialAmount?.currency; const [amount, setAmount] = useState( @@ -120,6 +131,14 @@ export function useComponentState(props: Props): RecursiveState<State> { props.goToWalletBankDeposit(currencyAndAmount); }), }, + sendAll: { + onClick: + total === undefined + ? undefined + : pushAlertOnError(async () => { + setAmount(total.balanceMerchantDepositable); + }), + }, goToWallet: { onClick: invalid ? undefined @@ -143,6 +162,7 @@ export function useComponentState(props: Props): RecursiveState<State> { setAmount(undefined); }), }, + sendAll: {}, goToBank: { onClick: invalid ? undefined diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/stories.tsx b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/stories.tsx index 111f47776..247affec6 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/stories.tsx @@ -35,6 +35,7 @@ export const GetCash = tests.createExample(ReadyView, { }, }, goToBank: {}, + sendAll: {}, goToWallet: {}, previous: [], selectCurrency: {}, @@ -49,6 +50,7 @@ export const SendCash = tests.createExample(ReadyView, { }, }, goToBank: {}, + sendAll: {}, goToWallet: {}, previous: [], selectCurrency: {}, diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts index b079ef0e8..c6a57270b 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts @@ -122,6 +122,16 @@ describe("Destination selection states", () => { Amounts.parseOrThrow("ARS:2"), ); }, + (state) => { + if (state.status !== "ready") expect.fail(); + if (state.error) expect.fail(); + expect(state.goToBank.onClick).not.eq(undefined); + expect(state.goToWallet.onClick).not.eq(undefined); + + expect(state.amountHandler.value).deep.eq( + Amounts.parseOrThrow("ARS:2"), + ); + }, ], TestingContext, ); diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx index 8a7a1fa97..0649fd12f 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx @@ -17,6 +17,7 @@ import { styled } from "@linaria/react"; import { Fragment, h, VNode } from "preact"; import { AmountField } from "../../components/AmountField.js"; +import { JustInDevMode } from "../../components/JustInDevMode.js"; import { SelectList } from "../../components/SelectList.js"; import { Input, @@ -283,6 +284,7 @@ export function ReadySendView({ goToBank, goToWallet, previous, + sendAll, }: State.Ready): VNode { const { i18n } = useTranslationContext(); @@ -292,13 +294,18 @@ export function ReadySendView({ <i18n.Translate>Specify the amount and the destination</i18n.Translate> </h1> - <div> + <Grid container columns={2} justifyContent="space-between"> <AmountField label={i18n.str`Amount`} required handler={amountHandler} /> - </div> + <JustInDevMode> + <Button onClick={sendAll.onClick}> + <i18n.Translate>Send all</i18n.Translate> + </Button> + </JustInDevMode> + </Grid> <Grid container spacing={1} columns={1}> {previous.length > 0 ? ( |