Fix walletconnect rejection from mobile

This commit is contained in:
Alexis Sellier
2021-08-03 18:19:09 +02:00
parent 2043d405fc
commit f97bc5b5f2
2 changed files with 10 additions and 2 deletions
+8 -2
View File
@@ -1,4 +1,4 @@
import { writable } from "svelte/store";
import { get, writable } from "svelte/store";
import type { Writable } from "svelte/store";
import { ethers } from "ethers";
import type { TypedDataSigner } from '@ethersproject/abstract-signer';
@@ -150,7 +150,7 @@ export class Config {
state.set({ state: "open", uri, onClose });
},
close: () => {
state.set({ state: "close" });
// We handle the "close" event through the "disconnect" handler.
}
},
clientMeta: {
@@ -165,6 +165,12 @@ export class Config {
walletConnect.on("modal_closed", () => {
state.set({ state: "close" });
});
walletConnect.on("disconnect", () => {
const wcs = get(state);
if (wcs.state === "open") {
wcs.onClose();
}
});
const walletConnectSigner = new WalletConnectSigner(walletConnect, provider);
+2
View File
@@ -87,6 +87,7 @@ export const loadState = (initial: State): Store => {
try {
await config.walletConnect.client.connect();
console.log("WalletConnect: connected.");
const address = await signer.getAddress();
const tokenBalance: BigNumber = await config.token.balanceOf(address);
@@ -103,6 +104,7 @@ export const loadState = (initial: State): Store => {
}
store.set({ connection: Connection.Connected, session });
} catch (e) {
console.log("WalletConnect: connection failed.");
store.set({ connection: Connection.Disconnected });
// There seems to be no way to detect this "error" caused by the user