fix(trading,wallet): improve errors from browser wallet (#5995)
This commit is contained in:
parent
3e2e3c3970
commit
49fdd0f68a
@ -23,6 +23,7 @@ interface InjectedError {
|
|||||||
message: string;
|
message: string;
|
||||||
code: number;
|
code: number;
|
||||||
}
|
}
|
||||||
|
| string[]
|
||||||
| string;
|
| string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +49,11 @@ export class InjectedConnector implements Connector {
|
|||||||
if (err instanceof ConnectorError) {
|
if (err instanceof ConnectorError) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.isInjectedError(err)) {
|
||||||
|
throw connectError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
throw connectError();
|
throw connectError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,6 +72,10 @@ export class InjectedConnector implements Connector {
|
|||||||
const res = await window.vega.getChainId();
|
const res = await window.vega.getChainId();
|
||||||
return { chainId: res.chainID };
|
return { chainId: res.chainID };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (this.isInjectedError(err)) {
|
||||||
|
throw connectError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
throw chainIdError();
|
throw chainIdError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,6 +94,10 @@ export class InjectedConnector implements Connector {
|
|||||||
const res = await window.vega.isConnected();
|
const res = await window.vega.isConnected();
|
||||||
return { connected: res };
|
return { connected: res };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (this.isInjectedError(err)) {
|
||||||
|
throw connectError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
throw isConnectedError();
|
throw isConnectedError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,11 +118,7 @@ export class InjectedConnector implements Connector {
|
|||||||
throw userRejectedError();
|
throw userRejectedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof err.data === 'string') {
|
throw sendTransactionError(JSON.stringify(err.data));
|
||||||
throw sendTransactionError(err.data);
|
|
||||||
} else {
|
|
||||||
throw sendTransactionError(err.data.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw sendTransactionError();
|
throw sendTransactionError();
|
||||||
|
@ -902,6 +902,7 @@ const VegaTxErrorToastContent = ({ tx }: VegaTxToastContentProps) => {
|
|||||||
const t = useT();
|
const t = useT();
|
||||||
let label = t('Error occurred');
|
let label = t('Error occurred');
|
||||||
let errorMessage = tx.error?.message;
|
let errorMessage = tx.error?.message;
|
||||||
|
const errorData = tx.error instanceof ConnectorError ? tx.error.data : '';
|
||||||
|
|
||||||
const reconnectVegaWallet = useReconnect();
|
const reconnectVegaWallet = useReconnect();
|
||||||
|
|
||||||
@ -912,7 +913,7 @@ const VegaTxErrorToastContent = ({ tx }: VegaTxToastContentProps) => {
|
|||||||
ConnectorErrors.noConnector.code,
|
ConnectorErrors.noConnector.code,
|
||||||
];
|
];
|
||||||
|
|
||||||
const walletError =
|
const noConnectionError =
|
||||||
tx.error instanceof ConnectorError &&
|
tx.error instanceof ConnectorError &&
|
||||||
walletNoConnectionCodes.includes(tx.error.code);
|
walletNoConnectionCodes.includes(tx.error.code);
|
||||||
|
|
||||||
@ -926,7 +927,7 @@ const VegaTxErrorToastContent = ({ tx }: VegaTxToastContentProps) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (walletError) {
|
if (noConnectionError) {
|
||||||
label = t('Wallet disconnected');
|
label = t('Wallet disconnected');
|
||||||
errorMessage = t('The connection to your Vega Wallet has been lost.');
|
errorMessage = t('The connection to your Vega Wallet has been lost.');
|
||||||
}
|
}
|
||||||
@ -935,7 +936,8 @@ const VegaTxErrorToastContent = ({ tx }: VegaTxToastContentProps) => {
|
|||||||
<>
|
<>
|
||||||
<ToastHeading>{label}</ToastHeading>
|
<ToastHeading>{label}</ToastHeading>
|
||||||
<p className="first-letter:uppercase">{errorMessage}</p>
|
<p className="first-letter:uppercase">{errorMessage}</p>
|
||||||
{walletError && (
|
{errorData && <p className="first-letter:uppercase">{errorData}</p>}
|
||||||
|
{noConnectionError && (
|
||||||
<Button size="xs" onClick={reconnectVegaWallet}>
|
<Button size="xs" onClick={reconnectVegaWallet}>
|
||||||
{t('Connect vega wallet')}
|
{t('Connect vega wallet')}
|
||||||
</Button>
|
</Button>
|
||||||
|
Loading…
Reference in New Issue
Block a user