diff --git a/src/app/editor/SourceHighlighters.js b/src/app/editor/SourceHighlighters.js index 9879f28f58..6bf8886fa8 100644 --- a/src/app/editor/SourceHighlighters.js +++ b/src/app/editor/SourceHighlighters.js @@ -17,22 +17,20 @@ class SourceHighlighters { } // TODO what to do with mod? - highlight (mod, lineColumnPos, filePath, hexColor, cb) { + async highlight (mod, lineColumnPos, filePath, hexColor) { let position try { position = JSON.parse(lineColumnPos) } catch (e) { - return cb(e.message) + throw e } if (!this.highlighters[mod]) this.highlighters[mod] = new SourceHighlighter() this.highlighters[mod].currentSourceLocation(null) this.highlighters[mod].currentSourceLocationFromfileName(position, filePath, hexColor) - cb() } - discardHighlight (mod, cb) { + async discardHighlight (mod) { if (this.highlighters[mod]) this.highlighters[mod].currentSourceLocation(null) - cb() } } diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 0e6b3c16b9..5d5b717b59 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -121,7 +121,8 @@ class FileManager { async getCurrentFile () { const path = this.currentFile() - if (!path) throw 'no file selected' + if (!path) throw new Error('no file selected') + console.log('Get current File', path) return path } @@ -206,12 +207,16 @@ class FileManager { } } - filesFromPath (path, cb) { - var provider = this.fileProviderOf(path) - if (provider) { - return provider.resolveDirectory(path, (error, filesTree) => { cb(error, filesTree) }) - } - cb(`provider for path ${path} not found`) + getFilesFromPath (path) { + const provider = this.fileProviderOf(path) + if (!provider) throw new Error(`provider for path ${path} not found`) + // TODO : Change provider with promise + return new Promise((resolve, reject) => { + provider.resolveDirectory(path, (error, filesTree) => { + if(error) reject(error) + resolve(filesTree) + }) + }) } fileProviderOf (file) { diff --git a/src/app/tabs/test-tab.js b/src/app/tabs/test-tab.js index b42dbf4476..6e408906db 100644 --- a/src/app/tabs/test-tab.js +++ b/src/app/tabs/test-tab.js @@ -98,15 +98,14 @@ module.exports = class TestTab { var provider = self._deps.fileManager.fileProviderOf(path) if (!provider) return cb(null, []) var tests = [] - self._deps.fileManager.filesFromPath(path, (error, files) => { - if (error) return cb(error) - if (!error) { + self._deps.fileManager.getFilesFromPath(path) + .then((files) => { for (var file in files) { if (/.(_test.sol)$/.exec(file)) tests.push(provider.type + '/' + file) } cb(null, tests) - } - }) + }) + .catch(err => cb(error)) } self._deps.filePanel.event.register('newTestFileCreated', file => { diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 0f6c4fa5f2..18251b1c54 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -231,23 +231,24 @@ UniversalDApp.prototype.getInputs = function (funABI) { * SHOULD BE TAKEN CAREFULLY! * * @param {Object} tx - transaction. - * @param {Function} callback - callback. */ -UniversalDApp.prototype.runTestTx = function (tx, cb) { - executionContext.detectNetwork((error, network) => { - if (error) return cb(error) - if (network.name === 'Main' && network.id === '1') { - return cb('It is not allowed to make this action against mainnet') - } - this.silentRunTx(tx, (error, result) => { - if (error) return cb(error) - cb(null, { - transactionHash: result.transactionHash, - status: result.result.status, - gasUsed: '0x' + result.result.gasUsed.toString('hex'), - error: result.result.vm.exceptionError, - return: result.result.vm.return ? '0x' + result.result.vm.return.toString('hex') : '0x', - createdAddress: result.result.createdAddress ? '0x' + result.result.createdAddress.toString('hex') : undefined +UniversalDApp.prototype.runTestTx = function (tx) { + return new Promise((resolve, reject) => { + executionContext.detectNetwork((error, network) => { + if (error) reject(error) + if (network.name === 'Main' && network.id === '1') { + reject(new Error('It is not allowed to make this action against mainnet')) + } + this.silentRunTx(tx, (error, result) => { + if (error) reject(error) + resolve({ + transactionHash: result.transactionHash, + status: result.result.status, + gasUsed: '0x' + result.result.gasUsed.toString('hex'), + error: result.result.vm.exceptionError, + return: result.result.vm.return ? '0x' + result.result.vm.return.toString('hex') : '0x', + createdAddress: result.result.createdAddress ? '0x' + result.result.createdAddress.toString('hex') : undefined + }) }) }) })