Merge pull request #1244 from ethereum/refactor_app.js

Refactor app.js
pull/1/head
yann300 7 years ago committed by GitHub
commit 7294918671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/app.js
  2. 19
      src/app/editor/editor.js
  3. 16
      src/app/tabs/compile-tab.js
  4. 14
      src/app/tabs/run-tab.js
  5. 16
      src/app/tabs/settings-tab.js
  6. 4
      src/recorder.js

@ -698,28 +698,12 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
// ---------------- Righthand-panel -------------------- // ---------------- Righthand-panel --------------------
var rhpAPI = { var rhpAPI = {
config: config,
setEditorSize (delta) { setEditorSize (delta) {
$('#righthand-panel').css('width', delta) $('#righthand-panel').css('width', delta)
self._view.centerpanel.style.right = delta + 'px' self._view.centerpanel.style.right = delta + 'px'
document.querySelector(`.${css.dragbar2}`).style.right = delta + 'px' document.querySelector(`.${css.dragbar2}`).style.right = delta + 'px'
onResize() onResize()
}, },
getAccounts: (cb) => {
udapp.getAccounts(cb)
},
getSource: (fileName) => {
return compiler.getSource(fileName)
},
editorContent: () => {
return editor.get(editor.current())
},
currentFile: () => {
return config.get('currentFile')
},
visitContracts: (cb) => {
compiler.visitContracts(cb)
},
switchFile: function (path) { switchFile: function (path) {
fileManager.switchFile(path) fileManager.switchFile(path)
}, },
@ -775,7 +759,9 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
udapp: udapp, udapp: udapp,
udappUI: udappUI, udappUI: udappUI,
compiler: compiler, compiler: compiler,
renderer: renderer renderer: renderer,
editor: editor,
config: config
} }
self._components.righthandpanel = new RighthandPanel(rhpAPI, rhpEvents, rhpOpts) self._components.righthandpanel = new RighthandPanel(rhpAPI, rhpEvents, rhpOpts)

@ -170,17 +170,25 @@ function Editor (opts = {}) {
} }
/** /**
* returns the content of the specified session @arg path * returns the content of the current session
* if @arg path is not provided, the content of the current editing session is returned *
* @return {String} content of the file referenced by @arg path
*/
this.currentContent = function () {
return this.get(this.current())
}
/**
* returns the content of the session targeted by @arg path
* if @arg path is null, the content of the current session is returned
* *
* @param {String} path - path of th file in edition
* @return {String} content of the file referenced by @arg path * @return {String} content of the file referenced by @arg path
*/ */
this.get = function (path) { this.get = function (path) {
if (!path || currentSession === path) { if (!path || currentSession === path) {
return editor.getValue() return editor.getValue()
} else if (sessions[path]) { } else if (sessions[path]) {
sessions[path].getValue() return sessions[path].getValue()
} }
} }
@ -188,8 +196,7 @@ function Editor (opts = {}) {
* returns the path of the currently editing file * returns the path of the currently editing file
* returns `undefined` if no session is being editer * returns `undefined` if no session is being editer
* *
* @param {String} path - path of th file in edition * @return {String} path of the current session
* @return {String} content of the file referenced by @arg path
*/ */
this.current = function () { this.current = function () {
if (editor.getSession() === emptySession) { if (editor.getSession() === emptySession) {

@ -36,7 +36,7 @@ function compileTab (appAPI = {}, appEvents = {}, opts = {}) {
var compileTimeout = null var compileTimeout = null
function scheduleCompilation () { function scheduleCompilation () {
if (!appAPI.config.get('autoCompile')) { if (!opts.config.get('autoCompile')) {
return return
} }
@ -59,16 +59,16 @@ function compileTab (appAPI = {}, appEvents = {}, opts = {}) {
// ----------------- autoCompile ----------------- // ----------------- autoCompile -----------------
var autoCompileInput = compileContainer.querySelector('#autoCompile') var autoCompileInput = compileContainer.querySelector('#autoCompile')
var autoCompile = false var autoCompile = false
if (appAPI.config.exists('autoCompile')) { if (opts.config.exists('autoCompile')) {
autoCompile = appAPI.config.get('autoCompile') autoCompile = opts.config.get('autoCompile')
} }
appAPI.config.set('autoCompile', autoCompile) opts.config.set('autoCompile', autoCompile)
if (autoCompile) { if (autoCompile) {
autoCompileInput.setAttribute('checked', autoCompile) autoCompileInput.setAttribute('checked', autoCompile)
} }
autoCompileInput.addEventListener('change', function () { autoCompileInput.addEventListener('change', function () {
appAPI.config.set('autoCompile', autoCompileInput.checked) opts.config.set('autoCompile', autoCompileInput.checked)
}) })
// REGISTER EVENTS // REGISTER EVENTS
@ -156,7 +156,7 @@ function compileTab (appAPI = {}, appEvents = {}, opts = {}) {
} }
if (!error) { if (!error) {
if (data.contracts) { if (data.contracts) {
appAPI.visitContracts((contract) => { opts.compiler.visitContracts((contract) => {
opts.renderer.error(contract.name, $(errorContainer), {type: 'success'}) opts.renderer.error(contract.name, $(errorContainer), {type: 'success'})
}) })
} }
@ -190,8 +190,8 @@ function compileTab (appAPI = {}, appEvents = {}, opts = {}) {
contractNames.innerHTML = '' contractNames.innerHTML = ''
if (success) { if (success) {
contractNames.removeAttribute('disabled') contractNames.removeAttribute('disabled')
appAPI.visitContracts((contract) => { opts.compiler.visitContracts((contract) => {
contractsDetails[contract.name] = parseContracts(contract.name, contract.object, appAPI.getSource(contract.file)) contractsDetails[contract.name] = parseContracts(contract.name, contract.object, opts.compiler.getSource(contract.file))
var contractName = yo` var contractName = yo`
<option> <option>
${contract.name} ${contract.name}

@ -187,7 +187,7 @@ function updateAccountBalances (container, appAPI) {
RECORDER RECORDER
------------------------------------------------ */ ------------------------------------------------ */
function makeRecorder (appAPI, appEvents, opts, self) { function makeRecorder (appAPI, appEvents, opts, self) {
var recorder = new Recorder(opts.compiler, { var recorder = new Recorder(opts.compiler, opts.udapp, {
events: { events: {
udapp: appEvents.udapp, udapp: appEvents.udapp,
executioncontext: executionContext.event, executioncontext: executionContext.event,
@ -240,7 +240,7 @@ function makeRecorder (appAPI, appEvents, opts, self) {
update account address in scenario.json update account address in scenario.json
popup if scenario.json not open - "Open a file with transactions you want to replay and click play again" popup if scenario.json not open - "Open a file with transactions you want to replay and click play again"
*/ */
var currentFile = appAPI.config.get('currentFile') var currentFile = opts.config.get('currentFile')
appAPI.fileProviderOf(currentFile).get(currentFile, (error, json) => { appAPI.fileProviderOf(currentFile).get(currentFile, (error, json) => {
if (error) { if (error) {
modalDialogCustom.alert('Invalid Scenario File ' + error) modalDialogCustom.alert('Invalid Scenario File ' + error)
@ -319,7 +319,7 @@ function contractDropdown (events, appAPI, appEvents, opts, self) {
${createPanel} ${createPanel}
<div class="${css.button}"> <div class="${css.button}">
${atAddressButtonInput} ${atAddressButtonInput}
<div class="${css.atAddress}" onclick=${function () { loadFromAddress(appAPI) }}>Access</div> <div class="${css.atAddress}" onclick=${function () { loadFromAddress(opts.editor, opts.config) }}>At Address</div>
</div> </div>
</div> </div>
</div> </div>
@ -384,7 +384,7 @@ function contractDropdown (events, appAPI, appEvents, opts, self) {
} }
// ACCESS DEPLOYED INSTANCE // ACCESS DEPLOYED INSTANCE
function loadFromAddress (appAPI) { function loadFromAddress (editor, config) {
var noInstancesText = self._view.noInstancesText var noInstancesText = self._view.noInstancesText
if (noInstancesText.parentNode) { noInstancesText.parentNode.removeChild(noInstancesText) } if (noInstancesText.parentNode) { noInstancesText.parentNode.removeChild(noInstancesText) }
var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`) var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`)
@ -395,11 +395,11 @@ function contractDropdown (events, appAPI, appEvents, opts, self) {
if (/[a-f]/.test(address) && /[A-F]/.test(address) && !ethJSUtil.isValidChecksumAddress(address)) { if (/[a-f]/.test(address) && /[A-F]/.test(address) && !ethJSUtil.isValidChecksumAddress(address)) {
return modalDialogCustom.alert('Invalid checksum address.') return modalDialogCustom.alert('Invalid checksum address.')
} }
if (/.(.abi)$/.exec(appAPI.currentFile())) { if (/.(.abi)$/.exec(config.get('currentFile'))) {
modalDialogCustom.confirm(null, 'Do you really want to interact with ' + address + ' using the current ABI definition ?', () => { modalDialogCustom.confirm(null, 'Do you really want to interact with ' + address + ' using the current ABI definition ?', () => {
var abi var abi
try { try {
abi = JSON.parse(appAPI.editorContent()) abi = JSON.parse(editor.currentContent())
} catch (e) { } catch (e) {
return modalDialogCustom.alert('Failed to parse the current file as JSON ABI.') return modalDialogCustom.alert('Failed to parse the current file as JSON ABI.')
} }
@ -417,7 +417,7 @@ function contractDropdown (events, appAPI, appEvents, opts, self) {
contractNames.innerHTML = '' contractNames.innerHTML = ''
if (success) { if (success) {
selectContractNames.removeAttribute('disabled') selectContractNames.removeAttribute('disabled')
appAPI.visitContracts((contract) => { opts.compiler.visitContracts((contract) => {
contractNames.appendChild(yo`<option>${contract.name}</option>`) contractNames.appendChild(yo`<option>${contract.name}</option>`)
}) })
} else { } else {

@ -56,16 +56,16 @@ module.exports = class SettingsTab {
// Gist settings // Gist settings
var gistAccessToken = yo`<input id="gistaccesstoken" type="password">` var gistAccessToken = yo`<input id="gistaccesstoken" type="password">`
var token = self._api.config.get('settings/gist-access-token') var token = self._opts.config.get('settings/gist-access-token')
if (token) gistAccessToken.value = token if (token) gistAccessToken.value = token
var gistAddToken = yo`<input class="${css.savegisttoken}" id="savegisttoken" onclick=${() => { self._api.config.set('settings/gist-access-token', gistAccessToken.value); tooltip('Access token saved') }} value="Save" type="button">` var gistAddToken = yo`<input class="${css.savegisttoken}" id="savegisttoken" onclick=${() => { self._opts.config.set('settings/gist-access-token', gistAccessToken.value); tooltip('Access token saved') }} value="Save" type="button">`
var gistRemoveToken = yo`<input id="removegisttoken" onclick=${() => { gistAccessToken.value = ''; self._api.config.set('settings/gist-access-token', ''); tooltip('Access token removed') }} value="Remove" type="button">` var gistRemoveToken = yo`<input id="removegisttoken" onclick=${() => { gistAccessToken.value = ''; self._opts.config.set('settings/gist-access-token', ''); tooltip('Access token removed') }} value="Remove" type="button">`
self._view.gistToken = yo`<div class="${css.checkboxText}">${gistAccessToken}${copyToClipboard(() => self._api.config.get('settings/gist-access-token'))}${gistAddToken}${gistRemoveToken}</div>` self._view.gistToken = yo`<div class="${css.checkboxText}">${gistAccessToken}${copyToClipboard(() => self._opts.config.get('settings/gist-access-token'))}${gistAddToken}${gistRemoveToken}</div>`
// //
self._view.optionVM = yo`<input onchange=${onchangeOption} id="alwaysUseVM" type="checkbox">` self._view.optionVM = yo`<input onchange=${onchangeOption} id="alwaysUseVM" type="checkbox">`
if (self._api.config.get('settings/always-use-vm')) self._view.optionVM.setAttribute('checked', '') if (self._opts.config.get('settings/always-use-vm')) self._view.optionVM.setAttribute('checked', '')
self._view.personal = yo`<input onchange=${onchangePersonal} id="personal" type="checkbox">` self._view.personal = yo`<input onchange=${onchangePersonal} id="personal" type="checkbox">`
if (self._api.config.get('settings/personal-mode')) self._view.personal.setAttribute('checked', '') if (self._opts.config.get('settings/personal-mode')) self._view.personal.setAttribute('checked', '')
self._view.optimize = yo`<input onchange=${onchangeOptimize} id="optimize" type="checkbox">` self._view.optimize = yo`<input onchange=${onchangeOptimize} id="optimize" type="checkbox">`
if (self.data.optimize) self._view.optimize.setAttribute('checked', '') if (self.data.optimize) self._view.optimize.setAttribute('checked', '')
var warnText = `Transaction sent over Web3 will use the web3.personal API - be sure the endpoint is opened before enabling it. var warnText = `Transaction sent over Web3 will use the web3.personal API - be sure the endpoint is opened before enabling it.
@ -187,7 +187,7 @@ module.exports = class SettingsTab {
${self._view.config.localremixd} ${self._view.config.localremixd}
</div>` </div>`
function onchangeOption (event) { function onchangeOption (event) {
self._api.config.set('settings/always-use-vm', !self._api.config.get('settings/always-use-vm')) self._opts.config.set('settings/always-use-vm', !self._opts.config.get('settings/always-use-vm'))
} }
function onloadPlugin (event) { function onloadPlugin (event) {
try { try {
@ -216,7 +216,7 @@ module.exports = class SettingsTab {
self._updateVersionSelector() self._updateVersionSelector()
} }
function onchangePersonal (event) { function onchangePersonal (event) {
self._api.config.set('settings/personal-mode', !self._api.config.get('settings/personal-mode')) self._opts.config.set('settings/personal-mode', !self._opts.config.get('settings/personal-mode'))
} }
return self._view.el return self._view.el
} }

@ -13,7 +13,7 @@ var modal = require('./app/ui/modal-dialog-custom')
* *
*/ */
class Recorder { class Recorder {
constructor (compiler, opts = {}) { constructor (compiler, udapp, opts = {}) {
var self = this var self = this
self._api = opts.api self._api = opts.api
self.event = new EventManager() self.event = new EventManager()
@ -61,7 +61,7 @@ class Recorder {
record.name = payLoad.funAbi.name record.name = payLoad.funAbi.name
record.type = payLoad.funAbi.type record.type = payLoad.funAbi.type
self._api.getAccounts((error, accounts) => { udapp.getAccounts((error, accounts) => {
if (error) return console.log(error) if (error) return console.log(error)
record.from = `account{${accounts.indexOf(from)}}` record.from = `account{${accounts.indexOf(from)}}`
self.data._usedAccounts[record.from] = from self.data._usedAccounts[record.from] = from

Loading…
Cancel
Save