Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Estimator url prod/dev (#1183)
Browse files Browse the repository at this point in the history
* differentiate prod/dev estimator url

* PRICE_ESTIMATOR_URL env var

* set PRICE_ESTIMATOR_URL in travis

* shorten development -> develop

* fix tests

* fix field name

* add release/* and hotfix/* to condition
  • Loading branch information
Velenir authored Jul 3, 2020
1 parent 564d840 commit 04bb98c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ before_install:
# Needed to deploy pull request and releases
- sudo apt-get -y install python-pip python-dev
- pip install awscli --upgrade --user
# use production url for price estimator on master or tagged
- export PRICE_ESTIMATOR_URL=$([[
$TRAVIS_BRANCH = master || \
$TRAVIS_BRANCH = release/* || \
$TRAVIS_BRANCH = hotfix/* || \
$TRAVIS_TAG != "" ]] && \
echo "production" || echo "develop")
before_deploy:
# zip ./dist folder if tag IS present
- if [[ $TRAVIS_TAG != "" && $IPFS_HASH = "" ]]; then
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,16 @@ dexPriceEstimator:
type: 'dex-price-estimator'
config:
- networkId: number
url: string
url_production: string
url_develop: string
```

Where:

- `type` can only be `dex-price-estimator`.
- `networkId` is a number, such as `1` for Mainnet, `4` for Rinkeby and so on.
- `url` the endpoint for given `networkId`
- `url_production` the endpoint for given `networkId` to use in production
- `url_develop` the endpoint for given `networkId` to use in development (optional)

### `theGraphApi`

Expand Down
6 changes: 4 additions & 2 deletions config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ dexPriceEstimator:
type: 'dex-price-estimator' # choices: dex-price-estimator
config:
- networkId: 1
url: https://dex-price-estimator.gnosis.io
url_production: https://dex-price-estimator.gnosis.io
url_develop: https://price-estimate-mainnet.dev.gnosisdev.com

- networkId: 4
url: https://dex-price-estimator.rinkeby.gnosis.io
url_production: https://dex-price-estimator.rinkeby.gnosis.io
url_develop: https://price-estimate-rinkeby.dev.gnosisdev.com

# Subgraph abstraction, used for getting the last price
theGraphApi:
Expand Down
9 changes: 7 additions & 2 deletions src/api/dexPriceEstimator/DexPriceEstimatorApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ interface GetPriceResponse {

export interface PriceEstimatorEndpoint {
networkId: number
url: string
url_production: string
url_develop?: string
}

export type DexPriceEstimatorParams = PriceEstimatorEndpoint[]
Expand All @@ -57,7 +58,11 @@ export class DexPriceEstimatorApiImpl implements DexPriceEstimatorApi {

public constructor(params: DexPriceEstimatorParams) {
params.forEach(endpoint => {
this.urlsByNetwork[endpoint.networkId] = getDexPriceEstimatorUrl(endpoint.url)
this.urlsByNetwork[endpoint.networkId] = getDexPriceEstimatorUrl(
process.env.PRICE_ESTIMATOR_URL === 'production'
? endpoint.url_production
: endpoint.url_develop || endpoint.url_production, // fallback on required url_production
)
})
}

Expand Down
6 changes: 4 additions & 2 deletions test/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ describe('Test config defaults', () => {
config: [
{
networkId: 1,
url: 'https://dex-price-estimator.gnosis.io',
url_production: 'https://dex-price-estimator.gnosis.io',
url_develop: 'https://price-estimate-mainnet.dev.gnosisdev.com',
},
{
networkId: 4,
url: 'https://dex-price-estimator.rinkeby.gnosis.io',
url_production: 'https://dex-price-estimator.rinkeby.gnosis.io',
url_develop: 'https://price-estimate-rinkeby.dev.gnosisdev.com',
},
],
}
Expand Down
1 change: 1 addition & 0 deletions webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ module.exports = ({ stats = false } = {}) => ({
MOCK_WEB3: process.env.MOCK || 'false',
// AUTOCONNECT: only applies for mock implementation
AUTOCONNECT: 'true',
PRICE_ESTIMATOR_URL: process.env.PRICE_ESTIMATOR_URL || 'develop',
}),
new ForkTsCheckerWebpackPlugin({ silent: stats }),
// define inside one plugin instance
Expand Down

0 comments on commit 04bb98c

Please sign in to comment.