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 {
|
export default class ContractLoader {
|
||||||
static async _doLoad(what, web3Helper) {
|
static async _doLoad(what, web3Helper) {
|
||||||
const where = web3Helper.getNetworkName().toLowerCase()
|
const where = (await web3Helper.getNetworkName()).toLowerCase()
|
||||||
Logger.log('Loading', what, 'from', where)
|
Logger.log('Loading', what, 'from', where)
|
||||||
try {
|
try {
|
||||||
/* eslint-disable-next-line security/detect-non-literal-require */
|
/* eslint-disable-next-line security/detect-non-literal-require */
|
||||||
|
@ -18,9 +18,9 @@ export default class Ocean {
|
|||||||
this.helper = new Web3Helper(this._web3)
|
this.helper = new Web3Helper(this._web3)
|
||||||
this.metadata = new MetaData(this._providerUri)
|
this.metadata = new MetaData(this._providerUri)
|
||||||
|
|
||||||
this._network = config.network || this.helper.getNetworkName().toLowerCase() || 'development'
|
|
||||||
|
|
||||||
return (async () => {
|
return (async () => {
|
||||||
|
this._network = config.network || (await this.helper.getNetworkName()).toLowerCase() || 'development'
|
||||||
|
|
||||||
this.market = await new OceanMarket(this.helper)
|
this.market = await new OceanMarket(this.helper)
|
||||||
this.auth = await new OceanAuth(this.helper)
|
this.auth = await new OceanAuth(this.helper)
|
||||||
this.token = await new OceanToken(this.helper)
|
this.token = await new OceanToken(this.helper)
|
||||||
@ -30,7 +30,7 @@ export default class Ocean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getAccounts() {
|
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)
|
// await ocean.market.requestTokens(account, 1000)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -74,7 +74,7 @@ export default class Ocean {
|
|||||||
.map(async (event) => ({
|
.map(async (event) => ({
|
||||||
...event.args,
|
...event.args,
|
||||||
timeout: event.args._timeout.toNumber(),
|
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),
|
paid: await this.market.verifyOrderPayment(event.args._id).then((received) => received),
|
||||||
key: null
|
key: null
|
||||||
}))
|
}))
|
||||||
|
@ -1,15 +1,30 @@
|
|||||||
|
import Logger from './logger'
|
||||||
|
|
||||||
export default class Web3Helper {
|
export default class Web3Helper {
|
||||||
constructor(web3) {
|
constructor(web3) {
|
||||||
this.web3 = web3
|
this.web3 = web3
|
||||||
}
|
}
|
||||||
|
|
||||||
getAccounts() {
|
async getAccounts() {
|
||||||
return this.web3.eth.accounts
|
return new Promise((resolve, reject) => {
|
||||||
|
this.web3.eth.getAccounts((err, accounts) => {
|
||||||
|
if (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
resolve(accounts)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
getNetworkName() {
|
async getNetworkName() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
let network = 'unknown'
|
let network = 'unknown'
|
||||||
switch (this.web3.version.network) {
|
this.web3.version.getNetwork((err, networkId) => {
|
||||||
|
Logger.log('networkId', networkId)
|
||||||
|
if (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
switch (networkId) {
|
||||||
case '1':
|
case '1':
|
||||||
network = 'Main'
|
network = 'Main'
|
||||||
break
|
break
|
||||||
@ -28,7 +43,9 @@ export default class Web3Helper {
|
|||||||
default:
|
default:
|
||||||
network = 'development'
|
network = 'development'
|
||||||
}
|
}
|
||||||
return network
|
resolve(network)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// web3 wrappers
|
// web3 wrappers
|
||||||
|
Loading…
Reference in New Issue
Block a user