Update API to promises

pull/1/head
Grandschtroumpf 6 years ago committed by yann300
parent 049354b8c2
commit 9b66798d80
  1. 8
      src/app/editor/SourceHighlighters.js
  2. 19
      src/app/files/fileManager.js
  3. 7
      src/app/tabs/test-tab.js
  4. 13
      src/universal-dapp.js

@ -17,22 +17,20 @@ class SourceHighlighters {
} }
// TODO what to do with mod? // TODO what to do with mod?
highlight (mod, lineColumnPos, filePath, hexColor, cb) { async highlight (mod, lineColumnPos, filePath, hexColor) {
let position let position
try { try {
position = JSON.parse(lineColumnPos) position = JSON.parse(lineColumnPos)
} catch (e) { } catch (e) {
return cb(e.message) throw e
} }
if (!this.highlighters[mod]) this.highlighters[mod] = new SourceHighlighter() if (!this.highlighters[mod]) this.highlighters[mod] = new SourceHighlighter()
this.highlighters[mod].currentSourceLocation(null) this.highlighters[mod].currentSourceLocation(null)
this.highlighters[mod].currentSourceLocationFromfileName(position, filePath, hexColor) this.highlighters[mod].currentSourceLocationFromfileName(position, filePath, hexColor)
cb()
} }
discardHighlight (mod, cb) { async discardHighlight (mod) {
if (this.highlighters[mod]) this.highlighters[mod].currentSourceLocation(null) if (this.highlighters[mod]) this.highlighters[mod].currentSourceLocation(null)
cb()
} }
} }

@ -121,7 +121,8 @@ class FileManager {
async getCurrentFile () { async getCurrentFile () {
const path = this.currentFile() 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 return path
} }
@ -206,12 +207,16 @@ class FileManager {
} }
} }
filesFromPath (path, cb) { getFilesFromPath (path) {
var provider = this.fileProviderOf(path) const provider = this.fileProviderOf(path)
if (provider) { if (!provider) throw new Error(`provider for path ${path} not found`)
return provider.resolveDirectory(path, (error, filesTree) => { cb(error, filesTree) }) // TODO : Change provider with promise
} return new Promise((resolve, reject) => {
cb(`provider for path ${path} not found`) provider.resolveDirectory(path, (error, filesTree) => {
if(error) reject(error)
resolve(filesTree)
})
})
} }
fileProviderOf (file) { fileProviderOf (file) {

@ -98,15 +98,14 @@ module.exports = class TestTab {
var provider = self._deps.fileManager.fileProviderOf(path) var provider = self._deps.fileManager.fileProviderOf(path)
if (!provider) return cb(null, []) if (!provider) return cb(null, [])
var tests = [] var tests = []
self._deps.fileManager.filesFromPath(path, (error, files) => { self._deps.fileManager.getFilesFromPath(path)
if (error) return cb(error) .then((files) => {
if (!error) {
for (var file in files) { for (var file in files) {
if (/.(_test.sol)$/.exec(file)) tests.push(provider.type + '/' + file) if (/.(_test.sol)$/.exec(file)) tests.push(provider.type + '/' + file)
} }
cb(null, tests) cb(null, tests)
}
}) })
.catch(err => cb(error))
} }
self._deps.filePanel.event.register('newTestFileCreated', file => { self._deps.filePanel.event.register('newTestFileCreated', file => {

@ -231,17 +231,17 @@ UniversalDApp.prototype.getInputs = function (funABI) {
* SHOULD BE TAKEN CAREFULLY! * SHOULD BE TAKEN CAREFULLY!
* *
* @param {Object} tx - transaction. * @param {Object} tx - transaction.
* @param {Function} callback - callback.
*/ */
UniversalDApp.prototype.runTestTx = function (tx, cb) { UniversalDApp.prototype.runTestTx = function (tx) {
return new Promise((resolve, reject) => {
executionContext.detectNetwork((error, network) => { executionContext.detectNetwork((error, network) => {
if (error) return cb(error) if (error) reject(error)
if (network.name === 'Main' && network.id === '1') { if (network.name === 'Main' && network.id === '1') {
return cb('It is not allowed to make this action against mainnet') reject(new Error('It is not allowed to make this action against mainnet'))
} }
this.silentRunTx(tx, (error, result) => { this.silentRunTx(tx, (error, result) => {
if (error) return cb(error) if (error) reject(error)
cb(null, { resolve({
transactionHash: result.transactionHash, transactionHash: result.transactionHash,
status: result.result.status, status: result.result.status,
gasUsed: '0x' + result.result.gasUsed.toString('hex'), gasUsed: '0x' + result.result.gasUsed.toString('hex'),
@ -251,6 +251,7 @@ UniversalDApp.prototype.runTestTx = function (tx, cb) {
}) })
}) })
}) })
})
} }
/** /**

Loading…
Cancel
Save