From bd88dcebbcf90414c790a86ee13740eaf20e3334 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 15 Oct 2022 12:59:26 +0200 Subject: wallet-core: simplify exchanges list response --- .../src/components/TermsOfService/utils.ts | 27 +++------------------- .../src/components/TermsOfService/views.tsx | 9 ++++---- .../src/cta/Withdraw/state.ts | 13 +++++++---- .../src/cta/Withdraw/test.ts | 3 +++ .../src/cta/Withdraw/views.tsx | 4 ++-- .../src/wallet/DeveloperPage.tsx | 17 +++++++------- .../src/wallet/Settings.tsx | 22 ++++++++---------- 7 files changed, 39 insertions(+), 56 deletions(-) (limited to 'packages/taler-wallet-webextension/src') diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/utils.ts b/packages/taler-wallet-webextension/src/components/TermsOfService/utils.ts index 5766883ae..a106c3d85 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/utils.ts +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/utils.ts @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see */ -import { GetExchangeTosResult } from "@gnu-taler/taler-util"; +import { ExchangeTosStatus, GetExchangeTosResult } from "@gnu-taler/taler-util"; export function buildTermsOfServiceState( tos: GetExchangeTosResult, @@ -24,26 +24,7 @@ export function buildTermsOfServiceState( tos.content, ); - const status: TermsStatus = buildTermsOfServiceStatus( - tos.content, - tos.acceptedEtag, - tos.currentEtag, - ); - - return { content, status, version: tos.currentEtag }; -} -export function buildTermsOfServiceStatus( - content: string | undefined, - acceptedVersion: string | undefined, - currentVersion: string | undefined, -): TermsStatus { - return !content - ? "notfound" - : !acceptedVersion - ? "new" - : acceptedVersion !== currentVersion - ? "changed" - : "accepted"; + return { content, status: tos.tosStatus, version: tos.currentEtag }; } function parseTermsOfServiceContent( @@ -91,12 +72,10 @@ function parseTermsOfServiceContent( export type TermsState = { content: TermsDocument | undefined; - status: TermsStatus; + status: ExchangeTosStatus; version: string; }; -type TermsStatus = "new" | "accepted" | "changed" | "notfound"; - export type TermsDocument = | TermsDocumentXml | TermsDocumentHtml diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx b/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx index c7f8ccb78..a7e03fd01 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx @@ -29,6 +29,7 @@ import { import { ExchangeXmlTos } from "../../components/ExchangeToS.js"; import { ToggleHandler } from "../../mui/handlers.js"; import { Button } from "../../mui/Button.js"; +import { ExchangeTosStatus } from "@gnu-taler/taler-util"; export function LoadingUriView({ error }: State.LoadingUriError): VNode { const { i18n } = useTranslationContext(); @@ -100,7 +101,7 @@ export function ShowButtonsNonAcceptedTosView({ if (!ableToReviewTermsOfService) { return ( - {terms.status === "notfound" && ( + {terms.status === ExchangeTosStatus.NotFound && (
@@ -115,7 +116,7 @@ export function ShowButtonsNonAcceptedTosView({ return ( - {terms.status === "notfound" && ( + {terms.status === ExchangeTosStatus.NotFound && (
@@ -163,7 +164,7 @@ export function ShowTosContentView({ return ( - {terms.status !== "notfound" && !terms.content && ( + {terms.status !== ExchangeTosStatus.NotFound && !terms.content && (
@@ -204,7 +205,7 @@ export function ShowTosContentView({
)} - {termsAccepted && terms.status !== "notfound" && ( + {termsAccepted && terms.status !== ExchangeTosStatus.NotFound && (
{ content: "just accept", acceptedEtag: "v1", currentEtag: "v1", + tosStatus: ExchangeTosStatus.Accepted, }), } as any, ), @@ -254,6 +256,7 @@ describe("Withdraw CTA states", () => { content: "just accept", acceptedEtag: "v1", currentEtag: "v2", + tosStatus: ExchangeTosStatus.Changed, }), setExchangeTosAccepted: async () => ({}), } as any, diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx index 468d22d54..5c35151c8 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx @@ -37,6 +37,7 @@ import editIcon from "../../svg/edit_24px.svg"; import { ExchangeDetails, WithdrawDetails } from "../../wallet/Transaction.js"; import { TermsOfService } from "../../components/TermsOfService/index.js"; import { State } from "./index.js"; +import { ExchangeTosStatus } from "@gnu-taler/taler-util"; export function LoadingUriView({ error }: State.LoadingUriError): VNode { const { i18n } = useTranslationContext(); @@ -65,8 +66,7 @@ export function LoadingInfoView({ error }: State.LoadingInfoError): VNode { export function SuccessView(state: State.Success): VNode { const { i18n } = useTranslationContext(); const currentTosVersionIsAccepted = - state.currentExchange.tos.acceptedVersion === - state.currentExchange.tos.currentVersion; + state.currentExchange.tosStatus === ExchangeTosStatus.Accepted; return ( diff --git a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx index c6f016e00..c0e35b17b 100644 --- a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx @@ -17,6 +17,7 @@ import { Amounts, CoinDumpJson, + CoinStatus, ExchangeListItem, NotificationType, } from "@gnu-taler/taler-util"; @@ -86,7 +87,7 @@ type CoinsInfo = CoinDumpJson["coins"]; type CalculatedCoinfInfo = { ageKeysCount: number | undefined; denom_value: number; - remain_value: number; + //remain_value: number; status: string; from_refresh: boolean; id: string; @@ -143,10 +144,10 @@ export function View({ prev[cur.exchange_base_url].push({ ageKeysCount: cur.ageCommitmentProof?.proof.privateKeys.length, denom_value: parseFloat(Amounts.stringifyValue(denom)), - remain_value: parseFloat( - Amounts.stringifyValue(Amounts.parseOrThrow(cur.remaining_value)), - ), - status: cur.coin_suspended ? "suspended" : "ok", + // remain_value: parseFloat( + // Amounts.stringifyValue(Amounts.parseOrThrow(cur.remaining_value)), + // ), + status: cur.coin_status, from_refresh: cur.refresh_parent_coin_pub !== undefined, id: cur.coin_pub, }); @@ -254,8 +255,8 @@ export function View({ const coins = allcoins.reduce( (prev, cur) => { - if (cur.remain_value > 0) prev.usable.push(cur); - if (cur.remain_value === 0) prev.spent.push(cur); + if (cur.status === CoinStatus.Fresh) prev.usable.push(cur); + if (cur.status === CoinStatus.Dormant) prev.spent.push(cur); return prev; }, { @@ -356,7 +357,6 @@ function ShowAllCoins({ {c.id.substring(0, 5)} {c.denom_value} - {c.remain_value} {c.status} {c.from_refresh ? "true" : "false"} {String(c.ageKeysCount)} @@ -396,7 +396,6 @@ function ShowAllCoins({ {c.id.substring(0, 5)} {c.denom_value} - {c.remain_value} {c.status} {c.from_refresh ? "true" : "false"} diff --git a/packages/taler-wallet-webextension/src/wallet/Settings.tsx b/packages/taler-wallet-webextension/src/wallet/Settings.tsx index 80843ac27..8412c4a12 100644 --- a/packages/taler-wallet-webextension/src/wallet/Settings.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Settings.tsx @@ -14,7 +14,11 @@ GNU Taler; see the file COPYING. If not, see */ -import { ExchangeListItem, WalletCoreVersion } from "@gnu-taler/taler-util"; +import { + ExchangeListItem, + ExchangeTosStatus, + WalletCoreVersion, +} from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; import { Checkbox } from "../components/Checkbox.js"; import { ErrorTalerOperation } from "../components/ErrorTalerOperation.js"; @@ -36,7 +40,6 @@ import { useBackupDeviceName } from "../hooks/useBackupDeviceName.js"; import { useAutoOpenPermissions } from "../hooks/useAutoOpenPermissions.js"; import { ToggleHandler } from "../mui/handlers.js"; import { Pages } from "../NavigationBar.js"; -import { buildTermsOfServiceStatus } from "../components/TermsOfService/utils.js"; import * as wxApi from "../wxApi.js"; import { platform } from "../platform/api.js"; import { useClipboardPermissions } from "../hooks/useClipboardPermissions.js"; @@ -181,26 +184,21 @@ export function SettingsView({ {knownExchanges.map((e, idx) => { function Status(): VNode { - const status = buildTermsOfServiceStatus( - e.tos.content, - e.tos.acceptedVersion, - e.tos.currentVersion, - ); - switch (status) { - case "accepted": + switch (e.tosStatus) { + case ExchangeTosStatus.Accepted: return ( ok ); - case "changed": + case ExchangeTosStatus.Changed: return ( changed ); - case "new": - case "notfound": + case ExchangeTosStatus.New: + case ExchangeTosStatus.NotFound: return ( not accepted -- cgit v1.2.3