Skip to content

Commit

Permalink
fix: Change networks by environment
Browse files Browse the repository at this point in the history
  • Loading branch information
gaquarius committed Feb 9, 2024
1 parent 9bd5165 commit 3979636
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 32 deletions.
19 changes: 19 additions & 0 deletions Dockerfile-Staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# hadolint global ignore=DL3016
# checkov:skip=CKV_DOCKER_3:Ensure that a user for the container has been created

# build environment
FROM node:21 as build

WORKDIR /app
COPY . .
RUN yarn policies set-version '3.3.1'

RUN yarn install \
&& yarn run build:staging

# staging environment
FROM nginx:1.25.3-alpine
HEALTHCHECK CMD wget -O /dev/null http://localhost || exit 1
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
2 changes: 1 addition & 1 deletion Dockerfile-Test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COPY . .
RUN yarn policies set-version '3.3.1'

RUN yarn install \
&& yarn run build:testnet
&& yarn run build:test

# test environment
FROM nginx:1.25.3-alpine
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "GPL-3.0-only",
"scripts": {
"build": "tsc && vite build --base '/'",
"build:testnet": "tsc && VITE_NETWORK='testnet' vite build --base '/'",
"build:test": "tsc && VITE_ENVIRONMENT='test' vite build --base '/'",
"build:staging": "tsc && VITE_ENVIRONMENT='staging' vite build --base '/'",
"build:pages": "tsc && vite build --base '/polkadot-staking-dashboard/'",
"clear": "rm -rf node_modules build tsconfig.tsbuildinfo",
"deploy:pages": "yarn build:pages && gh-pages -d build",
Expand Down
40 changes: 18 additions & 22 deletions src/config/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ const makeCreditcoinNetwork = ({

const makeNetworkList = () => {
const networks: Networks = {};
if (import.meta.env.VITE_NETWORK !== 'testnet') {
networks.creditcoin = makeCreditcoinNetwork({
name: 'creditcoin',
if (import.meta.env.VITE_ENVIRONMENT === 'test') {
networks.creditcoinDev = makeCreditcoinNetwork({
name: 'creditcoinDev',
endpoints: {
lightClient: null,
defaultRpcEndpoint: 'Gluwa',
rpcEndpoints: {
Gluwa: 'wss://rpc.cc3-mainnet.creditcoin.network/ws',
Gluwa: 'wss://rpc.cc3-devnet.creditcoin.network/ws',
},
},
namespace: 'creditcoin-mainnet',
namespace: '09573a3526818a8ecd6eb92f60f1175d',
subscanEndpoint: 'http://127.0.0.1:4399',
subscanUrl: 'https://creditcoin3.subscan.io/',
subscanUrl: 'https://creditcoin3-testnet.subscan.io/',
});
}
networks.creditcoinTest = makeCreditcoinNetwork({
Expand All @@ -109,23 +109,19 @@ const makeNetworkList = () => {
subscanEndpoint: 'http://127.0.0.1:4399',
subscanUrl: 'https://creditcoin3-testnet.subscan.io/',
});

if (import.meta.env.VITE_NETWORK !== 'testnet') {
networks.creditcoinDev = makeCreditcoinNetwork({
name: 'creditcoinDev',
endpoints: {
lightClient: null,
defaultRpcEndpoint: 'Gluwa',
rpcEndpoints: {
Gluwa: 'wss://rpc.cc3-devnet.creditcoin.network/ws',
},
networks.creditcoin = makeCreditcoinNetwork({
name: 'creditcoin',
endpoints: {
lightClient: null,
defaultRpcEndpoint: 'Gluwa',
rpcEndpoints: {
Gluwa: 'wss://rpc.cc3-mainnet.creditcoin.network/ws',
},
namespace: '09573a3526818a8ecd6eb92f60f1175d',
subscanEndpoint: 'http://127.0.0.1:4399',
subscanUrl: 'https://creditcoin3-testnet.subscan.io/',
});
}

},
namespace: 'creditcoin-mainnet',
subscanEndpoint: 'http://127.0.0.1:4399',
subscanUrl: 'https://creditcoin3.subscan.io/',
});
if (import.meta.env.DEV) {
networks.creditcoinLocal = makeCreditcoinNetwork({
name: 'creditcoinLocal',
Expand Down
7 changes: 6 additions & 1 deletion src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import type { Plugin } from 'types';
export const AppVersion = '1.0.8';
export const DappName = 'Creditcoin Staking Dashboard';
export const CreditcoinUrl = 'https://creditcoin.org';
export const DefaultNetwork = 'creditcoin';
export const DefaultNetwork =
import.meta.env.VITE_ENVIRONMENT === 'test'
? 'creditcoinDev'
: import.meta.env.VITE_ENVIRONMENT === 'staging'
? 'creditcoinTest'
: 'creditcoin';
export const ManualSigners = ['ledger', 'vault'];
/*
* Data Structure Helpers
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/Network/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import { NetworkList } from 'config/networks';

export const defaultNetworkContext = {
network: NetworkList.creditcoin?.name ?? NetworkList.creditcoinTest?.name,
networkData: NetworkList.creditcoin ?? NetworkList.creditcoinTest,
network: NetworkList.creditcoin?.name,
networkData: NetworkList.creditcoin,

switchNetwork: () => {},
};
7 changes: 2 additions & 5 deletions src/contexts/Network/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ export const NetworkProvider = ({
const localNetworkValid = !!Object.values(NetworkList).find(
(n) => n.name === localNetwork
);
return localNetworkValid
? localNetwork
: Object.keys(NetworkList).length > 0
? (Object.keys(NetworkList)[0] as NetworkName)
: DefaultNetwork;

return localNetworkValid ? localNetwork : DefaultNetwork;
};

// handle network switching
Expand Down

0 comments on commit 3979636

Please # to comment.