Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui-ux): set default network to mainnet #865

Merged
merged 17 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/src/components/WalletAddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export default function WalletAddressInput({
isPrimary && (
<EnvironmentNetworkSwitch
onChange={() => onAddressInputChange("")}
disabled={chain !== undefined}
fullstackninja864 marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
<div
Expand Down
35 changes: 17 additions & 18 deletions apps/web/src/layouts/contexts/NetworkEnvironmentContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export function NetworkEnvironmentProvider({
const router = useRouter();
const env = getEnvironment(process.env.NODE_ENV);
const networkQuery = router.query.network;

const defaultNetwork = EnvironmentNetwork.MainNet;
const { chain } = useNetwork();
const isEthereumMainNet = chain?.id === ETHEREUM_MAINNET_ID;

function getNetwork(n: EnvironmentNetwork): EnvironmentNetwork {
if (!isEthereumMainNet && env.networks.includes(n)) {
return n;
if (chain === undefined) {
return env.networks.includes(n) ? n : defaultNetwork;
}
return isEthereumMainNet
? EnvironmentNetwork.MainNet
Expand All @@ -48,22 +48,20 @@ export function NetworkEnvironmentProvider({
const [networkEnv, setNetworkEnv] =
useState<EnvironmentNetwork>(initialNetwork);

const updateRoute = (value: EnvironmentNetwork) => {
router.replace(
{
pathname: "/",
fullstackninja864 marked this conversation as resolved.
Show resolved Hide resolved
query: value === defaultNetwork ? {} : { network: value },
},
undefined,
{ shallow: true }
);
};

const handleNetworkEnvChange = (value: EnvironmentNetwork) => {
if (isEthereumMainNet) {
// Network environment should never be updated
return;
}
setNetworkEnv(value);
if (value !== initialNetwork) {
router.replace(
{
pathname: "/",
query: { network: value },
},
undefined,
{ shallow: true }
);
}
updateRoute(value);
};

const resetNetworkEnv = () => {
Expand All @@ -72,7 +70,8 @@ export function NetworkEnvironmentProvider({

useEffect(() => {
setNetworkEnv(initialNetwork);
}, [initialNetwork]);
updateRoute(initialNetwork);
}, [initialNetwork, chain]);

const context: NetworkContextI = useMemo(
() => ({
Expand Down