Skip to content

Commit

Permalink
Merge pull request #312 from 1Hive/force-chain
Browse files Browse the repository at this point in the history
Force chain
  • Loading branch information
Corantin committed Jun 7, 2022
2 parents 6cd176e + 1fb0b9e commit ff61b26
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
10 changes: 5 additions & 5 deletions packages/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@
},
"scripts": {
"start": "cross-env HTTPS=true npm run sync-assets && react-app-rewired start",
"start:local": "cross-env REACT_APP_CHAIN_ID=1337 yarn start",
"start:local": "cross-env REACT_APP_DEFAULT_CHAIN_ID=1337 yarn start",
"start:rinkeby": "cross-env REACT_APP_CHAIN_ID=4 yarn start",
"start:rinkeby-staging": "cross-env REACT_APP_CHAIN_ID=4 REACT_APP_STAGING=true yarn start",
"start:gnosis": "cross-env REACT_APP_CHAIN_ID=100 yarn start",
"start:rinkeby-staging": "cross-env REACT_APP_DEFAULT_CHAIN_ID=4 REACT_APP_STAGING=true yarn start",
"start:gnosis": "cross-env REACT_APP_DEFAULT_CHAIN_ID=100 yarn start",
"build": "npm run sync-assets && react-app-rewired build",
"build:gnosis": "cross-env REACT_APP_CHAIN=100 && yarn build",
"build:rinkeby": "cross-env REACT_APP_APP_NAME=conviction-beta REACT_APP_CHAIN_ID=4 yarn build",
"build:gnosis": "cross-env REACT_APP_DEFAULT_CHAIN_ID=100 && yarn build",
"build:rinkeby": "cross-env REACT_APP_DEFAULT_CHAIN_ID=4 yarn build",
"lint": "eslint src --no-error-on-unmatched-pattern --ext js,jsx,ts,tsx",
"lint-fix": "eslint --fix src --no-error-on-unmatched-pattern",
"format": "prettier --write \"src/**/*.+(js|jsx|json|css|md)\"",
Expand Down
6 changes: 5 additions & 1 deletion packages/react-app/src/components/account/account-module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ function AccountModule({ compact = false }: Props) {
return (
<AccountWrapperStyled ref={buttonRef}>
{wallet.isWrongNetwork ? (
<Button label="Switch network" onClick={() => wallet.changeNetwork()} mode="strong" />
<Button
label="Switch wallet network"
onClick={() => wallet.changeNetwork()}
mode="strong"
/>
) : screen.id === 'connected' ? (
<AccountButton onClick={toggle} />
) : (
Expand Down
3 changes: 2 additions & 1 deletion packages/react-app/src/components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import AccountModule from '../account/account-module';
import HeaderMenu from './header-menu';
import HeaderTitle from './header-title';
import { getNetwork, networks } from '../../networks';
import env from '../../environment';

// #region StyledComponents
const HeaderWraperStyled = styled.header`
Expand Down Expand Up @@ -96,7 +97,7 @@ function Header({ children }: Props) {
<HeaderRightPanelStyled compact={below('medium')}>
<HeaderMenu below={below} />
<AccountModule compact={layoutSmall} />
{!below('medium') && (
{!below('medium') && !env('FORCE_CHAIN_ID') && (
<NetworkSelectorStyled
borderColor={theme.border}
items={networkNames}
Expand Down
3 changes: 2 additions & 1 deletion packages/react-app/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import env from './environment';
import { FilterModel } from './models/filter.model';

export const PCT_BASE = BigInt(1e18);
Expand All @@ -16,7 +17,7 @@ export const GQL_MAX_INT_MS = (2 ** 31 - 1) * 1000;

export const QUESTS_PAGE_SIZE = 4;

export const EXPECTED_CHAIN_ID = [100, 4];
export const EXPECTED_CHAIN_ID = +env('FORCE_CHAIN_ID') ? [+env('FORCE_CHAIN_ID')] : [100, 4];

// Enums

Expand Down
2 changes: 1 addition & 1 deletion packages/react-app/src/contexts/wallet.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function WalletAugmented({ children }: Props) {
if (!newChainId) {
newChainId = chainId;
}
if (ethereum && +ethereum.chainId !== newChainId) {
if (ethereum && EXPECTED_CHAIN_ID.includes(newChainId) && +ethereum.chainId !== newChainId) {
try {
await ethereum.request({
method: 'wallet_switchEthereumChain',
Expand Down
10 changes: 7 additions & 3 deletions packages/react-app/src/local-settings.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { EXPECTED_CHAIN_ID } from './constants';
import env from './environment';

const CHAIN_ID = 'CHAIN_ID';

let currentChain = localStorage.getItem(CHAIN_ID) ?? +env(CHAIN_ID) ?? 100; // default xdai;
let currentChain =
env('FORCE_CHAIN_ID') ?? localStorage.getItem(CHAIN_ID) ?? env('DEFAULT_CHAIN_ID') ?? 100; // default xdai

export function getCurrentChain() {
return currentChain;
}

export function setCurrentChain(chainId: number) {
currentChain = chainId;
localStorage.setItem(CHAIN_ID, chainId.toString());
if (EXPECTED_CHAIN_ID.includes(chainId)) {
currentChain = chainId;
localStorage.setItem(CHAIN_ID, chainId.toString());
}
}

0 comments on commit ff61b26

Please sign in to comment.