From 47fdfc64a2e6a99a44f87974e608bdac5de83759 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 10 Oct 2023 15:08:59 +0200 Subject: [PATCH 1/3] wallet-core: return mock currency specification for KUDOS and TESTKUDOS --- packages/taler-harness/src/index.ts | 1 + packages/taler-util/src/wallet-types.ts | 37 +++++++------ .../taler-wallet-core/src/wallet-api-types.ts | 16 +++--- packages/taler-wallet-core/src/wallet.ts | 52 +++++++++++++++---- 4 files changed, 73 insertions(+), 33 deletions(-) diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts index f06a66a21..076f71355 100644 --- a/packages/taler-harness/src/index.ts +++ b/packages/taler-harness/src/index.ts @@ -581,6 +581,7 @@ deploymentCli logger.error( `unable to create instance ${instanceId}, HTTP status ${createResp.status}`, ); + process.exit(2); } const accountsUrl = new URL( diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index 4811d674f..9a4e15ae1 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -415,24 +415,28 @@ export const codecForScopeInfo = (): Codec => .alternative(ScopeType.Auditor, codecForScopeInfoAuditor()) .build("ScopeInfo"); -export interface GetCurrencyInfoRequest { +export interface GetCurrencySpecificationRequest { scope: ScopeInfo; } export const codecForGetCurrencyInfoRequest = - (): Codec => - buildCodecForObject() + (): Codec => + buildCodecForObject() .property("scope", codecForScopeInfo()) - .build("GetCurrencyInfoRequest"); + .build("GetCurrencySpecificationRequest"); -export interface GetCurrencyInfoResponse { - decimalSeparator: string; - numFractionalDigits: number; - numTinyDigits: number; - /** - * Is the currency name leading or trailing? - */ - isCurrencyNameLeading: boolean; +export interface GetCurrencySpecificationResponse { + currencySpecification: CurrencySpecification; +} + +export interface CurrencySpecification { + decimal_separator: string; + fractional_input_digits: number; + fractional_normal_digits: number; + fractional_trailing_zero_digits: number; + is_currency_name_leading: boolean; + name: string; + alt_unit_names: { [n: number]: string }; } export interface InitRequest { @@ -1605,10 +1609,11 @@ export interface UpdateExchangeEntryRequest { exchangeBaseUrl: string; } -export const codecForUpdateExchangeEntryRequest = (): Codec => - buildCodecForObject() - .property("exchangeBaseUrl", codecForString()) - .build("UpdateExchangeEntryRequest"); +export const codecForUpdateExchangeEntryRequest = + (): Codec => + buildCodecForObject() + .property("exchangeBaseUrl", codecForString()) + .build("UpdateExchangeEntryRequest"); export interface ForceExchangeUpdateRequest { exchangeBaseUrl: string; diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index 375e0a1b2..fadc7aa7f 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -61,8 +61,8 @@ import { GetAmountRequest, GetBalanceDetailRequest, GetContractTermsDetailsRequest, - GetCurrencyInfoRequest, - GetCurrencyInfoResponse, + GetCurrencySpecificationRequest, + GetCurrencySpecificationResponse, GetExchangeTosRequest, GetExchangeTosResult, GetPlanForOperationRequest, @@ -218,7 +218,7 @@ export enum WalletApiOperation { TestingWaitRefreshesFinal = "testingWaitRefreshesFinal", TestingWaitTransactionState = "testingWaitTransactionState", TestingSetTimetravel = "testingSetTimetravel", - GetScopedCurrencyInfo = "getScopedCurrencyInfo", + GetCurrencySpecification = "getCurrencySpecification", ListStoredBackups = "listStoredBackups", CreateStoredBackup = "createStoredBackup", DeleteStoredBackup = "deleteStoredBackup", @@ -627,10 +627,10 @@ export type ListCurrenciesOp = { response: WalletCurrencyInfo; }; -export type GetScopedCurrencyInfoOp = { - op: WalletApiOperation.GetScopedCurrencyInfo; - request: GetCurrencyInfoRequest; - response: GetCurrencyInfoResponse; +export type GetCurrencySpecificationOp = { + op: WalletApiOperation.GetCurrencySpecification; + request: GetCurrencySpecificationRequest; + response: GetCurrencySpecificationResponse; }; // group: Deposits @@ -1136,7 +1136,7 @@ export type WalletOperations = { [WalletApiOperation.TestingWaitRefreshesFinal]: TestingWaitRefreshesFinal; [WalletApiOperation.TestingSetTimetravel]: TestingSetTimetravelOp; [WalletApiOperation.TestingWaitTransactionState]: TestingWaitTransactionStateOp; - [WalletApiOperation.GetScopedCurrencyInfo]: GetScopedCurrencyInfoOp; + [WalletApiOperation.GetCurrencySpecification]: GetCurrencySpecificationOp; [WalletApiOperation.CreateStoredBackup]: CreateStoredBackupsOp; [WalletApiOperation.ListStoredBackups]: ListStoredBackupsOp; [WalletApiOperation.DeleteStoredBackup]: DeleteStoredBackupOp; diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index ead0ee407..42293735e 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -117,7 +117,7 @@ import { sampleWalletCoreTransactions, validateIban, codecForSharePaymentRequest, - GetCurrencyInfoResponse, + GetCurrencySpecificationResponse, codecForGetCurrencyInfoRequest, CreateStoredBackupResponse, StoredBackupList, @@ -1427,16 +1427,50 @@ async function dispatchRequestInternal( await waitTransactionState(ws, req.transactionId, req.txState); return {}; } - case WalletApiOperation.GetScopedCurrencyInfo: { + case WalletApiOperation.GetCurrencySpecification: { // Ignore result, just validate in this mock implementation - codecForGetCurrencyInfoRequest().decode(payload); - const resp: GetCurrencyInfoResponse = { - decimalSeparator: ",", - isCurrencyNameLeading: false, - numFractionalDigits: 2, - numTinyDigits: 1, + const req = codecForGetCurrencyInfoRequest().decode(payload); + // Hard-coded mock for KUDOS and TESTKUDOS + if (req.scope.currency === "KUDOS") { + const kudosResp: GetCurrencySpecificationResponse = { + currencySpecification: { + decimal_separator: ",", + name: "Kudos (Taler Demonstrator)", + fractional_input_digits: 2, + fractional_normal_digits: 2, + fractional_trailing_zero_digits: 2, + is_currency_name_leading: true, + alt_unit_names: { + "0": "ク", + }, + }, + }; + } else if (req.scope.currency === "TESTKUDOS") { + const testkudosResp: GetCurrencySpecificationResponse = { + currencySpecification: { + decimal_separator: ",", + name: "Test (Taler Unstable Demonstrator)", + fractional_input_digits: 0, + fractional_normal_digits: 0, + fractional_trailing_zero_digits: 0, + is_currency_name_leading: true, + alt_unit_names: {}, + }, + }; + return testkudosResp; + } + const defaultResp: GetCurrencySpecificationResponse = { + currencySpecification: { + decimal_separator: ",", + name: "Unknown", + fractional_input_digits: 2, + fractional_normal_digits: 2, + fractional_trailing_zero_digits: 2, + is_currency_name_leading: true, + alt_unit_names: {}, + }, }; - return resp; + return defaultResp; } case WalletApiOperation.ImportBackupRecovery: { const req = codecForAny().decode(payload); From 5d1e0ae008050f75776f8421b3c24a87622cd4d7 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 10 Oct 2023 15:21:20 +0200 Subject: [PATCH 2/3] -modify mock currency spec --- packages/taler-wallet-core/src/wallet.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 42293735e..571bf07ee 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -1445,6 +1445,7 @@ async function dispatchRequestInternal( }, }, }; + return kudosResp; } else if (req.scope.currency === "TESTKUDOS") { const testkudosResp: GetCurrencySpecificationResponse = { currencySpecification: { @@ -1453,7 +1454,7 @@ async function dispatchRequestInternal( fractional_input_digits: 0, fractional_normal_digits: 0, fractional_trailing_zero_digits: 0, - is_currency_name_leading: true, + is_currency_name_leading: false, alt_unit_names: {}, }, }; From 0631187f42921fab0e20be91a95c1d7eacda277f Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 10 Oct 2023 10:34:01 -0300 Subject: [PATCH 3/3] make install for taler-util into taler-js --- bootstrap | 3 ++- packages/taler-util/Makefile | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 packages/taler-util/Makefile diff --git a/bootstrap b/bootstrap index 4b03f0921..217bba297 100755 --- a/bootstrap +++ b/bootstrap @@ -29,5 +29,6 @@ copy_configure "$our_configure" ./configure copy_configure "$our_configure" ./packages/taler-wallet-cli/configure copy_configure "$our_configure" ./packages/anastasis-cli/configure copy_configure "$our_configure" ./packages/demobank-ui/configure -copy_configure "$our_configure" ./packages/merchant-backoffice-ui/configure copy_configure "$our_configure" ./packages/taler-harness/configure +copy_configure "$our_configure" ./packages/taler-util/configure +copy_configure "$our_configure" ./packages/merchant-backoffice-ui/configure diff --git a/packages/taler-util/Makefile b/packages/taler-util/Makefile new file mode 100644 index 000000000..def16c823 --- /dev/null +++ b/packages/taler-util/Makefile @@ -0,0 +1,42 @@ +# This Makefile has been placed in the public domain. + +ifeq ($(TOPLEVEL), yes) + $(info top-level build) + -include ../../.config.mk + override DESTDIR := $(TOP_DESTDIR) +else + $(info package-level build) + -include ../../.config.mk + -include .config.mk +endif + +$(info prefix is $(prefix)) + +all: + @echo use 'make install' to build and install taler-util + +ifndef prefix +.PHONY: warn-noprefix install +warn-noprefix: + @echo "no prefix configured, did you run ./configure?" +install: warn-noprefix +else +LIBDIR = $(prefix)/share/taler-js/taler-util +NODE_DEPS = $(shell jq "(.dependencies|keys|map(\"node_modules/\" + .)|join(\" \"))" package.json -r) +.PHONY: install install-nodeps deps +install-nodeps: + pnpm compile + @echo installing taler-util to $(DESTDIR)$(prefix) + install -d $(DESTDIR)$(LIBDIR)/lib/globbing + install lib/*.* $(DESTDIR)$(LIBDIR)/lib + install lib/globbing/*.* $(DESTDIR)$(LIBDIR)/lib/globbing + install package.json $(DESTDIR)$(LIBDIR) + tar hcf - $(NODE_DEPS) | (cd $(DESTDIR)$(LIBDIR); tar xf -) + +deps: + pnpm install --frozen-lockfile --filter @gnu-taler/taler-util... + pnpm run --filter @gnu-taler/taler-util... compile +install: + $(MAKE) deps + $(MAKE) install-nodeps +endif