diff options
Diffstat (limited to 'packages/taler-wallet-webextension')
15 files changed, 68 insertions, 55 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts index bb0f0d1af..804d216eb 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts @@ -30,7 +30,7 @@ export function useComponentState( const [subject, setSubject] = useState(""); const [talerUri, setTalerUri] = useState("") - const hook = useAsyncAsHook(api.listExchangesDetailled); + const hook = useAsyncAsHook(api.listExchanges); const [exchangeIdx, setExchangeIdx] = useState("0") const [operationError, setOperationError] = useState<TalerErrorDetail | undefined>(undefined) diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts index 58d3cfedf..015c9aaca 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -30,7 +30,7 @@ export function useComponentStateFromParams( const [ageRestricted, setAgeRestricted] = useState(0); - const exchangeHook = useAsyncAsHook(api.listExchangesDetailled); + const exchangeHook = useAsyncAsHook(api.listExchanges); const exchangeHookDep = !exchangeHook || exchangeHook.hasError || !exchangeHook.response @@ -65,6 +65,7 @@ export function useComponentStateFromParams( exchangeBaseUrl: exchange.exchangeBaseUrl, amount: chosenAmount, tosAcceptedFormat: ["text/xml"], + ageRestricted, }); const withdrawAmount = { @@ -72,7 +73,7 @@ export function useComponentStateFromParams( effective: Amounts.parseOrThrow(info.withdrawalAmountEffective), } - return { amount: withdrawAmount }; + return { amount: withdrawAmount, ageRestrictionOptions: info.ageRestrictionOptions }; }, [exchangeHookDep]); const [reviewing, setReviewing] = useState<boolean>(false); @@ -172,16 +173,16 @@ export function useComponentStateFromParams( termsState !== undefined && (termsState.status === "changed" || termsState.status === "new"); - const ageRestrictionOptions: Record<string, string> | undefined = "6:12:18" - .split(":") - .reduce((p, c) => ({ ...p, [c]: `under ${c}` }), {}); + const ageRestrictionOptions = amountHook.response. + ageRestrictionOptions?. + reduce((p, c) => ({ ...p, [c]: `under ${c}` }), {} as Record<string, string>) - if (ageRestrictionOptions) { + const ageRestrictionEnabled = ageRestrictionOptions !== undefined + if (ageRestrictionEnabled) { ageRestrictionOptions["0"] = "Not restricted"; } //TODO: calculate based on exchange info - const ageRestrictionEnabled = false; const ageRestriction = ageRestrictionEnabled ? { list: ageRestrictionOptions, value: String(ageRestricted), @@ -269,6 +270,7 @@ export function useComponentStateFromURI( exchangeBaseUrl: uriHookDep?.thisExchange, amount: Amounts.parseOrThrow(uriHookDep.amount), tosAcceptedFormat: ["text/xml"], + ageRestricted, }); const withdrawAmount = { @@ -276,7 +278,7 @@ export function useComponentStateFromURI( effective: Amounts.parseOrThrow(info.withdrawalAmountEffective), } - return { amount: withdrawAmount }; + return { amount: withdrawAmount, ageRestrictionOptions: info.ageRestrictionOptions }; }, [uriHookDep]); const [reviewing, setReviewing] = useState<boolean>(false); @@ -385,16 +387,16 @@ export function useComponentStateFromURI( termsState !== undefined && (termsState.status === "changed" || termsState.status === "new"); - const ageRestrictionOptions: Record<string, string> | undefined = "6:12:18" - .split(":") - .reduce((p, c) => ({ ...p, [c]: `under ${c}` }), {}); + const ageRestrictionOptions = amountHook.response. + ageRestrictionOptions?. + reduce((p, c) => ({ ...p, [c]: `under ${c}` }), {} as Record<string, string>) - if (ageRestrictionOptions) { + const ageRestrictionEnabled = ageRestrictionOptions !== undefined + if (ageRestrictionEnabled) { ageRestrictionOptions["0"] = "Not restricted"; } //TODO: calculate based on exchange info - const ageRestrictionEnabled = false; const ageRestriction = ageRestrictionEnabled ? { list: ageRestrictionOptions, value: String(ageRestricted), diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts index 6c9e0c3ba..ce964f7f7 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts @@ -21,7 +21,7 @@ import { Amounts, - ExchangeFullDetailsListItem, + ExchangeFullDetails, ExchangeListItem, GetExchangeTosResult, } from "@gnu-taler/taler-util"; @@ -30,7 +30,7 @@ import { expect } from "chai"; import { mountHook } from "../../test-utils.js"; import { useComponentStateFromURI } from "./state.js"; -const exchanges: ExchangeFullDetailsListItem[] = [ +const exchanges: ExchangeFullDetails[] = [ { currency: "ARS", exchangeBaseUrl: "http://exchange.demo.taler.net", diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection.tsx b/packages/taler-wallet-webextension/src/wallet/DestinationSelection.tsx index b63bbacaf..fa1a606f7 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection.tsx @@ -171,7 +171,7 @@ export function SelectCurrency({ }): VNode { const { i18n } = useTranslationContext(); - const hook = useAsyncAsHook(wxApi.listExchangesDetailled); + const hook = useAsyncAsHook(wxApi.listExchanges); if (!hook) { return <Loading />; diff --git a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx index 8ba92a8f2..3406b04ef 100644 --- a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx @@ -45,7 +45,7 @@ export function DeveloperPage(): VNode { const response = useAsyncAsHook(async () => { const op = await wxApi.getPendingOperations(); const c = await wxApi.dumpCoins(); - const ex = await wxApi.listExchangesDetailled(); + const ex = await wxApi.listExchanges(); return { operations: op.pendingOperations, coins: c.coins, diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx b/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx index 8ba5fb7e9..859a7f86b 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx @@ -36,7 +36,7 @@ export function ExchangeAddPage({ currency, onBack }: Props): VNode { { url: string; config: TalerConfigResponse } | undefined >(undefined); - const knownExchangesResponse = useAsyncAsHook(wxApi.listExchangesDetailled); + const knownExchangesResponse = useAsyncAsHook(wxApi.listExchanges); const knownExchanges = !knownExchangesResponse ? [] : knownExchangesResponse.hasError diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/example.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/example.ts index bdbd36596..3f37dda77 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/example.ts +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/example.ts @@ -15,7 +15,7 @@ */ import { - ExchangeFullDetailsListItem, + ExchangeFullDetails, ExchangeListItem, } from "@gnu-taler/taler-util"; @@ -24,7 +24,7 @@ import { * @author Sebastian Javier Marchano (sebasjm) */ -export const bitcoinExchanges: ExchangeFullDetailsListItem[] = [ +export const bitcoinExchanges: ExchangeFullDetails[] = [ { exchangeBaseUrl: "https://bitcoin1.ice.bfh.ch/", currency: "BITCOINBTC", @@ -11781,7 +11781,7 @@ export const bitcoinExchanges: ExchangeFullDetailsListItem[] = [ }, ] as any; -export const kudosExchanges: ExchangeFullDetailsListItem[] = [ +export const kudosExchanges: ExchangeFullDetails[] = [ { exchangeBaseUrl: "https://exchange1.demo.taler.net/", currency: "KUDOS", diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts index 0dec00b09..061c94ad7 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { AbsoluteTime, AmountJson, ExchangeFullDetailsListItem } from "@gnu-taler/taler-util"; +import { AbsoluteTime, AmountJson, ExchangeFullDetails } from "@gnu-taler/taler-util"; import { Loading } from "../../components/Loading.js"; import { HookError } from "../../hooks/useAsyncAsHook.js"; import { ButtonHandler, SelectFieldHandler } from "../../mui/handlers.js"; @@ -52,7 +52,7 @@ export namespace State { export interface BaseInfo { exchanges: SelectFieldHandler; - selected: ExchangeFullDetailsListItem; + selected: ExchangeFullDetails; nextFeeUpdate: AbsoluteTime; error: undefined; } diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts index eda755e96..28d34578a 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts @@ -25,11 +25,21 @@ export function useComponentState( { onCancel, onSelection, currency }: Props, api: typeof wxApi, ): State { - const hook = useAsyncAsHook(api.listExchangesDetailled); - const initialValue = 0 const [value, setValue] = useState(String(initialValue)); + const hook = useAsyncAsHook(async () => { + const { exchanges } = await api.listExchanges() + + const selectedIdx = parseInt(value, 10) + const selectedExchange = exchanges.length == 0 ? undefined : exchanges[selectedIdx] + const selected = !selectedExchange ? undefined : await api.getExchangeDetailedInfo(selectedExchange.exchangeBaseUrl) + + const initialExchange = selectedIdx === initialValue ? undefined : exchanges[initialValue] + const original = !initialExchange ? undefined : await api.getExchangeDetailedInfo(initialExchange.exchangeBaseUrl) + return { exchanges, selected, original } + }); + if (!hook) { return { status: "loading", @@ -43,18 +53,16 @@ export function useComponentState( }; } - const exchanges = hook.response.exchanges; + const { exchanges, selected, original } = hook.response; - if (exchanges.length === 0) { + if (!selected) { + //!selected <=> exchanges.length === 0 return { status: "no-exchanges", error: undefined } } - const original = exchanges[initialValue]; - const selected = exchanges[Number(value)]; - let nextFeeUpdate = TalerProtocolTimestamp.never(); nextFeeUpdate = Object.values(selected.wireInfo.feesForType).reduce( @@ -97,7 +105,8 @@ export function useComponentState( const exchangeMap = exchanges.reduce((prev, cur, idx) => ({ ...prev, [cur.exchangeBaseUrl]: String(idx) }), {} as Record<string, string>) - if (original === selected) { + if (!original) { + // !original <=> selected == original return { status: "ready", exchanges: { diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx index 094087517..cb4cc7c69 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx @@ -19,7 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { ExchangeFullDetailsListItem, ExchangeListItem } from "@gnu-taler/taler-util"; +import { ExchangeFullDetails, ExchangeListItem } from "@gnu-taler/taler-util"; import { createExample } from "../../test-utils.js"; import { bitcoinExchanges, kudosExchanges } from "./example.js"; import { FeeDescription, FeeDescriptionPair, OperationMap } from "./index.js"; @@ -34,7 +34,7 @@ export default { }; function timelineForExchange( - ex: ExchangeFullDetailsListItem, + ex: ExchangeFullDetails, ): OperationMap<FeeDescription[]> { return { deposit: createDenominationTimeline( @@ -61,8 +61,8 @@ function timelineForExchange( } function timelinePairForExchange( - ex1: ExchangeFullDetailsListItem, - ex2: ExchangeFullDetailsListItem, + ex1: ExchangeFullDetails, + ex2: ExchangeFullDetails, ): OperationMap<FeeDescriptionPair[]> { const om1 = timelineForExchange(ex1); const om2 = timelineForExchange(ex2); diff --git a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx index 5a82c96ed..a292914fb 100644 --- a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx @@ -50,7 +50,7 @@ export function ManualWithdrawPage({ amount, onCancel }: Props): VNode { >(undefined); const [error, setError] = useState<string | undefined>(undefined); - const state = useAsyncAsHook(wxApi.listExchangesDetailled); + const state = useAsyncAsHook(wxApi.listExchanges); useEffect(() => { return wxApi.onUpdateNotification([NotificationType.ExchangeAdded], () => { state?.retry(); diff --git a/packages/taler-wallet-webextension/src/wallet/Settings.tsx b/packages/taler-wallet-webextension/src/wallet/Settings.tsx index 36a356fba..4a520c3bb 100644 --- a/packages/taler-wallet-webextension/src/wallet/Settings.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Settings.tsx @@ -49,7 +49,7 @@ export function SettingsPage(): VNode { const webex = platform.getWalletWebExVersion(); const exchangesHook = useAsyncAsHook(async () => { - const list = await wxApi.listExchangesDetailled(); + const list = await wxApi.listExchanges(); const version = await wxApi.getVersion(); return { exchanges: list.exchanges, version }; }); diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx index acb50642a..dc8f067a5 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx @@ -563,7 +563,7 @@ export const InvoiceCreditComplete = createExample(TestedComponent, { export const InvoiceCreditIncomplete = createExample(TestedComponent, { transaction: { ...exampleData.pull_credit, - info: { ...exampleData.pull_credit.info, completed: false }, + pending: true, }, }); @@ -581,9 +581,6 @@ export const TransferDebitComplete = createExample(TestedComponent, { export const TransferDebitIncomplete = createExample(TestedComponent, { transaction: { ...exampleData.push_debit, - info: { - ...exampleData.push_debit.info, - completed: false, - }, + pending: true, }, }); diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index 44543c2cd..c1f5861e8 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -167,6 +167,8 @@ export function TransactionView({ } } + const SHOWING_RETRY_THRESHOLD_SECS = 30; + const { i18n } = useTranslationContext(); function TransactionTemplate({ @@ -174,15 +176,16 @@ export function TransactionView({ }: { children: ComponentChildren; }): VNode { - const showSend = - (transaction.type === TransactionType.PeerPullCredit || - transaction.type === TransactionType.PeerPushDebit) && - !transaction.info.completed; + const showSend = false; + // (transaction.type === TransactionType.PeerPullCredit || + // transaction.type === TransactionType.PeerPushDebit) && + // !transaction.info.completed; const showRetry = transaction.error !== undefined || transaction.timestamp.t_s === "never" || (transaction.pending && - differenceInSeconds(new Date(), transaction.timestamp.t_s * 1000) > 10); + differenceInSeconds(new Date(), transaction.timestamp.t_s * 1000) > + SHOWING_RETRY_THRESHOLD_SECS); return ( <Fragment> @@ -624,7 +627,7 @@ export function TransactionView({ text={transaction.exchangeBaseUrl} kind="neutral" /> - {!transaction.info.completed && ( + {transaction.pending && ( <Part title={<i18n.Translate>URI</i18n.Translate>} text={<ShowQrWithCopy text={transaction.talerUri} />} @@ -710,7 +713,7 @@ export function TransactionView({ text={transaction.exchangeBaseUrl} kind="neutral" /> - {!transaction.info.completed && ( + {transaction.pending && ( <Part title={<i18n.Translate>URI</i18n.Translate>} text={<ShowQrWithCopy text={transaction.talerUri} />} diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts index 1b26ea214..b797179c3 100644 --- a/packages/taler-wallet-webextension/src/wxApi.ts +++ b/packages/taler-wallet-webextension/src/wxApi.ts @@ -42,7 +42,7 @@ import { CreateDepositGroupRequest, CreateDepositGroupResponse, DeleteTransactionRequest, - ExchangesListRespose, + ExchangesListResponse, GetExchangeTosResult, GetExchangeWithdrawalInfo, GetFeeForDepositRequest, @@ -67,7 +67,7 @@ import { WalletDiagnostics, WalletCoreVersion, WithdrawUriInfoResponse, - ExchangeDetailledListRespose, + ExchangeFullDetails, } from "@gnu-taler/taler-util"; import { AddBackupProviderRequest, @@ -253,12 +253,14 @@ export function listKnownCurrencies(): Promise<ListOfKnownCurrencies> { }); } -export function listExchanges(): Promise<ExchangesListRespose> { +export function listExchanges(): Promise<ExchangesListResponse> { return callBackend("listExchanges", {}); } -export function listExchangesDetailled(): Promise<ExchangeDetailledListRespose> { - return callBackend("listExchangesDetailled", {}); +export function getExchangeDetailedInfo(exchangeBaseUrl: string): Promise<ExchangeFullDetails> { + return callBackend("getExchangeDetailedInfo", { + exchangeBaseUrl + }); } export function getVersion(): Promise<WalletCoreVersion> { |