Skip to content

Commit

Permalink
Force chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Corantin committed Jun 7, 2022
1 parent 6cd176e commit c5e9fce
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
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());
}
}

1 comment on commit c5e9fce

@vercel
Copy link

@vercel vercel bot commented on c5e9fce Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

quests – ./

quests.vercel.app
quests-git-force-chain-1hive.vercel.app
quests-1hive.vercel.app
quests.1hive.org

Please sign in to comment.