fix(react-dapp-v2): ensure clientId is logged and stored
This commit is contained in:
parent
3c8ebfe96a
commit
322d2ec977
@ -254,6 +254,22 @@ export function ClientContextProvider({
|
|||||||
[session, onSessionConnected]
|
[session, onSessionConnected]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const _logClientId = useCallback(async (_client: Client) => {
|
||||||
|
if (typeof _client === "undefined") {
|
||||||
|
throw new Error("WalletConnect is not initialized");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const clientId = await _client.core.crypto.getClientId();
|
||||||
|
console.log("WalletConnect ClientID: ", clientId);
|
||||||
|
localStorage.setItem("WALLETCONNECT_CLIENT_ID", clientId);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
"Failed to set WalletConnect clientId in localStorage: ",
|
||||||
|
error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const createClient = useCallback(async () => {
|
const createClient = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
setIsInitializing(true);
|
setIsInitializing(true);
|
||||||
@ -269,20 +285,20 @@ export function ClientContextProvider({
|
|||||||
prevRelayerValue.current = relayerRegion;
|
prevRelayerValue.current = relayerRegion;
|
||||||
await _subscribeToEvents(_client);
|
await _subscribeToEvents(_client);
|
||||||
await _checkPersistedState(_client);
|
await _checkPersistedState(_client);
|
||||||
|
await _logClientId(_client);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
setIsInitializing(false);
|
setIsInitializing(false);
|
||||||
}
|
}
|
||||||
}, [_checkPersistedState, _subscribeToEvents, relayerRegion]);
|
}, [_checkPersistedState, _subscribeToEvents, _logClientId, relayerRegion]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
createClient()
|
createClient();
|
||||||
}
|
} else if (prevRelayerValue.current !== relayerRegion) {
|
||||||
else if (prevRelayerValue.current !== relayerRegion) {
|
client.core.relayer.restartTransport(relayerRegion);
|
||||||
client.core.relayer.restartTransport(relayerRegion)
|
prevRelayerValue.current = relayerRegion;
|
||||||
prevRelayerValue.current = relayerRegion
|
|
||||||
}
|
}
|
||||||
}, [createClient, relayerRegion, client]);
|
}, [createClient, relayerRegion, client]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user