summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-02-12 21:13:30 +0100
committerFlorian Dold <florian@dold.me>2023-02-12 21:13:30 +0100
commit79b77a0c3c5a9a07d22c276a63ed81eb30507eba (patch)
tree4614511446ab3fbd7dc64f691b7b7ac271ba32c9
parent13f0442736479fb6ea8d1ecc7311cdac354a4de5 (diff)
downloadwallet-core-79b77a0c3c5a9a07d22c276a63ed81eb30507eba.tar.gz
wallet-core-79b77a0c3c5a9a07d22c276a63ed81eb30507eba.tar.bz2
wallet-core-79b77a0c3c5a9a07d22c276a63ed81eb30507eba.zip
wallet-core: skeleton support for regional currency scopes
-rw-r--r--packages/taler-util/src/wallet-types.ts30
-rw-r--r--packages/taler-wallet-core/src/db.ts35
-rw-r--r--packages/taler-wallet-core/src/operations/balance.ts5
3 files changed, 59 insertions, 11 deletions
diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts
index 0f29b964b..96251540e 100644
--- a/packages/taler-util/src/wallet-types.ts
+++ b/packages/taler-util/src/wallet-types.ts
@@ -27,11 +27,7 @@
/**
* Imports.
*/
-import {
- AmountJson,
- codecForAmountJson,
- codecForAmountString,
-} from "./amounts.js";
+import { AmountJson, codecForAmountString } from "./amounts.js";
import { BackupRecovery } from "./backup-types.js";
import {
buildCodecForObject,
@@ -116,6 +112,7 @@ export const codecForGetBalanceDetailRequest =
.build("GetBalanceDetailRequest");
export interface Balance {
+ scopeInfo: ScopeInfo;
available: AmountString;
pendingIncoming: AmountString;
pendingOutgoing: AmountString;
@@ -137,12 +134,24 @@ export interface InitResponse {
versionInfo: WalletCoreVersion;
}
+export enum ScopeType {
+ Global = "global",
+ Exchange = "exchange",
+ Auditor = "auditor",
+}
+
+export type ScopeInfo =
+ | { type: ScopeType.Global; currency: string }
+ | { type: ScopeType.Exchange; currency: string; url: string }
+ | { type: ScopeType.Auditor; currency: string; url: string };
+
export interface BalancesResponse {
balances: Balance[];
}
export const codecForBalance = (): Codec<Balance> =>
buildCodecForObject<Balance>()
+ .property("scopeInfo", codecForAny()) // FIXME
.property("available", codecForString())
.property("hasPendingTransactions", codecForBoolean())
.property("pendingIncoming", codecForString())
@@ -1423,11 +1432,12 @@ export interface PreparePayTemplateRequest {
templateParams: Record<string, string>;
}
-export const codecForPreparePayTemplateRequest = (): Codec<PreparePayTemplateRequest> =>
- buildCodecForObject<PreparePayTemplateRequest>()
- .property("talerPayTemplateUri", codecForString())
- .property("templateParams", codecForAny())
- .build("PreparePayTemplate");
+export const codecForPreparePayTemplateRequest =
+ (): Codec<PreparePayTemplateRequest> =>
+ buildCodecForObject<PreparePayTemplateRequest>()
+ .property("talerPayTemplateUri", codecForString())
+ .property("templateParams", codecForAny())
+ .build("PreparePayTemplate");
export interface ConfirmPayRequest {
proposalId: string;
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts
index 78c73fba5..8aff18c6d 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -121,7 +121,7 @@ export const CURRENT_DB_CONFIG_KEY = "currentMainDbName";
* backwards-compatible way or object stores and indices
* are added.
*/
-export const WALLET_DB_MINOR_VERSION = 2;
+export const WALLET_DB_MINOR_VERSION = 3;
/**
* Ranges for operation status fields.
@@ -1956,11 +1956,44 @@ export interface UserAttentionRecord {
read: TalerProtocolTimestamp | undefined;
}
+export interface DbExchangeHandle {
+ url: string;
+ exchangeMasterPub: string;
+}
+
+export interface DbAuditorHandle {
+ url: string;
+ auditorPub: string;
+}
+
+// Work in progress for regional currencies
+export interface CurrencySettingsRecord {
+ currency: string;
+
+ globalScopeExchanges: DbExchangeHandle[];
+
+ globalScopeAuditors: DbAuditorHandle[];
+
+ // Used to decide which auditor to show the currency under
+ // when multiple auditors apply.
+ auditorPriority: string[];
+
+ // Later, we might add stuff related to how the currency is rendered.
+}
+
/**
* Schema definition for the IndexedDB
* wallet database.
*/
export const WalletStoresV1 = {
+ currencySettings: describeStore(
+ "currencySettings",
+ describeContents<CurrencySettingsRecord>({
+ keyPath: ["currency"],
+ versionAdded: 3,
+ }),
+ {},
+ ),
coinAvailability: describeStore(
"coinAvailability",
describeContents<CoinAvailabilityRecord>({
diff --git a/packages/taler-wallet-core/src/operations/balance.ts b/packages/taler-wallet-core/src/operations/balance.ts
index 50613d0aa..59c49deaa 100644
--- a/packages/taler-wallet-core/src/operations/balance.ts
+++ b/packages/taler-wallet-core/src/operations/balance.ts
@@ -54,6 +54,7 @@ import {
GetBalanceDetailRequest,
Logger,
parsePaytoUri,
+ ScopeType,
} from "@gnu-taler/taler-util";
import {
AllowedAuditorInfo,
@@ -170,6 +171,10 @@ export async function getBalancesInsideTransaction(
.forEach((c) => {
const v = balanceStore[c];
balancesResponse.balances.push({
+ scopeInfo: {
+ type: ScopeType.Global,
+ currency: Amounts.currencyOf(v.available),
+ },
available: Amounts.stringify(v.available),
pendingIncoming: Amounts.stringify(v.pendingIncoming),
pendingOutgoing: Amounts.stringify(v.pendingOutgoing),