fix: filter out inactive pairings using client.pairing.getAll

This commit is contained in:
Ben Kremer 2022-06-21 11:34:05 +02:00
parent 4ab000ed05
commit 55249754f5
2 changed files with 5 additions and 5 deletions

View File

@ -43,6 +43,7 @@ export default function App() {
// Initialize the WalletConnect client. // Initialize the WalletConnect client.
const { const {
client, client,
pairings,
session, session,
connect, connect,
disconnect, disconnect,
@ -80,7 +81,7 @@ export default function App() {
throw new Error("WalletConnect is not initialized"); throw new Error("WalletConnect is not initialized");
} }
// Suggest existing pairings (if any). // Suggest existing pairings (if any).
if (client.pairing.values.length) { if (pairings.length) {
openPairingModal(); openPairingModal();
} else { } else {
// If no existing pairings are available, trigger `WalletConnectClient.connect`. // If no existing pairings are available, trigger `WalletConnectClient.connect`.
@ -190,7 +191,7 @@ export default function App() {
if (typeof client === "undefined") { if (typeof client === "undefined") {
throw new Error("WalletConnect is not initialized"); throw new Error("WalletConnect is not initialized");
} }
return <PairingModal pairings={client.pairing.values} connect={connect} />; return <PairingModal pairings={pairings} connect={connect} />;
case "request": case "request":
return <RequestModal pending={isRpcRequestPending} result={rpcResult} />; return <RequestModal pending={isRpcRequestPending} result={rpcResult} />;
case "ping": case "ping":

View File

@ -63,7 +63,6 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
const [chains, setChains] = useState<string[]>([]); const [chains, setChains] = useState<string[]>([]);
const reset = () => { const reset = () => {
setPairings([]);
setSession(undefined); setSession(undefined);
setBalances({}); setBalances({});
setAccounts([]); setAccounts([]);
@ -194,8 +193,8 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
throw new Error("WalletConnect is not initialized"); throw new Error("WalletConnect is not initialized");
} }
// populates existing pairings to state // populates existing pairings to state
setPairings(_client.pairing.values); setPairings(_client.pairing.getAll({ active: true }));
console.log("RESTORED PAIRINGS: ", _client.pairing.values); console.log("RESTORED PAIRINGS: ", _client.pairing.getAll({ active: true }));
if (typeof session !== "undefined") return; if (typeof session !== "undefined") return;
// populates (the last) existing session to state // populates (the last) existing session to state