mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
more tests, document config usage
This commit is contained in:
parent
2cb4478ba2
commit
44a26f687f
17
README.md
17
README.md
@ -47,6 +47,23 @@ npm install @oceanprotocol/lib
|
|||||||
|
|
||||||
## 🏄 Quick Start
|
## 🏄 Quick Start
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { Ocean, ConfigHelper } from '@oceanprotocol/lib'
|
||||||
|
|
||||||
|
const defaultConfig = new ConfigHelper().getConfig('rinkeby', 'YOUR_INFURA_PROJECT_ID')
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
...defaultConfig,
|
||||||
|
metadataStoreUri: 'https://your-metadata-store.com',
|
||||||
|
providerUri: 'https://your-provider.com'
|
||||||
|
}
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
const ocean = await Ocean.getInstance(config)
|
||||||
|
return ocean
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Simple Flow
|
### Simple Flow
|
||||||
|
|
||||||
This stripped-down flow shows the essence of Ocean. Just downloading, no metadata.
|
This stripped-down flow shows the essence of Ocean. Just downloading, no metadata.
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Config from '../models/Config'
|
import Config from '../models/Config'
|
||||||
|
import { Logger } from '../lib'
|
||||||
|
|
||||||
export declare type ConfigHelperNetworkName =
|
export declare type ConfigHelperNetworkName =
|
||||||
| 'mainnet'
|
| 'mainnet'
|
||||||
@ -56,10 +57,15 @@ export class ConfigHelper {
|
|||||||
const filterBy = typeof network === 'string' ? 'network' : 'chainId'
|
const filterBy = typeof network === 'string' ? 'network' : 'chainId'
|
||||||
const config = configs.find((c) => c[filterBy] === network)
|
const config = configs.find((c) => c[filterBy] === network)
|
||||||
|
|
||||||
|
if (!config) {
|
||||||
|
Logger.error(`No config found for given network '${network}'`)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const nodeUri = infuraProjectId
|
const nodeUri = infuraProjectId
|
||||||
? `${config.nodeUri}/${infuraProjectId}`
|
? `${config.nodeUri}/${infuraProjectId}`
|
||||||
: config.nodeUri
|
: config.nodeUri
|
||||||
|
|
||||||
return config ? { ...config, nodeUri } : null
|
return { ...config, nodeUri }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,4 +14,16 @@ describe('ConfigHelper', () => {
|
|||||||
const config = new ConfigHelper().getConfig(network, infuraId)
|
const config = new ConfigHelper().getConfig(network, infuraId)
|
||||||
assert(config.nodeUri.includes(infuraId))
|
assert(config.nodeUri.includes(infuraId))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should get config based on chain ID', () => {
|
||||||
|
const network = 4
|
||||||
|
const config = new ConfigHelper().getConfig(network)
|
||||||
|
assert(config.chainId === network)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return nothing with unknown network', () => {
|
||||||
|
const network = 'blabla'
|
||||||
|
const config = new ConfigHelper().getConfig(network)
|
||||||
|
assert(config === null)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user