fix(with-solana): adds missing useCallback dep

This commit is contained in:
Ben Kremer 2022-03-14 15:56:18 +01:00
parent 9bc970e8bc
commit dbc2aa5fa5

View File

@ -93,6 +93,20 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
setChainData(chainData); setChainData(chainData);
}; };
const onSessionConnected = useCallback(async (_session: SessionTypes.Settled) => {
const account = _session.state.accounts[0].split(":").pop();
if (!account) {
throw new Error("Could not derive account address from `session.state.accounts`.");
}
const _publicKey = new PublicKey(account);
setSession(_session);
setChain(_session.permissions.blockchain.chains[0]);
setAccounts(_session.state.accounts);
setPublicKey(_publicKey);
}, []);
const disconnect = useCallback(async () => { const disconnect = useCallback(async () => {
if (typeof client === "undefined") { if (typeof client === "undefined") {
throw new Error("WalletConnect is not initialized"); throw new Error("WalletConnect is not initialized");
@ -106,7 +120,8 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
}); });
}, [client, session]); }, [client, session]);
const _subscribeToClientEvents = useCallback(async (_client: Client) => { const _subscribeToClientEvents = useCallback(
async (_client: Client) => {
if (typeof _client === "undefined") { if (typeof _client === "undefined") {
throw new Error("WalletConnect is not initialized"); throw new Error("WalletConnect is not initialized");
} }
@ -132,7 +147,9 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
console.log("EVENT", "session_deleted"); console.log("EVENT", "session_deleted");
resetApp(); resetApp();
}); });
}, []); },
[onSessionConnected],
);
const createClient = useCallback(async () => { const createClient = useCallback(async () => {
try { try {
@ -153,20 +170,6 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
} }
}, [_subscribeToClientEvents]); }, [_subscribeToClientEvents]);
const onSessionConnected = useCallback(async (_session: SessionTypes.Settled) => {
const account = _session.state.accounts[0].split(":").pop();
if (!account) {
throw new Error("Could not derive account address from `session.state.accounts`.");
}
const _publicKey = new PublicKey(account);
setSession(_session);
setChain(_session.permissions.blockchain.chains[0]);
setAccounts(_session.state.accounts);
setPublicKey(_publicKey);
}, []);
const onEnable = useCallback( const onEnable = useCallback(
async (caipChainId: string) => { async (caipChainId: string) => {
if (!client) { if (!client) {