aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/wallet.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-06-28 14:19:12 +0200
committerFlorian Dold <florian@dold.me>2024-06-28 14:19:12 +0200
commit71f9676fc9d80bccc7353487d8527af74d25a02c (patch)
treee08ae9c3c6652ad6e36eaeb87d6941b1d78bc00f /packages/taler-wallet-core/src/wallet.ts
parentad98210b79f350de631e593ef520f5a57a44812e (diff)
downloadwallet-core-71f9676fc9d80bccc7353487d8527af74d25a02c.tar.xz
wallet-core: return currency specification from exchange
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r--packages/taler-wallet-core/src/wallet.ts111
1 files changed, 66 insertions, 45 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index 4e5fdab71..b6167be12 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -38,6 +38,7 @@ import {
DenominationInfo,
Duration,
ExchangesShortListResponse,
+ GetCurrencySpecificationRequest,
GetCurrencySpecificationResponse,
InitResponse,
KnownBankAccounts,
@@ -191,6 +192,7 @@ import {
CoinSourceType,
ConfigRecordKey,
DenominationRecord,
+ WalletDbHelpers,
WalletDbReadOnlyTransaction,
WalletStoresV1,
clearDatabase,
@@ -758,7 +760,7 @@ async function dispatchRequestInternal(
await fillDefaults(wex);
}
const resp: InitResponse = {
- versionInfo: getVersion(wex),
+ versionInfo: handleGetVersion(wex),
};
if (req.config?.lazyTaskLoop) {
@@ -777,7 +779,7 @@ async function dispatchRequestInternal(
exchangeBaseUrl: "https://exchange.test.taler.net/",
});
return {
- versionInfo: getVersion(wex),
+ versionInfo: handleGetVersion(wex),
};
}
case WalletApiOperation.WithdrawTestBalance: {
@@ -1197,48 +1199,8 @@ async function dispatchRequestInternal(
return {};
}
case WalletApiOperation.GetCurrencySpecification: {
- // Ignore result, just validate in this mock implementation
const req = codecForGetCurrencyInfoRequest().decode(payload);
- // Hard-coded mock for KUDOS and TESTKUDOS
- if (req.scope.currency === "KUDOS") {
- const kudosResp: GetCurrencySpecificationResponse = {
- currencySpecification: {
- name: "Kudos (Taler Demonstrator)",
- num_fractional_input_digits: 2,
- num_fractional_normal_digits: 2,
- num_fractional_trailing_zero_digits: 2,
- alt_unit_names: {
- "0": "ク",
- },
- },
- };
- return kudosResp;
- } else if (req.scope.currency === "TESTKUDOS") {
- const testkudosResp: GetCurrencySpecificationResponse = {
- currencySpecification: {
- name: "Test (Taler Unstable Demonstrator)",
- num_fractional_input_digits: 0,
- num_fractional_normal_digits: 0,
- num_fractional_trailing_zero_digits: 0,
- alt_unit_names: {
- "0": "テ",
- },
- },
- };
- return testkudosResp;
- }
- const defaultResp: GetCurrencySpecificationResponse = {
- currencySpecification: {
- name: req.scope.currency,
- num_fractional_input_digits: 2,
- num_fractional_normal_digits: 2,
- num_fractional_trailing_zero_digits: 2,
- alt_unit_names: {
- "0": req.scope.currency,
- },
- },
- };
- return defaultResp;
+ return handleGetCurrencySpecification(wex, req);
}
case WalletApiOperation.ImportBackupRecovery: {
const req = codecForAny().decode(payload);
@@ -1554,7 +1516,7 @@ async function dispatchRequestInternal(
return {};
}
case WalletApiOperation.GetVersion: {
- return getVersion(wex);
+ return handleGetVersion(wex);
}
case WalletApiOperation.TestingWaitTransactionsFinal:
return await waitUntilAllTransactionsFinal(wex);
@@ -1626,7 +1588,66 @@ async function dispatchRequestInternal(
);
}
-export function getVersion(wex: WalletExecutionContext): WalletCoreVersion {
+export async function handleGetCurrencySpecification(
+ wex: WalletExecutionContext,
+ req: GetCurrencySpecificationRequest,
+): Promise<GetCurrencySpecificationResponse> {
+ const spec = await wex.db.runReadOnlyTx(
+ {
+ storeNames: ["currencyInfo"],
+ },
+ async (tx) => {
+ return WalletDbHelpers.getCurrencyInfo(tx, req.scope);
+ },
+ );
+ if (spec) {
+ return {
+ currencySpecification: spec.currencySpec,
+ };
+ }
+ // Hard-coded mock for KUDOS and TESTKUDOS
+ if (req.scope.currency === "KUDOS") {
+ const kudosResp: GetCurrencySpecificationResponse = {
+ currencySpecification: {
+ name: "Kudos (Taler Demonstrator)",
+ num_fractional_input_digits: 2,
+ num_fractional_normal_digits: 2,
+ num_fractional_trailing_zero_digits: 2,
+ alt_unit_names: {
+ "0": "ク",
+ },
+ },
+ };
+ return kudosResp;
+ } else if (req.scope.currency === "TESTKUDOS") {
+ const testkudosResp: GetCurrencySpecificationResponse = {
+ currencySpecification: {
+ name: "Test (Taler Unstable Demonstrator)",
+ num_fractional_input_digits: 0,
+ num_fractional_normal_digits: 0,
+ num_fractional_trailing_zero_digits: 0,
+ alt_unit_names: {
+ "0": "テ",
+ },
+ },
+ };
+ return testkudosResp;
+ }
+ const defaultResp: GetCurrencySpecificationResponse = {
+ currencySpecification: {
+ name: req.scope.currency,
+ num_fractional_input_digits: 2,
+ num_fractional_normal_digits: 2,
+ num_fractional_trailing_zero_digits: 2,
+ alt_unit_names: {
+ "0": req.scope.currency,
+ },
+ },
+ };
+ return defaultResp;
+}
+
+function handleGetVersion(wex: WalletExecutionContext): WalletCoreVersion {
const result: WalletCoreVersion = {
implementationSemver: walletCoreBuildInfo.implementationSemver,
implementationGitHash: walletCoreBuildInfo.implementationGitHash,