update web3modal version

pull/3674/head
yann300 4 years ago committed by Aniket
parent 97b9181494
commit 257a22769a
  1. 32010
      package-lock.json
  2. 2
      src/App.js
  3. 56
      src/RemixClient.js

32010
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -5,7 +5,7 @@ import { RemixClient } from './RemixClient'
function App() { function App() {
const p = new RemixClient() const p = new RemixClient()
const openModal = () => { const openModal = () => {
p.openModal() p.onConnect()
} }
const clearLocalStorage = () => { const clearLocalStorage = () => {
localStorage.clear() localStorage.clear()

@ -4,7 +4,6 @@ import WalletConnectProvider from "@walletconnect/web3-provider";
import Torus from "@toruslabs/torus-embed"; import Torus from "@toruslabs/torus-embed";
import Authereum from "authereum"; import Authereum from "authereum";
import Web3Modal from "web3modal"; import Web3Modal from "web3modal";
import UniLogin from "@unilogin/provider";
import BurnerConnectProvider from "@burner-wallet/burner-connect-provider"; import BurnerConnectProvider from "@burner-wallet/burner-connect-provider";
import MewConnect from "@myetherwallet/mewconnect-web-client"; import MewConnect from "@myetherwallet/mewconnect-web-client";
import EventManager from "events" import EventManager from "events"
@ -18,10 +17,13 @@ export class RemixClient extends PluginClient {
this.internalEvents = new EventManager() this.internalEvents = new EventManager()
createClient(this); createClient(this);
this.onload() this.onload()
this.web3Modal = new Web3Modal({
providerOptions: this.getProviderOptions() // required
});
} }
async initModal () { async init() {
try {
const currentTheme = await this.call('theme', 'currentTheme') const currentTheme = await this.call('theme', 'currentTheme')
console.log('theme', currentTheme) console.log('theme', currentTheme)
this.web3Modal.updateTheme(currentTheme.quality) this.web3Modal.updateTheme(currentTheme.quality)
@ -31,33 +33,38 @@ export class RemixClient extends PluginClient {
console.log('theme', theme) console.log('theme', theme)
}) })
this.web3Modal.on('connect', (provider) => { }
this.provider = provider
this.internalEvents.emit('accountsChanged', provider.accounts || []) /**
this.internalEvents.emit('chainChanged', provider.chainId) * Connect wallet button pressed.
*/
async onConnect() {
console.log("Opening a dialog", this.web3Modal);
try {
this.provider = await this.web3Modal.connect();
} catch(e) {
console.log("Could not get a wallet connection", e);
return;
}
this.internalEvents.emit('accountsChanged', this.provider.accounts || [])
this.internalEvents.emit('chainChanged', this.provider.chainId)
// Subscribe to accounts change
this.provider.on("accountsChanged", (accounts) => { this.provider.on("accountsChanged", (accounts) => {
this.internalEvents.emit('accountsChanged', accounts || []) this.internalEvents.emit('accountsChanged', accounts || [])
}); });
this.provider.on("chainChanged", (chain) => { // Subscribe to chainId change
this.internalEvents.emit('chainChanged', chain) this.provider.on("chainChanged", (chainId) => {
this.internalEvents.emit('chainChanged', chainId)
}); });
})
} catch (e) {
console.log(e)
}
}
async openModal () { // Subscribe to networkId change
if (!this.web3Modal) { this.provider.on("networkChanged", (networkId) => {
this.web3Modal = new Web3Modal({ this.internalEvents.emit('networkChanged', networkId)
providerOptions: this.getProviderOptions() // required
}); });
await this.initModal()
}
if (!this.web3Modal.show) {
this.web3Modal.toggleModal()
}
} }
getProviderOptions () { getProviderOptions () {
@ -75,9 +82,6 @@ export class RemixClient extends PluginClient {
authereum: { authereum: {
package: Authereum package: Authereum
}, },
unilogin: {
package: UniLogin // required
},
burnerconnect: { burnerconnect: {
package: BurnerConnectProvider, // required package: BurnerConnectProvider, // required
options: { options: {

Loading…
Cancel
Save