chore: improve handling wallet errors in connection dialog - use api errors
This commit is contained in:
@@ -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 = (
|
||||
<span className="flex flex-col">
|
||||
@@ -209,15 +207,15 @@ const Error = ({
|
||||
</span>
|
||||
);
|
||||
} else {
|
||||
title = error.message;
|
||||
text = `${error.data || text} (${error.code})`;
|
||||
title = t(error.title);
|
||||
text = t(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ConnectDialogTitle>{title}</ConnectDialogTitle>
|
||||
<p className="text-center mb-2">{text}</p>
|
||||
<p className="text-center mb-2 first-letter:uppercase">{text}</p>
|
||||
{tryAgain}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user