1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

switch to @ethereum-navigator/navigator for network lookup

This commit is contained in:
Matthias Kretschmann 2020-01-29 22:43:04 +01:00
parent db6864d921
commit 92dbaaeb25
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 20 additions and 29 deletions

14
package-lock.json generated
View File

@ -229,6 +229,20 @@
} }
} }
}, },
"@ethereum-navigator/atlas": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/@ethereum-navigator/atlas/-/atlas-0.5.1.tgz",
"integrity": "sha512-ZK8S30ITBolyJaJp0DQNcf8Ish+hPHdJ9otlaIyJUbRXSfzPyPNBeP3NbYG9pxDDrYvfxy/07HH1tUcsRecrIA=="
},
"@ethereum-navigator/navigator": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/@ethereum-navigator/navigator/-/navigator-0.4.1.tgz",
"integrity": "sha512-wOLlwiJprq6fAJETCM1dG1kft2UxXOSr2qU5ZxCkX0uRqL6mikUTZVAJif9e5HgL+EzVFI4/u03rpoGzljriWw==",
"requires": {
"@ethereum-navigator/atlas": "~0.5.1",
"web3": "^1.2.4"
}
},
"@iarna/toml": { "@iarna/toml": {
"version": "2.2.3", "version": "2.2.3",
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.3.tgz", "resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.3.tgz",

View File

@ -51,6 +51,7 @@
"web3": "^1.2.3" "web3": "^1.2.3"
}, },
"dependencies": { "dependencies": {
"@ethereum-navigator/navigator": "^0.4.1",
"@oceanprotocol/keeper-contracts": "^0.13.2", "@oceanprotocol/keeper-contracts": "^0.13.2",
"@oceanprotocol/secret-store-client": "^0.0.15", "@oceanprotocol/secret-store-client": "^0.0.15",
"bignumber.js": "^9.0.0", "bignumber.js": "^9.0.0",

1
src/@types/node_modules.d.ts vendored Normal file
View File

@ -0,0 +1 @@
declare module '@ethereum-navigator/navigator'

View File

@ -1,3 +1,4 @@
import { lookup } from '@ethereum-navigator/navigator'
import { ContractBase } from './contracts/ContractBase' import { ContractBase } from './contracts/ContractBase'
import DIDRegistry from './contracts/DIDRegistry' import DIDRegistry from './contracts/DIDRegistry'
@ -234,36 +235,10 @@ export class Keeper extends Instantiable {
* Returns the network by name. * Returns the network by name.
* @return {Promise<string>} Network name. * @return {Promise<string>} Network name.
*/ */
public getNetworkName(): Promise<string> { public async getNetworkName(): Promise<string> {
return this.web3.eth.net.getId().then((networkId: number) => { return this.web3.eth.net.getId().then((networkId: number) => {
switch (networkId) { const network = lookup(networkId)
case 1: return network && network.name ? network.name : 'Development'
return 'Main'
case 2:
return 'Morden'
case 3:
return 'Ropsten'
case 4:
return 'Rinkeby'
case 77:
return 'POA_Sokol'
case 99:
return 'POA_Core'
case 42:
return 'Kovan'
case 100:
return 'xDai'
case 2199:
return 'Duero'
case 8996:
return 'Spree'
case 8995:
return 'Nile'
case 0xcea11:
return 'Pacific'
default:
return 'Development'
}
}) })
} }