fix(trading,wallet): improve errors from browser wallet (#5995)

This commit is contained in:
Matthew Russell 2024-03-14 10:36:39 +00:00 committed by GitHub
parent 3e2e3c3970
commit 49fdd0f68a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 8 deletions

View File

@ -23,6 +23,7 @@ interface InjectedError {
message: string;
code: number;
}
| string[]
| string;
}
@ -48,6 +49,11 @@ export class InjectedConnector implements Connector {
if (err instanceof ConnectorError) {
throw err;
}
if (this.isInjectedError(err)) {
throw connectError(err.message);
}
throw connectError();
}
}
@ -66,6 +72,10 @@ export class InjectedConnector implements Connector {
const res = await window.vega.getChainId();
return { chainId: res.chainID };
} catch (err) {
if (this.isInjectedError(err)) {
throw connectError(err.message);
}
throw chainIdError();
}
}
@ -84,6 +94,10 @@ export class InjectedConnector implements Connector {
const res = await window.vega.isConnected();
return { connected: res };
} catch (err) {
if (this.isInjectedError(err)) {
throw connectError(err.message);
}
throw isConnectedError();
}
}
@ -104,11 +118,7 @@ export class InjectedConnector implements Connector {
throw userRejectedError();
}
if (typeof err.data === 'string') {
throw sendTransactionError(err.data);
} else {
throw sendTransactionError(err.data.message);
}
throw sendTransactionError(JSON.stringify(err.data));
}
throw sendTransactionError();

View File

@ -902,6 +902,7 @@ const VegaTxErrorToastContent = ({ tx }: VegaTxToastContentProps) => {
const t = useT();
let label = t('Error occurred');
let errorMessage = tx.error?.message;
const errorData = tx.error instanceof ConnectorError ? tx.error.data : '';
const reconnectVegaWallet = useReconnect();
@ -912,7 +913,7 @@ const VegaTxErrorToastContent = ({ tx }: VegaTxToastContentProps) => {
ConnectorErrors.noConnector.code,
];
const walletError =
const noConnectionError =
tx.error instanceof ConnectorError &&
walletNoConnectionCodes.includes(tx.error.code);
@ -926,7 +927,7 @@ const VegaTxErrorToastContent = ({ tx }: VegaTxToastContentProps) => {
);
}
if (walletError) {
if (noConnectionError) {
label = t('Wallet disconnected');
errorMessage = t('The connection to your Vega Wallet has been lost.');
}
@ -935,7 +936,8 @@ const VegaTxErrorToastContent = ({ tx }: VegaTxToastContentProps) => {
<>
<ToastHeading>{label}</ToastHeading>
<p className="first-letter:uppercase">{errorMessage}</p>
{walletError && (
{errorData && <p className="first-letter:uppercase">{errorData}</p>}
{noConnectionError && (
<Button size="xs" onClick={reconnectVegaWallet}>
{t('Connect vega wallet')}
</Button>