From 3a889c177dd35a114d2c95efd296274cd185ce52 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 27 Feb 2024 12:30:24 -0300 Subject: fix #8469 --- .../src/NavigationBar.tsx | 2 +- .../src/components/TermsOfService/state.ts | 7 +- .../src/cta/Withdraw/views.tsx | 17 +- .../src/hooks/useSettings.ts | 3 +- .../taler-wallet-webextension/src/platform/api.ts | 6 +- .../src/wallet/AddExchange/test.ts | 1 + .../src/wallet/DestinationSelection/test.ts | 1 + .../src/wallet/DestinationSelection/views.tsx | 6 +- .../src/wallet/DeveloperPage.stories.tsx | 2 +- .../src/wallet/DeveloperPage.tsx | 362 +++++++++++++-------- .../src/wallet/Settings.stories.tsx | 53 --- .../src/wallet/Settings.tsx | 193 +++-------- .../src/wallet/Transaction.tsx | 2 +- packages/taler-wallet-webextension/src/wxApi.ts | 8 - .../taler-wallet-webextension/src/wxBackend.ts | 12 - .../taler-wallet-webextension/static/wallet.html | 1 + 16 files changed, 293 insertions(+), 383 deletions(-) (limited to 'packages/taler-wallet-webextension') diff --git a/packages/taler-wallet-webextension/src/NavigationBar.tsx b/packages/taler-wallet-webextension/src/NavigationBar.tsx index fe4fcc2d9..1837f0508 100644 --- a/packages/taler-wallet-webextension/src/NavigationBar.tsx +++ b/packages/taler-wallet-webextension/src/NavigationBar.tsx @@ -259,7 +259,7 @@ export function WalletNavBar({ path }: { path?: WalletNavBarOptions }): VNode { )} - + Dev tools diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts index 0b27c9dcf..88d97af81 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts @@ -39,7 +39,7 @@ export function useComponentState({ showEvenIfaccepted, exchangeUrl, readOnly, c WalletApiOperation.GetExchangeTos, { exchangeBaseUrl: exchangeUrl, - acceptedFormat: ["text/html"], + acceptedFormat: ["text/xml"], acceptLanguage: acceptedLang, }, ); @@ -77,14 +77,9 @@ export function useComponentState({ showEvenIfaccepted, exchangeUrl, readOnly, c if (accepted) { await api.wallet.call(WalletApiOperation.SetExchangeTosAccepted, { exchangeBaseUrl: exchangeUrl, - etag: state.version, }); } else { // mark as not accepted - await api.wallet.call(WalletApiOperation.SetExchangeTosAccepted, { - exchangeBaseUrl: exchangeUrl, - etag: undefined, - }); } terms?.retry() } diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx index 4ceaad010..aade67835 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx @@ -33,6 +33,7 @@ import { getAmountWithFee, } from "../../wallet/Transaction.js"; import { State } from "./index.js"; +import { EnabledBySettings } from "../../components/EnabledBySettings.js"; export function FinalStateOperation(state: State.AlreadyCompleted): VNode { const { i18n } = useTranslationContext(); @@ -77,13 +78,15 @@ export function SuccessView(state: State.Success): VNode { }} > Exchange - + + + } text={ diff --git a/packages/taler-wallet-webextension/src/hooks/useSettings.ts b/packages/taler-wallet-webextension/src/hooks/useSettings.ts index 29449cd59..09fe28888 100644 --- a/packages/taler-wallet-webextension/src/hooks/useSettings.ts +++ b/packages/taler-wallet-webextension/src/hooks/useSettings.ts @@ -36,13 +36,14 @@ export const codecForSettings = (): Codec => .property("walletAllowHttp", codecForBoolean()) .property("injectTalerSupport", codecForBoolean()) .property("autoOpen", codecForBoolean()) - .property("advanceMode", codecForBoolean()) + .property("advancedMode", codecForBoolean()) .property("backup", codecForBoolean()) .property("langSelector", codecForBoolean()) .property("showJsonOnError", codecForBoolean()) .property("extendedAccountTypes", codecForBoolean()) .property("suspendIndividualTransaction", codecForBoolean()) .property("showRefeshTransactions", codecForBoolean()) + .property("showExchangeManagement", codecForBoolean()) .build("Settings"); const SETTINGS_KEY = buildStorageKey("wallet-settings", codecForSettings()); diff --git a/packages/taler-wallet-webextension/src/platform/api.ts b/packages/taler-wallet-webextension/src/platform/api.ts index 5bc7fd6c5..a16200cc5 100644 --- a/packages/taler-wallet-webextension/src/platform/api.ts +++ b/packages/taler-wallet-webextension/src/platform/api.ts @@ -113,25 +113,27 @@ type WebexWalletConfig = { export interface Settings extends WebexWalletConfig { injectTalerSupport: boolean; autoOpen: boolean; - advanceMode: boolean; + advancedMode: boolean; backup: boolean; langSelector: boolean; showJsonOnError: boolean; extendedAccountTypes: boolean; showRefeshTransactions: boolean; suspendIndividualTransaction: boolean; + showExchangeManagement: boolean; } export const defaultSettings: Settings = { injectTalerSupport: false, autoOpen: true, - advanceMode: false, + advancedMode: false, backup: false, langSelector: false, showRefeshTransactions: false, suspendIndividualTransaction: false, showJsonOnError: false, extendedAccountTypes: false, + showExchangeManagement: false, walletAllowHttp: false, }; diff --git a/packages/taler-wallet-webextension/src/wallet/AddExchange/test.ts b/packages/taler-wallet-webextension/src/wallet/AddExchange/test.ts index 60d5b274c..aa6384df2 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddExchange/test.ts +++ b/packages/taler-wallet-webextension/src/wallet/AddExchange/test.ts @@ -49,6 +49,7 @@ describe("AddExchange states", () => { exchangeBaseUrl: "http://exchange.local/", ageRestrictionOptions: [], scopeInfo: undefined, + masterPub: "123qwe123", currency: "ARS", exchangeEntryStatus: ExchangeEntryStatus.Ephemeral, tosStatus: ExchangeTosStatus.Pending, diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts index 3082ae7a4..0a99e6af9 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts @@ -36,6 +36,7 @@ import { useComponentState } from "./state.js"; const exchangeArs: ExchangeListItem = { currency: "ARS", exchangeBaseUrl: "http://", + masterPub:"123qwe123", scopeInfo: undefined, tosStatus: ExchangeTosStatus.Accepted, exchangeEntryStatus: ExchangeEntryStatus.Used, diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx index f8e2c6707..c40a3a64c 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx @@ -14,6 +14,7 @@ GNU Taler; see the file COPYING. If not, see */ +import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { styled } from "@linaria/react"; import { Fragment, h, VNode } from "preact"; import { AmountField } from "../../components/AmountField.js"; @@ -25,7 +26,6 @@ import { LinkPrimary, SvgIcon, } from "../../components/styled/index.js"; -import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { Button } from "../../mui/Button.js"; import { Grid } from "../../mui/Grid.js"; import { Paper } from "../../mui/Paper.js"; @@ -34,8 +34,6 @@ import arrowIcon from "../../svg/chevron-down.inline.svg"; import bankIcon from "../../svg/ri-bank-line.inline.svg"; import { assertUnreachable } from "../../utils/index.js"; import { Contact, State } from "./index.js"; -import { useEffect } from "preact/hooks"; -import { Checkbox } from "../../components/Checkbox.js"; export function SelectCurrencyView({ currencies, @@ -303,7 +301,7 @@ export function ReadySendView({ required handler={amountHandler} /> - + diff --git a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.stories.tsx b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.stories.tsx index c2c794e89..e7c9111fd 100644 --- a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.stories.tsx @@ -21,7 +21,7 @@ import { AbsoluteTime } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; -import { View as TestedComponent } from "./DeveloperPage.js"; +import { DeveloperPage as TestedComponent } from "./DeveloperPage.js"; export default { title: "developer", diff --git a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx index 0db7a07eb..d19fef155 100644 --- a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx @@ -20,8 +20,12 @@ import { CoinDumpJson, CoinStatus, ExchangeListItem, + ExchangeTosStatus, LogLevel, NotificationType, + ScopeType, + parseWithdrawUri, + stringifyWithdrawExchange, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; @@ -31,7 +35,7 @@ import { useEffect, useRef, useState } from "preact/hooks"; import { Checkbox } from "../components/Checkbox.js"; import { SelectList } from "../components/SelectList.js"; import { Time } from "../components/Time.js"; -import { NotifyUpdateFadeOut } from "../components/styled/index.js"; +import { DestructiveText, LinkPrimary, NotifyUpdateFadeOut, SubTitle, SuccessText, WarningText } from "../components/styled/index.js"; import { useAlertContext } from "../context/alert.js"; import { useBackendContext } from "../context/backend.js"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; @@ -40,50 +44,8 @@ import { Button } from "../mui/Button.js"; import { Grid } from "../mui/Grid.js"; import { Paper } from "../mui/Paper.js"; import { TextField } from "../mui/TextField.js"; - -export function DeveloperPage(): VNode { - const listenAllEvents = Array.from({ length: 1 }); - - const api = useBackendContext(); - - const response = useAsyncAsHook(async () => { - const op = await api.wallet.call( - WalletApiOperation.GetPendingOperations, - {}, - ); - const c = await api.wallet.call(WalletApiOperation.DumpCoins, {}); - const ex = await api.wallet.call(WalletApiOperation.ListExchanges, {}); - return { - operations: op.pendingOperations, - coins: c.coins, - exchanges: ex.exchanges, - }; - }); - - useEffect(() => { - return api.listener.onUpdateNotification(listenAllEvents, response?.retry); - }); - - const nonResponse = { operations: [], coins: [], exchanges: [] }; - const { operations, coins, exchanges } = - response === undefined - ? nonResponse - : response.hasError - ? nonResponse - : response.response; - - return ( - { - const db = await api.wallet.call(WalletApiOperation.ExportDb, {}); - return JSON.stringify(db); - }} - /> - ); -} +import { Pages } from "../NavigationBar.js"; +import { CoinInfo } from "@gnu-taler/taler-wallet-core/dbless"; type CoinsInfo = CoinDumpJson["coins"]; type CalculatedCoinfInfo = { @@ -103,23 +65,20 @@ type SplitedCoinInfo = { export interface Props { // FIXME: Pending operations don't exist anymore. - operations: any[]; - coins: CoinsInfo; - exchanges: ExchangeListItem[]; - onDownloadDatabase: () => Promise; } function hashObjectId(o: any): string { return JSON.stringify(o); } -export function View({ operations, coins, onDownloadDatabase }: Props): VNode { +export function DeveloperPage({ }: Props): VNode { const { i18n } = useTranslationContext(); const [downloadedDatabase, setDownloadedDatabase] = useState< { time: Date; content: string } | undefined >(undefined); async function onExportDatabase(): Promise { - const content = await onDownloadDatabase(); + const db = await api.wallet.call(WalletApiOperation.ExportDb, {}); + const content = JSON.stringify(db); setDownloadedDatabase({ time: new Date(), content, @@ -136,10 +95,28 @@ export function View({ operations, coins, onDownloadDatabase }: Props): VNode { const [settings, updateSettings] = useSettings(); const { safely } = useAlertContext(); - const hook = useAsyncAsHook(() => - api.wallet.call(WalletApiOperation.ListExchanges, {}), - ); + // const hook = useAsyncAsHook(() => + // api.wallet.call(WalletApiOperation.ListExchanges, {}), + // ); + const listenAllEvents = Array.from({ length: 1 }); + + const hook = useAsyncAsHook(async () => { + const list = await api.wallet.call(WalletApiOperation.ListExchanges, {}); + const version = await api.wallet.call(WalletApiOperation.GetVersion, {}); + const operations: any[] = await api.wallet.call( + WalletApiOperation.GetPendingOperations, + {}, + ); + const coins = await api.wallet.call(WalletApiOperation.DumpCoins, {}); + return { exchanges: list.exchanges, version, coins, operations }; + }); const exchangeList = hook && !hook.hasError ? hook.response.exchanges : []; + const coins = hook && !hook.hasError ? hook.response.coins.coins : []; + const operations = hook && !hook.hasError ? hook.response.operations : []; + + useEffect(() => { + return api.listener.onUpdateNotification(listenAllEvents, hook?.retry); + }); const currencies: { [ex: string]: string } = {}; const money_by_exchange = coins.reduce( @@ -202,30 +179,6 @@ export function View({ operations, coins, onDownloadDatabase }: Props): VNode { run gc - - - - - - - - - - - - {" "} - - - - - -