Skip to content

Commit

Permalink
Merge pull request #2793 from Giveth/add-optimism-goerli
Browse files Browse the repository at this point in the history
Add optimism goerli
  • Loading branch information
RamRamez authored Jul 31, 2023
2 parents 0e513a1 + 7576df8 commit 4dc201f
Show file tree
Hide file tree
Showing 32 changed files with 238 additions and 95 deletions.
10 changes: 5 additions & 5 deletions pages/test1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useRouter } from 'next/router';
import { Container } from '@giveth/ui-design-system';
import { gToast, ToastType } from '@/components/toasts';
import { useAppDispatch } from '@/features/hooks';
import { fetchXDaiInfoAsync } from '@/features/subgraph/subgraph.thunks';
import { fetchGnosisInfoAsync } from '@/features/subgraph/subgraph.thunks';
import { FlowRateTooltip } from '@/components/GIVeconomyPages/GIVstream.sc';
import { IconWithTooltip } from '@/components/IconWithToolTip';
import { removeQueryParamAndRedirect } from '@/helpers/url';
Expand All @@ -35,8 +35,8 @@ const TestRoute = () => {
//This comment is for testing1

const TestIndex = () => {
// const xDaiValues = useSelector(
// (state: RootState) => state.subgraph.xDaiValues,
// const gnosisValues = useSelector(
// (state: RootState) => state.subgraph.gnosisValues,
// );
const [showModal, setShowModal] = useState(false);
const { account } = useWeb3React();
Expand Down Expand Up @@ -80,7 +80,7 @@ const TestIndex = () => {
console.log('res1', res);
};

// console.log('xDaiValues', xDaiValues);
// console.log('gnosisValues', gnosisValues);
// useEffect(() => {
// if (!library) return;
// library.on('block', (evt: any) => {
Expand Down Expand Up @@ -114,7 +114,7 @@ const TestIndex = () => {
<button
onClick={() => {
if (account) {
dispatch(fetchXDaiInfoAsync(account));
dispatch(fetchGnosisInfoAsync(account));
}
}}
>
Expand Down
14 changes: 9 additions & 5 deletions src/components/GIVeconomyPages/GIVbacks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,19 @@ export const TabGIVbacksTop = () => {
const [showGivBackExplain, setShowGivBackExplain] = useState(false);
const [givBackStream, setGivBackStream] = useState<BigNumber.Value>(0);
const { givTokenDistroHelper } = useGIVTokenDistroHelper(showHarvestModal);
const xDaiValues = useAppSelector(
state => state.subgraph.xDaiValues,
const { chainId } = useWeb3React();
const values = useAppSelector(
state =>
chainId === config.OPTIMISM_NETWORK_NUMBER
? state.subgraph.optimismValues
: state.subgraph.gnosisValues,
() => (showHarvestModal ? true : false),
);

const givTokenDistroBalance = useMemo(() => {
const sdh = new SubgraphDataHelper(xDaiValues);
const sdh = new SubgraphDataHelper(values);
return sdh.getGIVTokenDistroBalance();
}, [xDaiValues]);
const { chainId } = useWeb3React();
}, [values]);

useEffect(() => {
const _givback = BN(givTokenDistroBalance.givback);
Expand Down
2 changes: 1 addition & 1 deletion src/components/GIVeconomyPages/GIVpower.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function TabPowerTop() {
const { formatMessage } = useIntl();
const { account } = useWeb3React();
const sdh = new SubgraphDataHelper(
useAppSelector(state => state.subgraph.xDaiValues),
useAppSelector(state => state.subgraph.gnosisValues),
);
const givPower = sdh.getUserGIVPowerBalance();
const givPowerFormatted = formatWeiHelper(givPower.balance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const BaseStakingCard: FC<IBaseStakingCardProps> = ({

const isGIVStaking = type === StakingType.GIV_LM;
const isGIVpower =
isGIVStaking && poolNetwork === config.XDAI_NETWORK_NUMBER;
isGIVStaking &&
(poolNetwork === config.XDAI_NETWORK_NUMBER ||
poolNetwork === config.OPTIMISM_NETWORK_NUMBER);

const isDiscontinued = farmEndTimeMS
? getNowUnixMS() > farmEndTimeMS
Expand Down
7 changes: 5 additions & 2 deletions src/components/controller/subgraph.ctrl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { useEffect } from 'react';
import { useAppDispatch } from '@/features/hooks';
import config from '@/configuration';
import {
fetchXDaiInfoAsync,
fetchGnosisInfoAsync,
fetchMainnetInfoAsync,
fetchCurrentInfoAsync,
fetchOptimismInfoAsync,
} from '@/features/subgraph/subgraph.thunks';

const SubgraphController = () => {
Expand All @@ -16,9 +17,11 @@ const SubgraphController = () => {
const _account = account ? account : undefined;
const _chainID = chainId || config.MAINNET_NETWORK_NUMBER;
if (chainId !== config.XDAI_NETWORK_NUMBER)
dispatch(fetchXDaiInfoAsync(_account));
dispatch(fetchGnosisInfoAsync(_account));
if (chainId !== config.MAINNET_NETWORK_NUMBER)
dispatch(fetchMainnetInfoAsync(_account));
if (chainId !== config.OPTIMISM_NETWORK_NUMBER)
dispatch(fetchOptimismInfoAsync(_account));
dispatch(
fetchCurrentInfoAsync({
userAddress: _account,
Expand Down
2 changes: 1 addition & 1 deletion src/components/givfarm/RegenStreamCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const RegenStreamCard: FC<RegenStreamProps> = ({ streamConfig }) => {
const currentValues = useAppSelector(
state =>
streamNetwork === config.XDAI_NETWORK_NUMBER
? state.subgraph.xDaiValues
? state.subgraph.gnosisValues
: state.subgraph.mainnetValues,
() => (showModal ? true : false),
);
Expand Down
12 changes: 6 additions & 6 deletions src/components/modals/Boost/BoostModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ test('showing the ZeroGivpowerModal if the user GIVpower balance is zero', async
const setStateMock = jest.fn();
const useStateMock: any = (state: any) => [state, setStateMock];
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
const xDaiValues: ISubgraphState = {};
xDaiValues[
const gnosisValues: ISubgraphState = {};
gnosisValues[
`unipoolBalance_${config.XDAI_CONFIG.GIV.LM_ADDRESS.toLowerCase()}`
] = {
balance: '0',
Expand All @@ -39,7 +39,7 @@ test('showing the ZeroGivpowerModal if the user GIVpower balance is zero', async
{
preloadedState: {
subgraph: {
xDaiValues: xDaiValues,
gnosisValues: gnosisValues,
mainnetValues: {},
currentValues: {},
},
Expand All @@ -53,8 +53,8 @@ test('showing the BoostModal if the user GIVpower balance is not zero', async ()
const setStateMock = jest.fn();
const useStateMock: any = (state: any) => [state, setStateMock];
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
const xDaiValues: ISubgraphState = {};
xDaiValues[
const gnosisValues: ISubgraphState = {};
gnosisValues[
`unipoolBalance_${config.XDAI_CONFIG.GIV.LM_ADDRESS.toLowerCase()}`
] = {
balance: '1',
Expand All @@ -66,7 +66,7 @@ test('showing the BoostModal if the user GIVpower balance is not zero', async ()
{
preloadedState: {
subgraph: {
xDaiValues: xDaiValues,
gnosisValues: gnosisValues,
mainnetValues: {},
currentValues: {},
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/Boost/BoostModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const BoostModal: FC<IBoostModalProps> = ({ setShowModal, projectId }) => {
const [percentage, setPercentage] = useState(0);
const [state, setState] = useState(EBoostModalState.BOOSTING);
const sdh = new SubgraphDataHelper(
useAppSelector(state => state.subgraph.xDaiValues),
useAppSelector(state => state.subgraph.gnosisValues),
);
const givPower = sdh.getUserGIVPowerBalance();

Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/StakeLock/LockSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const LockSlider: FC<ILockSlider> = ({ round, setRound }) => {
const { formatMessage, locale } = useIntl();
const [isChanged, setIsChanged] = useState(false);
const givpowerInfo = useAppSelector(
state => state.subgraph.xDaiValues.givpowerInfo,
state => state.subgraph.gnosisValues.givpowerInfo,
) as IGIVpower;
const unlockDate = new Date(getUnlockDate(givpowerInfo, round));
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/StakeLock/LockingBrief.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const LockingBrief: FC<ILockingBrief> = ({
onLocking = false,
}) => {
const givpowerInfo = useAppSelector(
state => state.subgraph.xDaiValues.givpowerInfo,
state => state.subgraph.gnosisValues.givpowerInfo,
) as IGIVpower;
const unlockDate = new Date(getUnlockDate(givpowerInfo, round));
return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/modals/StakeLock/TotalGIVpowerBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import LottieControl from '@/components/LottieControl';
const TotalGIVpowerBox = () => {
const [totalGIVpower, setTotalGIVpower] = useState<BigNumber>();
const { account, library, chainId } = useWeb3React();
const xDaiValues = useAppSelector(state => state.subgraph.xDaiValues);
const gnosisValues = useAppSelector(state => state.subgraph.gnosisValues);

useEffect(() => {
async function fetchTotalGIVpower() {
Expand All @@ -39,7 +39,7 @@ const TotalGIVpowerBox = () => {
}
} catch (err) {
console.log({ err });
const sdh = new SubgraphDataHelper(xDaiValues);
const sdh = new SubgraphDataHelper(gnosisValues);
const userGIVPowerBalance = sdh.getUserGIVPowerBalance();
setTotalGIVpower(new BigNumber(userGIVPowerBalance.balance));
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/claim/cards/Govern.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const GovernCard: FC<IClaimViewCardProps> = ({ index }) => {
const [earnEstimate, setEarnEstimate] = useState<BigNumber>(Zero);
const [apr, setApr] = useState<APR>(null);
const { givTokenDistroHelper } = useGIVTokenDistroHelper();
const xDaiValues = useAppSelector(state => state.subgraph.xDaiValues);
const gnosisValues = useAppSelector(state => state.subgraph.gnosisValues);

useEffect(() => {
let _stacked = 0;
Expand Down Expand Up @@ -148,7 +148,7 @@ const GovernCard: FC<IClaimViewCardProps> = ({ index }) => {

useEffect(() => {
const cb = () => {
getGivStakingAPR(config.XDAI_NETWORK_NUMBER, xDaiValues, null)
getGivStakingAPR(config.XDAI_NETWORK_NUMBER, gnosisValues, null)
.then(_apr => {
mounted.current && setApr(_apr);
})
Expand All @@ -166,7 +166,7 @@ const GovernCard: FC<IClaimViewCardProps> = ({ index }) => {
const interval = setInterval(cb, 120 * 1000);

return () => clearInterval(interval);
}, [stacked, xDaiValues]);
}, [stacked, gnosisValues]);

return (
<GovernCardContainer activeIndex={step} index={index}>
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/claim/cards/Stake.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const InvestCard: FC<IClaimViewCardProps> = ({ index }) => {
const [earnEstimate, setEarnEstimate] = useState<BigNumber>(Zero);
const [APR, setAPR] = useState<BigNumber>(Zero);
const { givTokenDistroHelper } = useGIVTokenDistroHelper();
const { xDaiValues, mainnetValues } = useAppSelector(
const { gnosisValues, mainnetValues } = useAppSelector(
state => state.subgraph,
);

Expand Down Expand Up @@ -153,7 +153,7 @@ const InvestCard: FC<IClaimViewCardProps> = ({ index }) => {
const promise: Promise<APR> = getLPStakingAPR(
poolStakingConfig as SimplePoolStakingConfig,
networkProviders[config.XDAI_NETWORK_NUMBER],
xDaiValues,
gnosisValues,
);
promiseQueue.push(promise);
});
Expand All @@ -176,7 +176,7 @@ const InvestCard: FC<IClaimViewCardProps> = ({ index }) => {
promiseQueue.push(promise);
});
getMaxAPR(promiseQueue);
}, [mainnetValues, xDaiValues]);
}, [mainnetValues, gnosisValues]);

return (
<InvestCardContainer activeIndex={step} index={index}>
Expand Down
36 changes: 29 additions & 7 deletions src/components/views/givfarm/GIVfarmBottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,25 @@ const renderPools = (chainId?: number, showArchivedPools?: boolean) => {
...config.XDAI_CONFIG.regenPools,
...config.MAINNET_CONFIG.pools,
...config.MAINNET_CONFIG.regenPools,
...config.OPTIMISM_CONFIG.pools,
...config.OPTIMISM_CONFIG.regenPools,
]
: chainId === config.OPTIMISM_NETWORK_NUMBER
? [
...config.OPTIMISM_CONFIG.pools,
...config.OPTIMISM_CONFIG.regenPools,
...config.XDAI_CONFIG.pools,
...config.XDAI_CONFIG.regenPools,
...config.MAINNET_CONFIG.pools,
...config.MAINNET_CONFIG.regenPools,
]
: [
...config.MAINNET_CONFIG.pools,
...config.MAINNET_CONFIG.regenPools,
...config.XDAI_CONFIG.pools,
...config.XDAI_CONFIG.regenPools,
...config.OPTIMISM_CONFIG.pools,
...config.OPTIMISM_CONFIG.regenPools,
];

const now = getNowUnixMS();
Expand Down Expand Up @@ -153,13 +166,22 @@ export const GIVfarmBottom = () => {
</GIVfarmToolBoxRow>
<PoolRow>
{!showArchivedPools && (
<Col sm={6} lg={4} key={`givpower_card`}>
<StakingPoolCard
poolStakingConfig={getGivStakingConfig(
config.XDAI_CONFIG,
)}
/>
</Col>
<>
<Col sm={6} lg={4} key={`givpower_card_gnosis`}>
<StakingPoolCard
poolStakingConfig={getGivStakingConfig(
config.XDAI_CONFIG,
)}
/>
</Col>
<Col sm={6} lg={4} key={`givpower_card_optimism`}>
<StakingPoolCard
poolStakingConfig={getGivStakingConfig(
config.OPTIMISM_CONFIG,
)}
/>
</Col>
</>
)}
{showArchivedPools && (
<Col sm={6} lg={4}>
Expand Down
1 change: 1 addition & 0 deletions src/components/views/givfarm/GIVfarmTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const GIVfarmTop = () => {
targetNetworks={[
config.MAINNET_NETWORK_NUMBER,
config.XDAI_NETWORK_NUMBER,
config.OPTIMISM_NETWORK_NUMBER,
]}
/>
</Col>
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/userProfile/ProfileOverviewTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const ProfileOverviewTab: FC<IUserProfileView> = ({ user, myAccount }) => {

const [section, setSection] = useState<ISection>(_sections.getGiv);
const sdh = new SubgraphDataHelper(
useAppSelector(state => state.subgraph.xDaiValues),
useAppSelector(state => state.subgraph.gnosisValues),
);
const { userData } = useAppSelector(state => state.user);
const boostedProjectsCount = userData?.boostedProjectsCount ?? 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface IEmptyPowerBoosting {

export const EmptyPowerBoosting: FC<IEmptyPowerBoosting> = ({ myAccount }) => {
const sdh = new SubgraphDataHelper(
useAppSelector(state => state.subgraph.xDaiValues),
useAppSelector(state => state.subgraph.gnosisValues),
);
const givPower = sdh.getUserGIVPowerBalance();
const { formatMessage } = useIntl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const ProfileBoostedTab: FC<IUserProfileView> = ({
});

const sdh = new SubgraphDataHelper(
useAppSelector(state => state.subgraph.xDaiValues),
useAppSelector(state => state.subgraph.gnosisValues),
);
const { userData } = useAppSelector(state => state.user);
const boostedProjectsCount = userData?.boostedProjectsCount ?? 0;
Expand Down
24 changes: 19 additions & 5 deletions src/config/development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const SEPT_8TH_2022 = 1662595200000;
const MAINNET_NETWORK_NUMBER = 5; // Goerli
const XDAI_NETWORK_NUMBER = 100; // xDAI
const POLYGON_NETWORK_NUMBER = 137;
const OPTIMISM_NETWORK_NUMBER = 10;
const OPTIMISM_NETWORK_NUMBER = 420;
const CELO_NETWORK_NUMBER = 44787;

const config: EnvConfig = {
Expand Down Expand Up @@ -263,13 +263,27 @@ const config: EnvConfig = {
},

OPTIMISM_CONFIG: {
nodeUrl: networksParams[10]?.rpcUrls[0],
...networksParams[10],
nodeUrl: networksParams[420]?.rpcUrls[0],
...networksParams[420],
gasPreference: {
// Keep it empty for automatic configuration
},
blockExplorerName: ['OptimismScan'],
subgraphAddress: '',
blockExplorerName: ['GoerliOptimismScan'],
subgraphAddress:
'https://api.thegraph.com/subgraphs/name/giveth/giveth-economy-optim-staging',
TOKEN_ADDRESS: '0xc916Ce4025Cb479d9BA9D798A80094a449667F5D',
tokenAddressOnUniswapV2: '0x4f4F9b8D5B4d0Dc10506e5551B0513B61fD59e75',
TOKEN_DISTRO_ADDRESS: '0x8D2cBce8ea0256bFFBa6fa4bf7CEC46a1d9b43f6',
pools: [],
regenPools: [],
regenStreams: [],
GIV: {
network: OPTIMISM_NETWORK_NUMBER,
LM_ADDRESS: '0x632AC305ed88817480d12155A7F1244cC182C298',
GARDEN_ADDRESS: '0x632AC305ed88817480d12155A7F1244cC182C298',
BUY_LINK: 'https://',
},
uniswapV2Subgraph: '',
},

CELO_CONFIG: {
Expand Down
Loading

0 comments on commit 4dc201f

Please sign in to comment.