wallet-core: skeleton support for regional currency scopes
This commit is contained in:
parent
13f0442736
commit
79b77a0c3c
@ -27,11 +27,7 @@
|
|||||||
/**
|
/**
|
||||||
* Imports.
|
* Imports.
|
||||||
*/
|
*/
|
||||||
import {
|
import { AmountJson, codecForAmountString } from "./amounts.js";
|
||||||
AmountJson,
|
|
||||||
codecForAmountJson,
|
|
||||||
codecForAmountString,
|
|
||||||
} from "./amounts.js";
|
|
||||||
import { BackupRecovery } from "./backup-types.js";
|
import { BackupRecovery } from "./backup-types.js";
|
||||||
import {
|
import {
|
||||||
buildCodecForObject,
|
buildCodecForObject,
|
||||||
@ -116,6 +112,7 @@ export const codecForGetBalanceDetailRequest =
|
|||||||
.build("GetBalanceDetailRequest");
|
.build("GetBalanceDetailRequest");
|
||||||
|
|
||||||
export interface Balance {
|
export interface Balance {
|
||||||
|
scopeInfo: ScopeInfo;
|
||||||
available: AmountString;
|
available: AmountString;
|
||||||
pendingIncoming: AmountString;
|
pendingIncoming: AmountString;
|
||||||
pendingOutgoing: AmountString;
|
pendingOutgoing: AmountString;
|
||||||
@ -137,12 +134,24 @@ export interface InitResponse {
|
|||||||
versionInfo: WalletCoreVersion;
|
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 {
|
export interface BalancesResponse {
|
||||||
balances: Balance[];
|
balances: Balance[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const codecForBalance = (): Codec<Balance> =>
|
export const codecForBalance = (): Codec<Balance> =>
|
||||||
buildCodecForObject<Balance>()
|
buildCodecForObject<Balance>()
|
||||||
|
.property("scopeInfo", codecForAny()) // FIXME
|
||||||
.property("available", codecForString())
|
.property("available", codecForString())
|
||||||
.property("hasPendingTransactions", codecForBoolean())
|
.property("hasPendingTransactions", codecForBoolean())
|
||||||
.property("pendingIncoming", codecForString())
|
.property("pendingIncoming", codecForString())
|
||||||
@ -1423,11 +1432,12 @@ export interface PreparePayTemplateRequest {
|
|||||||
templateParams: Record<string, string>;
|
templateParams: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const codecForPreparePayTemplateRequest = (): Codec<PreparePayTemplateRequest> =>
|
export const codecForPreparePayTemplateRequest =
|
||||||
buildCodecForObject<PreparePayTemplateRequest>()
|
(): Codec<PreparePayTemplateRequest> =>
|
||||||
.property("talerPayTemplateUri", codecForString())
|
buildCodecForObject<PreparePayTemplateRequest>()
|
||||||
.property("templateParams", codecForAny())
|
.property("talerPayTemplateUri", codecForString())
|
||||||
.build("PreparePayTemplate");
|
.property("templateParams", codecForAny())
|
||||||
|
.build("PreparePayTemplate");
|
||||||
|
|
||||||
export interface ConfirmPayRequest {
|
export interface ConfirmPayRequest {
|
||||||
proposalId: string;
|
proposalId: string;
|
||||||
|
@ -121,7 +121,7 @@ export const CURRENT_DB_CONFIG_KEY = "currentMainDbName";
|
|||||||
* backwards-compatible way or object stores and indices
|
* backwards-compatible way or object stores and indices
|
||||||
* are added.
|
* are added.
|
||||||
*/
|
*/
|
||||||
export const WALLET_DB_MINOR_VERSION = 2;
|
export const WALLET_DB_MINOR_VERSION = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ranges for operation status fields.
|
* Ranges for operation status fields.
|
||||||
@ -1956,11 +1956,44 @@ export interface UserAttentionRecord {
|
|||||||
read: TalerProtocolTimestamp | undefined;
|
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
|
* Schema definition for the IndexedDB
|
||||||
* wallet database.
|
* wallet database.
|
||||||
*/
|
*/
|
||||||
export const WalletStoresV1 = {
|
export const WalletStoresV1 = {
|
||||||
|
currencySettings: describeStore(
|
||||||
|
"currencySettings",
|
||||||
|
describeContents<CurrencySettingsRecord>({
|
||||||
|
keyPath: ["currency"],
|
||||||
|
versionAdded: 3,
|
||||||
|
}),
|
||||||
|
{},
|
||||||
|
),
|
||||||
coinAvailability: describeStore(
|
coinAvailability: describeStore(
|
||||||
"coinAvailability",
|
"coinAvailability",
|
||||||
describeContents<CoinAvailabilityRecord>({
|
describeContents<CoinAvailabilityRecord>({
|
||||||
|
@ -54,6 +54,7 @@ import {
|
|||||||
GetBalanceDetailRequest,
|
GetBalanceDetailRequest,
|
||||||
Logger,
|
Logger,
|
||||||
parsePaytoUri,
|
parsePaytoUri,
|
||||||
|
ScopeType,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
AllowedAuditorInfo,
|
AllowedAuditorInfo,
|
||||||
@ -170,6 +171,10 @@ export async function getBalancesInsideTransaction(
|
|||||||
.forEach((c) => {
|
.forEach((c) => {
|
||||||
const v = balanceStore[c];
|
const v = balanceStore[c];
|
||||||
balancesResponse.balances.push({
|
balancesResponse.balances.push({
|
||||||
|
scopeInfo: {
|
||||||
|
type: ScopeType.Global,
|
||||||
|
currency: Amounts.currencyOf(v.available),
|
||||||
|
},
|
||||||
available: Amounts.stringify(v.available),
|
available: Amounts.stringify(v.available),
|
||||||
pendingIncoming: Amounts.stringify(v.pendingIncoming),
|
pendingIncoming: Amounts.stringify(v.pendingIncoming),
|
||||||
pendingOutgoing: Amounts.stringify(v.pendingOutgoing),
|
pendingOutgoing: Amounts.stringify(v.pendingOutgoing),
|
||||||
|
Loading…
Reference in New Issue
Block a user