wallet-core: currency hint for preset exchanges
This commit is contained in:
parent
671bbf2954
commit
8e70b89593
@ -620,6 +620,12 @@ export interface ExchangeEntryRecord {
|
|||||||
*/
|
*/
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Currency hint for a preset exchange, relevant
|
||||||
|
* when we didn't contact a preset exchange yet.
|
||||||
|
*/
|
||||||
|
presetCurrencyHint?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When did we confirm the last withdrawal from this exchange?
|
* When did we confirm the last withdrawal from this exchange?
|
||||||
*
|
*
|
||||||
|
@ -593,7 +593,7 @@ export function makeExchangeListItem(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
exchangeBaseUrl: r.baseUrl,
|
exchangeBaseUrl: r.baseUrl,
|
||||||
currency: exchangeDetails?.currency,
|
currency: exchangeDetails?.currency ?? r.presetCurrencyHint,
|
||||||
exchangeUpdateStatus,
|
exchangeUpdateStatus,
|
||||||
exchangeEntryStatus,
|
exchangeEntryStatus,
|
||||||
tosStatus: exchangeDetails
|
tosStatus: exchangeDetails
|
||||||
|
@ -309,6 +309,7 @@ export async function downloadExchangeInfo(
|
|||||||
export async function addPresetExchangeEntry(
|
export async function addPresetExchangeEntry(
|
||||||
tx: WalletDbReadWriteTransaction<"exchanges">,
|
tx: WalletDbReadWriteTransaction<"exchanges">,
|
||||||
exchangeBaseUrl: string,
|
exchangeBaseUrl: string,
|
||||||
|
currencyHint?: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let exchange = await tx.exchanges.get(exchangeBaseUrl);
|
let exchange = await tx.exchanges.get(exchangeBaseUrl);
|
||||||
if (!exchange) {
|
if (!exchange) {
|
||||||
@ -316,6 +317,7 @@ export async function addPresetExchangeEntry(
|
|||||||
entryStatus: ExchangeEntryDbRecordStatus.Preset,
|
entryStatus: ExchangeEntryDbRecordStatus.Preset,
|
||||||
updateStatus: ExchangeEntryDbUpdateStatus.Initial,
|
updateStatus: ExchangeEntryDbUpdateStatus.Initial,
|
||||||
baseUrl: exchangeBaseUrl,
|
baseUrl: exchangeBaseUrl,
|
||||||
|
presetCurrencyHint: currencyHint,
|
||||||
detailsPointer: undefined,
|
detailsPointer: undefined,
|
||||||
lastUpdate: undefined,
|
lastUpdate: undefined,
|
||||||
lastKeysEtag: undefined,
|
lastKeysEtag: undefined,
|
||||||
@ -330,7 +332,7 @@ export async function addPresetExchangeEntry(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function provideExchangeRecordInTx(
|
async function provideExchangeRecordInTx(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
tx: GetReadWriteAccess<{
|
tx: GetReadWriteAccess<{
|
||||||
exchanges: typeof WalletStoresV1.exchanges;
|
exchanges: typeof WalletStoresV1.exchanges;
|
||||||
|
@ -254,6 +254,11 @@ export type GetVersionOp = {
|
|||||||
*/
|
*/
|
||||||
export type WalletConfigParameter = RecursivePartial<WalletConfig>;
|
export type WalletConfigParameter = RecursivePartial<WalletConfig>;
|
||||||
|
|
||||||
|
export interface BuiltinExchange {
|
||||||
|
exchangeBaseUrl: string;
|
||||||
|
currencyHint?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface WalletConfig {
|
export interface WalletConfig {
|
||||||
/**
|
/**
|
||||||
* Initialization values useful for a complete startup.
|
* Initialization values useful for a complete startup.
|
||||||
@ -261,7 +266,7 @@ export interface WalletConfig {
|
|||||||
* These are values may be overridden by different wallets
|
* These are values may be overridden by different wallets
|
||||||
*/
|
*/
|
||||||
builtin: {
|
builtin: {
|
||||||
exchanges: string[];
|
exchanges: BuiltinExchange[];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -200,7 +200,6 @@ import {
|
|||||||
downloadTosFromAcceptedFormat,
|
downloadTosFromAcceptedFormat,
|
||||||
getExchangeDetails,
|
getExchangeDetails,
|
||||||
getExchangeRequestTimeout,
|
getExchangeRequestTimeout,
|
||||||
provideExchangeRecordInTx,
|
|
||||||
updateExchangeFromUrl,
|
updateExchangeFromUrl,
|
||||||
updateExchangeFromUrlHandler,
|
updateExchangeFromUrlHandler,
|
||||||
} from "./operations/exchanges.js";
|
} from "./operations/exchanges.js";
|
||||||
@ -535,10 +534,12 @@ async function fillDefaults(ws: InternalWalletState): Promise<void> {
|
|||||||
logger.trace("defaults already applied");
|
logger.trace("defaults already applied");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const baseUrl of ws.config.builtin.exchanges) {
|
for (const exch of ws.config.builtin.exchanges) {
|
||||||
await addPresetExchangeEntry(tx, baseUrl);
|
await addPresetExchangeEntry(
|
||||||
const now = AbsoluteTime.now();
|
tx,
|
||||||
provideExchangeRecordInTx(ws, tx, baseUrl, now);
|
exch.exchangeBaseUrl,
|
||||||
|
exch.currencyHint,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
await tx.config.put({
|
await tx.config.put({
|
||||||
key: ConfigRecordKey.CurrencyDefaultsApplied,
|
key: ConfigRecordKey.CurrencyDefaultsApplied,
|
||||||
@ -1672,7 +1673,12 @@ export class Wallet {
|
|||||||
|
|
||||||
public static defaultConfig: Readonly<WalletConfig> = {
|
public static defaultConfig: Readonly<WalletConfig> = {
|
||||||
builtin: {
|
builtin: {
|
||||||
exchanges: ["https://exchange.demo.taler.net/"],
|
exchanges: [
|
||||||
|
{
|
||||||
|
exchangeBaseUrl: "https://exchange.demo.taler.net/",
|
||||||
|
currencyHint: "KUDOS",
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
features: {
|
features: {
|
||||||
allowHttp: false,
|
allowHttp: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user