From e0e33a88db7641775de16f5425bfc08e461a4f75 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 5 Sep 2022 10:04:56 -0300 Subject: adding informantion about the service worker version on the setting page --- packages/taler-util/src/walletTypes.ts | 8 ++- packages/taler-wallet-core/rollup.config.js | 24 +++++++ packages/taler-wallet-core/src/wallet.ts | 17 +++++ .../taler-wallet-webextension/src/platform/api.ts | 4 +- .../src/platform/chrome.ts | 4 +- .../taler-wallet-webextension/src/platform/dev.ts | 2 +- .../src/wallet/Settings.stories.tsx | 18 +++++ .../src/wallet/Settings.tsx | 76 +++++++++++++++++----- packages/taler-wallet-webextension/src/wxApi.ts | 6 +- .../taler-wallet-webextension/src/wxBackend.ts | 2 +- 10 files changed, 137 insertions(+), 24 deletions(-) diff --git a/packages/taler-util/src/walletTypes.ts b/packages/taler-util/src/walletTypes.ts index eefc04595..94a988c67 100644 --- a/packages/taler-util/src/walletTypes.ts +++ b/packages/taler-util/src/walletTypes.ts @@ -571,7 +571,13 @@ export interface DepositInfo { export interface ExchangesListRespose { exchanges: ExchangeListItem[]; } - +export interface WalletCoreVersion { + hash: string | undefined; + version: string; + exchange: string; + merchant: string; + bank: string; +} export interface KnownBankAccounts { accounts: { [payto: string]: PaytoUri }; } diff --git a/packages/taler-wallet-core/rollup.config.js b/packages/taler-wallet-core/rollup.config.js index 3b6eff3a6..c6cd3ccef 100644 --- a/packages/taler-wallet-core/rollup.config.js +++ b/packages/taler-wallet-core/rollup.config.js @@ -5,6 +5,17 @@ import json from "@rollup/plugin-json"; import builtins from "builtin-modules"; import pkg from "./package.json"; import sourcemaps from "rollup-plugin-sourcemaps"; +import replace from '@rollup/plugin-replace'; +import path from "path" +import fs from "fs" + +const BASE = process.cwd() + +let GIT_ROOT = BASE +while (!fs.existsSync(path.join(GIT_ROOT, '.git')) && GIT_ROOT !== '/') { + GIT_ROOT = path.join(GIT_ROOT, '../') +} +const GIT_HASH = GIT_ROOT === '/' ? undefined : git_hash() const nodeEntryPoint = { input: "lib/index.node.js", @@ -21,6 +32,10 @@ const nodeEntryPoint = { }), sourcemaps(), + replace({ + '__VERSION__': `"${pkg.version}"`, + '__GIT_HASH__': `"${GIT_HASH}"`, + }), commonjs({ include: [/node_modules/, /dist/], @@ -61,3 +76,12 @@ const browserEntryPoint = { }; export default [nodeEntryPoint, browserEntryPoint]; + +function git_hash() { + const rev = fs.readFileSync(path.join(GIT_ROOT, '.git', 'HEAD')).toString().trim().split(/.*[: ]/).slice(-1)[0]; + if (rev.indexOf('/') === -1) { + return rev; + } else { + return fs.readFileSync(path.join(GIT_ROOT, '.git', rev)).toString().trim(); + } +} diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index b3fee6bff..688985521 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -86,6 +86,7 @@ import { TalerErrorCode, URL, WalletNotification, + WalletCoreVersion, } from "@gnu-taler/taler-util"; import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js"; import { @@ -206,6 +207,7 @@ import { } from "./util/promiseUtils.js"; import { DbAccess, GetReadWriteAccess } from "./util/query.js"; import { TimerAPI, TimerGroup } from "./util/timer.js"; +import { WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, WALLET_EXCHANGE_PROTOCOL_VERSION, WALLET_MERCHANT_PROTOCOL_VERSION } from "./versions.js"; import { WalletCoreApiClient } from "./wallet-api-types.js"; const builtinAuditors: AuditorTrustRecord[] = [ @@ -714,6 +716,11 @@ export async function getClientFromWalletState( return client; } +declare const __VERSION__: string; +declare const __GIT_HASH__: string; + +const VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "dev"; +const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined; /** * Implementation of the "wallet-core" API. */ @@ -1064,6 +1071,16 @@ async function dispatchRequestInternal( await acceptPeerPullPayment(ws, req); return {}; } + case "getVersion": { + const version: WalletCoreVersion = { + hash: GIT_HASH, + version: VERSION, + exchange: WALLET_EXCHANGE_PROTOCOL_VERSION, + merchant: WALLET_MERCHANT_PROTOCOL_VERSION, + bank: WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, + } + return version; + } } throw TalerError.fromDetail( TalerErrorCode.WALLET_CORE_API_OPERATION_UNKNOWN, diff --git a/packages/taler-wallet-webextension/src/platform/api.ts b/packages/taler-wallet-webextension/src/platform/api.ts index 21f50196b..37f52192f 100644 --- a/packages/taler-wallet-webextension/src/platform/api.ts +++ b/packages/taler-wallet-webextension/src/platform/api.ts @@ -46,7 +46,7 @@ export type MessageFromBackend = { type: NotificationType; }; -export interface WalletVersion { +export interface WalletWebExVersion { version_name?: string | undefined; version: string; } @@ -120,7 +120,7 @@ export interface PlatformAPI { /** * Get the wallet version from manifest */ - getWalletVersion(): WalletVersion; + getWalletWebExVersion(): WalletWebExVersion; /** * Backend API diff --git a/packages/taler-wallet-webextension/src/platform/chrome.ts b/packages/taler-wallet-webextension/src/platform/chrome.ts index f2c7e9d2d..f888d131e 100644 --- a/packages/taler-wallet-webextension/src/platform/chrome.ts +++ b/packages/taler-wallet-webextension/src/platform/chrome.ts @@ -31,7 +31,7 @@ const api: PlatformAPI = { isFirefox, findTalerUriInActiveTab, getPermissionsApi, - getWalletVersion, + getWalletWebExVersion, listenToWalletBackground, notifyWhenAppIsReady, openWalletPage, @@ -338,7 +338,7 @@ interface WalletVersion { version: string; } -function getWalletVersion(): WalletVersion { +function getWalletWebExVersion(): WalletVersion { const manifestData = chrome.runtime.getManifest(); return manifestData; } diff --git a/packages/taler-wallet-webextension/src/platform/dev.ts b/packages/taler-wallet-webextension/src/platform/dev.ts index fce5722c0..e5db0c8ec 100644 --- a/packages/taler-wallet-webextension/src/platform/dev.ts +++ b/packages/taler-wallet-webextension/src/platform/dev.ts @@ -32,7 +32,7 @@ const api: PlatformAPI = { removeHostPermissions: async () => false, requestHostPermissions: async () => false, }), - getWalletVersion: () => ({ + getWalletWebExVersion: () => ({ version: "none", }), notifyWhenAppIsReady: (fn: () => void) => { diff --git a/packages/taler-wallet-webextension/src/wallet/Settings.stories.tsx b/packages/taler-wallet-webextension/src/wallet/Settings.stories.tsx index 5c01b1132..9e85a9bed 100644 --- a/packages/taler-wallet-webextension/src/wallet/Settings.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Settings.stories.tsx @@ -30,16 +30,32 @@ export default { }, }; +const version = { + coreVersion: { + exchange: "12:0:0", + merchant: "2:0:1", + bank: "0:0:0", + hash: "d439c3e1bc743f2aa47de4457953dba6ecb0e20f", + version: "0.9.0-dev.1", + }, + webexVersion: { + version: "0.9.0.13", + hash: "d439c3e1bc743f2aa47de4457953dba6ecb0e20f", + }, +}; + export const AllOff = createExample(TestedComponent, { deviceName: "this-is-the-device-name", permissionToggle: { value: false, button: {} }, setDeviceName: () => Promise.resolve(), + ...version, }); export const OneChecked = createExample(TestedComponent, { deviceName: "this-is-the-device-name", permissionToggle: { value: false, button: {} }, setDeviceName: () => Promise.resolve(), + ...version, }); export const WithOneExchange = createExample(TestedComponent, { @@ -59,6 +75,7 @@ export const WithOneExchange = createExample(TestedComponent, { paytoUris: ["payto://x-taler-bank/bank.rpi.sebasjm.com/exchangeminator"], } as any, //TODO: complete with auditors, wireInfo and denominations ], + ...version, }); export const WithExchangeInDifferentState = createExample(TestedComponent, { @@ -99,4 +116,5 @@ export const WithExchangeInDifferentState = createExample(TestedComponent, { paytoUris: ["payto://x-taler-bank/bank.rpi.sebasjm.com/exchangeminator"], }, ], + ...version, }); diff --git a/packages/taler-wallet-webextension/src/wallet/Settings.tsx b/packages/taler-wallet-webextension/src/wallet/Settings.tsx index 1b75ee6c9..4a520c3bb 100644 --- a/packages/taler-wallet-webextension/src/wallet/Settings.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Settings.tsx @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see */ -import { ExchangeListItem } from "@gnu-taler/taler-util"; +import { ExchangeListItem, WalletCoreVersion } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; import { Checkbox } from "../components/Checkbox.js"; import { ErrorTalerOperation } from "../components/ErrorTalerOperation.js"; @@ -38,26 +38,39 @@ import { ToggleHandler } from "../mui/handlers.js"; import { Pages } from "../NavigationBar.js"; import { buildTermsOfServiceStatus } from "../utils/index.js"; import * as wxApi from "../wxApi.js"; +import { platform } from "../platform/api.js"; + +const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined; export function SettingsPage(): VNode { const permissionToggle = useExtendedPermissions(); const { devMode, toggleDevMode } = useDevContext(); const { name, update } = useBackupDeviceName(); + const webex = platform.getWalletWebExVersion(); - const exchangesHook = useAsyncAsHook(wxApi.listExchanges); + const exchangesHook = useAsyncAsHook(async () => { + const list = await wxApi.listExchanges(); + const version = await wxApi.getVersion(); + return { exchanges: list.exchanges, version }; + }); + const { exchanges, version } = + !exchangesHook || exchangesHook.hasError + ? { exchanges: [], version: undefined } + : exchangesHook.response; return ( ); } @@ -69,14 +82,19 @@ export interface ViewProps { developerMode: boolean; toggleDeveloperMode: () => Promise; knownExchanges: Array; + coreVersion: WalletCoreVersion | undefined; + webexVersion: { + version: string; + hash: string | undefined; + }; } -const VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "dev"; -const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined; export function SettingsView({ knownExchanges, permissionToggle, developerMode, + coreVersion, + webexVersion, toggleDeveloperMode, }: ViewProps): VNode { const { i18n, lang, supportedLang, changeLanguage } = useTranslationContext(); @@ -216,16 +234,42 @@ export function SettingsView({ Version - Release} - text={{VERSION}} - /> - {GIT_HASH && ( + {coreVersion && ( Hash} - text={{GIT_HASH}} + title={Wallet Core} + text={ + + {coreVersion.version}{" "} + {coreVersion.hash} + + } /> )} + Web Extension} + text={ + + {webexVersion.version}{" "} + {webexVersion.hash} + + } + /> + {coreVersion && ( + + Exchange compatibility} + text={{coreVersion.exchange}} + /> + Merchant compatibility} + text={{coreVersion.merchant}} + /> + Bank compatibility} + text={{coreVersion.bank}} + /> + + )} ); diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts index 8c5b9a48c..074dbbfb0 100644 --- a/packages/taler-wallet-webextension/src/wxApi.ts +++ b/packages/taler-wallet-webextension/src/wxApi.ts @@ -65,6 +65,7 @@ import { SetWalletDeviceIdRequest, TransactionsResponse, WalletDiagnostics, + WalletCoreVersion, WithdrawUriInfoResponse, } from "@gnu-taler/taler-util"; import { @@ -77,7 +78,7 @@ import { } from "@gnu-taler/taler-wallet-core"; import type { DepositGroupFees } from "@gnu-taler/taler-wallet-core/src/operations/deposits"; import type { ExchangeWithdrawDetails } from "@gnu-taler/taler-wallet-core/src/operations/withdraw"; -import { platform, MessageFromBackend } from "./platform/api.js"; +import { platform, MessageFromBackend, WalletWebExVersion } from "./platform/api.js"; /** * @@ -249,6 +250,9 @@ export function listKnownCurrencies(): Promise { export function listExchanges(): Promise { return callBackend("listExchanges", {}); } +export function getVersion(): Promise { + return callBackend("getVersion", {}); +} export function listKnownBankAccounts( currency?: string, ): Promise { diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts index ae0103555..0835aae12 100644 --- a/packages/taler-wallet-webextension/src/wxBackend.ts +++ b/packages/taler-wallet-webextension/src/wxBackend.ts @@ -71,7 +71,7 @@ const walletInit: OpenedPromise = openPromise(); const logger = new Logger("wxBackend.ts"); async function getDiagnostics(): Promise { - const manifestData = platform.getWalletVersion(); + const manifestData = platform.getWalletWebExVersion(); const errors: string[] = []; let firefoxIdbProblem = false; let dbOutdated = false; -- cgit v1.2.3