diff --git a/src/App.tsx b/src/App.tsx index 6bc5845997..aa4f6fe01d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -82,7 +82,7 @@ const extendConsole = () => { window.console = {}; } if (window.console[level] === 'undefined' || !window.console[level] || window.console[level] === null) { - window.console[level] = function () {}; + window.console[level] = function () { }; } if (enabled) { if (disabledConsoles[level]) { @@ -90,7 +90,7 @@ const extendConsole = () => { } } else { disabledConsoles[level] = window.console[level]; - window.console[level] = function () {}; + window.console[level] = function () { }; } }; } catch (e) { @@ -376,6 +376,8 @@ const HeaderContainer = styled.header` const ParentContainer = styled.div` flex-wrap: wrap; + position: relative; + z-index:0; display: flex; flex-direction: row; justify-content: center; diff --git a/src/components/YieldFarmChainError.tsx b/src/components/YieldFarmChainError.tsx index 2b05bc43fc..c1e0931f3d 100644 --- a/src/components/YieldFarmChainError.tsx +++ b/src/components/YieldFarmChainError.tsx @@ -1,24 +1,33 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import Close from 'assets/chat/group-chat/close.svg?react'; import { ButtonV2, ItemHV2, ItemVV2 } from './reusables/SharedStylingV2'; -import styled from 'styled-components'; +import styled, { useTheme } from 'styled-components'; import { ethers } from 'ethers'; import { appConfig } from 'config/index.js'; import { useAccount } from 'hooks'; -const YieldFarmChainError = () => { +const YieldFarmChainError = ({ onClose }) => { const { account, chainId: currentChainId, switchChain } = useAccount(); + const theme = useTheme(); + const handleChainChange = () => { const chainIdToPass = appConfig.allowedNetworks[0]; if (currentChainId !== 1 && currentChainId !== 11155111) { - console.debug('Current Chain ID ', currentChainId); - console.debug('Chain Id to pass', chainIdToPass); + console.info('Current Chain ID ', currentChainId); + console.info('Chain Id to pass', chainIdToPass); switchChain(appConfig.coreContractChain); } }; + useEffect(() => { + if (currentChainId === appConfig.coreContractChain || currentChainId === appConfig.mainnetCoreContractChain) { + onClose(); + } + }, [currentChainId]) + + return ( @@ -56,10 +65,11 @@ const BodyContainer = styled(ItemVV2)` const PrimaryText = styled.div` font-size: 28px; font-weight: 500; + color: ${(props) => props.theme.stakingSecondaryText}; `; const SecondaryText = styled.div` - color: #657795; + color: ${(props) => props.theme.activeButtonText}; text-align: center; font-size: 18px; font-weight: 400; diff --git a/src/helpers/pushStaking/src/index.ts b/src/helpers/pushStaking/src/index.ts index 65354d8fc6..7242c76be8 100644 --- a/src/helpers/pushStaking/src/index.ts +++ b/src/helpers/pushStaking/src/index.ts @@ -1,18 +1,15 @@ -import { ethers } from "ethers"; -import { PushCoreV2 } from "../types"; -import { CoreV2Reward } from "./CoreV2Reward"; -import { Helpers } from "./helpers"; -import { Constants } from "./constants"; +import { ethers } from 'ethers'; +import { PushCoreV2 } from '../types'; +import { CoreV2Reward } from './CoreV2Reward'; +import { Helpers } from './helpers'; +import { Constants } from './constants'; export const getUserPushStakingInfo = async ( provider: ethers.providers.JsonRpcProvider, userAddress: string, - contractAddress:string + contractAddress: string ) => { - const coreV2Contract = Helpers.getCoreV2Contract( - provider, - contractAddress - ); + const coreV2Contract = Helpers.getCoreV2Contract(provider, contractAddress); const avilableRewardHelper = new CoreV2Reward(coreV2Contract, userAddress); const userRewardInfoHelper = new CoreV2Reward(coreV2Contract, userAddress); diff --git a/src/primaries/Profile.tsx b/src/primaries/Profile.tsx index 9678218c68..0b1693b114 100644 --- a/src/primaries/Profile.tsx +++ b/src/primaries/Profile.tsx @@ -51,21 +51,21 @@ const Profile = ({ isDarkMode }) => { id: 'walletAddress', value: account, title: account, - function: () => {}, + function: () => { }, invertedIcon: './copy.svg', }, { id: 'userSettings', value: '', title: 'Settings', - function: () => {}, + function: () => { }, to: APP_PATHS.UserSettings, invertedIcon: 'svg/setting.svg', }, { id: 'prodDapp', value: '', - function: () => {}, + function: () => { }, link: `https://${envUtil.prod}`, title: 'Production dapp', invertedIcon: './prod.svg', @@ -89,7 +89,7 @@ const Profile = ({ isDarkMode }) => { setShowDropdown(false); }); - const ConnectWallet = () => { + const handleConnectWallet = () => { connect(); }; @@ -103,7 +103,7 @@ const Profile = ({ isDarkMode }) => { bg="linear-gradient(87.17deg, #B6A0F5 0%, #F46EF7 57.29%, #FF95D5 100%)" color="#FFF" isDarkMode={isDarkMode} - onClick={() => ConnectWallet()} + onClick={() => handleConnectWallet()} > Connect Wallet @@ -169,7 +169,7 @@ const Profile = ({ isDarkMode }) => { bg="linear-gradient(87.17deg, #B6A0F5 0%, #F46EF7 57.29%, #FF95D5 100%)" color="#FFF" isDarkMode={isDarkMode} - onClick={() => ConnectWallet()} + onClick={() => handleConnectWallet()} > Connect Wallet diff --git a/src/sections/yield/NewYieldFarming.tsx b/src/sections/yield/NewYieldFarming.tsx index f48c1fad80..dfd248d7fb 100644 --- a/src/sections/yield/NewYieldFarming.tsx +++ b/src/sections/yield/NewYieldFarming.tsx @@ -1,5 +1,5 @@ // React + Web3 Essentials -import React, { useEffect, useState } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { ethers } from 'ethers'; // External Packages @@ -16,18 +16,17 @@ import YieldPushFeeV3 from 'components/yield/YieldPushFeeV3'; import { useAccount } from 'hooks'; // Internal Configs -import { abis, addresses } from 'config/index.js'; -import useModalBlur, { MODAL_POSITION } from 'hooks/useModalBlur'; -import StepsTransactionModal from 'components/StepsTransactionModal'; +import { abis, addresses, appConfig } from 'config/index.js'; +import { GlobalContext } from 'contexts/GlobalContext'; const NewYieldFarming = ({ setActiveTab }) => { - const { provider, account } = useAccount(); + const { provider, account, chainId } = useAccount(); - const [pushToken, setPushToken] = useState(null); - const [staking, setStaking] = useState(null); - const [yieldFarmingLP, setYieldFarmingLP] = useState(null); - const [pushCoreV2, setPushCoreV2] = useState(null); - const [uniswapV2Router02Instance, setUniswapV2Router02Instance] = useState(null); + const [pushToken, setPushToken] = useState(); + const [staking, setStaking] = useState(); + const [yieldFarmingLP, setYieldFarmingLP] = useState(); + const [pushCoreV2, setPushCoreV2] = useState(); + const [uniswapV2Router02Instance, setUniswapV2Router02Instance] = useState(); const [poolStats, setPoolStats] = useState(null); const [lpPoolStats, setLpPoolStats] = useState(null); @@ -37,13 +36,19 @@ const NewYieldFarming = ({ setActiveTab }) => { const library = provider?.getSigner(account); + const getPoolStats = React.useCallback(async () => { + const poolStats = await YieldFarmingDataStoreV2.getInstance().getPoolStats(provider); + + setPoolStats({ ...poolStats }); + }, [staking, pushToken, pushCoreV2, yieldFarmingLP, uniswapV2Router02Instance, provider]); + + const getLpPoolStats = React.useCallback(async () => { const poolStats = await YieldFarmingDataStoreV2.getInstance().getPoolStats(provider); const lpPoolStats = await YieldFarmingDataStoreV2.getInstance().getLPPoolStats(poolStats); - setPoolStats({ ...poolStats }); setLpPoolStats({ ...lpPoolStats }); - }, [staking, pushToken, pushCoreV2, yieldFarmingLP, uniswapV2Router02Instance]); + }, [staking, pushToken, pushCoreV2, yieldFarmingLP, uniswapV2Router02Instance, provider]); const getPUSHPoolStats = React.useCallback(async () => { // const pushPoolStats = await YieldFarmingDataStoreV2.getInstance().getPUSHPoolStats(provider); @@ -54,17 +59,22 @@ const NewYieldFarming = ({ setActiveTab }) => { const userDataLP = await YieldFarmingDataStoreV2.getInstance().getUserDataLP(); setUserDataLP({ ...userDataLP }); - }, [yieldFarmingLP]); + }, [staking, pushToken, pushCoreV2, yieldFarmingLP, uniswapV2Router02Instance]); const getUserDataPush = React.useCallback(async () => { const [pushPoolStats, userDataPush] = await YieldFarmingDataStoreV2.getInstance().getUserDataPUSH(provider); setPUSHPoolStats({ ...pushPoolStats }); setUserDataPush({ ...userDataPush }); - }, [staking, pushToken, pushCoreV2, yieldFarmingLP, uniswapV2Router02Instance]); + }, [staking, pushToken, pushCoreV2, yieldFarmingLP, uniswapV2Router02Instance, provider]); //initiate the YieldFarmV2 data store here React.useEffect(() => { + + if (chainId !== appConfig.coreContractChain && chainId !== appConfig.mainnetCoreContractChain) { + return; + } + setLpPoolStats(null); setUserDataLP(null); setPUSHPoolStats(null); @@ -98,6 +108,7 @@ const NewYieldFarming = ({ setActiveTab }) => { setUniswapV2Router02Instance(uniswapV2Router02Instance); } + YieldFarmingDataStoreV2.getInstance().init( account, staking, @@ -107,11 +118,12 @@ const NewYieldFarming = ({ setActiveTab }) => { uniswapV2Router02Instance ); - getLpPoolStats(); + getPoolStats(); getUserDataLP(); + getLpPoolStats(); getUserDataPush(); - getPUSHPoolStats(); - }, [account]); + + }, [account, chainId]); return ( <> diff --git a/src/singletons/YieldFarmingDataStoreV2.js b/src/singletons/YieldFarmingDataStoreV2.js index 76a83cf4e7..6f967945c1 100644 --- a/src/singletons/YieldFarmingDataStoreV2.js +++ b/src/singletons/YieldFarmingDataStoreV2.js @@ -4,7 +4,7 @@ import { ethers } from 'ethers'; // Internal Configs import { addresses, appConfig } from 'config/index.js'; -import {getUserPushStakingInfo} from 'helpers/pushStaking' +import { getUserPushStakingInfo } from 'helpers/pushStaking' // Constants const ONE_PUSH = ethers.BigNumber.from(1).mul(ethers.BigNumber.from(10).pow(ethers.BigNumber.from(18))); @@ -34,16 +34,18 @@ const bnToInt = function (bnAmount) { return parseInt(bnAmount.div(bn(10).pow(18))); }; +const guestWalletAddress = '0x0000000000000000000000000000000000000001'; + export default class YieldFarmingDataStoreV2 { static instance = null; - // Singleton getter - static getInstance() { - if (!YieldFarmingDataStoreV2.instance) { - YieldFarmingDataStoreV2.instance = new YieldFarmingDataStoreV2(); - } - return YieldFarmingDataStoreV2.instance; + // Singleton getter + static getInstance() { + if (!YieldFarmingDataStoreV2.instance) { + YieldFarmingDataStoreV2.instance = new YieldFarmingDataStoreV2(); } + return YieldFarmingDataStoreV2.instance; + } state = { account: null, @@ -85,7 +87,6 @@ export default class YieldFarmingDataStoreV2 { const yieldFarmingLP = this.state.yieldFarmingLP; const currentEpochLP = await yieldFarmingLP.getCurrentEpoch() const currentEpochPUSH = await this.currentEpochCalculation(provider); - let pushPrice; const pushPriceAmounts = await this.state.uniswapV2Router02.getAmountsOut(ONE_PUSH.toString(), [addresses.pushToken, addresses.WETHAddress, addresses.USDTAddress]); if (appConfig.coreContractChain === 42 || appConfig.coreContractChain === 5) { @@ -114,7 +115,7 @@ export default class YieldFarmingDataStoreV2 { const pushStakedAmount = tokenBNtoNumber(await pushCoreV2.totalStakedAmount()); const totalValueLocked = pushStakedAmount * pushPrice + lpNextPoolSize * uniLpPrice; - + //calculating epoch Duration const epochDurations = await yieldFarmingLP.epochDuration(); const epochStart = await yieldFarmingLP.epochStart(); @@ -126,7 +127,7 @@ export default class YieldFarmingDataStoreV2 { currentBlockNumber = currentBlockNumber.number; const genesisEpoch = await pushCoreV2.genesisEpoch(); const epochDuration = await pushCoreV2.epochDuration(); - const remainingBlocks = epochDuration.toNumber() - ( (currentBlockNumber - genesisEpoch.toNumber() ) % epochDuration.toNumber() ) ; + const remainingBlocks = epochDuration.toNumber() - ((currentBlockNumber - genesisEpoch.toNumber()) % epochDuration.toNumber()); let epochEndTime = (remainingBlocks * 12.6); epochEndTime = Math.round(epochEndTime); @@ -233,8 +234,8 @@ export default class YieldFarmingDataStoreV2 { .getCurrentEpoch() .then((epoch) => (epoch.toNumber() > totalNumEpochs.toNumber() ? totalNumEpochs : epoch)); - //Calculating User Deposit - const epochStakeNext = await contract.getEpochStake(this.state.account, currentEpochLP.add(1)); + // Calculating User Deposit + let epochStake = contract.getEpochStake(this.state.account, currentEpochLP.add(1)); //Calcuating Current Epoch Reward const potentialUserReward = (await this.calculateUserEpochReward(currentEpochLP.toNumber(), contract)).toFixed(2); @@ -243,7 +244,7 @@ export default class YieldFarmingDataStoreV2 { let accumulatedReward = this.getAccumulatedReward(currentEpochLP, contract); let availableReward = this.getTotalAvailableRewards(lastEpochIdHarvested, currentEpochLP, contract) - let [totalAccumulatedReward, totalAvailableReward] = await Promise.all([accumulatedReward, availableReward]); + let [totalAccumulatedReward, totalAvailableReward, epochStakeNext] = await Promise.all([accumulatedReward, availableReward, epochStake]); resolve({ potentialUserReward, @@ -321,19 +322,31 @@ export default class YieldFarmingDataStoreV2 { getUserDataPUSH = async (provider) => { return new Promise(async (resolve, reject) => { if (this.state.account) { - // Rewards Claimed const pushCoreV2 = this.state.pushCoreV2; let { - epochRewards, - currentEpochNumber, - userStaked, - potentialReward, - availableRewards - } = await getUserPushStakingInfo(provider,this.state.account,addresses.pushCoreV2); - - //Calculating TotalStaked Amount + epochRewards = bn(0), //BN + currentEpochNumber = 0,//BN + userStaked = bn(0),//BN + potentialReward = bn(0),//BN + availableRewards = bn(0),//BN + } = {}; + + ({ epochRewards, currentEpochNumber } = await getUserPushStakingInfo(provider, this.state.account, addresses.pushCoreV2)); + + //these values changes if the account changes. + if (this.state.account !== guestWalletAddress) { + ({ + userStaked, + potentialReward, + availableRewards + } = await getUserPushStakingInfo(provider, this.state.account, addresses.pushCoreV2)); + } + const totalStakedAmount = await pushCoreV2.totalStakedAmount(); + let claimedReward = await pushCoreV2.usersRewardsClaimed(this.state.account); + + claimedReward = tokenBNtoNumber(claimedReward); //Calculating Current Reward let currentReward = epochRewards; @@ -342,8 +355,6 @@ export default class YieldFarmingDataStoreV2 { //Calculating Staking APR let stakingAPR = this.calcPushStakingAPR(totalStakedAmount); stakingAPR = Math.min(this.state.highCapPUSHStakingAPR, stakingAPR); - let claimedReward = await pushCoreV2.usersRewardsClaimed(this.state.account); - claimedReward = tokenBNtoNumber(claimedReward); //Current Epoch Rewards potentialReward = tokenBNtoNumber(potentialReward); @@ -365,7 +376,7 @@ export default class YieldFarmingDataStoreV2 { stakingAPR, } - resolve([userPushStats,userPushInfo]); + resolve([userPushStats, userPushInfo]); } }); };