diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-04-06 18:06:32 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-04-06 18:06:32 +0200 |
| commit | faaa5d91fe49f7b104d21dd868ad649b26fd0f98 (patch) | |
| tree | cb855987a10e2d546fa46d7d632d282217a6386e /gui/src/main | |
| parent | 6157a809ad6eb5cdb06b7fcaea9549b3f100f07a (diff) | |
| parent | e09e863cc858f8d04a1963c629328f77ae383f51 (diff) | |
| download | mullvadvpn-faaa5d91fe49f7b104d21dd868ad649b26fd0f98.tar.xz mullvadvpn-faaa5d91fe49f7b104d21dd868ad649b26fd0f98.zip | |
Merge branch 'add-submit-voucher-function'
Diffstat (limited to 'gui/src/main')
| -rw-r--r-- | gui/src/main/daemon-rpc.ts | 25 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 3 |
2 files changed, 28 insertions, 0 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts index 02b9deceec..5db6f621c2 100644 --- a/gui/src/main/daemon-rpc.ts +++ b/gui/src/main/daemon-rpc.ts @@ -12,6 +12,8 @@ import { KeygenEvent, RelaySettingsUpdate, TunnelState, + VoucherErrorCode, + VoucherResponse, } from '../shared/daemon-rpc-types'; import { CommunicationError, InvalidAccountError, NoDaemonError } from './errors'; import JsonRpcClient, { @@ -227,6 +229,10 @@ const accountDataSchema = partialObject({ expiry: string, }); +const voucherResponseSchema = partialObject({ + new_expiry: string, +}); + const tunnelStateSchema = oneOf( object({ state: enumeration('disconnecting'), @@ -443,6 +449,25 @@ export class DaemonRpc { } } + public async submitVoucher(voucherCode: string): Promise<VoucherResponse> { + try { + const response = await this.transport.send('submit_voucher', voucherCode); + const new_expiry = validate(voucherResponseSchema, response).new_expiry; + return { type: 'success', new_expiry }; + } catch (error) { + if (error instanceof JsonRpcRemoteError) { + switch (error.code) { + case VoucherErrorCode.Invalid: + return { type: 'invalid' }; + case VoucherErrorCode.AlreadyUsed: + return { type: 'already_used' }; + } + } + } + + return { type: 'error' }; + } + public async getRelayLocations(): Promise<IRelayList> { const response = await this.transport.send('get_relay_locations'); try { diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 28956d8c88..2c3d71e628 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -995,6 +995,9 @@ class ApplicationMain { IpcMainEventChannel.account.handleLogin((token: AccountToken) => this.login(token)); IpcMainEventChannel.account.handleLogout(() => this.logout()); IpcMainEventChannel.account.handleWwwAuthToken(() => this.daemonRpc.getWwwAuthToken()); + IpcMainEventChannel.account.handleSubmitVoucher((voucherCode: string) => + this.daemonRpc.submitVoucher(voucherCode), + ); IpcMainEventChannel.accountHistory.handleRemoveItem(async (token: AccountToken) => { await this.daemonRpc.removeAccountFromHistory(token); |
