Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async createProvider(config: EthereumConfig) {
const net = config.networkId === "1" ? "mainnet" : "rinkeby"
const provider = new WalletConnectProvider({
bridge: "https://bridge.walletconnect.org",
// infuraId: "5Ic91y0T9nLh6qUg33K0", // Required
infuraId: "44ad2034a545495ca22dda2a4d50feba",
})
provider.on("chainChanged", (chainId) => console.log("chainChanged", chainId))
provider.on("networkChanged", (net) => console.log("networkChanged", net))
provider.on("accountsChanged", (acc) => window.location.reload())
// wc is WalletConnect class in library
provider.wc.on('disconnect', (error, payload) => {
if (error) {
throw error
}
console.log("User cancel a sign-in request")
WalletConnectQRCodeModal.close()
provider.updateState({...INITIAL_STATE})
})
return new Promise(async (resolve, reject) => {
let bridge = "https://bridge.walletconnect.org";
let qrcode = true;
let onUri: SimpleFunction | null = null;
if (opts) {
bridge = opts.bridge || bridge;
qrcode = typeof opts.qrcode !== "undefined" ? opts.qrcode : qrcode;
onUri = opts.onUri || onUri;
}
if (!qrcode && !onUri) {
throw new Error("Must provide onUri callback when qrcode is disabled");
}
const provider = new WalletConnectProvider({ bridge, qrcode });
if (!provider.wc.connected) {
await provider.wc.createSession();
if (onUri) {
onUri(provider.wc.uri);
}
provider.wc.on("connect", async (error: Error) => {
if (error) {
return reject(error);
}
return resolve(provider);
});
} else {