Feat/dockerize frontends (#388)

* feat: unhardcode contract addresses

* fix: linting and tests

* feat: switch contract usage in token app to use unhardcoded addresses

* chore: remove other usage of hard coded contract addresses

* feat: convert contracts to classes, update claim contract to fix circular dependency

* feat: add hard coded contract addresses to contracts page

* fix: misc tidy up

* chore: rename ethers big num conversion func

* fix: remove pending transactions modal

* chore: add single toBigNum function that can accept number string or EthersBignNumber

* chore: delete unused tranche helpers and decimals functions from smart contracts lib

* feat: add faucetable token class

* fix: reset tx state after early exit from approve tx

* feat: re add transaction modal using zustand store

* fix: loader colors for eth wallet

* fix: pass ethereum config to gurantee existence before tx execution

* add docker image for building explorer

* add arg

* env file changes

* add docker file to build env file

* add requirement for env file in explorer

* fix env file syntax

* containers functional

* default to testnet

* make env flag logic consistent in all places

* pre populate env file

* ensure working for all projects

* address PR comment

* generalising env for token

* invert config dependency from ui toolkit

* fix: merge issues

* docs: running containers documentation

* style: lint

* fix: env varibales not being added properly

* chore: fix merge issues

* chore: fix docker file to support new exectutors

* chore: set address on all contracts as a property

* feat: pull token from contract rather than relying on env var

* chore: fix typing

* chore: remove duplicated prop

* chore: don't use chainId

* style: lint

* style: lint

* Merge branch 'master' into feat/dockerize-frontends

* Merge remote-tracking branch 'origin/master' into feat/dockerize-frontends

* test: revert changes to explorer e2e file

* fix: creating client without base causing token to error

* test: fix tests erroring in before hook due to file not being found

* chore: remove node env from configurable flags

Co-authored-by: Matthew Russell <mattrussell36@gmail.com>
This commit is contained in:
Dexter Edwards 2022-06-13 15:39:17 +01:00 committed by GitHub
parent 5f8061d5ce
commit bcaab22891
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
108 changed files with 772 additions and 576 deletions

5
.dockerignore Normal file
View File

@ -0,0 +1,5 @@
dist/*
node_modules/*
tmp/*
.dockerignore
Dockerfile

29
Dockerfile Normal file
View File

@ -0,0 +1,29 @@
# Build container
FROM node:16.14.0-alpine as build
WORKDIR /app
# Argument to allow building of different apps
ARG APP
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY yarn.lock ./
COPY . ./
RUN yarn
RUN yarn nx build $APP
# Production environment
FROM nginx:stable-alpine
ARG APP
COPY --from=build /app/dist/apps/$APP /usr/share/nginx/html
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
WORKDIR /usr/share/nginx/html
COPY ./env.sh .
COPY ./apps/$APP/.env .env
# Add bash
RUN apk add --no-cache bash
RUN chmod +x ./env.sh
CMD ["/bin/bash", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""]

View File

@ -103,24 +103,42 @@ In CI linting, formatting and also run. These checks can be seen in the [CI work
Visit the [Nx Documentation](https://nx.dev/getting-started/intro) to learn more. Visit the [Nx Documentation](https://nx.dev/getting-started/intro) to learn more.
# Vegacapsule # Docker & Vegacapsule
## Explorer ## Docker
Follow the following steps to start using a local network with the Vega Explorer: The [Dockerfile](./Dockerfile) for running the frontends is pretty basic, merely building the application with the APP arg that is passed in and serving the application from [nginx](./nginx/nginx.conf). The only complexity that exists is that there is a script which allows the passing of run time environement variabels to the containers. See configuration below for how to do this.
1. Prepare vegacapsule. Follow the [Vegacapsule instructions](https://github.com/vegaprotocol/vegacapsule#quick-start) You can build any of the containers locally with the following command:
2. Build the explorer frontend application
3. Start the explorer frontend application with the `.env.vegacapsule` env file
4. Go to [http://localhost:3000](http://localhost:3000) in your browser
If you simply want to run Explorer locally, without using a local network:
```bash ```bash
cd apps/explorer && cp .env.testnet .env.local docker build . --build-arg APP=[YOUR APP] --tag=[TAG]
yarn nx run explorer:serve
``` ```
In order to run a container:
```bash
docker run -p 3000:80 [TAG]
```
## Config
As envrionment variabels are build time and not run time in frontend applications. We have built a system which allows for passing run time environment variables, this generates a JSON file that will override the default environement vairbales that the container was built with (which is always testnet, using the default .env files).
In order to override specific environment variables you can pass these to the container like this:
```bash
docker run -e NX_VEGA_URL=https://n04.d.vega.xyz/query -p 3000:80 [TAG]
```
Which will now point the app to use a devnet data node. To see a list of all possible config properties see the readme.md for each app in the app directory.
## Vega capsule
Coming soon! You will be able to run the containers within Vega Capsule.
You can run against a local intance of Vega Cpasule today by using the .env.capsule present in the apps.
# 📑 License # 📑 License
[MIT](./LICENSE) [MIT](./LICENSE)

View File

@ -1,11 +1,11 @@
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = 'http://localhost:26617' NX_TENDERMINT_URL=http://localhost:26617
NX_TENDERMINT_WEBSOCKET_URL = 'wss://localhost:26617/websocket' NX_TENDERMINT_WEBSOCKET_URL=wss://localhost:26617/websocket
NX_VEGA_URL = "http://localhost:3028/query" NX_VEGA_URL=http://localhost:3028/query
NX_VEGA_ENV = 'LOCAL' NX_VEGA_ENV=LOCAL
NX_VEGA_REST = 'http://localhost:3029' NX_VEGA_REST=http://localhost:3029
CYPRESS_VEGA_TENDERMINT_URL='http://localhost:26617' CYPRESS_VEGA_TENDERMINT_URL=http://localhost:26617
NX_EXPLORER_ASSETS=1 NX_EXPLORER_ASSETS=1
NX_EXPLORER_GENESIS=1 NX_EXPLORER_GENESIS=1

View File

@ -1,16 +1,16 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = "https://n04.d.vega.xyz/tm" NX_TENDERMINT_URL=https://n04.d.vega.xyz/tm
NX_TENDERMINT_WEBSOCKET_URL = "wss://n04.d.vega.xyz/tm/websocket" NX_TENDERMINT_WEBSOCKET_URL=wss://n04.d.vega.xyz/tm/websocket
NX_VEGA_URL = "https://n04.d.vega.xyz/query" NX_VEGA_URL=https://n04.d.vega.xyz/query
NX_VEGA_ENV = 'DEVNET' NX_VEGA_ENV=DEVNET
NX_VEGA_REST = 'https://n04.d.vega.xyz/datanode/rest' NX_VEGA_REST=https://n04.d.vega.xyz/datanode/rest
# App flags # App flags
NX_EXPLORER_ASSETS = 1 NX_EXPLORER_ASSETS=1
NX_EXPLORER_GENESIS = 1 NX_EXPLORER_GENESIS=1
NX_EXPLORER_GOVERNANCE = 1 NX_EXPLORER_GOVERNANCE=1
NX_EXPLORER_MARKETS = 1 NX_EXPLORER_MARKETS=1
NX_EXPLORER_NETWORK_PARAMETERS = 1 NX_EXPLORER_NETWORK_PARAMETERS=1
NX_EXPLORER_PARTIES = 1 NX_EXPLORER_PARTIES=1
NX_EXPLORER_VALIDATORS = 1 NX_EXPLORER_VALIDATORS=1

View File

@ -1,15 +1,15 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = "https://mainnet-observer-proxy01.ops.vega.xyz/" NX_TENDERMINT_URL=https://mainnet-observer-proxy01.ops.vega.xyz/
NX_TENDERMINT_WEBSOCKET_URL = "wss://mainnet-observer-proxy01.ops.vega.xyz/websocket" NX_TENDERMINT_WEBSOCKET_URL=wss://mainnet-observer-proxy01.ops.vega.xyz/websocket
NX_VEGA_URL = "https://api.token.vega.xyz/query" NX_VEGA_URL=https://api.token.vega.xyz/query
NX_VEGA_ENV = 'MAINNET' NX_VEGA_ENV=MAINNET
NX_VEGA_REST = 'https://api.token.vega.xyz/' NX_VEGA_REST=https://api.token.vega.xyz/
# App flags # App flags
NX_EXPLORER_ASSETS = 1 NX_EXPLORER_ASSETS=1
NX_EXPLORER_GENESIS = 1 NX_EXPLORER_GENESIS=1
NX_EXPLORER_GOVERNANCE = 1 NX_EXPLORER_GOVERNANCE=1
NX_EXPLORER_NETWORK_PARAMETERS = 1 NX_EXPLORER_NETWORK_PARAMETERS=1
NX_EXPLORER_PARTIES = 1 NX_EXPLORER_PARTIES=1
NX_EXPLORER_VALIDATORS = 1 NX_EXPLORER_VALIDATORS=1

View File

@ -1,16 +1,16 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = "https://n03.s.vega.xyz/tm" NX_TENDERMINT_URL=https://n03.s.vega.xyz/tm
NX_TENDERMINT_WEBSOCKET_URL = "wss://n03.s.vega.xyz/tm/websocket" NX_TENDERMINT_WEBSOCKET_URL=wss://n03.s.vega.xyz/tm/websocket
NX_VEGA_URL = "https://n03.s.vega.xyz/query" NX_VEGA_URL=https://n03.s.vega.xyz/query
NX_VEGA_ENV = 'STAGNET' NX_VEGA_ENV=STAGNET
NX_VEGA_REST = 'https://n03.s.vega.xyz/datanode/rest' NX_VEGA_REST=https://n03.s.vega.xyz/datanode/rest
# App flags # App flags
NX_EXPLORER_ASSETS = 1 NX_EXPLORER_ASSETS=1
NX_EXPLORER_GENESIS = 1 NX_EXPLORER_GENESIS=1
NX_EXPLORER_GOVERNANCE = 1 NX_EXPLORER_GOVERNANCE=1
NX_EXPLORER_MARKETS = 1 NX_EXPLORER_MARKETS=1
NX_EXPLORER_NETWORK_PARAMETERS = 1 NX_EXPLORER_NETWORK_PARAMETERS=1
NX_EXPLORER_PARTIES = 1 NX_EXPLORER_PARTIES=1
NX_EXPLORER_VALIDATORS = 1 NX_EXPLORER_VALIDATORS=1

View File

@ -1,16 +1,16 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = "https://n03.stagnet2.vega.xyz/tm" NX_TENDERMINT_URL=https://n03.stagnet2.vega.xyz/tm
NX_TENDERMINT_WEBSOCKET_URL = "wss://n03.stagnet2.vega.xyz/tm/websocket" NX_TENDERMINT_WEBSOCKET_URL=wss://n03.stagnet2.vega.xyz/tm/websocket
NX_VEGA_URL = "https://n03.stagnet2.vega.xyz/query" NX_VEGA_URL=https://n03.stagnet2.vega.xyz/query
NX_VEGA_ENV = 'STAGNET2' NX_VEGA_ENV=STAGNET2
NX_VEGA_REST = 'https://n01.stagnet2.vega.xyz/datanode/rest' NX_VEGA_REST=https://n01.stagnet2.vega.xyz/datanode/rest
# App flags # App flags
NX_EXPLORER_ASSETS = 1 NX_EXPLORER_ASSETS=1
NX_EXPLORER_GENESIS = 1 NX_EXPLORER_GENESIS=1
NX_EXPLORER_GOVERNANCE = 1 NX_EXPLORER_GOVERNANCE=1
NX_EXPLORER_MARKETS = 1 NX_EXPLORER_MARKETS=1
NX_EXPLORER_NETWORK_PARAMETERS = 1 NX_EXPLORER_NETWORK_PARAMETERS=1
NX_EXPLORER_PARTIES = 1 NX_EXPLORER_PARTIES=1
NX_EXPLORER_VALIDATORS = 1 NX_EXPLORER_VALIDATORS=1

View File

@ -1,16 +1,16 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = "https://lb.testnet.vega.xyz/tm" NX_TENDERMINT_URL=https://lb.testnet.vega.xyz/tm
NX_TENDERMINT_WEBSOCKET_URL = "wss://lb.testnet.vega.xyz/tm/websocket" NX_TENDERMINT_WEBSOCKET_URL=wss://lb.testnet.vega.xyz/tm/websocket
NX_VEGA_URL = "https://lb.testnet.vega.xyz/query" NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_VEGA_ENV = 'TESTNET' NX_VEGA_ENV=TESTNET
NX_VEGA_REST = 'https://lb.testnet.vega.xyz/datanode/rest' NX_VEGA_REST=https://lb.testnet.vega.xyz/datanode/rest
# App flags # App flags
NX_EXPLORER_ASSETS = 1 NX_EXPLORER_ASSETS=1
NX_EXPLORER_GENESIS = 1 NX_EXPLORER_GENESIS=1
NX_EXPLORER_GOVERNANCE = 1 NX_EXPLORER_GOVERNANCE=1
NX_EXPLORER_MARKETS = 1 NX_EXPLORER_MARKETS=1
NX_EXPLORER_NETWORK_PARAMETERS = 1 NX_EXPLORER_NETWORK_PARAMETERS=1
NX_EXPLORER_PARTIES = 1 NX_EXPLORER_PARTIES=1
NX_EXPLORER_VALIDATORS = 1 NX_EXPLORER_VALIDATORS=1

View File

@ -1,36 +1,24 @@
# React Environment Variables NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
# https://facebook.github.io/create-react-app/docs/adding-custom-environment-variables#expanding-environment-variables-in-env NX_TENDERMINT_URL=http://localhost:26617
NX_TENDERMINT_WEBSOCKET_URL=wss://localhost:26617/websocket
NX_VEGA_URL=http://localhost:3028/query
NX_VEGA_ENV=LOCAL
NX_VEGA_REST=http://localhost:3029
# Netlify Environment Variables NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
# https://www.netlify.com/docs/continuous-deployment/#environment-variables NX_TENDERMINT_URL=https://lb.testnet.vega.xyz/tm
NX_VERSION=$npm_package_version NX_TENDERMINT_WEBSOCKET_URL=wss://lb.testnet.vega.xyz/tm/websocket
NX_REPOSITORY_URL=$REPOSITORY_URL NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_BRANCH=$BRANCH NX_VEGA_ENV=TESTNET
NX_PULL_REQUEST=$PULL_REQUEST NX_VEGA_REST=https://lb.testnet.vega.xyz/datanode/rest
NX_HEAD=$HEAD NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
NX_COMMIT_REF=$COMMIT_REF CYPRESS_VEGA_TENDERMINT_URL=https://lb.testnet.vega.xyz/tm
NX_CONTEXT=$CONTEXT
NX_REVIEW_ID=$REVIEW_ID
NX_INCOMING_HOOK_TITLE=$INCOMING_HOOK_TITLE
NX_INCOMING_HOOK_URL=$INCOMING_HOOK_URL
NX_INCOMING_HOOK_BODY=$INCOMING_HOOK_BODY
NX_URL=$URL
NX_DEPLOY_URL=$DEPLOY_URL
NX_DEPLOY_PRIME_URL=$DEPLOY_PRIME_URL
NX_CHAIN_EXPLORER_URL = 'https://explorer.vega.trading/.netlify/functions/chain-explorer-api'
NX_TENDERMINT_URL = 'https://lb.testnet.vega.xyz/tm'
NX_TENDERMINT_WEBSOCKET_URL = 'wss://lb.testnet.vega.xyz/tm/websocket'
NX_VEGA_URL = 'https://lb.testnet.vega.xyz/query'
NX_VEGA_ENV = 'TESTNET'
NX_VEGA_REST = 'https://lb.testnet.vega.xyz/datanode/rest'
NX_VEGA_NETWORKS = '{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
CYPRESS_VEGA_TENDERMINT_URL='https://lb.testnet.vega.xyz/tm'
# App flags # App flags
NX_EXPLORER_ASSETS = 1 NX_EXPLORER_ASSETS=1
NX_EXPLORER_GENESIS = 1 NX_EXPLORER_GENESIS=1
NX_EXPLORER_GOVERNANCE = 1 NX_EXPLORER_GOVERNANCE=1
NX_EXPLORER_NETWORK_PARAMETERS = 1 NX_EXPLORER_NETWORK_PARAMETERS=1
NX_EXPLORER_PARTIES = 1 NX_EXPLORER_PARTIES=1
NX_EXPLORER_VALIDATORS = 1 NX_EXPLORER_VALIDATORS=1
NX_EXPLORER_MARKETS=1

View File

@ -1,17 +1,17 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = "http://localhost:26617" NX_TENDERMINT_URL=http://localhost:26617
NX_TENDERMINT_WEBSOCKET_URL = "wss://localhost:26617/websocket" NX_TENDERMINT_WEBSOCKET_URL=wss://localhost:26617/websocket
NX_VEGA_URL = "http://localhost:3028/query" NX_VEGA_URL=http://localhost:3028/query
NX_VEGA_NETWORKS = '{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}' NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
NX_VEGA_ENV = 'LOCAL' NX_VEGA_ENV=LOCAL
NX_VEGA_REST = 'http://localhost:3029' NX_VEGA_REST=http://localhost:3029
# App flags # App flags
NX_EXPLORER_ASSETS = 1 NX_EXPLORER_ASSETS=1
NX_EXPLORER_GENESIS = 1 NX_EXPLORER_GENESIS=1
NX_EXPLORER_GOVERNANCE = 1 NX_EXPLORER_GOVERNANCE=1
NX_EXPLORER_MARKETS = 1 NX_EXPLORER_MARKETS=1
NX_EXPLORER_NETWORK_PARAMETERS = 1 NX_EXPLORER_NETWORK_PARAMETERS=1
NX_EXPLORER_PARTIES = 1 NX_EXPLORER_PARTIES=1
NX_EXPLORER_VALIDATORS = 1 NX_EXPLORER_VALIDATORS=1

View File

@ -1,8 +1,8 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = "https://n04.d.vega.xyz/tm" NX_TENDERMINT_URL=https://n04.d.vega.xyz/tm
NX_TENDERMINT_WEBSOCKET_URL = "wss://n04.d.vega.xyz/tm/websocket" NX_TENDERMINT_WEBSOCKET_URL=wss://n04.d.vega.xyz/tm/websocket
NX_VEGA_URL = "https://n04.d.vega.xyz/query" NX_VEGA_URL=https://n04.d.vega.xyz/query
NX_VEGA_NETWORKS = '{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}' NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
NX_VEGA_ENV = 'DEVNET' NX_VEGA_ENV=DEVNET
NX_VEGA_REST = 'https://n04.d.vega.xyz/datanode/rest' NX_VEGA_REST=https://n04.d.vega.xyz/datanode/rest

View File

@ -1,8 +1,8 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = "https://mainnet-observer-proxy01.ops.vega.xyz/" NX_TENDERMINT_URL=https://mainnet-observer-proxy01.ops.vega.xyz/
NX_TENDERMINT_WEBSOCKET_URL = "wss://mainnet-observer-proxy01.ops.vega.xyz/websocket" NX_TENDERMINT_WEBSOCKET_URL=wss://mainnet-observer-proxy01.ops.vega.xyz/websocket
NX_VEGA_URL = "https://api.token.vega.xyz/query" NX_VEGA_URL=https://api.token.vega.xyz/query
NX_VEGA_NETWORKS = '{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}' NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
NX_VEGA_ENV = 'MAINNET' NX_VEGA_ENV=MAINNET
NX_VEGA_REST = 'https://api.token.vega.xyz/' NX_VEGA_REST=https://api.token.vega.xyz/

View File

@ -1,8 +1,8 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = "https://n03.s.vega.xyz/tm" NX_TENDERMINT_URL=https://n03.s.vega.xyz/tm
NX_TENDERMINT_WEBSOCKET_URL = "wss://n03.s.vega.xyz/tm/websocket" NX_TENDERMINT_WEBSOCKET_URL=wss://n03.s.vega.xyz/tm/websocket
NX_VEGA_URL = "https://n03.s.vega.xyz/query" NX_VEGA_URL=https://n03.s.vega.xyz/query
NX_VEGA_NETWORKS = '{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}' NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
NX_VEGA_ENV = 'STAGNET' NX_VEGA_ENV=STAGNET
NX_VEGA_REST = 'https://n03.s.vega.xyz/datanode/rest' NX_VEGA_REST=https://n03.s.vega.xyz/datanode/rest

View File

@ -1,8 +1,8 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = "https://n03.stagnet2.vega.xyz/tm" NX_TENDERMINT_URL=https://n03.stagnet2.vega.xyz/tm
NX_TENDERMINT_WEBSOCKET_URL = "wss://n03.stagnet2.vega.xyz/tm/websocket" NX_TENDERMINT_WEBSOCKET_URL=wss://n03.stagnet2.vega.xyz/tm/websocket
NX_VEGA_URL = "https://n03.stagnet2.vega.xyz/query" NX_VEGA_URL=https://n03.stagnet2.vega.xyz/query
NX_VEGA_NETWORKS = '{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}' NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
NX_VEGA_ENV = 'STAGNET2' NX_VEGA_ENV=STAGNET2
NX_VEGA_REST = 'https://n01.stagnet2.vega.xyz/datanode/rest' NX_VEGA_REST=https://n01.stagnet2.vega.xyz/datanode/rest

View File

@ -1,8 +1,8 @@
# App configuration variables # App configuration variables
NX_CHAIN_EXPLORER_URL = "https://explorer.vega.trading/.netlify/functions/chain-explorer-api" NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL = "https://lb.testnet.vega.xyz/tm" NX_TENDERMINT_URL=https://lb.testnet.vega.xyz/tm
NX_TENDERMINT_WEBSOCKET_URL = "wss://lb.testnet.vega.xyz/tm/websocket" NX_TENDERMINT_WEBSOCKET_URL=wss://lb.testnet.vega.xyz/tm/websocket
NX_VEGA_URL = "https://lb.testnet.vega.xyz/query" NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_VEGA_NETWORKS = '{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}' NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
NX_VEGA_ENV = 'TESTNET' NX_VEGA_ENV=TESTNET
NX_VEGA_REST = 'https://lb.testnet.vega.xyz/datanode/rest' NX_VEGA_REST=https://lb.testnet.vega.xyz/datanode/rest

View File

@ -0,0 +1,7 @@
# App configuration variables
NX_CHAIN_EXPLORER_URL=https://explorer.vega.trading/.netlify/functions/chain-explorer-api
NX_TENDERMINT_URL=http://localhost:26607/
NX_TENDERMINT_WEBSOCKET_URL=wss://localhost:26607/websocket
NX_VEGA_URL=http://localhost:3003/query
NX_VEGA_ENV=CUSTOM
NX_VEGA_REST=http://localhost:3029/rest

5
apps/explorer/index.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
/// <reference types="react-scripts" />
interface Window {
_env_?: Record<string, string>;
}

View File

@ -0,0 +1,33 @@
const windowOrDefault = (key: string) => {
if (window._env_ && window._env_[key]) {
return window._env_[key] as string;
}
return (process.env[key] as string) || '';
};
const truthy = ['1', 'true'];
export const ENV = {
// Data sources
// Environment
dsn: windowOrDefault('NX_EXPLORER_SENTRY_DSN'),
envName: windowOrDefault('NX_VEGA_ENV'),
dataSources: {
chainExplorerUrl: windowOrDefault('NX_CHAIN_EXPLORER_URL'),
tendermintUrl: windowOrDefault('NX_TENDERMINT_URL'),
tendermintWebsocketUrl: windowOrDefault('NX_TENDERMINT_WEBSOCKET_URL'),
dataNodeUrl: windowOrDefault('NX_VEGA_URL'),
restEndpoint: windowOrDefault('NX_VEGA_REST'),
},
flags: {
assets: truthy.includes(windowOrDefault('NX_EXPLORER_ASSETS')),
genesis: truthy.includes(windowOrDefault('NX_EXPLORER_GENESIS')),
governance: truthy.includes(windowOrDefault('NX_EXPLORER_GOVERNANCE')),
markets: truthy.includes(windowOrDefault('NX_EXPLORER_MARKETS')),
networkParameters: truthy.includes(
windowOrDefault('NX_EXPLORER_NETWORK_PARAMETERS')
),
parties: truthy.includes(windowOrDefault('NX_EXPLORER_PARTIES')),
validators: truthy.includes(windowOrDefault('NX_EXPLORER_VALIDATORS')),
},
};

View File

@ -0,0 +1,5 @@
import { ENV } from './env';
export default {
...ENV.flags,
};

View File

@ -1,8 +1,5 @@
import { ENV } from './env';
export const DATA_SOURCES = { export const DATA_SOURCES = {
chainExplorerUrl: process.env['NX_CHAIN_EXPLORER_URL'] as string, ...ENV.dataSources,
tendermintUrl: process.env['NX_TENDERMINT_URL'] as string,
tendermintWebsocketUrl: process.env['NX_TENDERMINT_WEBSOCKET_URL'] as string,
dataNodeUrl: process.env['NX_VEGA_URL'] as string,
envName: process.env['NX_VEGA_ENV'] as string,
restEndpoint: process.env['NX_VEGA_REST'] as string,
}; };

View File

@ -1,13 +0,0 @@
const truthy = ['1', 'true'];
export default {
assets: truthy.includes(process.env['NX_EXPLORER_ASSETS'] || ''),
genesis: truthy.includes(process.env['NX_EXPLORER_GENESIS'] || ''),
governance: truthy.includes(process.env['NX_EXPLORER_GOVERNANCE'] || ''),
markets: truthy.includes(process.env['NX_EXPLORER_MARKETS'] || ''),
networkParameters: truthy.includes(
process.env['NX_EXPLORER_NETWORK_PARAMETERS'] || ''
),
parties: truthy.includes(process.env['NX_EXPLORER_PARTIES'] || ''),
validators: truthy.includes(process.env['NX_EXPLORER_VALIDATORS'] || ''),
};

View File

@ -1,7 +1,8 @@
import { DATA_SOURCES } from '../../config'; import { DATA_SOURCES } from '../../config';
import { StatsManager } from '@vegaprotocol/network-stats'; import { StatsManager } from '@vegaprotocol/network-stats';
import { ENV } from '../../config/env';
const envName = DATA_SOURCES.envName; const envName = ENV.envName;
const restEndpoint = DATA_SOURCES.restEndpoint; const restEndpoint = DATA_SOURCES.restEndpoint;
const statsEndpoint = `${restEndpoint}/statistics`; const statsEndpoint = `${restEndpoint}/statistics`;
const nodesEndpoint = `${restEndpoint}/nodes-data`; const nodesEndpoint = `${restEndpoint}/nodes-data`;

View File

@ -14,7 +14,7 @@ import { Blocks } from './blocks/home';
import { Tx } from './txs/id'; import { Tx } from './txs/id';
import { Txs as TxHome } from './txs/home'; import { Txs as TxHome } from './txs/home';
import { PendingTxs } from './pending'; import { PendingTxs } from './pending';
import flags from '../lib/flags'; import flags from '../config/flags';
import { t } from '@vegaprotocol/react-helpers'; import { t } from '@vegaprotocol/react-helpers';
import { Routes } from './route-names'; import { Routes } from './route-names';
import { NetworkParameters } from './network-parameters'; import { NetworkParameters } from './network-parameters';

View File

@ -0,0 +1 @@
window._env_ = {};

View File

@ -18,6 +18,7 @@
href="https://static.vega.xyz/favicon.ico" href="https://static.vega.xyz/favicon.ico"
/> />
<link rel="stylesheet" href="https://static.vega.xyz/fonts.css" /> <link rel="stylesheet" href="https://static.vega.xyz/fonts.css" />
<script src="./assets/env-config.js"></script>
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>

View File

@ -6,8 +6,9 @@ import { BrowserRouter } from 'react-router-dom';
import './styles.css'; import './styles.css';
import App from './app/app'; import App from './app/app';
import { ENV } from './app/config/env';
const dsn = process.env['NX_EXPLORER_SENTRY_DSN']; const { dsn } = ENV;
/* istanbul ignore next */ /* istanbul ignore next */
if (dsn) { if (dsn) {
@ -15,7 +16,7 @@ if (dsn) {
dsn, dsn,
integrations: [new BrowserTracing()], integrations: [new BrowserTracing()],
tracesSampleRate: 1, tracesSampleRate: 1,
environment: process.env['NX_VEGA_ENV'], environment: ENV.envName,
}); });
} }

View File

@ -21,6 +21,6 @@ NX_URL=$URL
NX_DEPLOY_URL=$DEPLOY_URL NX_DEPLOY_URL=$DEPLOY_URL
NX_DEPLOY_PRIME_URL=$DEPLOY_PRIME_URL NX_DEPLOY_PRIME_URL=$DEPLOY_PRIME_URL
NX_VEGA_URL = "https://lb.testnet.vega.xyz/query" NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_VEGA_ENV = 'TESTNET' NX_VEGA_ENV=TESTNET
NX_VEGA_REST = 'https://lb.testnet.vega.xyz/datanode/rest' NX_VEGA_REST=https://lb.testnet.vega.xyz/datanode/rest

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_URL = "http://localhost:3028/query" NX_VEGA_URL=http://localhost:3028/query
NX_VEGA_ENV = 'LOCAL' NX_VEGA_ENV=LOCAL
NX_VEGA_REST = 'http://localhost:3029' NX_VEGA_REST=http://localhost:3029

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_URL = "https://n04.d.vega.xyz/query" NX_VEGA_URL=https://n04.d.vega.xyz/query
NX_VEGA_ENV = 'DEVNET' NX_VEGA_ENV=DEVNET
NX_VEGA_REST = 'https://n04.d.vega.xyz/datanode/rest' NX_VEGA_REST=https://n04.d.vega.xyz/datanode/rest

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_URL = "https://api.token.vega.xyz/query" NX_VEGA_URL=https://api.token.vega.xyz/query
NX_VEGA_ENV = 'MAINNET' NX_VEGA_ENV=MAINNET
NX_VEGA_REST = 'https://api.token.vega.xyz/' NX_VEGA_REST=https://api.token.vega.xyz/

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_URL = "https://n03.s.vega.xyz/query" NX_VEGA_URL=https://n03.s.vega.xyz/query
NX_VEGA_ENV = 'STAGNET' NX_VEGA_ENV=STAGNET
NX_VEGA_REST = 'https://n03.s.vega.xyz/datanode/rest' NX_VEGA_REST=https://n03.s.vega.xyz/datanode/rest

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_URL = "https://n03.stagnet2.vega.xyz/query" NX_VEGA_URL=https://n03.stagnet2.vega.xyz/query
NX_VEGA_ENV = 'STAGNET2' NX_VEGA_ENV=STAGNET2
NX_VEGA_REST = 'https://n01.stagnet2.vega.xyz/datanode/rest' NX_VEGA_REST=https://n01.stagnet2.vega.xyz/datanode/rest

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_URL = "https://lb.testnet.vega.xyz/query" NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_VEGA_ENV = 'TESTNET' NX_VEGA_ENV=TESTNET
NX_VEGA_REST = 'https://lb.testnet.vega.xyz/datanode/rest' NX_VEGA_REST=https://lb.testnet.vega.xyz/datanode/rest

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = 'TESTNET' NX_VEGA_ENV=TESTNET
CYPRESS_VEGA_ENV = 'TESTNET' CYPRESS_VEGA_ENV=TESTNET
NX_VEGA_REST = 'https://lb.testnet.vega.xyz/datanode/rest' NX_VEGA_REST=https://lb.testnet.vega.xyz/datanode/rest

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = 'DEVNET' NX_VEGA_ENV=DEVNET
CYPRESS_VEGA_ENV = 'DEVNET' CYPRESS_VEGA_ENV=DEVNET
NX_VEGA_REST = 'https://n04.d.vega.xyz/datanode/rest' NX_VEGA_REST=https://n04.d.vega.xyz/datanode/rest

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = 'MAINNET' NX_VEGA_ENV=MAINNET
CYPRESS_VEGA_ENV = 'MAINNET' CYPRESS_VEGA_ENV=MAINNET
NX_VEGA_REST = 'https://api.token.vega.xyz/' NX_VEGA_REST=https://api.token.vega.xyz/

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = 'STAGNET 1' NX_VEGA_ENV=STAGNET 1
CYPRESS_VEGA_ENV = 'STAGNET 1' CYPRESS_VEGA_ENV=STAGNET 1
NX_VEGA_REST = 'https://n03.s.vega.xyz/datanode/rest' NX_VEGA_REST=https://n03.s.vega.xyz/datanode/rest

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = 'STAGNET 2' NX_VEGA_ENV=STAGNET 2
CYPRESS_VEGA_ENV = 'STAGNET 2' CYPRESS_VEGA_ENV=STAGNET 2
NX_VEGA_REST = 'https://n01.stagnet2.vega.xyz/datanode/rest' NX_VEGA_REST=https://n01.stagnet2.vega.xyz/datanode/rest

View File

@ -1,4 +1,4 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = 'TESTNET' NX_VEGA_ENV=TESTNET
CYPRESS_VEGA_ENV = 'TESTNET' CYPRESS_VEGA_ENV=TESTNET
NX_VEGA_REST = 'https://lb.testnet.vega.xyz/datanode/rest' NX_VEGA_REST=https://lb.testnet.vega.xyz/datanode/rest

View File

@ -1,3 +1,3 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = 'MAINNET' NX_VEGA_ENV=MAINNET
NX_VEGA_REST = 'https://api.token.vega.xyz/' NX_VEGA_REST=https://api.token.vega.xyz/

View File

@ -1,3 +1,3 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = 'DEVNET' NX_VEGA_ENV=DEVNET
NX_VEGA_REST = 'https://n04.d.vega.xyz/datanode/rest' NX_VEGA_REST=https://n04.d.vega.xyz/datanode/rest

View File

@ -1,3 +1,3 @@
# App configuration variables. No overrides for default urls # App configuration variables. No overrides for default urls
NX_VEGA_ENV = 'MAINNET' NX_VEGA_ENV=MAINNET
NX_VEGA_REST = 'https://api.token.vega.xyz/' NX_VEGA_REST=https://api.token.vega.xyz/

View File

@ -1,3 +1,3 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = 'STAGNET1' NX_VEGA_ENV=STAGNET1;
NX_VEGA_REST = 'https://n03.s.vega.xyz/datanode/rest' NX_VEGA_REST=https://n03.s.vega.xyz/datanode/rest;

View File

@ -1,3 +1,3 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = 'STAGNET2' NX_VEGA_REST=https://n01.stagnet2.vega.xyz/datanode/rest;
NX_VEGA_REST = 'https://n03.stagnet2.vega.xyz/datanode/rest' NX_VEGA_ENV=STAGNET2;

View File

@ -1,3 +1,3 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = 'TESTNET' NX_VEGA_ENV=TESTNET
NX_VEGA_REST = 'https://lb.testnet.vega.xyz/datanode/rest' NX_VEGA_REST=https://lb.testnet.vega.xyz/datanode/rest

View File

@ -19,12 +19,12 @@ REACT_APP_DEPLOY_URL=$DEPLOY_URL
REACT_APP_DEPLOY_PRIME_URL=$DEPLOY_PRIME_URL REACT_APP_DEPLOY_PRIME_URL=$DEPLOY_PRIME_URL
# App configuration variables # App configuration variables
NX_VEGA_ENV = "TESTNET" NX_VEGA_ENV=TESTNET
NX_VEGA_URL = "https://lb.testnet.vega.xyz/query" NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io
NX_FAIRGROUND = false NX_FAIRGROUND=false
#Test configuration variables #Test configuration variables
CYPRESS_FAIRGROUND = false CYPRESS_FAIRGROUND=false

View File

@ -1,6 +1,6 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "DEVNET" NX_VEGA_ENV=DEVNET
NX_VEGA_URL = "https://n04.d.vega.xyz/query" NX_VEGA_URL=https://n04.d.vega.xyz/query
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

View File

@ -1,6 +1,6 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "MAINNET" NX_VEGA_ENV=MAINNET
NX_VEGA_URL = "https://api.token.vega.xyz/query" NX_VEGA_URL=https://api.token.vega.xyz/query
NX_ETHEREUM_CHAIN_ID = 1 NX_ETHEREUM_CHAIN_ID=1
NX_ETHEREUM_PROVIDER_URL = "https://mainnet.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://mainnet.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://etherscan.io" NX_ETHERSCAN_URL=https://etherscan.io

View File

@ -1,6 +1,6 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "STAGNET" NX_VEGA_ENV=STAGNET
NX_VEGA_URL = "https://n03.s.vega.xyz/query" NX_VEGA_URL=https://n03.s.vega.xyz/query
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

View File

@ -1,6 +1,6 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "STAGNET2" NX_VEGA_ENV=STAGNET2
NX_VEGA_URL = "https://n03.stagnet2.vega.xyz/query" NX_VEGA_URL=https://n03.stagnet2.vega.xyz/query
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

View File

@ -1,6 +1,6 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "TESTNET" NX_VEGA_ENV=TESTNET
NX_VEGA_URL = "https://lb.testnet.vega.xyz/query" NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

View File

@ -19,14 +19,14 @@ REACT_APP_DEPLOY_URL=$DEPLOY_URL
REACT_APP_DEPLOY_PRIME_URL=$DEPLOY_PRIME_URL REACT_APP_DEPLOY_PRIME_URL=$DEPLOY_PRIME_URL
# App configuration variables # App configuration variables
NX_VEGA_ENV = "TESTNET" NX_VEGA_ENV=TESTNET
NX_VEGA_URL = "https://lb.testnet.vega.xyz/query" NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io
NX_FAIRGROUND = false NX_FAIRGROUND=false
NX_IS_NEW_BRIDGE_CONTRACT = true NX_IS_NEW_BRIDGE_CONTRACT=true
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}' NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
#Test configuration variables #Test configuration variables
CYPRESS_FAIRGROUND = false CYPRESS_FAIRGROUND=false

View File

@ -1,7 +1,7 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "DEVNET" NX_VEGA_ENV=DEVNET
NX_VEGA_URL = "https://n04.d.vega.xyz/query" NX_VEGA_URL=https://n04.d.vega.xyz/query
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}' NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

View File

@ -1,7 +1,7 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "MAINNET" NX_VEGA_ENV=MAINNET
NX_VEGA_URL = "https://api.token.vega.xyz/query" NX_VEGA_URL=https://api.token.vega.xyz/query
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}' NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
NX_ETHEREUM_CHAIN_ID = 1 NX_ETHEREUM_CHAIN_ID=1
NX_ETHEREUM_PROVIDER_URL = "https://mainnet.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://mainnet.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://etherscan.io" NX_ETHERSCAN_URL=https://etherscan.io

View File

@ -1,7 +1,7 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "STAGNET" NX_VEGA_ENV=STAGNET
NX_VEGA_URL = "https://n03.s.vega.xyz/query" NX_VEGA_URL=https://n03.s.vega.xyz/query
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}' NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

View File

@ -1,7 +1,7 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "STAGNET2" NX_VEGA_ENV=STAGNET2
NX_VEGA_URL = "https://n03.stagnet2.vega.xyz/query" NX_VEGA_URL=https://n03.stagnet2.vega.xyz/query
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}' NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

View File

@ -1,7 +1,7 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "TESTNET" NX_VEGA_ENV=TESTNET
NX_VEGA_URL = "https://lb.testnet.vega.xyz/query" NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}' NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

5
apps/token/index.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
/// <reference types="react-scripts" />
interface Window {
_env_?: Record<string, string>;
}

View File

@ -1,6 +1,6 @@
import './i18n'; import './i18n';
import React from 'react';
import { ApolloProvider } from '@apollo/client'; import React, { useMemo } from 'react';
import { BrowserRouter as Router } from 'react-router-dom'; import { BrowserRouter as Router } from 'react-router-dom';
import { AppLoader } from './app-loader'; import { AppLoader } from './app-loader';
import { AppBanner } from './components/app-banner'; import { AppBanner } from './components/app-banner';
@ -15,47 +15,64 @@ import { AppStateProvider } from './contexts/app-state/app-state-provider';
import { ContractsProvider } from './contexts/contracts/contracts-provider'; import { ContractsProvider } from './contexts/contracts/contracts-provider';
import { AppRouter } from './routes'; import { AppRouter } from './routes';
import { Web3Provider } from '@vegaprotocol/web3'; import { Web3Provider } from '@vegaprotocol/web3';
import { Connectors } from './lib/web3-connectors';
import { VegaWalletDialogs } from './components/vega-wallet-dialogs'; import { VegaWalletDialogs } from './components/vega-wallet-dialogs';
import { VegaWalletProvider } from '@vegaprotocol/wallet'; import { VegaWalletProvider } from '@vegaprotocol/wallet';
import { EnvironmentProvider } from '@vegaprotocol/network-switcher'; import { createConnectors } from './lib/web3-connectors';
import { client } from './lib/apollo-client'; import { ApolloProvider } from '@apollo/client';
import { createClient } from './lib/apollo-client';
import {
EnvironmentProvider,
useEnvironment,
} from '@vegaprotocol/network-switcher';
function App() { const AppContainer = () => {
const sideBar = React.useMemo(() => [<EthWallet />, <VegaWallet />], []); const sideBar = React.useMemo(() => [<EthWallet />, <VegaWallet />], []);
const { ETHEREUM_PROVIDER_URL, ETHEREUM_CHAIN_ID, VEGA_URL } =
useEnvironment();
const Connectors = useMemo(
() => createConnectors(ETHEREUM_PROVIDER_URL, ETHEREUM_CHAIN_ID),
[ETHEREUM_CHAIN_ID, ETHEREUM_PROVIDER_URL]
);
const client = useMemo(() => createClient(VEGA_URL), [VEGA_URL]);
return ( return (
<ApolloProvider client={client}> <ApolloProvider client={client}>
<Router> <Router>
<EnvironmentProvider> <AppStateProvider>
<AppStateProvider> <Web3Provider connectors={Connectors}>
<Web3Provider connectors={Connectors}> <Web3Connector>
<Web3Connector> <VegaWalletProvider>
<VegaWalletProvider> <ContractsProvider>
<ContractsProvider> <AppLoader>
<AppLoader> <BalanceManager>
<BalanceManager> <>
<> <div className="app dark max-w-[1300px] mx-auto my-0 grid grid-rows-[min-content_1fr_min-content] min-h-full lg:border-l-1 lg:border-r-1 lg:border-white font-sans text-body lg:text-body-large text-white-80">
<div className="app dark max-w-[1300px] mx-auto my-0 grid grid-rows-[min-content_1fr_min-content] min-h-full lg:border-l-1 lg:border-r-1 lg:border-white font-sans text-body lg:text-body-large text-white-80"> <AppBanner />
<AppBanner /> <TemplateSidebar sidebar={sideBar}>
<TemplateSidebar sidebar={sideBar}> <AppRouter />
<AppRouter /> </TemplateSidebar>
</TemplateSidebar> <AppFooter />
<AppFooter /> </div>
</div> <VegaWalletDialogs />
<VegaWalletDialogs /> <TransactionModal />
<TransactionModal /> </>
</> </BalanceManager>
</BalanceManager> </AppLoader>
</AppLoader> </ContractsProvider>
</ContractsProvider> </VegaWalletProvider>
</VegaWalletProvider> </Web3Connector>
</Web3Connector> </Web3Provider>
</Web3Provider> </AppStateProvider>
</AppStateProvider>
</EnvironmentProvider>
</Router> </Router>
</ApolloProvider> </ApolloProvider>
); );
};
function App() {
return (
<EnvironmentProvider>
<AppContainer />
</EnvironmentProvider>
);
} }
export default App; export default App;

View File

@ -0,0 +1 @@
window._env_ = {};

View File

@ -2,13 +2,12 @@ import { Link } from '@vegaprotocol/ui-toolkit';
import { Trans } from 'react-i18next'; import { Trans } from 'react-i18next';
import { Links } from '../../config'; import { Links } from '../../config';
import { ENV } from '../../config/env';
export const AppFooter = () => { export const AppFooter = () => {
return ( return (
<footer className="p-12 text-ui"> <footer className="p-12 text-ui">
<p className="mb-8"> <p className="mb-8">Version: {ENV.commit || 'development'}</p>
Version: {process.env['NX_COMMIT_REF'] || 'development'}
</p>
<p> <p>
<Trans <Trans
i18nKey="footerLinksText" i18nKey="footerLinksText"

View File

@ -17,7 +17,7 @@ import type {
DelegationsVariables, DelegationsVariables,
} from './__generated__/Delegations'; } from './__generated__/Delegations';
import { useVegaWallet } from '@vegaprotocol/wallet'; import { useVegaWallet } from '@vegaprotocol/wallet';
import { useEnvironment } from '@vegaprotocol/network-switcher'; import { useContracts } from '../../contexts/contracts/contracts-context';
const DELEGATIONS_QUERY = gql` const DELEGATIONS_QUERY = gql`
query Delegations($partyId: ID!) { query Delegations($partyId: ID!) {
@ -60,7 +60,7 @@ const DELEGATIONS_QUERY = gql`
`; `;
export const usePollForDelegations = () => { export const usePollForDelegations = () => {
const { ADDRESSES } = useEnvironment(); const { token: vegaToken } = useContracts();
const { t } = useTranslation(); const { t } = useTranslation();
const { keypair } = useVegaWallet(); const { keypair } = useVegaWallet();
const client = useApolloClient(); const client = useApolloClient();
@ -118,8 +118,7 @@ export const usePollForDelegations = () => {
.map((a) => { .map((a) => {
const isVega = const isVega =
a.asset.source.__typename === 'ERC20' && a.asset.source.__typename === 'ERC20' &&
a.asset.source.contractAddress === a.asset.source.contractAddress === vegaToken.address;
ADDRESSES.vegaTokenAddress;
return { return {
isVega, isVega,
@ -228,7 +227,7 @@ export const usePollForDelegations = () => {
clearInterval(interval); clearInterval(interval);
mounted = false; mounted = false;
}; };
}, [client, keypair?.pub, t, ADDRESSES.vegaTokenAddress]); }, [client, keypair?.pub, t, vegaToken.address]);
return { delegations, currentStakeAvailable, delegatedNodes, accounts }; return { delegations, currentStakeAvailable, delegatedNodes, accounts };
}; };

View File

@ -1,13 +1,14 @@
import { useEnvironment } from '@vegaprotocol/network-switcher';
import { Button, Splash } from '@vegaprotocol/ui-toolkit'; import { Button, Splash } from '@vegaprotocol/ui-toolkit';
import { Web3ConnectDialog } from '@vegaprotocol/web3'; import { Web3ConnectDialog } from '@vegaprotocol/web3';
import { useWeb3React } from '@web3-react/core'; import { useWeb3React } from '@web3-react/core';
import type { ReactElement } from 'react'; import type { ReactElement } from 'react';
import { useCallback, useEffect } from 'react'; import { useCallback, useEffect, useMemo } from 'react';
import { import {
AppStateActionType, AppStateActionType,
useAppState, useAppState,
} from '../../contexts/app-state/app-state-context'; } from '../../contexts/app-state/app-state-context';
import { Connectors } from '../../lib/web3-connectors'; import { createConnectors } from '../../lib/web3-connectors';
interface Web3ConnectorProps { interface Web3ConnectorProps {
children: ReactElement; children: ReactElement;
@ -15,13 +16,18 @@ interface Web3ConnectorProps {
export function Web3Connector({ children }: Web3ConnectorProps) { export function Web3Connector({ children }: Web3ConnectorProps) {
const { appState, appDispatch } = useAppState(); const { appState, appDispatch } = useAppState();
const { ETHEREUM_PROVIDER_URL, ETHEREUM_CHAIN_ID } = useEnvironment();
const Connectors = useMemo(
() => createConnectors(ETHEREUM_PROVIDER_URL, ETHEREUM_CHAIN_ID),
[ETHEREUM_CHAIN_ID, ETHEREUM_PROVIDER_URL]
);
const setDialogOpen = useCallback( const setDialogOpen = useCallback(
(isOpen: boolean) => { (isOpen: boolean) => {
appDispatch({ type: AppStateActionType.SET_ETH_WALLET_OVERLAY, isOpen }); appDispatch({ type: AppStateActionType.SET_ETH_WALLET_OVERLAY, isOpen });
}, },
[appDispatch] [appDispatch]
); );
const appChainId = Number(process.env['NX_ETHEREUM_CHAIN_ID']); const appChainId = Number(ETHEREUM_CHAIN_ID);
return ( return (
<> <>
<Web3Content appChainId={appChainId} setDialogOpen={setDialogOpen}> <Web3Content appChainId={appChainId} setDialogOpen={setDialogOpen}>

View File

@ -0,0 +1,29 @@
const windowOrDefault = (key: string) => {
if (window._env_ && window._env_[key]) {
return window._env_[key];
}
return process.env[key] || '';
};
const TRUTHY = ['1', 'true'];
export const ENV = {
// Environment
dsn: windowOrDefault('NX_SENTRY_DSN'),
envName: windowOrDefault('NX_VEGA_ENV'),
commit: windowOrDefault('NX_COMMIT_REF'),
branch: windowOrDefault('NX_BRANCH'),
vegaUrl: windowOrDefault('NX_VEGA_URL'),
flags: {
NETWORK_DOWN: TRUTHY.includes(windowOrDefault('NX_NETWORK_DOWN')),
HOSTED_WALLET_ENABLED: TRUTHY.includes(
windowOrDefault('NX_HOSTED_WALLET_ENABLED')
),
MOCK: TRUTHY.includes(windowOrDefault('NX_MOCKED')),
FAIRGROUND: TRUTHY.includes(windowOrDefault('NX_FAIRGROUND')),
NETWORK_LIMITS: TRUTHY.includes(windowOrDefault('NX_NETWORK_LIMITS')),
USE_NEW_BRIDGE_CONTRACT: TRUTHY.includes(
process.env['NX_IS_NEW_BRIDGE_CONTRACT'] as string
),
},
};

View File

@ -1,14 +1,5 @@
const TRUTHY = ['1', 'true']; import { ENV } from './env';
export const Flags = { export const Flags = {
NETWORK_DOWN: TRUTHY.includes(process.env['NX_NETWORK_DOWN'] as string), ...ENV.flags,
HOSTED_WALLET_ENABLED: TRUTHY.includes(
process.env['NX_HOSTED_WALLET_ENABLED'] as string
),
MOCK: TRUTHY.includes(process.env['NX_MOCKED'] as string),
FAIRGROUND: TRUTHY.includes(process.env['NX_FAIRGROUND'] as string),
NETWORK_LIMITS: TRUTHY.includes(process.env['NX_NETWORK_LIMITS'] as string),
USE_NEW_BRIDGE_CONTRACT: TRUTHY.includes(
process.env['NX_IS_NEW_BRIDGE_CONTRACT'] as string
),
}; };

View File

@ -17,31 +17,6 @@ export type NetworkConfig = {
[N in Networks]: string[]; [N in Networks]: string[];
}; };
const splitFilter = (a: string) => a.split(',').filter((a) => a.length > 0);
const getCustomNodesFromOptionalEnvironmentVariables = () => {
const validatorUrls = process.env['CUSTOM_URLS'] || '';
const validatorUrlsWithGraphQL =
process.env['CUSTOM_URLS_WITH_GRAPHQL'] || '';
const validatorUrlsList: string[] = splitFilter(validatorUrls);
const validatorUrlsWithGraphQLList: string[] = splitFilter(
validatorUrlsWithGraphQL
);
const customNodes: VegaNode[] = validatorUrlsList
.map((a) => ({ url: a, api: { GraphQL: false } }))
.concat(
validatorUrlsWithGraphQLList.map((a) => ({
url: a,
api: { GraphQL: true },
}))
);
return customNodes;
};
const customNodes = getCustomNodesFromOptionalEnvironmentVariables();
export const VegaNetworks: VegaNets = { export const VegaNetworks: VegaNets = {
[Networks.DEVNET]: { [Networks.DEVNET]: {
nodes: [ nodes: [
@ -179,9 +154,6 @@ export const VegaNetworks: VegaNets = {
}, },
], ],
}, },
[Networks.CUSTOM]: {
nodes: customNodes,
},
[Networks.MAINNET]: { [Networks.MAINNET]: {
nodes: [], nodes: [],
}, },

View File

@ -11,7 +11,7 @@ import React from 'react';
import { SplashLoader } from '../../components/splash-loader'; import { SplashLoader } from '../../components/splash-loader';
import type { ContractsContextShape } from './contracts-context'; import type { ContractsContextShape } from './contracts-context';
import { ContractsContext } from './contracts-context'; import { ContractsContext } from './contracts-context';
import { defaultProvider } from '../../lib/web3-connectors'; import { createDefaultProvider } from '../../lib/web3-connectors';
import { useEthereumConfig } from '@vegaprotocol/web3'; import { useEthereumConfig } from '@vegaprotocol/web3';
import { useEnvironment } from '@vegaprotocol/network-switcher'; import { useEnvironment } from '@vegaprotocol/network-switcher';
@ -21,41 +21,55 @@ import { useEnvironment } from '@vegaprotocol/network-switcher';
export const ContractsProvider = ({ children }: { children: JSX.Element }) => { export const ContractsProvider = ({ children }: { children: JSX.Element }) => {
const { provider: activeProvider, account } = useWeb3React(); const { provider: activeProvider, account } = useWeb3React();
const { config } = useEthereumConfig(); const { config } = useEthereumConfig();
const { VEGA_ENV, ADDRESSES } = useEnvironment(); const { VEGA_ENV, ADDRESSES, ETHEREUM_PROVIDER_URL, ETHEREUM_CHAIN_ID } =
useEnvironment();
const [contracts, setContracts] = const [contracts, setContracts] =
React.useState<ContractsContextShape | null>(null); React.useState<ContractsContextShape | null>(null);
const defaultProvider = createDefaultProvider(
ETHEREUM_PROVIDER_URL,
ETHEREUM_CHAIN_ID
);
// Create instances of contract classes. If we have an account use a signer for the // Create instances of contract classes. If we have an account use a signer for the
// contracts so that we can sign transactions, otherwise use the provider for just // contracts so that we can sign transactions, otherwise use the provider for just
// reading data // reading data
React.useEffect(() => { React.useEffect(() => {
let signer = null; const run = async () => {
let signer = null;
const provider = activeProvider ? activeProvider : defaultProvider; const provider = activeProvider ? activeProvider : defaultProvider;
if ( if (
account && account &&
activeProvider && activeProvider &&
typeof activeProvider.getSigner === 'function' typeof activeProvider.getSigner === 'function'
) { ) {
signer = provider.getSigner(); signer = provider.getSigner();
} }
if (provider && config) { if (provider && config) {
setContracts({ const staking = new StakingBridge(
token: new Token(ADDRESSES.vegaTokenAddress, signer || provider),
staking: new StakingBridge(
config.staking_bridge_contract.address, config.staking_bridge_contract.address,
signer || provider signer || provider
), );
vesting: new TokenVesting( const vegaAddress = await staking.stakingToken();
config.token_vesting_contract.address,
signer || provider setContracts({
), token: new Token(vegaAddress, signer || provider),
claim: new Claim(ADDRESSES.claimAddress, signer || provider), staking: new StakingBridge(
}); config.staking_bridge_contract.address,
} signer || provider
}, [activeProvider, account, config, ADDRESSES, VEGA_ENV]); ),
vesting: new TokenVesting(
config.token_vesting_contract.address,
signer || provider
),
claim: new Claim(ADDRESSES.claimAddress, signer || provider),
});
}
};
run();
}, [activeProvider, account, config, ADDRESSES, VEGA_ENV, defaultProvider]);
if (!contracts) { if (!contracts) {
return ( return (

View File

@ -12,7 +12,6 @@ const TRANCHES_URLS: { [N in Networks]: string } = {
STAGNET: 'https://static.vega.xyz/assets/stagnet1-tranches.json', STAGNET: 'https://static.vega.xyz/assets/stagnet1-tranches.json',
STAGNET2: 'https://static.vega.xyz/assets/stagnet2-tranches.json', STAGNET2: 'https://static.vega.xyz/assets/stagnet2-tranches.json',
DEVNET: 'https://static.vega.xyz/assets/devnet-tranches.json', DEVNET: 'https://static.vega.xyz/assets/devnet-tranches.json',
CUSTOM: '',
}; };
export function useTranches() { export function useTranches() {

View File

@ -25,6 +25,7 @@
crossorigin="anonymous" crossorigin="anonymous"
/> />
<title>Vega Token dApp</title> <title>Vega Token dApp</title>
<script src="./assets/env-config.js"></script>
</head> </head>
<body class="h-full"> <body class="h-full">
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>

View File

@ -8,7 +8,6 @@ import uniqBy from 'lodash/uniqBy';
import { BigNumber } from './bignumber'; import { BigNumber } from './bignumber';
import { addDecimal } from './decimals'; import { addDecimal } from './decimals';
import { deterministicShuffle } from './deterministic-shuffle'; import { deterministicShuffle } from './deterministic-shuffle';
import { getDataNodeUrl } from './get-data-node-url';
// Create seed in memory. Validator list order will remain the same // Create seed in memory. Validator list order will remain the same
// until the page is refreshed. // until the page is refreshed.
@ -16,9 +15,10 @@ const VALIDATOR_RANDOMISER_SEED = (
Math.floor(Math.random() * 1000) + 1 Math.floor(Math.random() * 1000) + 1
).toString(); ).toString();
export function createClient() { export function createClient(base?: string) {
const { graphql } = getDataNodeUrl(); if (!base) {
throw new Error('Base must be passed into createClient!');
}
const formatUintToNumber = (amount: string, decimals = 18) => const formatUintToNumber = (amount: string, decimals = 18) =>
addDecimal(new BigNumber(amount), decimals).toString(); addDecimal(new BigNumber(amount), decimals).toString();
@ -155,7 +155,7 @@ export function createClient() {
}); });
const httpLink = new HttpLink({ const httpLink = new HttpLink({
uri: graphql, uri: base,
credentials: 'same-origin', credentials: 'same-origin',
}); });
@ -172,5 +172,3 @@ export function createClient() {
cache, cache,
}); });
} }
export const client = createClient();

View File

@ -1,5 +1,7 @@
import { ENV } from '../config/env';
export function getDataNodeUrl() { export function getDataNodeUrl() {
const base = process.env['NX_VEGA_URL']; const base = ENV.vegaUrl;
if (!base) { if (!base) {
throw new Error('Environment variable NX_VEGA_URL must be set'); throw new Error('Environment variable NX_VEGA_URL must be set');
} }

View File

@ -4,34 +4,30 @@ import { initializeConnector } from '@web3-react/core';
import { MetaMask } from '@web3-react/metamask'; import { MetaMask } from '@web3-react/metamask';
import { WalletConnect } from '@web3-react/walletconnect'; import { WalletConnect } from '@web3-react/walletconnect';
export const [metamask, metamaskHooks] = initializeConnector<MetaMask>( const [metamask, metamaskHooks] = initializeConnector<MetaMask>(
(actions) => new MetaMask(actions) (actions) => new MetaMask(actions)
); );
const CHAIN_ID = Number(process.env['NX_ETHEREUM_CHAIN_ID']); export const createDefaultProvider = (providerUrl: string, chainId: number) => {
const PROVIDER_URL = process.env['NX_ETHEREUM_PROVIDER_URL'] as string; return new ethers.providers.JsonRpcProvider(providerUrl, chainId);
};
if (isNaN(CHAIN_ID)) { export const createConnectors = (providerUrl: string, chainId: number) => {
throw new Error('Invalid Ethereum chain ID for environment'); if (isNaN(chainId)) {
} throw new Error('Invalid Ethereum chain ID for environment');
}
export const [walletconnect, walletconnectHooks] = const [walletconnect, walletconnectHooks] =
initializeConnector<WalletConnect>( initializeConnector<WalletConnect>(
(actions) => (actions) =>
new WalletConnect(actions, { new WalletConnect(actions, {
rpc: { rpc: {
[CHAIN_ID]: PROVIDER_URL, [chainId]: providerUrl,
}, },
}), }),
[CHAIN_ID] [chainId]
); );
return [
export const defaultProvider = new ethers.providers.JsonRpcProvider( [metamask, metamaskHooks],
PROVIDER_URL, [walletconnect, walletconnectHooks],
CHAIN_ID ] as [MetaMask | WalletConnect, Web3ReactHooks][];
); };
export const Connectors: [MetaMask | WalletConnect, Web3ReactHooks][] = [
[metamask, metamaskHooks],
[walletconnect, walletconnectHooks],
];

View File

@ -7,11 +7,12 @@ import ReactDOM from 'react-dom';
import App from './app'; import App from './app';
import reportWebVitals from './report-web-vitals'; import reportWebVitals from './report-web-vitals';
import { ENV } from './config/env';
const dsn = process.env['NX_SENTRY_DSN'] || false; const dsn = ENV.dsn || false;
const environment = process.env['NX_VEGA_ENV'] || 'local'; const environment = ENV.envName || 'local';
const commit = process.env['NX_COMMIT_REF'] || 'local'; const commit = ENV.commit || 'local';
const branch = process.env['NX_BRANCH'] || 'unknown'; const branch = ENV.branch || 'unknown';
/* istanbul ignore next */ /* istanbul ignore next */
if (dsn) { if (dsn) {

View File

@ -9,6 +9,7 @@ import { formatNumber } from '../../../lib/format-number';
import { TokenDetailsCirculating } from './token-details-circulating'; import { TokenDetailsCirculating } from './token-details-circulating';
import { SplashLoader } from '../../../components/splash-loader'; import { SplashLoader } from '../../../components/splash-loader';
import { useEthereumConfig } from '@vegaprotocol/web3'; import { useEthereumConfig } from '@vegaprotocol/web3';
import { useContracts } from '../../../contexts/contracts/contracts-context';
export const TokenDetails = ({ export const TokenDetails = ({
totalSupply, totalSupply,
@ -17,11 +18,12 @@ export const TokenDetails = ({
totalSupply: BigNumber; totalSupply: BigNumber;
totalStaked: BigNumber; totalStaked: BigNumber;
}) => { }) => {
const { ADDRESSES, ETHERSCAN_URL } = useEnvironment(); const { ETHERSCAN_URL } = useEnvironment();
const { t } = useTranslation(); const { t } = useTranslation();
const { tranches, loading, error } = useTranches(); const { tranches, loading, error } = useTranches();
const { config } = useEthereumConfig(); const { config } = useEthereumConfig();
const { token } = useContracts();
if (error) { if (error) {
return ( return (
@ -47,10 +49,9 @@ export const TokenDetails = ({
data-testid="token-address" data-testid="token-address"
title={t('View on Etherscan (opens in a new tab)')} title={t('View on Etherscan (opens in a new tab)')}
className="font-mono" className="font-mono"
href={`${ETHERSCAN_URL}/address/${ADDRESSES.vegaTokenAddress}`} href={`${ETHERSCAN_URL}/address/${token.address}`}
target="_blank"
> >
{ADDRESSES.vegaTokenAddress} {token.address}
</Link> </Link>
</KeyValueTableRow> </KeyValueTableRow>
<KeyValueTableRow> <KeyValueTableRow>

View File

@ -3,7 +3,6 @@ import { Trans, useTranslation } from 'react-i18next';
import { Link, useParams, useOutletContext } from 'react-router-dom'; import { Link, useParams, useOutletContext } from 'react-router-dom';
import { TransactionCallout } from '../../../components/transaction-callout'; import { TransactionCallout } from '../../../components/transaction-callout';
import { useEnvironment } from '@vegaprotocol/network-switcher';
import { useAppState } from '../../../contexts/app-state/app-state-context'; import { useAppState } from '../../../contexts/app-state/app-state-context';
import { useContracts } from '../../../contexts/contracts/contracts-context'; import { useContracts } from '../../../contexts/contracts/contracts-context';
import { import {
@ -25,7 +24,6 @@ export const RedeemFromTranche = () => {
address: string; address: string;
}>(); }>();
const { vesting } = useContracts(); const { vesting } = useContracts();
const { ADDRESSES } = useEnvironment();
const { t } = useTranslation(); const { t } = useTranslation();
const { const {
appState: { lien, totalVestedBalance, trancheBalances, totalLockedBalance }, appState: { lien, totalVestedBalance, trancheBalances, totalLockedBalance },
@ -44,6 +42,8 @@ export const RedeemFromTranche = () => {
perform, perform,
dispatch: txDispatch, dispatch: txDispatch,
} = useTransaction(() => vesting.withdrawFromTranche(numberId)); } = useTransaction(() => vesting.withdrawFromTranche(numberId));
const { token } = useContracts();
const redeemedAmount = React.useMemo(() => { const redeemedAmount = React.useMemo(() => {
return ( return (
trancheBalances.find(({ id: bId }) => bId.toString() === id?.toString()) trancheBalances.find(({ id: bId }) => bId.toString() === id?.toString())
@ -111,7 +111,7 @@ export const RedeemFromTranche = () => {
{t( {t(
'The VEGA token address is {{address}}, make sure you add this to your wallet to see your tokens', 'The VEGA token address is {{address}}, make sure you add this to your wallet to see your tokens',
{ {
address: ADDRESSES.vegaTokenAddress, address: token.address,
} }
)} )}
</p> </p>

1
apps/trading-e2e/.env Normal file
View File

@ -0,0 +1 @@
NX_USE_ENV_OVERRIDES=0

View File

@ -14,7 +14,6 @@
"chromeWebSecurity": false, "chromeWebSecurity": false,
"projectId": "et4snf", "projectId": "et4snf",
"defaultCommandTimeout": 10000, "defaultCommandTimeout": 10000,
"env": { "env": {
"TRADING_TEST_VEGA_WALLET_NAME": "UI_Trading_Test", "TRADING_TEST_VEGA_WALLET_NAME": "UI_Trading_Test",
"ETHEREUM_PROVIDER_URL": "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8", "ETHEREUM_PROVIDER_URL": "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8",
@ -26,6 +25,8 @@
"ETHEREUM_WALLET_ADDRESS": "0x265Cc6d39a1B53d0d92068443009eE7410807158", "ETHEREUM_WALLET_ADDRESS": "0x265Cc6d39a1B53d0d92068443009eE7410807158",
"ETHERSCAN_URL": "https://ropsten.etherscan.io", "ETHERSCAN_URL": "https://ropsten.etherscan.io",
"tsConfig": "tsconfig.json", "tsConfig": "tsconfig.json",
"TAGS": "not @todo and not @ignore and not @manual" "TAGS": "not @todo and not @ignore and not @manual",
"TRADING_TEST_VEGA_WALLET_PASSPHRASE": "123",
"ETH_WALLET_MNEMONIC": "ugly gallery notice network true range brave clarify flat logic someone chunk"
} }
} }

View File

@ -1,27 +1,8 @@
# React Environment Variables
# https://facebook.github.io/create-react-app/docs/adding-custom-environment-variables#expanding-environment-variables-in-env
# Netlify Environment Variables
# https://www.netlify.com/docs/continuous-deployment/#environment-variables
NX_VERSION=$npm_package_version
NX_REPOSITORY_URL=$REPOSITORY_URL
NX_BRANCH=$BRANCH
NX_PULL_REQUEST=$PULL_REQUEST
NX_HEAD=$HEAD
NX_COMMIT_REF=$COMMIT_REF
NX_CONTEXT=$CONTEXT
NX_REVIEW_ID=$REVIEW_ID
NX_INCOMING_HOOK_TITLE=$INCOMING_HOOK_TITLE
NX_INCOMING_HOOK_URL=$INCOMING_HOOK_URL
NX_INCOMING_HOOK_BODY=$INCOMING_HOOK_BODY
NX_URL=$URL
NX_DEPLOY_URL=$DEPLOY_URL
NX_DEPLOY_PRIME_URL=$DEPLOY_PRIME_URL
# App configuration variables # App configuration variables
NX_VEGA_ENV = "TESTNET" NX_VEGA_ENV=TESTNET
NX_VEGA_URL = "https://lb.testnet.vega.xyz/query" NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io
NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}' NX_VEGA_NETWORKS={\"MAINNET\":\"https://alpha.console.vega.xyz\"}
NX_USE_ENV_OVERRIDES=1

View File

@ -1,7 +1,7 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "DEVNET" NX_VEGA_ENV=DEVNET
NX_VEGA_URL = "https://n04.d.vega.xyz/query" NX_VEGA_URL=https://n04.d.vega.xyz/query
NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}' NX_VEGA_NETWORKS={\"MAINNET\":\"https://alpha.console.vega.xyz\"}
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

View File

@ -1,7 +1,7 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "MAINNET" NX_VEGA_ENV=MAINNET
NX_VEGA_URL = "https://api.token.vega.xyz/query" NX_VEGA_URL=https://api.token.vega.xyz/query
NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}' NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}'
NX_ETHEREUM_CHAIN_ID = 1 NX_ETHEREUM_CHAIN_ID=1
NX_ETHEREUM_PROVIDER_URL = "https://mainnet.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://mainnet.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://etherscan.io" NX_ETHERSCAN_URL=https://etherscan.io

View File

@ -1,7 +1,7 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "STAGNET" NX_VEGA_ENV=STAGNET
NX_VEGA_URL = "https://n03.s.vega.xyz/query" NX_VEGA_URL=https://n03.s.vega.xyz/query
NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}' NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}'
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

View File

@ -1,7 +1,7 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "STAGNET2" NX_VEGA_ENV=STAGNET2
NX_VEGA_URL = "https://n03.stagnet2.vega.xyz/query" NX_VEGA_URL=https://n03.stagnet2.vega.xyz/query
NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}' NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}'
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

View File

@ -1,7 +1,7 @@
# App configuration variables # App configuration variables
NX_VEGA_ENV = "TESTNET" NX_VEGA_ENV=TESTNET
NX_VEGA_URL = "https://lb.testnet.vega.xyz/query" NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}' NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}'
NX_ETHEREUM_CHAIN_ID = 3 NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL = "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8" NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL = "https://ropsten.etherscan.io" NX_ETHERSCAN_URL=https://ropsten.etherscan.io

View File

View File

@ -0,0 +1 @@
window._env_ = {};

View File

@ -5,6 +5,7 @@ import { Web3Container } from './web3-container';
import type { useWeb3React } from '@web3-react/core'; import type { useWeb3React } from '@web3-react/core';
import type { NetworkParamsQuery } from '@vegaprotocol/web3'; import type { NetworkParamsQuery } from '@vegaprotocol/web3';
import { NETWORK_PARAMS_QUERY } from '@vegaprotocol/web3'; import { NETWORK_PARAMS_QUERY } from '@vegaprotocol/web3';
import { EnvironmentProvider } from '@vegaprotocol/network-switcher';
const defaultHookValue = { const defaultHookValue = {
isActive: false, isActive: false,
@ -50,14 +51,16 @@ jest.mock('@web3-react/core', () => {
function setup(mock = networkParamsQueryMock) { function setup(mock = networkParamsQueryMock) {
return render( return render(
<MockedProvider mocks={[mock]}> <EnvironmentProvider>
<Web3Container> <MockedProvider mocks={[mock]}>
<div> <Web3Container>
<div>Child</div> <div>
<div>{mockEthereumConfig.collateral_bridge_contract.address}</div> <div>Child</div>
</div> <div>{mockEthereumConfig.collateral_bridge_contract.address}</div>
</Web3Container> </div>
</MockedProvider> </Web3Container>
</MockedProvider>
</EnvironmentProvider>
); );
} }

View File

@ -6,9 +6,10 @@ import {
} from '@vegaprotocol/web3'; } from '@vegaprotocol/web3';
import { useWeb3React } from '@web3-react/core'; import { useWeb3React } from '@web3-react/core';
import type { ReactNode } from 'react'; import type { ReactNode } from 'react';
import { useEffect, useState } from 'react'; import { useEffect, useState, useMemo } from 'react';
import { Connectors } from '../../lib/web3-connectors';
import { t } from '@vegaprotocol/react-helpers'; import { t } from '@vegaprotocol/react-helpers';
import { useEnvironment } from '@vegaprotocol/network-switcher';
import { createConnectors } from '../../lib/web3-connectors';
interface Web3ContainerProps { interface Web3ContainerProps {
children: ReactNode; children: ReactNode;
@ -17,7 +18,11 @@ interface Web3ContainerProps {
export const Web3Container = ({ children }: Web3ContainerProps) => { export const Web3Container = ({ children }: Web3ContainerProps) => {
const [dialogOpen, setDialogOpen] = useState(false); const [dialogOpen, setDialogOpen] = useState(false);
const { config, loading, error } = useEthereumConfig(); const { config, loading, error } = useEthereumConfig();
const { ETHEREUM_PROVIDER_URL, ETHEREUM_CHAIN_ID } = useEnvironment();
const Connectors = useMemo(
() => createConnectors(ETHEREUM_PROVIDER_URL, ETHEREUM_CHAIN_ID),
[ETHEREUM_CHAIN_ID, ETHEREUM_PROVIDER_URL]
);
return ( return (
<AsyncRenderer data={config} loading={loading} error={error}> <AsyncRenderer data={config} loading={loading} error={error}>
{config ? ( {config ? (

View File

@ -4,3 +4,7 @@ declare module '*.svg' {
export const ReactComponent: any; export const ReactComponent: any;
export default content; export default content;
} }
interface Window {
_env_?: Record<string, string>;
}

View File

@ -0,0 +1,21 @@
const windowOrDefault = (key: string, defaultValue?: string) => {
if (typeof window !== 'undefined') {
if (window._env_ && window._env_[key]) {
return window._env_[key];
}
}
return defaultValue || '';
};
/**
* Need to have default value as next in-lines environment variables. Cannot figure out dynamic keys.
* So must provide the default with the key so that next can figure it out.
*/
export const ENV = {
dsn: windowOrDefault(
'NX_TRADING_SENTRY_DSN',
process.env['NX_TRADING_SENTRY_DSN']
),
envName: windowOrDefault('NX_VEGA_ENV', process.env['NX_VEGA_ENV']),
vegaUrl: windowOrDefault('NX_VEGA_URL', process.env['NX_VEGA_URL']),
};

View File

@ -0,0 +1 @@
export * from './env';

View File

@ -7,24 +7,22 @@ const [metamask, metamaskHooks] = initializeConnector<MetaMask>(
(actions) => new MetaMask(actions) (actions) => new MetaMask(actions)
); );
const CHAIN_ID = Number(process.env['NX_ETHEREUM_CHAIN_ID']); export const createConnectors = (providerUrl: string, chainId: number) => {
const PROVIDER_URL = process.env['NX_ETHEREUM_PROVIDER_URL'] as string; if (isNaN(chainId)) {
throw new Error('Invalid Ethereum chain ID for environment');
if (isNaN(CHAIN_ID)) { }
throw new Error('Invalid Ethereum chain ID for environment'); const [walletconnect, walletconnectHooks] =
} initializeConnector<WalletConnect>(
(actions) =>
const [walletconnect, walletconnectHooks] = initializeConnector<WalletConnect>( new WalletConnect(actions, {
(actions) => rpc: {
new WalletConnect(actions, { [chainId]: providerUrl,
rpc: { },
[CHAIN_ID]: PROVIDER_URL, }),
}, [chainId]
}), );
[CHAIN_ID] return [
); [metamask, metamaskHooks],
[walletconnect, walletconnectHooks],
export const Connectors: [MetaMask | WalletConnect, Web3ReactHooks][] = [ ] as [MetaMask | WalletConnect, Web3ReactHooks][];
[metamask, metamaskHooks], };
[walletconnect, walletconnectHooks],
];

View File

@ -7,11 +7,7 @@ import {
VegaManageDialog, VegaManageDialog,
VegaWalletProvider, VegaWalletProvider,
} from '@vegaprotocol/wallet'; } from '@vegaprotocol/wallet';
import { import { NetworkSwitcherDialog } from '@vegaprotocol/network-switcher';
useEnvironment,
EnvironmentProvider,
NetworkSwitcherDialog,
} from '@vegaprotocol/network-switcher';
import { Connectors } from '../lib/vega-connectors'; import { Connectors } from '../lib/vega-connectors';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { createClient } from '../lib/apollo-client'; import { createClient } from '../lib/apollo-client';
@ -21,6 +17,9 @@ import { AppLoader } from '../components/app-loader';
import { VegaWalletConnectButton } from '../components/vega-wallet-connect-button'; import { VegaWalletConnectButton } from '../components/vega-wallet-connect-button';
import './styles.css'; import './styles.css';
import { useGlobalStore } from '../stores'; import { useGlobalStore } from '../stores';
import { ENV } from '../lib/config/env';
import { EnvironmentProvider } from '@vegaprotocol/network-switcher';
import { useEnvironment } from '@vegaprotocol/network-switcher';
function AppBody({ Component, pageProps }: AppProps) { function AppBody({ Component, pageProps }: AppProps) {
const store = useGlobalStore(); const store = useGlobalStore();
@ -72,7 +71,7 @@ function AppBody({ Component, pageProps }: AppProps) {
function VegaTradingApp(props: AppProps) { function VegaTradingApp(props: AppProps) {
const [theme] = useThemeSwitcher(); const [theme] = useThemeSwitcher();
const client = useMemo(() => createClient(process.env['NX_VEGA_URL']), []); const client = useMemo(() => createClient(ENV.vegaUrl), []);
return ( return (
<EnvironmentProvider> <EnvironmentProvider>
@ -98,6 +97,12 @@ function VegaTradingApp(props: AppProps) {
rel="stylesheet" rel="stylesheet"
href="https://static.vega.xyz/fonts.css" href="https://static.vega.xyz/fonts.css"
/> />
{['1', 'true'].includes(
process.env['NX_USE_ENV_OVERRIDES'] || ''
) ? (
/* eslint-disable-next-line @next/next/no-sync-scripts */
<script src="./env-config.js" type="text/javascript" />
) : null}
</Head> </Head>
<AppBody {...props} /> <AppBody {...props} />
</AppLoader> </AppLoader>

View File

@ -1,9 +1,9 @@
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { WithdrawPageContainer } from './withdraw-page-container'; import { WithdrawPageContainer } from './withdraw-page-container';
import { t } from '@vegaprotocol/react-helpers';
import { VegaWalletContainer } from '../../../components/vega-wallet-container'; import { VegaWalletContainer } from '../../../components/vega-wallet-container';
import { Web3Container } from '../../../components/web3-container'; import { Web3Container } from '../../../components/web3-container';
import { t } from '@vegaprotocol/react-helpers';
const Withdraw = () => { const Withdraw = () => {
const { query } = useRouter(); const { query } = useRouter();

View File

@ -1,13 +1,14 @@
import * as Sentry from '@sentry/nextjs'; import * as Sentry from '@sentry/nextjs';
import { BrowserTracing } from '@sentry/tracing'; import { BrowserTracing } from '@sentry/tracing';
import { ENV } from './lib/config/env';
const dsn = process.env['NX_TRADING_SENTRY_DSN']; const { dsn } = ENV;
if (dsn) { if (dsn) {
Sentry.init({ Sentry.init({
dsn, dsn,
integrations: [new BrowserTracing()], integrations: [new BrowserTracing()],
tracesSampleRate: 1, tracesSampleRate: 1,
environment: process.env['NX_VEGA_ENV'], environment: ENV.envName,
}); });
} }

View File

@ -1,13 +1,14 @@
import * as Sentry from '@sentry/nextjs'; import * as Sentry from '@sentry/nextjs';
import { BrowserTracing } from '@sentry/tracing'; import { BrowserTracing } from '@sentry/tracing';
import { ENV } from './lib/config/env';
const dsn = process.env['NX_TRADING_SENTRY_DSN']; const { dsn } = ENV;
if (dsn) { if (dsn) {
Sentry.init({ Sentry.init({
dsn, dsn,
integrations: [new BrowserTracing()], integrations: [new BrowserTracing()],
tracesSampleRate: 1, tracesSampleRate: 1,
environment: process.env['NX_VEGA_ENV'], environment: ENV.envName,
}); });
} }

18
env-config.js Normal file
View File

@ -0,0 +1,18 @@
window._env_ = {
NX_CHAIN_EXPLORER_URL:
'https://explorer.vega.trading/.netlify/functions/chain-explorer-api;',
NX_TENDERMINT_URL: 'http://localhost:26617;',
NX_TENDERMINT_WEBSOCKET_URL: 'wss://localhost:26617/websocket;',
NX_VEGA_URL: 'http://localhost:3028/query;',
NX_VEGA_ENV: 'LOCAL;',
NX_VEGA_REST: 'http://localhost:3029;',
NX_VEGA_REST: 'http://localhost:3029;',
NX_VEGA_REST: 'http://localhost:3029;',
NX_EXPLORER_ASSETS: '1;',
NX_EXPLORER_GENESIS: '1;',
NX_EXPLORER_GOVERNANCE: '1;',
NX_EXPLORER_MARKETS: '1;',
NX_EXPLORER_NETWORK_PARAMETERS: '1;',
NX_EXPLORER_PARTIES: '1;',
NX_EXPLORER_VALIDATORS: '1;',
};

32
env.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
# Recreate config file
mkdir assets
rm -rf ./assets/env-config.js
touch ./assets/env-config.js
# Add assignment
echo "window._env_ = {" >> ./assets/env-config.js
# Read each line in .env file
# Each line represents key=value pairs
while read -r line || [[ -n "$line" ]];
do
# Split env variables by character `=`
if printf '%s\n' "$line" | grep -q -e '='; then
varname=$(printf '%s\n' "$line" | sed -e 's/=.*//')
varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//')
fi
# Read value of current variable if exists as Environment variable
value=$(printf '%s\n' "${!varname}")
# Otherwise use value from .env file
[[ -z $value ]] && value=${varvalue}
# Append configuration property to JS file if non-empty
if [ ! -z "$varname" ]; then
echo " $varname: \"$value\"," >> ./assets/env-config.js
fi
done < .env
echo "}" >> ./assets/env-config.js

View File

@ -1,52 +1,38 @@
import { useState } from 'react';
import type { ReactNode } from 'react';
import { createContext, useContext } from 'react';
import type { Networks } from '@vegaprotocol/react-helpers'; import type { Networks } from '@vegaprotocol/react-helpers';
import type { ReactNode } from 'react';
import { useState } from 'react';
import { createContext, useContext } from 'react';
const isBrowser = typeof window !== 'undefined'; const isBrowser = typeof window !== 'undefined';
declare global { declare global {
interface Window { interface Window {
_ENV?: RawEnvironment; _env_?: Record<string, string>;
} }
} }
const customVegaTokenAddress = process.env['CUSTOM_TOKEN_ADDRESS'] as string;
const customClaimAddress = process.env['CUSTOM_CLAIM_ADDRESS'] as string;
const customLockedAddress = process.env['CUSTOM_LOCKED_ADDRESS'] as string;
interface VegaContracts { interface VegaContracts {
vegaTokenAddress: string;
claimAddress: string; claimAddress: string;
lockedAddress: string; lockedAddress: string;
} }
export const ContractAddresses: { [key in Networks]: VegaContracts } = { export const ContractAddresses: { [key in Networks]: VegaContracts } = {
CUSTOM: {
vegaTokenAddress: customVegaTokenAddress,
claimAddress: customClaimAddress,
lockedAddress: customLockedAddress,
},
DEVNET: { DEVNET: {
vegaTokenAddress: '0xc93137f9F4B820Ca85FfA3C7e84cCa6Ebc7bB517',
claimAddress: '0x8Cef746ab7C83B61F6461cC92882bD61AB65a994', claimAddress: '0x8Cef746ab7C83B61F6461cC92882bD61AB65a994',
lockedAddress: '0x0', lockedAddress: '0x0',
}, },
STAGNET: { STAGNET: {
vegaTokenAddress: '0x547cbA83a7eb82b546ee5C7ff0527F258Ba4546D',
claimAddress: '0x8Cef746ab7C83B61F6461cC92882bD61AB65a994', // TODO not deployed to this env, but random address so app doesn't error claimAddress: '0x8Cef746ab7C83B61F6461cC92882bD61AB65a994', // TODO not deployed to this env, but random address so app doesn't error
lockedAddress: '0x0', // TODO not deployed to this env lockedAddress: '0x0', // TODO not deployed to this env
}, },
STAGNET2: { STAGNET2: {
vegaTokenAddress: '0xd8fa193B93a179DdCf51FFFDe5320E0872cdcf44',
claimAddress: '0x8Cef746ab7C83B61F6461cC92882bD61AB65a994', // TODO not deployed to this env, but random address so app doesn't error claimAddress: '0x8Cef746ab7C83B61F6461cC92882bD61AB65a994', // TODO not deployed to this env, but random address so app doesn't error
lockedAddress: '0x0', // TODO not deployed to this env lockedAddress: '0x0', // TODO not deployed to this env
}, },
TESTNET: { TESTNET: {
vegaTokenAddress: '0xDc335304979D378255015c33AbFf09B60c31EBAb',
claimAddress: '0x8Cef746ab7C83B61F6461cC92882bD61AB65a994', // TODO not deployed to this env, but random address so app doesn't error claimAddress: '0x8Cef746ab7C83B61F6461cC92882bD61AB65a994', // TODO not deployed to this env, but random address so app doesn't error
lockedAddress: '0x0', // TODO not deployed to this env lockedAddress: '0x0', // TODO not deployed to this env
}, },
MAINNET: { MAINNET: {
vegaTokenAddress: '0xcB84d72e61e383767C4DFEb2d8ff7f4FB89abc6e',
claimAddress: '0x0ee1fb382caf98e86e97e51f9f42f8b4654020f3', claimAddress: '0x0ee1fb382caf98e86e97e51f9f42f8b4654020f3',
lockedAddress: '0x78344c7305d73a7a0ac3c94cd9960f4449a1814e', lockedAddress: '0x78344c7305d73a7a0ac3c94cd9960f4449a1814e',
}, },
@ -133,7 +119,7 @@ const getValue = (key: EnvKey, definitions: Partial<RawEnvironment> = {}) => {
} }
return transformValue( return transformValue(
key, key,
window._ENV?.[key] ?? definitions[key] ?? getBundledEnvironmentValue(key) window._env_?.[key] ?? definitions[key] ?? getBundledEnvironmentValue(key)
); );
}; };

View File

@ -1,5 +1,4 @@
export enum Networks { export enum Networks {
CUSTOM = 'CUSTOM',
TESTNET = 'TESTNET', TESTNET = 'TESTNET',
STAGNET = 'STAGNET', STAGNET = 'STAGNET',
STAGNET2 = 'STAGNET2', STAGNET2 = 'STAGNET2',

Some files were not shown because too many files have changed in this diff Show More