|
|
@ -61,6 +61,7 @@ export class Blockchain extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
providers: {[key: string]: VMProvider | InjectedProvider | NodeProvider} |
|
|
|
providers: {[key: string]: VMProvider | InjectedProvider | NodeProvider} |
|
|
|
transactionContextAPI: TransactionContextAPI |
|
|
|
transactionContextAPI: TransactionContextAPI |
|
|
|
|
|
|
|
registeredPluginEvents: string[] |
|
|
|
|
|
|
|
|
|
|
|
// NOTE: the config object will need to be refactored out in remix-lib
|
|
|
|
// NOTE: the config object will need to be refactored out in remix-lib
|
|
|
|
constructor(config: Config) { |
|
|
|
constructor(config: Config) { |
|
|
@ -91,6 +92,7 @@ export class Blockchain extends Plugin { |
|
|
|
|
|
|
|
|
|
|
|
this.networkcallid = 0 |
|
|
|
this.networkcallid = 0 |
|
|
|
this.networkStatus = {network: {name: ' - ', id: ' - '}} |
|
|
|
this.networkStatus = {network: {name: ' - ', id: ' - '}} |
|
|
|
|
|
|
|
this.registeredPluginEvents = [] |
|
|
|
this.setupEvents() |
|
|
|
this.setupEvents() |
|
|
|
this.setupProviders() |
|
|
|
this.setupProviders() |
|
|
|
} |
|
|
|
} |
|
|
@ -103,34 +105,23 @@ export class Blockchain extends Plugin { |
|
|
|
|
|
|
|
|
|
|
|
onActivation() { |
|
|
|
onActivation() { |
|
|
|
this.active = true |
|
|
|
this.active = true |
|
|
|
this.on('injected', 'chainChanged', () => { |
|
|
|
this.on('manager', 'pluginActivated', (plugin) => { |
|
|
|
this.detectNetwork((error, network) => { |
|
|
|
if (plugin && plugin.name && (plugin.name.startsWith('injected') || plugin.name === 'walletconnect')) { |
|
|
|
this.networkStatus = {network, error} |
|
|
|
this.on(plugin.name, 'chainChanged', () => { |
|
|
|
this._triggerEvent('networkStatus', [this.networkStatus]) |
|
|
|
this.detectNetwork((error, network) => { |
|
|
|
}) |
|
|
|
this.networkStatus = {network, error} |
|
|
|
}) |
|
|
|
this._triggerEvent('networkStatus', [this.networkStatus]) |
|
|
|
|
|
|
|
}) |
|
|
|
this.on('injected-trustwallet', 'chainChanged', () => { |
|
|
|
}) |
|
|
|
this.detectNetwork((error, network) => { |
|
|
|
} |
|
|
|
this.networkStatus = {network, error} |
|
|
|
|
|
|
|
this._triggerEvent('networkStatus', [this.networkStatus]) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.on('walletconnect', 'chainChanged', () => { |
|
|
|
|
|
|
|
this.detectNetwork((error, network) => { |
|
|
|
|
|
|
|
this.networkStatus = {network, error} |
|
|
|
|
|
|
|
this._triggerEvent('networkStatus', [this.networkStatus]) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onDeactivation() { |
|
|
|
onDeactivation() { |
|
|
|
this.active = false |
|
|
|
this.active = false |
|
|
|
this.off('injected', 'chainChanged') |
|
|
|
for (const plugin of this.registeredPluginEvents) { |
|
|
|
this.off('injected-trustwallet', 'chainChanged') |
|
|
|
this.off(plugin, 'chainChanged') |
|
|
|
this.off('walletconnect', 'chainChanged') |
|
|
|
} |
|
|
|
this.off('walletconnect', 'accountsChanged') |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setupEvents() { |
|
|
|
setupEvents() { |
|
|
@ -175,6 +166,7 @@ export class Blockchain extends Plugin { |
|
|
|
getCurrentProvider() { |
|
|
|
getCurrentProvider() { |
|
|
|
const provider = this.getProvider() |
|
|
|
const provider = this.getProvider() |
|
|
|
if (provider && provider.startsWith('vm')) return this.providers['vm'] |
|
|
|
if (provider && provider.startsWith('vm')) return this.providers['vm'] |
|
|
|
|
|
|
|
if (provider && provider.startsWith('injected')) return this.providers['injected'] |
|
|
|
if (this.providers[provider]) return this.providers[provider] |
|
|
|
if (this.providers[provider]) return this.providers[provider] |
|
|
|
return this.providers.web3 // default to the common type of provider
|
|
|
|
return this.providers.web3 // default to the common type of provider
|
|
|
|
} |
|
|
|
} |
|
|
@ -534,16 +526,6 @@ export class Blockchain extends Plugin { |
|
|
|
return this.executionContext.getCurrentFork() |
|
|
|
return this.executionContext.getCurrentFork() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isWeb3Provider() { |
|
|
|
|
|
|
|
const isVM = this.executionContext.isVM() |
|
|
|
|
|
|
|
const isInjected = this.getProvider() === 'injected' |
|
|
|
|
|
|
|
return !isVM && !isInjected |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isInjectedWeb3() { |
|
|
|
|
|
|
|
return this.getProvider() === 'injected' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
signMessage(message, account, passphrase, cb) { |
|
|
|
signMessage(message, account, passphrase, cb) { |
|
|
|
this.getCurrentProvider().signMessage(message, account, passphrase, cb) |
|
|
|
this.getCurrentProvider().signMessage(message, account, passphrase, cb) |
|
|
|
} |
|
|
|
} |
|
|
|