fixes double creation of client in react

pull/3674/head
filip mertens 4 years ago committed by Aniket
parent d16130ee7f
commit 3ce56270f4
  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-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": { "@remixproject/plugin-utils": {
"version": "0.3.11", "version": "0.3.11",
"resolved": "https://registry.npmjs.org/@remixproject/plugin-utils/-/plugin-utils-0.3.11.tgz", "resolved": "https://registry.npmjs.org/@remixproject/plugin-utils/-/plugin-utils-0.3.11.tgz",

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

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

Loading…
Cancel
Save