From 7b62d04f2c3fec5ee1a67650da4b4087cae7b4dd Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 30 Nov 2023 11:08:56 -0300 Subject: alt currency WIP --- .../src/cta/Withdraw/index.ts | 2 ++ .../src/cta/Withdraw/state.ts | 6 ++-- .../src/cta/Withdraw/stories.tsx | 33 ++++++++++++++++++++++ .../src/cta/Withdraw/views.tsx | 18 +++++++++++- 4 files changed, 56 insertions(+), 3 deletions(-) (limited to 'packages/taler-wallet-webextension') diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts index f80e5a648..3dc2b7f3d 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts @@ -18,6 +18,7 @@ import { AmountJson, AmountString, ExchangeListItem, + WithdrawalExchangeAccountDetails, } from "@gnu-taler/taler-util"; import { Loading } from "../../components/Loading.js"; import { State as SelectExchangeState } from "../../hooks/useSelectedExchange.js"; @@ -91,6 +92,7 @@ export namespace State { doWithdrawal: ButtonHandler; doSelectExchange: ButtonHandler; + accounts: WithdrawalExchangeAccountDetails[]; ageRestriction?: SelectFieldHandler; diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts index a3855c2f4..46d221766 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -324,10 +324,11 @@ function exchangeSelectionState( raw: Amounts.parseOrThrow(info.amountRaw), effective: Amounts.parseOrThrow(info.amountEffective), }; - + return { amount: withdrawAmount, ageRestrictionOptions: info.ageRestrictionOptions, + accounts: info.withdrawalAccountList }; }, []); @@ -335,7 +336,7 @@ function exchangeSelectionState( undefined, ); const [doingWithdraw, setDoingWithdraw] = useState(false); - + async function doWithdrawAndCheckError(): Promise { try { setDoingWithdraw(true); @@ -406,6 +407,7 @@ function exchangeSelectionState( doSelectExchange: selectedExchange.doSelect, currentExchange, toBeReceived, + accounts: amountHook.response.accounts, withdrawalFee, chosenAmount, talerWithdrawUri, diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/stories.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw/stories.tsx index 29f7e0a30..df70a5c95 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/stories.tsx @@ -64,6 +64,7 @@ export const TermsOfServiceNotYetLoaded = tests.createExample(SuccessView, { fraction: 0, value: 1, }, + accounts: [], }); export const WithSomeFee = tests.createExample(SuccessView, { @@ -90,6 +91,7 @@ export const WithSomeFee = tests.createExample(SuccessView, { value: 1, }, doSelectExchange: {}, + accounts: [], }); export const WithoutFee = tests.createExample(SuccessView, { @@ -116,6 +118,7 @@ export const WithoutFee = tests.createExample(SuccessView, { fraction: 0, value: 2, }, + accounts: [], }); export const EditExchangeUntouched = tests.createExample(SuccessView, { @@ -142,6 +145,7 @@ export const EditExchangeUntouched = tests.createExample(SuccessView, { fraction: 0, value: 2, }, + accounts: [], }); export const EditExchangeModified = tests.createExample(SuccessView, { @@ -168,6 +172,7 @@ export const EditExchangeModified = tests.createExample(SuccessView, { fraction: 0, value: 2, }, + accounts: [], }); export const WithAgeRestriction = tests.createExample(SuccessView, { @@ -195,4 +200,32 @@ export const WithAgeRestriction = tests.createExample(SuccessView, { fraction: 0, value: 2, }, + accounts: [], +}); + +export const WithAlternateCurrencies = tests.createExample(SuccessView, { + error: undefined, + status: "success", + chosenAmount: { + currency: "USD", + value: 2, + fraction: 10000000, + }, + accounts: [], + doWithdrawal: { onClick: nullFunction }, + currentExchange: { + exchangeBaseUrl: "https://exchange.demo.taler.net", + tos: {}, + } as Partial as any, + withdrawalFee: { + currency: "USD", + fraction: 10000000, + value: 1, + }, + doSelectExchange: {}, + toBeReceived: { + currency: "USD", + fraction: 0, + value: 1, + }, }); diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx index 8a01edaaf..aa8b58707 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx @@ -39,7 +39,8 @@ export function SuccessView(state: State.Success): VNode { const { i18n } = useTranslationContext(); const currentTosVersionIsAccepted = state.currentExchange.tosStatus === ExchangeTosStatus.Accepted; - return ( + const altCurrencies = state.accounts.filter(a => !!a.currencySpecification).map(a => a.currencySpecification!.name) + return (
+

+ This exchange allows alternative currency +

+

+ + +