only load state 500ms after the last step change

pull/7/head
yann300 8 years ago
parent 842cc9834e
commit 6cdfb38ec9
  1. 47
      src/ui/DropdownPanel.js
  2. 28
      src/ui/SolidityState.js

@ -20,11 +20,32 @@ function DropdownPanel (_name, _opts) {
this.view this.view
} }
DropdownPanel.prototype.setMessage = function (message) {
if (this.view) {
this.view.querySelector('.dropdownpanel .dropdownrawcontent').style.display = 'none'
this.view.querySelector('.dropdownpanel .dropdowncontent').style.display = 'none'
this.view.querySelector('.dropdownpanel .fa-refresh').style.display = 'none'
this.message(message)
}
}
DropdownPanel.prototype.setLoading = function () {
if (this.view) {
this.view.querySelector('.dropdownpanel .dropdownrawcontent').style.display = 'none'
this.view.querySelector('.dropdownpanel .dropdowncontent').style.display = 'none'
this.view.querySelector('.dropdownpanel .fa-refresh').style.display = 'inline-block'
this.message('')
}
}
DropdownPanel.prototype.update = function (_data, _header) { DropdownPanel.prototype.update = function (_data, _header) {
if (this.view) { if (this.view) {
this.view.querySelector('.dropdownpanel .fa-refresh').style.display = 'none'
this.view.querySelector('.dropdownpanel .dropdowncontent').style.display = 'block'
this.view.querySelector('.dropdownpanel .dropdownrawcontent').innerText = JSON.stringify(_data, null, '\t') this.view.querySelector('.dropdownpanel .dropdownrawcontent').innerText = JSON.stringify(_data, null, '\t')
this.view.querySelector('.dropdownpanel button.btn').style.display = 'block' this.view.querySelector('.dropdownpanel button.btn').style.display = 'block'
this.view.querySelector('.title span').innerText = _header || ' ' this.view.querySelector('.title span').innerText = _header || ' '
this.message('')
if (this.json) { if (this.json) {
this.treeView.update(_data) this.treeView.update(_data)
} }
@ -32,8 +53,10 @@ DropdownPanel.prototype.update = function (_data, _header) {
} }
DropdownPanel.prototype.setContent = function (node) { DropdownPanel.prototype.setContent = function (node) {
if (this.view) {
var parent = this.view.querySelector('.dropdownpanel div.dropdowncontent') var parent = this.view.querySelector('.dropdownpanel div.dropdowncontent')
parent.replaceChild(node, parent.firstElementChild) parent.replaceChild(node, parent.firstElementChild)
}
} }
DropdownPanel.prototype.render = function (overridestyle) { DropdownPanel.prototype.render = function (overridestyle) {
@ -43,7 +66,19 @@ DropdownPanel.prototype.render = function (overridestyle) {
} }
overridestyle === undefined ? {} : overridestyle overridestyle === undefined ? {} : overridestyle
var self = this var self = this
var view = yo`<div> var view = yo`
<div>
<style>
@-moz-keyframes spin {
to { -moz-transform: rotate(359deg); }
}
@-webkit-keyframes spin {
to { -webkit-transform: rotate(359deg); }
}
@keyframes spin {
to {transform:rotate(359deg);}
}
</style>
<div class='title' style=${ui.formatCss(styleDropdown.title)} onclick=${function () { self.toggle() }}> <div class='title' style=${ui.formatCss(styleDropdown.title)} onclick=${function () { self.toggle() }}>
<div style=${ui.formatCss(styleDropdown.caret)} class='fa fa-caret-right'></div> <div style=${ui.formatCss(styleDropdown.caret)} class='fa fa-caret-right'></div>
<div style=${ui.formatCss(styleDropdown.inner, styleDropdown.titleInner)}>${this.name}</div><span></span> <div style=${ui.formatCss(styleDropdown.inner, styleDropdown.titleInner)}>${this.name}</div><span></span>
@ -51,8 +86,10 @@ DropdownPanel.prototype.render = function (overridestyle) {
<div class='dropdownpanel' style=${ui.formatCss(styleDropdown.content)} style='display:none'> <div class='dropdownpanel' style=${ui.formatCss(styleDropdown.content)} style='display:none'>
<button onclick=${function () { self.toggleRaw() }} style=${ui.formatCss(basicStyles.button, styleDropdown.copyBtn)} title='raw' class="btn fa fa-eye" type="button"> <button onclick=${function () { self.toggleRaw() }} style=${ui.formatCss(basicStyles.button, styleDropdown.copyBtn)} title='raw' class="btn fa fa-eye" type="button">
</button> </button>
<i class="fa fa-refresh" style=${ui.formatCss(styleDropdown.inner, overridestyle, {display: 'none', 'margin-left': '4px', 'margin-top': '4px', 'animation': 'spin 2s linear infinite'})} aria-hidden="true"></i>
<div style=${ui.formatCss(styleDropdown.inner, overridestyle)} class='dropdowncontent'>${content}</div> <div style=${ui.formatCss(styleDropdown.inner, overridestyle)} class='dropdowncontent'>${content}</div>
<div style=${ui.formatCss(styleDropdown.inner, overridestyle)} class='dropdownrawcontent' style='display:none'></div> <div style=${ui.formatCss(styleDropdown.inner, overridestyle)} class='dropdownrawcontent' style='display:none'></div>
<div style=${ui.formatCss(styleDropdown.inner, overridestyle)} class='message' style='display:none'></div>
</div> </div>
</div>` </div>`
if (!this.view) { if (!this.view) {
@ -102,4 +139,12 @@ DropdownPanel.prototype.show = function () {
} }
} }
DropdownPanel.prototype.message = function (message) {
if (this.view) {
var mes = this.view.querySelector('.dropdownpanel .message')
mes.innerText = message
mes.style.display = (message === '') ? 'none' : 'block'
}
}
module.exports = DropdownPanel module.exports = DropdownPanel

@ -24,34 +24,44 @@ function SolidityState (_parent, _traceManager, _codeManager, _solidityProxy) {
} }
SolidityState.prototype.render = function () { SolidityState.prototype.render = function () {
if (!this.view) {
this.view = yo`<div id='soliditystate' > this.view = yo`<div id='soliditystate' >
<div id='warning'></div>
${this.basicPanel.render()} ${this.basicPanel.render()}
</div>` </div>`
}
return this.view return this.view
} }
SolidityState.prototype.init = function () { SolidityState.prototype.init = function () {
var self = this var self = this
var decodeTimeout = null
this.parent.event.register('indexChanged', this, function (index) { this.parent.event.register('indexChanged', this, function (index) {
var warningDiv = this.view.querySelector('#warning') self.basicPanel.setMessage('')
warningDiv.innerHTML = ''
if (index < 0) { if (index < 0) {
warningDiv.innerHTML = 'invalid step index' self.basicPanel.setMessage('invalid step index')
return return
} }
if (self.parent.currentStepIndex !== index) return if (self.parent.currentStepIndex !== index) return
if (!this.solidityProxy.loaded()) { if (!self.solidityProxy.loaded()) {
warningDiv.innerHTML = 'no source has been specified' self.basicPanel.setMessage('no source has been specified')
return return
} }
if (!self.storageResolver) { if (!self.storageResolver) {
warningDiv.innerHTML = 'storage not ready'
return return
} }
if (decodeTimeout) {
window.clearTimeout(decodeTimeout)
}
self.basicPanel.setLoading()
decodeTimeout = setTimeout(() => {
decode(self, index)
}, 500)
})
}
function decode (self, index) {
self.traceManager.getCurrentCalledAddressAt(self.parent.currentStepIndex, (error, address) => { self.traceManager.getCurrentCalledAddressAt(self.parent.currentStepIndex, (error, address) => {
if (error) { if (error) {
self.basicPanel.update({}) self.basicPanel.update({})
@ -72,7 +82,6 @@ SolidityState.prototype.init = function () {
} }
} }
}) })
})
} }
function extractStateVariables (self, stateVars, address) { function extractStateVariables (self, stateVars, address) {
@ -82,8 +91,11 @@ function extractStateVariables (self, stateVars, address) {
address: address address: address
}, self.storageResolver, self.traceManager) }, self.storageResolver, self.traceManager)
stateDecoder.decodeState(stateVars, storageViewer).then((result) => { stateDecoder.decodeState(stateVars, storageViewer).then((result) => {
self.basicPanel.setMessage('')
if (!result.error) { if (!result.error) {
self.basicPanel.update(result) self.basicPanel.update(result)
} else {
self.basicPanel.setMessage(result.error)
} }
}) })
} }

Loading…
Cancel
Save