|
|
|
@ -11,12 +11,12 @@ const globalRegistry = require('../../../global/registry') |
|
|
|
|
|
|
|
|
|
class SettingsUI { |
|
|
|
|
|
|
|
|
|
constructor (settings, networkModule) { |
|
|
|
|
this.settings = settings |
|
|
|
|
constructor (blockchain, networkModule) { |
|
|
|
|
this.blockchain = blockchain |
|
|
|
|
this.event = new EventManager() |
|
|
|
|
this._components = {} |
|
|
|
|
|
|
|
|
|
this.settings.event.register('transactionExecuted', (error, from, to, data, lookupOnly, txResult) => { |
|
|
|
|
this.blockchain.event.register('transactionExecuted', (error, from, to, data, lookupOnly, txResult) => { |
|
|
|
|
if (error) return |
|
|
|
|
if (!lookupOnly) this.el.querySelector('#value').value = '0' |
|
|
|
|
this.updateAccountBalances() |
|
|
|
@ -44,7 +44,7 @@ class SettingsUI { |
|
|
|
|
if (!this.el) return |
|
|
|
|
var accounts = $(this.el.querySelector('#txorigin')).children('option') |
|
|
|
|
accounts.each((index, account) => { |
|
|
|
|
this.settings.getAccountBalanceForAddress(account.value, (err, balance) => { |
|
|
|
|
this.blockchain.getAccountBalanceForAddress(account.value, (err, balance) => { |
|
|
|
|
if (err) return |
|
|
|
|
account.innerText = helper.shortenAddress(account.value, balance) |
|
|
|
|
}) |
|
|
|
@ -139,7 +139,7 @@ class SettingsUI { |
|
|
|
|
var selectExEnv = environmentEl.querySelector('#selectExEnvOptions') |
|
|
|
|
this.setDropdown(selectExEnv) |
|
|
|
|
|
|
|
|
|
this.settings.event.register('contextChanged', (context, silent) => { |
|
|
|
|
this.blockchain.event.register('contextChanged', (context, silent) => { |
|
|
|
|
this.setFinalContext() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -156,7 +156,7 @@ class SettingsUI { |
|
|
|
|
setDropdown (selectExEnv) { |
|
|
|
|
this.selectExEnv = selectExEnv |
|
|
|
|
|
|
|
|
|
this.settings.event.register('addProvider', (network) => { |
|
|
|
|
this.blockchain.event.register('addProvider', (network) => { |
|
|
|
|
selectExEnv.appendChild(yo`<option
|
|
|
|
|
title="Manually added environment: ${network.url}" |
|
|
|
|
value="${network.name}" |
|
|
|
@ -167,7 +167,7 @@ class SettingsUI { |
|
|
|
|
addTooltip(`${network.name} [${network.url}] added`) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
this.settings.event.register('removeProvider', (name) => { |
|
|
|
|
this.blockchain.event.register('removeProvider', (name) => { |
|
|
|
|
var env = selectExEnv.querySelector(`option[value="${name}"]`) |
|
|
|
|
if (env) { |
|
|
|
|
selectExEnv.removeChild(env) |
|
|
|
@ -177,9 +177,9 @@ class SettingsUI { |
|
|
|
|
|
|
|
|
|
selectExEnv.addEventListener('change', (event) => { |
|
|
|
|
let context = selectExEnv.options[selectExEnv.selectedIndex].value |
|
|
|
|
this.settings.changeExecutionContext(context, () => { |
|
|
|
|
this.blockchain.changeExecutionContext(context, () => { |
|
|
|
|
modalDialogCustom.prompt('External node request', this.web3ProviderDialogBody(), 'http://localhost:8545', (target) => { |
|
|
|
|
this.settings.setProviderFromEndpoint(target, context, (alertMsg) => { |
|
|
|
|
this.blockchain.setProviderFromEndpoint(target, context, (alertMsg) => { |
|
|
|
|
if (alertMsg) addTooltip(alertMsg) |
|
|
|
|
this.setFinalContext() |
|
|
|
|
}) |
|
|
|
@ -189,7 +189,7 @@ class SettingsUI { |
|
|
|
|
}, this.setFinalContext.bind(this)) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
selectExEnv.value = this.settings.getProvider() |
|
|
|
|
selectExEnv.value = this.blockchain.getProvider() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
web3ProviderDialogBody () { |
|
|
|
@ -208,7 +208,7 @@ class SettingsUI { |
|
|
|
|
|
|
|
|
|
setFinalContext () { |
|
|
|
|
// set the final context. Cause it is possible that this is not the one we've originaly selected
|
|
|
|
|
this.selectExEnv.value = this.settings.getProvider() |
|
|
|
|
this.selectExEnv.value = this.blockchain.getProvider() |
|
|
|
|
this.event.trigger('clearInstance', []) |
|
|
|
|
this.updateNetwork() |
|
|
|
|
this.updatePlusButton() |
|
|
|
@ -250,7 +250,7 @@ class SettingsUI { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
newAccount () { |
|
|
|
|
this.settings.newAccount( |
|
|
|
|
this.blockchain.newAccount( |
|
|
|
|
(cb) => { |
|
|
|
|
modalDialogCustom.promptPassphraseCreation((error, passphrase) => { |
|
|
|
|
if (error) { |
|
|
|
@ -269,14 +269,14 @@ class SettingsUI { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
signMessage () { |
|
|
|
|
this.settings.getAccounts((err, accounts) => { |
|
|
|
|
this.blockchain.getAccounts((err, accounts) => { |
|
|
|
|
if (err) { |
|
|
|
|
return addTooltip(`Cannot get account list: ${err}`) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var signMessageDialog = { 'title': 'Sign a message', 'text': 'Enter a message to sign', 'inputvalue': 'Message to sign' } |
|
|
|
|
var $txOrigin = this.el.querySelector('#txorigin') |
|
|
|
|
if (!$txOrigin.selectedOptions[0] && (this.settings.isInjectedWeb3() || this.settings.isWeb3Provider())) { |
|
|
|
|
if (!$txOrigin.selectedOptions[0] && (this.blockchain.isInjectedWeb3() || this.blockchain.isWeb3Provider())) { |
|
|
|
|
return addTooltip(`Account list is empty, please make sure the current provider is properly connected to remix`) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -284,7 +284,7 @@ class SettingsUI { |
|
|
|
|
|
|
|
|
|
var promptCb = (passphrase) => { |
|
|
|
|
const modal = modalDialogCustom.promptMulti(signMessageDialog, (message) => { |
|
|
|
|
this.settings.signMessage(message, account, passphrase, (err, msgHash, signedData) => { |
|
|
|
|
this.blockchain.signMessage(message, account, passphrase, (err, msgHash, signedData) => { |
|
|
|
|
if (err) { |
|
|
|
|
return addTooltip(err) |
|
|
|
|
} |
|
|
|
@ -301,7 +301,7 @@ class SettingsUI { |
|
|
|
|
}, false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.settings.isWeb3Provider()) { |
|
|
|
|
if (this.blockchain.isWeb3Provider()) { |
|
|
|
|
return modalDialogCustom.promptPassphrase( |
|
|
|
|
'Passphrase to sign a message', |
|
|
|
|
'Enter your passphrase for this account to sign the message', |
|
|
|
@ -315,7 +315,7 @@ class SettingsUI { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
updateNetwork () { |
|
|
|
|
this.settings.updateNetwork((err, {id, name} = {}) => { |
|
|
|
|
this.blockchain.updateNetwork((err, {id, name} = {}) => { |
|
|
|
|
if (err) { |
|
|
|
|
this.netUI.innerHTML = 'can\'t detect network ' |
|
|
|
|
return |
|
|
|
@ -331,7 +331,7 @@ class SettingsUI { |
|
|
|
|
this.accountListCallId++ |
|
|
|
|
var callid = this.accountListCallId |
|
|
|
|
var txOrigin = this.el.querySelector('#txorigin') |
|
|
|
|
this.settings.getAccounts((err, accounts) => { |
|
|
|
|
this.blockchain.getAccounts((err, accounts) => { |
|
|
|
|
if (this.accountListCallId > callid) return |
|
|
|
|
this.accountListCallId++ |
|
|
|
|
if (err) { addTooltip(`Cannot get account list: ${err}`) } |
|
|
|
|