Skip to content

Commit

Permalink
ADD .addInstance after rerunTx
Browse files Browse the repository at this point in the history
  • Loading branch information
serapath authored and yann300 committed Dec 6, 2017
1 parent eebccbd commit dfdde07
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
57 changes: 34 additions & 23 deletions src/app/tabs/run-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,42 @@ var pendingTxsText = yo`<div class="${css.pendingTxsText}"></div>`
var pendingTxsContainer = yo`<div class="${css.pendingTxsContainer}">${pendingTxsText}</div>`

function runTab (container, appAPI, appEvents, opts) {
var self = {
_view: {},
addInstance: addInstance
}
var udapp = appAPI.udapp()
var el = yo`
<div class="${css.runTabView}" id="runTabView">
${settings(appAPI, appEvents)}
${contractDropdown(appAPI, appEvents, instanceContainer)}
${settings(self, appAPI, appEvents)}
${contractDropdown(self, appAPI, appEvents, instanceContainer)}
${pendingTxsContainer}
${instanceContainer}
</div>
`
container.appendChild(el)

function addInstance (result) {
// {
// "result": {
// "gasUsed": "5318",
// "vm": { "exception": 1, "selfdestruct": {} },
// "bloom": { "bitvector": { "type": "Buffer", "data": [0, /* ... */ 0, 0] } },
// "amountSpent": "5318"
// },
// "transactionHash": "0x84f68f96944a47b27af4b4ed1986637aa1bc05fd7a6f5cb1d6a53f68058276d8"
// }
console.log(result)
var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`)
var contract = appAPI.getContracts()[contractNames.children[contractNames.selectedIndex].innerHTML]
var address = self._view.atAddressButtonInput.value
var instance = udapp.renderInstance(contract, address, self._view.selectContractNames.value)
instanceContainer.appendChild(instance)
}

// PENDING transactions
function updatePendingTxs (container, appAPI) {
var pendingCount = Object.keys(appAPI.udapp().pendingTransactions()).length
var pendingCount = Object.keys(udapp.pendingTransactions()).length
pendingTxsText.innerText = pendingCount + ' pending transactions'
}

Expand Down Expand Up @@ -244,7 +267,7 @@ function updateAccountBalances (container, appAPI) {
/* ------------------------------------------------
RECORDER
------------------------------------------------ */
function makeRecorder (appAPI, appEvents) {
function makeRecorder (self, appAPI, appEvents) {
var udapp = appAPI.udapp()
var recorder = new Recorder({
events: {
Expand Down Expand Up @@ -292,29 +315,15 @@ function makeRecorder (appAPI, appEvents) {
modalDialogCustom.alert('Invalid JSON, please try again')
}
if (txArray.length) {
txArray.forEach(tx => udapp.replayTx(tx.record, CALLBACK))
txArray.forEach(tx => udapp.rerunTx(tx.record, CALLBACK))
}
}, function cancel () { })
}
function CALLBACK (err, result) {
if (err) console.error(err)
else {
console.log(result)
// {
// "result": {
// "gasUsed": "5318",
// "vm": { "exception": 1, "selfdestruct": {} },
// "bloom": { "bitvector": { "type": "Buffer", "data": [0, /* ... */ 0, 0] } },
// "amountSpent": "5318"
// },
// "transactionHash": "0x84f68f96944a47b27af4b4ed1986637aa1bc05fd7a6f5cb1d6a53f68058276d8"
// }
/*
at each callback call, if the transaction succeed and if this is a creation transaction, we should call
runtab.addInstance( ... ) // which basically does:
instanceContainer.appendChild(appAPI.udapp().renderInstance(contract, address, selectContractNames.value))
*/
// at each callback call, if the transaction succeed and if this is a creation transaction, we should call
self.addInstance(result)
}
}
return el
Expand All @@ -323,7 +332,7 @@ function makeRecorder (appAPI, appEvents) {
section CONTRACT DROPDOWN and BUTTONS
------------------------------------------------ */

function contractDropdown (appAPI, appEvents, instanceContainer) {
function contractDropdown (self, appAPI, appEvents, instanceContainer) {
instanceContainer.appendChild(noInstancesText)
var compFails = yo`<i title="Contract compilation failed. Please check the compile tab for more information." class="fa fa-thumbs-down ${css.errorIcon}" ></i>`
appEvents.compiler.register('compilationFinished', function (success, data, source) {
Expand All @@ -338,6 +347,8 @@ function contractDropdown (appAPI, appEvents, instanceContainer) {
var atAddressButtonInput = yo`<input class="${css.input} ataddressinput" placeholder="Load contract from Address" title="atAddress" />`
var createButtonInput = yo`<input class="${css.input}" placeholder="" title="Create" />`
var selectContractNames = yo`<select class="${css.contractNames}" disabled></select>`
self._view.atAddressButtonInput = atAddressButtonInput
self._view.selectContractNames = selectContractNames
var el = yo`
<div class="${css.container}">
<div class="${css.subcontainer}">
Expand Down Expand Up @@ -509,7 +520,7 @@ function settings (appAPI, appEvents) {
</select>
</div>
<div class=${css.buttons}>
${makeRecorder(appAPI, appEvents)}
${makeRecorder(self, appAPI, appEvents)}
</div>
</div>
`
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/modal-dialog-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
},
promptMulti: function ({ title, text, inputValue }, ok, cancel) {
if (!inputValue) inputValue = ''
var input =yo`<textarea id="prompt_text" class=${css.prompt_text} rows="4" cols="50"></textarea>`
var input = yo`<textarea id="prompt_text" class=${css.prompt_text} rows="4" cols="50"></textarea>`
modal(title, yo`<div>${text}<div>${input}</div></div>`,
{
fn: () => { if (typeof ok === 'function') ok(document.getElementById('prompt_text').value) }
Expand Down
2 changes: 1 addition & 1 deletion src/universal-dapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ function execute (pipeline, env, callback) {
next(null, env)
}

UniversalDApp.prototype.replayTx = function (args, cb) {
UniversalDApp.prototype.rerunTx = function (args, cb) {
var self = this
self.getAccounts(function (err, accounts = []) {
if (err) console.error(err)
Expand Down

0 comments on commit dfdde07

Please sign in to comment.