summaryrefslogtreecommitdiffhomepage
path: root/gui/src/main
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-06-15 11:44:25 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-06-28 09:00:49 +0200
commitbb7fe6f9054d5fb3735fd6836c137885620076d6 (patch)
treea610f18134720bf5979aa79646290bcfe4ae9444 /gui/src/main
parent069126aeb673fe070b28481d8339b875aabb0585 (diff)
downloadmullvadvpn-bb7fe6f9054d5fb3735fd6836c137885620076d6.tar.xz
mullvadvpn-bb7fe6f9054d5fb3735fd6836c137885620076d6.zip
Properly add new expiry to account data cache after redeeming voucher
Diffstat (limited to 'gui/src/main')
-rw-r--r--gui/src/main/account-data-cache.ts8
-rw-r--r--gui/src/main/index.ts13
2 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 7d3c59e5ef..8b81a29472 100644
--- a/gui/src/main/account-data-cache.ts
+++ b/gui/src/main/account-data-cache.ts
@@ -1,5 +1,5 @@
import { closeToExpiry, hasExpired } from '../shared/account-expiry';
-import { AccountToken, IAccountData } from '../shared/daemon-rpc-types';
+import { AccountToken, IAccountData, VoucherResponse } from '../shared/daemon-rpc-types';
import { DateComponent, dateByAddingComponent } from '../shared/date-helper';
import log from '../shared/logging';
import consumePromise from '../shared/promise';
@@ -66,6 +66,12 @@ export default class AccountDataCache {
});
}
+ public handleVoucherResponse(accountToken: AccountToken, voucherResponse: VoucherResponse) {
+ if (accountToken === this.currentAccount && voucherResponse.type === 'success') {
+ this.setValue({ expiry: voucherResponse.newExpiry });
+ }
+ }
+
private setValue(value: IAccountData) {
this.expiresAt = new Date(Date.now() + 60 * 1000); // 60s expiration
this.updateHandler(value);
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index d86a6cba53..cbf798f6f2 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -1124,9 +1124,16 @@ class ApplicationMain {
IpcMainEventChannel.account.handleLogin((token: AccountToken) => this.login(token));
IpcMainEventChannel.account.handleLogout(() => this.logout());
IpcMainEventChannel.account.handleGetWwwAuthToken(() => this.daemonRpc.getWwwAuthToken());
- IpcMainEventChannel.account.handleSubmitVoucher((voucherCode: string) =>
- this.daemonRpc.submitVoucher(voucherCode),
- );
+ IpcMainEventChannel.account.handleSubmitVoucher(async (voucherCode: string) => {
+ const currentAccountToken = this.settings.accountToken;
+ const response = await this.daemonRpc.submitVoucher(voucherCode);
+
+ if (currentAccountToken) {
+ this.accountDataCache.handleVoucherResponse(currentAccountToken, response);
+ }
+
+ return response;
+ });
IpcMainEventChannel.accountHistory.handleClear(async () => {
await this.daemonRpc.clearAccountHistory();