refactor: simplify by using higher-level provider.disconnect
This commit is contained in:
parent
9172b368b9
commit
bf553a2c2d
@ -51,6 +51,7 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
|
|||||||
const [pairings, setPairings] = useState<string[]>([]);
|
const [pairings, setPairings] = useState<string[]>([]);
|
||||||
const [session, setSession] = useState<SessionTypes.Created>();
|
const [session, setSession] = useState<SessionTypes.Created>();
|
||||||
|
|
||||||
|
const [ethereumProvider, setEthereumProvider] = useState<EthereumProvider>();
|
||||||
const [web3Provider, setWeb3Provider] = useState<providers.Web3Provider>();
|
const [web3Provider, setWeb3Provider] = useState<providers.Web3Provider>();
|
||||||
|
|
||||||
const [isFetchingBalances, setIsFetchingBalances] = useState(false);
|
const [isFetchingBalances, setIsFetchingBalances] = useState(false);
|
||||||
@ -70,15 +71,11 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
|
|||||||
};
|
};
|
||||||
|
|
||||||
const disconnect = useCallback(async () => {
|
const disconnect = useCallback(async () => {
|
||||||
if (typeof client === "undefined") {
|
if (typeof ethereumProvider === "undefined") {
|
||||||
throw new Error("WalletConnect is not initialized");
|
throw new Error("ethereumProvider is not initialized");
|
||||||
}
|
}
|
||||||
const _session = await client.session.get(client.session.topics[0]);
|
await ethereumProvider.disconnect();
|
||||||
await client.disconnect({
|
}, [ethereumProvider]);
|
||||||
topic: _session.topic,
|
|
||||||
reason: ERROR.USER_DISCONNECTED.format(),
|
|
||||||
});
|
|
||||||
}, [client]);
|
|
||||||
|
|
||||||
const _subscribeToClientEvents = useCallback(async (_client: Client) => {
|
const _subscribeToClientEvents = useCallback(async (_client: Client) => {
|
||||||
if (typeof _client === "undefined") {
|
if (typeof _client === "undefined") {
|
||||||
@ -153,6 +150,7 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
|
|||||||
|
|
||||||
console.log(ethereumProvider);
|
console.log(ethereumProvider);
|
||||||
|
|
||||||
|
setEthereumProvider(ethereumProvider);
|
||||||
setWeb3Provider(web3Provider);
|
setWeb3Provider(web3Provider);
|
||||||
|
|
||||||
const _accounts = await ethereumProvider.enable();
|
const _accounts = await ethereumProvider.enable();
|
||||||
|
Loading…
Reference in New Issue
Block a user