fixes double creation of client in react

pull/3674/head
filip mertens 4 years ago committed by Aniket
parent b8bbbefc92
commit e86d7d16d7
  1. 10
      package-lock.json
  2. 7
      src/App.js
  3. 11
      src/RemixClient.js

10
package-lock.json generated

@ -4851,6 +4851,16 @@
"@remixproject/plugin-utils": "0.3.11"
}
},
"@remixproject/plugin-iframe": {
"version": "0.3.11",
"resolved": "https://registry.npmjs.org/@remixproject/plugin-iframe/-/plugin-iframe-0.3.11.tgz",
"integrity": "sha512-zvn7SIUK4jIQbY9O1kC8G3gzXrvflkbLof2cG1FGeqZDW+Yv164Rf98tLlGo8sUALYvKuTBBcl+89e//BWFKPg==",
"requires": {
"@remixproject/plugin": "0.3.11",
"@remixproject/plugin-api": "0.3.11",
"@remixproject/plugin-utils": "0.3.11"
}
},
"@remixproject/plugin-utils": {
"version": "0.3.11",
"resolved": "https://registry.npmjs.org/@remixproject/plugin-utils/-/plugin-utils-0.3.11.tgz",

@ -1,9 +1,9 @@
import React from 'react';
import './App.css';
import { RemixClient } from './RemixClient'
function App() {
const p = new RemixClient()
function App() {
const openModal = () => {
p.onConnect()
}
@ -22,11 +22,12 @@ function App() {
for(const account of accounts){
document.getElementById('accounts').innerHTML += `<li className="list-group-item">${account}</li>`
}
showButtons(accounts.length > 0)
})
p.internalEvents.on('chainChanged', (chain) => {
document.getElementById('chain').innerHTML = chain
showButtons(chain)
})
p.internalEvents.on('disconnect', (chain) => {

@ -14,14 +14,13 @@ import EventManager from "events"
export class RemixClient extends PluginClient {
provider
constructor() {
super();
createClient(this);
this.methods = ["sendAsync"];
this.internalEvents = new EventManager()
createClient(this);
this.onload()
this.web3Modal = new Web3Modal({
providerOptions: this.getProviderOptions() // required
});
@ -79,7 +78,7 @@ export class RemixClient extends PluginClient {
async detectNetwork(id) {
let networkName = null;
id = parseInt(id)
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
if (id === 1) networkName = "Main";
else if (id === 2) networkName = "Morden (deprecated)";
@ -119,6 +118,7 @@ export class RemixClient extends PluginClient {
package: WalletConnectProvider,
options: {
infuraId: '83d4d660ce3546299cbe048ed95b6fad',
bridge: 'https://static.225.91.181.135.clients.your-server.de:9090/'
}
},
torus: {
@ -182,12 +182,11 @@ export class RemixClient extends PluginClient {
return new Promise((resolve, reject) => {
if (this.provider) {
this.provider.sendAsync(data, (error, message) => {
// console.log('in plugin', data, error, message)
if (error) return reject(error)
resolve(message)
})
} else {
return reject('Provider not loaded')
resolve({"jsonrpc": "2.0", "result": [], "id": data.id})
}
})
}

Loading…
Cancel
Save