summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/main/account-data-cache.ts21
1 files changed, 17 insertions, 4 deletions
diff --git a/gui/src/main/account-data-cache.ts b/gui/src/main/account-data-cache.ts
index 9a3df33d35..a79a934537 100644
--- a/gui/src/main/account-data-cache.ts
+++ b/gui/src/main/account-data-cache.ts
@@ -1,4 +1,4 @@
-import { closeToExpiry } from '../shared/account-expiry';
+import { closeToExpiry, hasExpired } from '../shared/account-expiry';
import { AccountToken, IAccountData, VoucherResponse } from '../shared/daemon-rpc-types';
import { DateComponent, dateByAddingComponent } from '../shared/date-helper';
import log from '../shared/logging';
@@ -11,6 +11,11 @@ interface IAccountFetchWatcher {
onError: (error: Error) => void;
}
+// Account data is valid for 1 minute unless the account has expired.
+const ACCOUNT_DATA_VALIDITY_SECONDS = 60_000;
+// Account data is valid for 10 seconds if the account has expired.
+const ACCOUNT_DATA_EXPIRED_VALIDITY_SECONDS = 10_000;
+
// An account data cache that helps to throttle RPC requests to get_account_data and retain the
// cached value for 1 minute.
export default class AccountDataCache {
@@ -70,9 +75,9 @@ export default class AccountDataCache {
}
}
- private setValue(value: IAccountData) {
- this.validUntil = new Date(Date.now() + 60 * 1000); // 60s expiration
- this.updateHandler(value);
+ private setValue(accountData: IAccountData) {
+ this.validUntil = this.getValidUntil(accountData);
+ this.updateHandler(accountData);
this.notifyWatchers((watcher) => watcher.onFinish());
}
@@ -80,6 +85,14 @@ export default class AccountDataCache {
return this.validUntil && this.validUntil > new Date();
}
+ private getValidUntil(accountData: IAccountData): Date {
+ if (hasExpired(accountData.expiry)) {
+ return new Date(Date.now() + ACCOUNT_DATA_EXPIRED_VALIDITY_SECONDS);
+ } else {
+ return new Date(Date.now() + ACCOUNT_DATA_VALIDITY_SECONDS);
+ }
+ }
+
private async performFetch(accountToken: AccountToken) {
this.performingFetch = true;
try {