mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
made getNetworkName and getAccounts async
This commit is contained in:
parent
68a7823c4b
commit
9a6838a437
@ -5,7 +5,7 @@ const contracts = []
|
||||
|
||||
export default class ContractLoader {
|
||||
static async _doLoad(what, web3Helper) {
|
||||
const where = web3Helper.getNetworkName().toLowerCase()
|
||||
const where = (await web3Helper.getNetworkName()).toLowerCase()
|
||||
Logger.log('Loading', what, 'from', where)
|
||||
try {
|
||||
/* eslint-disable-next-line security/detect-non-literal-require */
|
||||
|
@ -18,9 +18,9 @@ export default class Ocean {
|
||||
this.helper = new Web3Helper(this._web3)
|
||||
this.metadata = new MetaData(this._providerUri)
|
||||
|
||||
this._network = config.network || this.helper.getNetworkName().toLowerCase() || 'development'
|
||||
|
||||
return (async () => {
|
||||
this._network = config.network || (await this.helper.getNetworkName()).toLowerCase() || 'development'
|
||||
|
||||
this.market = await new OceanMarket(this.helper)
|
||||
this.auth = await new OceanAuth(this.helper)
|
||||
this.token = await new OceanToken(this.helper)
|
||||
@ -30,7 +30,7 @@ export default class Ocean {
|
||||
}
|
||||
|
||||
async getAccounts() {
|
||||
return Promise.all(this.helper.getAccounts().map(async (account) => {
|
||||
return Promise.all((await this.helper.getAccounts()).map(async (account) => {
|
||||
// await ocean.market.requestTokens(account, 1000)
|
||||
|
||||
return {
|
||||
@ -74,7 +74,7 @@ export default class Ocean {
|
||||
.map(async (event) => ({
|
||||
...event.args,
|
||||
timeout: event.args._timeout.toNumber(),
|
||||
status: await this.market.getOrderStatus(event.args._id).then((status) => status.toNumber()),
|
||||
status: await this.auth.getOrderStatus(event.args._id).then((status) => status.toNumber()),
|
||||
paid: await this.market.verifyOrderPayment(event.args._id).then((received) => received),
|
||||
key: null
|
||||
}))
|
||||
|
@ -1,34 +1,51 @@
|
||||
import Logger from './logger'
|
||||
|
||||
export default class Web3Helper {
|
||||
constructor(web3) {
|
||||
this.web3 = web3
|
||||
}
|
||||
|
||||
getAccounts() {
|
||||
return this.web3.eth.accounts
|
||||
async getAccounts() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.web3.eth.getAccounts((err, accounts) => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
resolve(accounts)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
getNetworkName() {
|
||||
let network = 'unknown'
|
||||
switch (this.web3.version.network) {
|
||||
case '1':
|
||||
network = 'Main'
|
||||
break
|
||||
case '2':
|
||||
network = 'Morden'
|
||||
break
|
||||
case '3':
|
||||
network = 'Ropsten'
|
||||
break
|
||||
case '4':
|
||||
network = 'Rinkeby'
|
||||
break
|
||||
case '42':
|
||||
network = 'Kovan'
|
||||
break
|
||||
default:
|
||||
network = 'development'
|
||||
}
|
||||
return network
|
||||
async getNetworkName() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let network = 'unknown'
|
||||
this.web3.version.getNetwork((err, networkId) => {
|
||||
Logger.log('networkId', networkId)
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
switch (networkId) {
|
||||
case '1':
|
||||
network = 'Main'
|
||||
break
|
||||
case '2':
|
||||
network = 'Morden'
|
||||
break
|
||||
case '3':
|
||||
network = 'Ropsten'
|
||||
break
|
||||
case '4':
|
||||
network = 'Rinkeby'
|
||||
break
|
||||
case '42':
|
||||
network = 'Kovan'
|
||||
break
|
||||
default:
|
||||
network = 'development'
|
||||
}
|
||||
resolve(network)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// web3 wrappers
|
||||
|
Loading…
Reference in New Issue
Block a user