diff --git a/libs/wallet/src/connect-dialog/json-rpc-connector-form.tsx b/libs/wallet/src/connect-dialog/json-rpc-connector-form.tsx
index 62abcf658..a9fd6b893 100644
--- a/libs/wallet/src/connect-dialog/json-rpc-connector-form.tsx
+++ b/libs/wallet/src/connect-dialog/json-rpc-connector-form.tsx
@@ -17,7 +17,6 @@ import { useEnvironment } from '@vegaprotocol/environment';
export const ServiceErrors = {
NO_HEALTHY_NODE: 1000,
- CONNECTION_DECLINED: 3001,
REQUEST_PROCESSING: -32000,
};
@@ -158,19 +157,15 @@ const Error = ({
if (error) {
if (error.code === ClientErrors.NO_SERVICE.code) {
title = t('No wallet detected');
- text = t(
- 'No wallet application running at %s',
- connectorUrl || 'unknown host'
- );
+ text = connectorUrl
+ ? t('No wallet application running at %s', connectorUrl)
+ : t('No Vega Wallet application running');
} else if (error.code === ClientErrors.WRONG_NETWORK.code) {
title = t('Wrong network');
text = t(
'To complete your wallet connection, set your wallet network in your app to "%s".',
appChainId
);
- } else if (error.code === ServiceErrors.CONNECTION_DECLINED) {
- title = t('Connection declined');
- text = t('Your wallet connection was rejected');
} else if (error.code === ServiceErrors.NO_HEALTHY_NODE) {
title = error.message;
text = (
@@ -194,12 +189,15 @@ const Error = ({
title = t('Wrong network');
text = (
<>
- {t(`To complete your wallet connection, set your wallet network in your
- app to ${appChainId}.`)}
+ {t(
+ `To complete your wallet connection, set your wallet network in your
+ app to %s.`,
+ appChainId
+ )}
>
);
} else if (error.code === ClientErrors.INVALID_WALLET.code) {
- title = error.message;
+ title = error.title;
const errorData = error.data?.split('\n ') || [];
text = (
@@ -209,15 +207,15 @@ const Error = ({
);
} else {
- title = error.message;
- text = `${error.data || text} (${error.code})`;
+ title = t(error.title);
+ text = t(error.message);
}
}
return (
<>
{text}
+{text}
{tryAgain} > ); diff --git a/libs/wallet/src/connectors/json-rpc-connector.ts b/libs/wallet/src/connectors/json-rpc-connector.ts index d8762b5a9..a9c0dacbf 100644 --- a/libs/wallet/src/connectors/json-rpc-connector.ts +++ b/libs/wallet/src/connectors/json-rpc-connector.ts @@ -63,7 +63,9 @@ export class JsonRpcConnector implements VegaConnector { }), }); } - + get url() { + return this._url || ''; + } async getChainId() { if (!this.client) { throw ClientErrors.NO_CLIENT; @@ -75,8 +77,9 @@ export class JsonRpcConnector implements VegaConnector { const { code = ClientErrors.UNKNOWN.code, message = ClientErrors.UNKNOWN.message, + title, } = err as WalletClientError; - throw new WalletError(message, code); + throw new WalletError(title, code, message); } } @@ -92,8 +95,9 @@ export class JsonRpcConnector implements VegaConnector { const { code = ClientErrors.UNKNOWN.code, message = ClientErrors.UNKNOWN.message, + title, } = err as WalletClientError; - throw new WalletError(message, code); + throw new WalletError(title, code, message); } } @@ -111,8 +115,9 @@ export class JsonRpcConnector implements VegaConnector { const { code = ClientErrors.UNKNOWN.code, message = ClientErrors.UNKNOWN.message, + title, } = err as WalletClientError; - throw new WalletError(message, code); + throw new WalletError(title, code, message); } } @@ -148,17 +153,17 @@ export class JsonRpcConnector implements VegaConnector { try { const result = await fetch(`${this._url}/api/${this.version}/methods`); if (!result.ok) { - const err = ClientErrors.INVALID_WALLET; const sent1 = t( 'The version of the wallet service running at %s is not supported.', this._url as string ); const sent2 = t( - 'Update the wallet software to a version that expose the API version %s.', + 'Update the wallet software to a version that expose the API %s.', this.version ); - err.data = `${sent1}\n ${sent2}`; - throw err; + const data = `${sent1}\n ${sent2}`; + const title = t('Wallet version invalid'); + throw new WalletError(title, ClientErrors.INVALID_WALLET.code, data); } return true; } catch (err) { diff --git a/libs/wallet/src/connectors/vega-connector.ts b/libs/wallet/src/connectors/vega-connector.ts index e64d2fe12..7128b5a8f 100644 --- a/libs/wallet/src/connectors/vega-connector.ts +++ b/libs/wallet/src/connectors/vega-connector.ts @@ -331,14 +331,10 @@ export interface TransactionResponse { sentAt: string; } export class WalletError extends WalletClientError { - override message: string; - override code: number; - data?: string; + data: string; - constructor(message: string, code: number, data?: string) { - super({ code, message, data: data || '' }); - this.message = message; - this.code = code; + constructor(message: string, code: number, data = 'Wallet error') { + super({ code, message, data }); this.data = data; } } diff --git a/package.json b/package.json index 6779bbe18..898f5e226 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@sentry/nextjs": "^6.19.3", "@sentry/react": "^6.19.2", "@sentry/tracing": "^6.19.2", - "@vegaprotocol/wallet-client": "0.1.8", + "@vegaprotocol/wallet-client": "0.1.9", "@walletconnect/ethereum-provider": "^1.7.5", "@web3-react/core": "8.0.20-beta.0", "@web3-react/metamask": "8.0.16-beta.0", diff --git a/yarn.lock b/yarn.lock index 41936e6bc..47a1aa6f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7321,10 +7321,10 @@ "@typescript-eslint/types" "5.40.0" eslint-visitor-keys "^3.3.0" -"@vegaprotocol/wallet-client@0.1.8": - version "0.1.8" - resolved "https://registry.yarnpkg.com/@vegaprotocol/wallet-client/-/wallet-client-0.1.8.tgz#38ca8566d78b9f6694b12ad9364bb34d6482935d" - integrity sha512-FVvDvvlccKyXn0ujhivPUCVnkZYQJxtI1q8OgipNnbmAjU1mLyeuRTBw0Isu330yPI1KppNbW6Qicd8OTHBmxw== +"@vegaprotocol/wallet-client@0.1.9": + version "0.1.9" + resolved "https://registry.yarnpkg.com/@vegaprotocol/wallet-client/-/wallet-client-0.1.9.tgz#8c6a71c8b2222b3de5d73cade8fc6db57e332de9" + integrity sha512-oacfJGT0zHM+1If4I/pgIWi7zzU/3uHy4+sjuFEh8pWI8bWBzCF+mHbOGA6iTM+5/5mhayMFc+YZ9GexH1sBnQ== dependencies: express "4.18.2" nanoid "3.3.4"