fix: diconnect event

This commit is contained in:
asiaznik
2024-01-15 15:34:18 +01:00
parent ec1032cbd2
commit f743cffcd4
2 changed files with 9 additions and 18 deletions
@@ -1,14 +1,10 @@
import { clearConfig, setConfig } from '../storage';
import type { Transaction, VegaConnector } from './vega-connector';
type VegaWalletEvent = 'disconnect';
type VegaWalletEvent = 'client.disconnected';
declare global {
interface Vega {
/**
* @deprecated
*/
getChainId: () => Promise<{ chainID: string }>;
connectWallet: (args: { chainId: string }) => Promise<null>;
disconnectWallet: () => Promise<void>;
listKeys: () => Promise<{
@@ -59,13 +55,6 @@ export class InjectedConnector implements VegaConnector {
chainId: string | null = null;
description = 'Connects using the Vega wallet browser extension';
/**
* @deprecated
*/
async getChainId() {
return window.vega.getChainId();
}
async connectWallet(chainId: string) {
this.chainId = chainId;
try {
@@ -79,7 +68,7 @@ export class InjectedConnector implements VegaConnector {
}
onDisconnect(cb: () => void) {
window.vega.on('client.disconnect', () => {
window.vega.on('client.disconnected', () => {
this.isConnected = false;
cb();
});
+7 -5
View File
@@ -40,11 +40,13 @@ export const useInjectedConnector = (onConnect: () => void) => {
connector.nodeAddress = new URL(vegaUrl).origin;
}
setStatus(Status.GettingChainId);
const { chainID } = await connector.getChainId();
if (chainID !== appChainId) {
throw InjectedConnectorErrors.INVALID_CHAIN;
// check the chain id for snap connector
if (connector instanceof SnapConnector) {
setStatus(Status.GettingChainId);
const { chainID } = await connector.getChainId();
if (chainID !== appChainId) {
throw InjectedConnectorErrors.INVALID_CHAIN;
}
}
setStatus(Status.Connecting);