fix(with-solana): adds missing useCallback dep
This commit is contained in:
parent
9bc970e8bc
commit
dbc2aa5fa5
@ -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,33 +120,36 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
|
|||||||
});
|
});
|
||||||
}, [client, session]);
|
}, [client, session]);
|
||||||
|
|
||||||
const _subscribeToClientEvents = useCallback(async (_client: Client) => {
|
const _subscribeToClientEvents = useCallback(
|
||||||
if (typeof _client === "undefined") {
|
async (_client: Client) => {
|
||||||
throw new Error("WalletConnect is not initialized");
|
if (typeof _client === "undefined") {
|
||||||
}
|
throw new Error("WalletConnect is not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
_client.on(CLIENT_EVENTS.pairing.proposal, async (proposal: PairingTypes.Proposal) => {
|
_client.on(CLIENT_EVENTS.pairing.proposal, async (proposal: PairingTypes.Proposal) => {
|
||||||
const { uri } = proposal.signal.params;
|
const { uri } = proposal.signal.params;
|
||||||
console.log("EVENT", "QR Code Modal open");
|
console.log("EVENT", "QR Code Modal open");
|
||||||
QRCodeModal.open(uri, () => {
|
QRCodeModal.open(uri, () => {
|
||||||
console.log("EVENT", "QR Code Modal closed");
|
console.log("EVENT", "QR Code Modal closed");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
_client.on(CLIENT_EVENTS.pairing.created, async () => {
|
_client.on(CLIENT_EVENTS.pairing.created, async () => {
|
||||||
setPairings(_client.pairing.topics);
|
setPairings(_client.pairing.topics);
|
||||||
});
|
});
|
||||||
|
|
||||||
_client.on(CLIENT_EVENTS.session.updated, (updatedSession: SessionTypes.Settled) => {
|
_client.on(CLIENT_EVENTS.session.updated, (updatedSession: SessionTypes.Settled) => {
|
||||||
console.log("EVENT", "session_updated");
|
console.log("EVENT", "session_updated");
|
||||||
onSessionConnected(updatedSession);
|
onSessionConnected(updatedSession);
|
||||||
});
|
});
|
||||||
|
|
||||||
_client.on(CLIENT_EVENTS.session.deleted, () => {
|
_client.on(CLIENT_EVENTS.session.deleted, () => {
|
||||||
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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user