diff options
author | Sebastian <sebasjm@gmail.com> | 2022-09-05 10:04:56 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-09-05 13:04:31 -0300 |
commit | e0e33a88db7641775de16f5425bfc08e461a4f75 (patch) | |
tree | 678c656c07e0940706d71c06a5bb6650fee2a8c8 /packages | |
parent | 4a0512884d27f9cf576af00f5a58191b1d189188 (diff) |
adding informantion about the service worker version on the setting page
Diffstat (limited to 'packages')
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 <http://www.gnu.org/licenses/> */ -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 ( <SettingsView - knownExchanges={ - !exchangesHook || exchangesHook.hasError - ? [] - : exchangesHook.response.exchanges - } + knownExchanges={exchanges} deviceName={name} setDeviceName={update} permissionToggle={permissionToggle} developerMode={devMode} toggleDeveloperMode={toggleDevMode} + webexVersion={{ + version: webex.version, + hash: GIT_HASH, + }} + coreVersion={version} /> ); } @@ -69,14 +82,19 @@ export interface ViewProps { developerMode: boolean; toggleDeveloperMode: () => Promise<void>; knownExchanges: Array<ExchangeListItem>; + 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({ <SubTitle> <i18n.Translate>Version</i18n.Translate> </SubTitle> - <Part - title={<i18n.Translate>Release</i18n.Translate>} - text={<span>{VERSION}</span>} - /> - {GIT_HASH && ( + {coreVersion && ( <Part - title={<i18n.Translate>Hash</i18n.Translate>} - text={<span>{GIT_HASH}</span>} + title={<i18n.Translate>Wallet Core</i18n.Translate>} + text={ + <span> + {coreVersion.version}{" "} + <JustInDevMode>{coreVersion.hash}</JustInDevMode> + </span> + } /> )} + <Part + title={<i18n.Translate>Web Extension</i18n.Translate>} + text={ + <span> + {webexVersion.version}{" "} + <JustInDevMode>{webexVersion.hash}</JustInDevMode> + </span> + } + /> + {coreVersion && ( + <JustInDevMode> + <Part + title={<i18n.Translate>Exchange compatibility</i18n.Translate>} + text={<span>{coreVersion.exchange}</span>} + /> + <Part + title={<i18n.Translate>Merchant compatibility</i18n.Translate>} + text={<span>{coreVersion.merchant}</span>} + /> + <Part + title={<i18n.Translate>Bank compatibility</i18n.Translate>} + text={<span>{coreVersion.bank}</span>} + /> + </JustInDevMode> + )} </section> </Fragment> ); 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<ListOfKnownCurrencies> { export function listExchanges(): Promise<ExchangesListRespose> { return callBackend("listExchanges", {}); } +export function getVersion(): Promise<WalletCoreVersion> { + return callBackend("getVersion", {}); +} export function listKnownBankAccounts( currency?: string, ): Promise<KnownBankAccounts> { 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<void> = openPromise<void>(); const logger = new Logger("wxBackend.ts"); async function getDiagnostics(): Promise<WalletDiagnostics> { - const manifestData = platform.getWalletVersion(); + const manifestData = platform.getWalletWebExVersion(); const errors: string[] = []; let firefoxIdbProblem = false; let dbOutdated = false; |