fix: diconnect event
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user