towards auto-refresh
This commit is contained in:
parent
8a3ac7f08b
commit
09b5bfe0db
@ -92,7 +92,8 @@ async function gatherExchangePending(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (e.details && e.details.nextUpdateTime.t_ms < now.t_ms) {
|
const keysUpdateRequired = e.details && e.details.nextUpdateTime.t_ms < now.t_ms;
|
||||||
|
if (keysUpdateRequired) {
|
||||||
resp.pendingOperations.push({
|
resp.pendingOperations.push({
|
||||||
type: PendingOperationType.ExchangeUpdate,
|
type: PendingOperationType.ExchangeUpdate,
|
||||||
givesLifeness: false,
|
givesLifeness: false,
|
||||||
|
@ -634,3 +634,8 @@ export async function createRefreshGroup(
|
|||||||
refreshGroupId,
|
refreshGroupId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function autoRefresh(
|
||||||
|
ws: InternalWalletState,
|
||||||
|
exchangeBaseUrl: string,
|
||||||
|
): Promise<void> {}
|
||||||
|
@ -620,6 +620,8 @@ async function processWithdrawGroupImpl(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await updateExchangeFromUrl(ws, withdrawalGroup.exchangeBaseUrl);
|
||||||
|
|
||||||
const numTotalCoins = withdrawalGroup.denomsSel.selectedDenoms
|
const numTotalCoins = withdrawalGroup.denomsSel.selectedDenoms
|
||||||
.map((x) => x.count)
|
.map((x) => x.count)
|
||||||
.reduce((a, b) => a + b);
|
.reduce((a, b) => a + b);
|
||||||
|
@ -648,6 +648,14 @@ export interface ExchangeRecord {
|
|||||||
* Retry status for fetching updated information about the exchange.
|
* Retry status for fetching updated information about the exchange.
|
||||||
*/
|
*/
|
||||||
retryInfo: RetryInfo;
|
retryInfo: RetryInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Next time that we should check if coins need to be refreshed.
|
||||||
|
*
|
||||||
|
* Updated whenever the exchange's denominations are updated or when
|
||||||
|
* the refresh check has been done.
|
||||||
|
*/
|
||||||
|
nextRefreshCheck?: Timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ import { Timestamp, Duration } from "../util/time";
|
|||||||
export enum PendingOperationType {
|
export enum PendingOperationType {
|
||||||
Bug = "bug",
|
Bug = "bug",
|
||||||
ExchangeUpdate = "exchange-update",
|
ExchangeUpdate = "exchange-update",
|
||||||
|
ExchangeCheckRefresh = "exchange-check-refresh",
|
||||||
Pay = "pay",
|
Pay = "pay",
|
||||||
ProposalChoice = "proposal-choice",
|
ProposalChoice = "proposal-choice",
|
||||||
ProposalDownload = "proposal-download",
|
ProposalDownload = "proposal-download",
|
||||||
@ -47,6 +48,7 @@ export type PendingOperationInfo = PendingOperationInfoCommon &
|
|||||||
(
|
(
|
||||||
| PendingBugOperation
|
| PendingBugOperation
|
||||||
| PendingExchangeUpdateOperation
|
| PendingExchangeUpdateOperation
|
||||||
|
| PendingExchangeCheckRefreshOperation
|
||||||
| PendingPayOperation
|
| PendingPayOperation
|
||||||
| PendingProposalChoiceOperation
|
| PendingProposalChoiceOperation
|
||||||
| PendingProposalDownloadOperation
|
| PendingProposalDownloadOperation
|
||||||
@ -70,6 +72,15 @@ export interface PendingExchangeUpdateOperation {
|
|||||||
lastError: TalerErrorDetails | undefined;
|
lastError: TalerErrorDetails | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The wallet should check whether coins from this exchange
|
||||||
|
* need to be auto-refreshed.
|
||||||
|
*/
|
||||||
|
export interface PendingExchangeCheckRefreshOperation {
|
||||||
|
type: PendingOperationType.ExchangeCheckRefresh;
|
||||||
|
exchangeBaseUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some interal error happened in the wallet. This pending operation
|
* Some interal error happened in the wallet. This pending operation
|
||||||
* should *only* be reported for problems in the wallet, not when
|
* should *only* be reported for problems in the wallet, not when
|
||||||
|
@ -89,22 +89,25 @@ export function timestampMax(t1: Timestamp, t2: Timestamp): Timestamp {
|
|||||||
const SECONDS = 1000
|
const SECONDS = 1000
|
||||||
const MINUTES = SECONDS * 60;
|
const MINUTES = SECONDS * 60;
|
||||||
const HOURS = MINUTES * 60;
|
const HOURS = MINUTES * 60;
|
||||||
|
const DAYS = HOURS * 24;
|
||||||
|
const MONTHS = DAYS * 30;
|
||||||
|
const YEARS = DAYS * 365;
|
||||||
|
|
||||||
export function durationFromSpec(spec: {
|
export function durationFromSpec(spec: {
|
||||||
seconds?: number,
|
seconds?: number,
|
||||||
hours?: number,
|
|
||||||
minutes?: number,
|
minutes?: number,
|
||||||
|
hours?: number,
|
||||||
|
days?: number,
|
||||||
|
months?: number,
|
||||||
|
years?: number,
|
||||||
}): Duration {
|
}): Duration {
|
||||||
let d_ms = 0;
|
let d_ms = 0;
|
||||||
if (spec.seconds) {
|
d_ms += (spec.seconds ?? 0) * SECONDS;
|
||||||
d_ms += spec.seconds * SECONDS;
|
d_ms += (spec.minutes ?? 0) * MINUTES;
|
||||||
}
|
d_ms += (spec.hours ?? 0) * HOURS;
|
||||||
if (spec.minutes) {
|
d_ms += (spec.days ?? 0) * DAYS;
|
||||||
d_ms += spec.minutes * MINUTES;
|
d_ms += (spec.months ?? 0) * MONTHS;
|
||||||
}
|
d_ms += (spec.years ?? 0) * YEARS;
|
||||||
if (spec.hours) {
|
|
||||||
d_ms += spec.hours * HOURS;
|
|
||||||
}
|
|
||||||
return { d_ms };
|
return { d_ms };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ import {
|
|||||||
|
|
||||||
import { InternalWalletState } from "./operations/state";
|
import { InternalWalletState } from "./operations/state";
|
||||||
import { createReserve } from "./operations/reserves";
|
import { createReserve } from "./operations/reserves";
|
||||||
import { processRefreshGroup, createRefreshGroup } from "./operations/refresh";
|
import { processRefreshGroup, createRefreshGroup, autoRefresh } from "./operations/refresh";
|
||||||
import { processWithdrawGroup } from "./operations/withdraw";
|
import { processWithdrawGroup } from "./operations/withdraw";
|
||||||
import { getPendingOperations } from "./operations/pending";
|
import { getPendingOperations } from "./operations/pending";
|
||||||
import { getBalances } from "./operations/balance";
|
import { getBalances } from "./operations/balance";
|
||||||
@ -267,6 +267,9 @@ export class Wallet {
|
|||||||
case PendingOperationType.Recoup:
|
case PendingOperationType.Recoup:
|
||||||
await processRecoupGroup(this.ws, pending.recoupGroupId, forceNow);
|
await processRecoupGroup(this.ws, pending.recoupGroupId, forceNow);
|
||||||
break;
|
break;
|
||||||
|
case PendingOperationType.ExchangeCheckRefresh:
|
||||||
|
await autoRefresh(this.ws, pending.exchangeBaseUrl)
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assertUnreachable(pending);
|
assertUnreachable(pending);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user