diff --git a/libs/react-helpers/src/lib/vega-wallet/connectors.ts b/libs/react-helpers/src/lib/vega-wallet/connectors.ts index 38946e073..99410d130 100644 --- a/libs/react-helpers/src/lib/vega-wallet/connectors.ts +++ b/libs/react-helpers/src/lib/vega-wallet/connectors.ts @@ -7,7 +7,7 @@ import { import { LocalStorage } from '@vegaprotocol/storage'; export interface VegaConnector { - connect(): Promise; + connect(): Promise; disconnect(): Promise; } @@ -46,13 +46,26 @@ export class RestConnector implements VegaConnector { } async connect() { - const res = await this.service.keysGet(); - return res.keys; + try { + const res = await this.service.keysGet(); + return res.keys; + } catch (err) { + console.error(err); + // keysGet failed, its likely that the session has expired so remove the token from storage + LocalStorage.removeItem('vega_wallet_token'); + return null; + } } async disconnect() { - await this.service.authTokenDelete(); - LocalStorage.removeItem('vega_wallet_token'); + try { + await this.service.authTokenDelete(); + } catch (err) { + console.error(err); + } finally { + // Always clear the tokens + LocalStorage.removeItem('vega_wallet_token'); + } } } diff --git a/libs/react-helpers/src/lib/vega-wallet/rest-connector-form.tsx b/libs/react-helpers/src/lib/vega-wallet/rest-connector-form.tsx index c69849f4f..53dd38770 100644 --- a/libs/react-helpers/src/lib/vega-wallet/rest-connector-form.tsx +++ b/libs/react-helpers/src/lib/vega-wallet/rest-connector-form.tsx @@ -19,7 +19,12 @@ export function RestConnectorForm({ register, handleSubmit, formState: { errors }, - } = useForm(); + } = useForm({ + defaultValues: { + wallet: 'test6', + passphrase: '123', + }, + }); async function onSubmit(fields: FormFields) { try {