Prevent double initialization of wallet connect client (#10)
This commit is contained in:
parent
3adcdfa39c
commit
1f11e283d7
@ -6,6 +6,7 @@ import React, {
|
||||
useState,
|
||||
useEffect,
|
||||
useCallback,
|
||||
useRef,
|
||||
} from "react";
|
||||
import { SnackbarProvider, enqueueSnackbar } from "notistack";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
@ -46,6 +47,7 @@ export const WalletConnectProvider = ({
|
||||
}) => {
|
||||
const [signClient, setSignClient] = useState<SignClient>();
|
||||
const [session, setSession] = useState<SessionTypes.Struct | null>(null);
|
||||
const isSignClientInitializing = useRef<boolean>(false);
|
||||
const navigate = useNavigate()
|
||||
|
||||
const disconnect = useCallback(async () => {
|
||||
@ -85,6 +87,7 @@ export const WalletConnectProvider = ({
|
||||
);
|
||||
|
||||
const createClient = useCallback(async () => {
|
||||
isSignClientInitializing.current = true;
|
||||
const signClient = await SignClient.init({
|
||||
projectId: PROJECT_ID,
|
||||
metadata: {
|
||||
@ -98,6 +101,7 @@ export const WalletConnectProvider = ({
|
||||
setSignClient(signClient);
|
||||
await subscribeToEvents(signClient);
|
||||
await checkPersistedState(signClient);
|
||||
isSignClientInitializing.current = false;
|
||||
}, [checkPersistedState, subscribeToEvents])
|
||||
|
||||
const connect = async () => {
|
||||
@ -136,7 +140,7 @@ export const WalletConnectProvider = ({
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!signClient) {
|
||||
if (!signClient && !isSignClientInitializing.current) {
|
||||
createClient();
|
||||
}
|
||||
}, [signClient, createClient]);
|
||||
|
Loading…
Reference in New Issue
Block a user