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

View File

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