Skip to content
Open
Changes from all commits
Commits
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
10 changes: 6 additions & 4 deletions pages/sgho.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AaveV3Ethereum } from '@bgd-labs/aave-address-book';
import { Trans } from '@lingui/macro';
import { Box, Paper, Typography, useMediaQuery, useTheme } from '@mui/material';
import dynamic from 'next/dynamic';
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { ContentContainer } from 'src/components/ContentContainer';
import { ConnectWalletButton } from 'src/components/WalletConnection/ConnectWalletButton';
Expand Down Expand Up @@ -49,14 +50,15 @@ export default function SavingsGho() {
const { data: stakeUserResult } = useUserStakeUiData(currentMarketData);

const { data: stakeGeneralResult } = useGeneralStakeUiData(currentMarketData);

// Automatically switch to mainnet if not already on mainnet
const router = useRouter();
// Automatically switch to mainnet if not already on mainnet when entering the sGHO page
// since sGHO only exists on Ethereum mainnet
// NOTE: Having currentMarket as a dependency in useEffect causes conflicts with the Horizon Banner interaction.
Copy link
Contributor

Choose a reason for hiding this comment

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

what exactly

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When we click the link in the banner to go to the Horizon Markets page, the useEffect detects that currentMarket has changed and re-renders the component, preventing us from reaching the desired page. The solution is to remove currentMarket from the useEffect dependency array.

useEffect(() => {
if (currentMarket !== CustomMarket.proto_mainnet_v3) {
if (router.pathname === '/sgho' && currentMarket !== CustomMarket.proto_mainnet_v3) {
setCurrentMarket(CustomMarket.proto_mainnet_v3);
}
}, [currentMarket, setCurrentMarket]);
}, [router.pathname, setCurrentMarket]);

useEffect(() => {
trackEvent('Page Viewed', {
Expand Down
Loading