diff options
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); |
