diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src')
8 files changed, 57 insertions, 9 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 ? ( diff --git a/packages/taler-wallet-webextension/src/wallet/History.tsx b/packages/taler-wallet-webextension/src/wallet/History.tsx index 1d51f835a..f2a239f83 100644 --- a/packages/taler-wallet-webextension/src/wallet/History.tsx +++ b/packages/taler-wallet-webextension/src/wallet/History.tsx @@ -111,8 +111,10 @@ export function HistoryView({ balances: Balance[]; }): VNode { const { i18n } = useTranslationContext(); - const currencies = balances.map((b) => b.available.split(":")[0]); const { pushAlertOnError } = useAlertContext(); + const currencies = balances + .filter((b) => Amounts.isNonZero(b.available)) + .map((b) => b.available.split(":")[0]); const defaultCurrencyIndex = currencies.findIndex( (c) => c === defaultCurrency, diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts index 001f77934..c064d7111 100644 --- a/packages/taler-wallet-webextension/src/wxApi.ts +++ b/packages/taler-wallet-webextension/src/wxApi.ts @@ -88,8 +88,8 @@ export interface BackgroundOperations { }; setLoggingLevel: { request: { - tag?: string, - level: LogLevel + tag?: string; + level: LogLevel; }; response: void; }; diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts index 1bfee1064..2055953e3 100644 --- a/packages/taler-wallet-webextension/src/wxBackend.ts +++ b/packages/taler-wallet-webextension/src/wxBackend.ts @@ -186,12 +186,18 @@ const backendHandlers: BackendHandlerType = { setLoggingLevel, }; -async function setLoggingLevel({ tag, level }: { tag?: string, level: LogLevel }): Promise<void> { - logger.info(`setting ${tag} to ${level}`) +async function setLoggingLevel({ + tag, + level, +}: { + tag?: string; + level: LogLevel; +}): Promise<void> { + logger.info(`setting ${tag} to ${level}`); if (!tag) { - setGlobalLogLevelFromString(level) + setGlobalLogLevelFromString(level); } else { - setLogLevelFromString(tag, level) + setLogLevelFromString(tag, level); } } |