From 63f631e2122bad76225c7695e4e2c70a2ad97db0 Mon Sep 17 00:00:00 2001 From: Fakorede Damilola Date: Fri, 21 Oct 2022 18:19:29 +0100 Subject: [PATCH 1/9] changes --- src/pages/FarmingV2/ShowYieldFarmDetails.tsx | 4 + src/pages/FarmingV2/index.tsx | 1388 +----------------- src/utils/hooks/useGetFarmData.ts | 1 - 3 files changed, 7 insertions(+), 1386 deletions(-) diff --git a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx index ce865f25..7b0da429 100644 --- a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx +++ b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx @@ -149,6 +149,7 @@ const ShowYieldFarmDetails = ({ const {loadingState} = useUpdateFarm({reload, setReload, content}); useFetchYieldFarmDetails({content, section, setLoading, loading}); + console.log({content}) //const {loadingFarm} = useUpdateNewFarm({reload, setReload, content}); @@ -194,6 +195,7 @@ useEffect(()=>{ checkEnoughApproval(content.poolAllowance,content.availableToken) },[depositTokenValue]) useEffect(() => { + console.log({content}) const poolAllowance = async (contract: Contract) => { if (account) { const rgpApproval = await contract.allowance( @@ -378,6 +380,8 @@ useEffect(()=>{ }; const checkUser = async (val :string) => { + alert(1) + console.log({content}) if (content.deposit === "RGP" && Number(content.id) === 1) { await RGPSpecialPoolV1Approval(); setApproveValueForOtherToken(true); diff --git a/src/pages/FarmingV2/index.tsx b/src/pages/FarmingV2/index.tsx index 41b9bbd8..57a2d717 100644 --- a/src/pages/FarmingV2/index.tsx +++ b/src/pages/FarmingV2/index.tsx @@ -106,35 +106,18 @@ export function Index() { const location = useLocation().pathname; const mode = useColorModeValue(LIGHT_THEME, DARK_THEME); const filterBorderColor = useColorModeValue("#DEE5ED", "#324D68"); - const useNotSelectedBackgroundColor = useColorModeValue("#FFFFFF", "#15202B"); - const useSelectedBackgroundColor = useColorModeValue("#DEE5ED", "#213345"); - const useNotSelectedBorderColor = useColorModeValue("#008DFF", "#324D68"); - const useSelectedBorderColor = useColorModeValue("#0760A8", "#F2F5F8"); - const useNotSelectedTextColor = useColorModeValue("#333333", "#0760A8"); - const useSelectedTextColor = useColorModeValue("#0760A8", "#008DFF"); - - const borderColor = useColorModeValue("#F2F5F8", "#324D68"); - const useSelectedColor = useColorModeValue("#333333", "#213345"); - const placeholderTextColor = useColorModeValue("#333333", "#DCE5EF"); - const titleColor = useColorModeValue("#333333", "#ffffff"); const [selected, setSelected] = useState(farmSection.LIQUIDITY); - const [isActive, setIsActive] = useState(V2); const [showAlert, setShowAlert] = useState(true); const [farmDataLoading, setfarmDataLoading] = useState(false); - const [initialLoad, setInitialLoad] = useState(false); const [switchTab, setSwitchTab] = useState(true); const [tabIndex, setTabIndex] = useState(0); - const [liquidityIndex, setLiquidityIndex] = useState(0); - const [productFarmIndex, setProductFarmIndex] = useState(4); const [stakingIndex, setStakingIndex] = useState(1); - const [newFarmIndex, setNewFarmIndex] = useState(5); const [isMobileDevice] = useMediaQuery("(max-width: 750px)"); const [referralCode, setReferralCode] = useState(""); const [refAddress, setRefAddress] = useState(""); const [referralLink, setReferralLink] = useState(""); const hostName = window.location.href.split("?")[0]; const { hasCopied, onCopy } = useClipboard(`${hostName}?ref=${referralCode}`); - const [URLRefCode, setURLRefCode] = useState(""); const [newestToOldest, setNewestToOldest] = useState(false); const [oldestToNewest, setOldestToNewest] = useState(true); const [range0, setRange0] = useState(0); @@ -215,60 +198,9 @@ export function Index() { saveChanges, }); - const handleTabsChange = (index: number) => { - if (ChainId !== SupportedChainId.OASISMAINNET) { - const useIndex = - index === 0 - ? liquidityIndex - : index === 1 - ? stakingIndex - : liquidityIndex === 2 - ? setTabIndex(3) - : index; - setTabIndex(useIndex); - } - }; - - const goToV1 = (index: number) => { - setTabIndex(index); - }; - const handleStakingTab = (event: { target: { value: string } }) => { - if (parseInt(event.target.value, 10) === 1) { - setStakingIndex(1); - setTabIndex(1); - history.push(`/farm/RGPv2${search}`); - } else if (parseInt(event.target.value, 10) === 3) { - setStakingIndex(3); - setTabIndex(3); - history.push(`/farm/RGPv1${search}`); - } - }; - - const handleLiquidityTab = (event: { target: { value: string } }) => { - if (parseInt(event.target.value, 10) === 0) { - setLiquidityIndex(0); - setTabIndex(0); - } else if (parseInt(event.target.value, 10) === 2) { - setLiquidityIndex(2); - setTabIndex(4); - } - }; - - const handleNewFarmTab = (event: { target: { value: string } }) => { - if (parseInt(event.target.value, 10) === 5) { - setNewFarmIndex(5); - setTabIndex(5); - history.push(`/farm/new-farm${search}`); - } else if (parseInt(event.target.value, 10) === 6) { - setNewFarmIndex(6); - setTabIndex(6); - history.push(`/farm/stable-lp${search}`); - } - }; const { account, chainId, library } = useActiveWeb3React(); const dispatch = useDispatch(); - let match = useRouteMatch("/farm/RGPv2"); const FarmData = useFarms(); const { farmdata, loadingState } = useGetFarmData(); const { LPData, loadingLP } = useGetNewFarms( @@ -286,6 +218,8 @@ export function Index() { const { specialPool } = useSelector((state) => state.newfarm); + console.log({specialPool}) + useEffect(() => { dispatch(clearAllFarms()); }, [ChainId]); @@ -528,1323 +462,7 @@ export function Index() { ) : null} - {/**/} - {/* */} - {/* */} - {/* handleSelect(farmSection.LIQUIDITY)}*/} - {/* borderRadius={isMobileDevice ? "10px 0px 0px 10px" : 0}*/} - {/* >*/} - {/* */} - {/* Liquidity Pools*/} - {/* */} - {/* {Number(ChainId) === Number(SupportedChainId.POLYGON) ||*/} - {/* Number(ChainId) === Number(SupportedChainId.POLYGONTEST) ||*/} - {/* Number(ChainId) ===*/} - {/* Number(SupportedChainId.OASISMAINNET) ? null : (*/} - {/* e.stopPropagation()}*/} - {/* flex-grow="0"*/} - {/* margin={isMobileDevice ? "5px 12px" : "10px 16px"}*/} - {/* >*/} - {/* */} - {/* */} - {/* */} - {/* )}*/} - {/* */} - {/* {*/} - {/* handleSelect(farmSection.STAKING);*/} - {/* }}*/} - {/* >*/} - {/* */} - {/* Staking*/} - {/* */} - {/* {Number(ChainId) === Number(SupportedChainId.POLYGON) ||*/} - {/* Number(ChainId) === Number(SupportedChainId.POLYGONTEST) ||*/} - {/* Number(ChainId) ===*/} - {/* Number(SupportedChainId.OASISMAINNET) ? null : (*/} - {/* e.stopPropagation()}*/} - {/* border=" 1px solid #008DFF"*/} - {/* box-sizing="border-box"*/} - {/* borderRadius="50px"*/} - {/* width={isMobileDevice ? undefined : "fit-content"}*/} - {/* flex="none"*/} - {/* order="1"*/} - {/* flex-grow="0"*/} - {/* margin={isMobileDevice ? "5px 12px" : "10px 16px"}*/} - {/* >*/} - {/* */} - {/* */} - {/* */} - {/* )}*/} - {/* */} - {/* {Number(ChainId) === Number(SupportedChainId.OASISTEST) ||*/} - {/* Number(ChainId) === Number(SupportedChainId.OASISMAINNET) ? null : (*/} - {/* handleSelect(farmSection.PRODUCT_FARM)}*/} - {/* >*/} - {/* */} - {/* }*/} - {/* >*/} - {/* Product Farm*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* Product Farm*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* Other Farm*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* )}*/} - - {/* {Number(ChainId) === Number(SupportedChainId.OASISTEST) ||*/} - {/* Number(ChainId) === Number(SupportedChainId.OASISMAINNET) ? null : (*/} - {/* */} - {/* {isMobileDevice ? (*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* handleSelect(farmSection.NEW_LP)}*/} - {/* >*/} - {/* */} - {/* */} - {/* {Number(ChainId) ===*/} - {/* Number(SupportedChainId.POLYGONTEST) ||*/} - {/* Number(ChainId) === Number(SupportedChainId.POLYGON)*/} - {/* ? "QuickSwap"*/} - {/* : "Pancake LP"}*/} - {/* */} - {/* */} - {/* */} - - {/* handleSelect(farmSection.SECOND_NEW_LP)}*/} - {/* >*/} - {/* */} - {/* Stable LP*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* ) : (*/} - {/* <>*/} - {/* New Farms*/} - {/* e.stopPropagation()}*/} - {/* border=" 1px solid #008DFF"*/} - {/* box-sizing="border-box"*/} - {/* borderRadius="50px"*/} - {/* width={isMobileDevice ? undefined : "fit-content"}*/} - {/* flex="none"*/} - {/* order="1"*/} - {/* flex-grow="0"*/} - {/* margin="10px 16px"*/} - {/* >*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* )}*/} - {/* */} - {/* )}*/} - {/* */} - {/* */} - {/* FilterFarm()}*/} - {/* showPopOver={showPopOver}*/} - {/* setShowPopover={setShowPopover}*/} - {/* setSavedChanges={setSavedChanges}*/} - {/* />*/} - - {/* */} - {/* }*/} - {/* />*/} - {/* {*/} - {/* GFarmingInputSearchFarm(true);*/} - {/* const formattedValue = e.target.value.toUpperCase();*/} - {/* setKeyword(formattedValue);*/} - {/* }}*/} - {/* borderLeft={0}*/} - {/* borderColor={filterBorderColor}*/} - {/* _focus={{ borderColor: "none" }}*/} - {/* />*/} - {/* */} - {/* */} - {/* */} - {/* List your project*/} - {/* */} - {/* */} - {/* */} - {/* */} - - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* Deposit*/} - {/* Earn*/} - {/* APY*/} - {/* Total Liquidity*/} - {/* */} - {/* */} - - {/* {loadingState ? (*/} - {/* */} - {/* {new Array(5).fill("1").map((item, index) => {*/} - {/* return (*/} - {/* */} - {/* */} - {/* {new Array(5).fill("1").map((item, index) => {*/} - {/* return (*/} - {/* */} - {/* */} - {/* */} - {/* );*/} - {/* })}*/} - {/* */} - {/* */} - {/* );*/} - {/* })}*/} - {/* */} - {/* ) : // */} - {/* keyword &&*/} - {/* searchResults.searchResult === undefined ? null : keyword &&*/} - {/* searchResults.searchResult !== undefined ? (*/} - {/* searchSection.newSearchResult === undefined ? (*/} - {/* searchResults.searchResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* ) : (*/} - {/* searchSection.newSearchResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* )*/} - {/* ) : searchResults.filterResult !== undefined ? (*/} - {/* searchSection.newFilterResult === undefined ? (*/} - {/* searchResults.filterResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* ) : (*/} - {/* searchSection.newFilterResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* )*/} - {/* ) : searchResults.filterResult === undefined ? (*/} - {/* farms === undefined ? (*/} - {/* data.contents?.map((content: any, index: number) => (*/} - {/* */} - {/* ))*/} - {/* ) : (*/} - {/* farms.map((content: any, index: number) => (*/} - {/* */} - {/* ))*/} - {/* )*/} - {/* ) : null}*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* //STAKING V2 PANEL*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* Deposit*/} - {/* Earn*/} - {/* APY*/} - {/* Total Liquidity*/} - {/* */} - {/* */} - {/* {specialPool?.map((content: any, index: number) => (*/} - {/* */} - {/* ))}*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* // PRODUCT FARM PANEL*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* {selected === farmSection.PRODUCT_FARM*/} - {/* ? "Auto-Period Product"*/} - {/* : "Deposit"}*/} - {/* */} - {/* */} - {/* {selected === farmSection.PRODUCT_FARM*/} - {/* ? "Percentage Profit Share"*/} - {/* : "Earn"}*/} - {/* */} - {/* */} - {/* {selected === farmSection.PRODUCT_FARM*/} - {/* ? "Profit Timeline"*/} - {/* : "APY"}*/} - {/* */} - {/* */} - {/* Total Liquidity*/} - {/* */} - {/* {selected === farmSection.PRODUCT_FARM && (*/} - {/* */} - {/* Estimated Total Profits*/} - {/* */} - {/* )}*/} - {/* */} - {/* */} - {/* {FarmData.productFarm.map((content: any, index: number) =>*/} - {/* index === 0 ? (*/} - {/* */} - {/* ) : null*/} - {/* )}*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* Deposit*/} - {/* Earn*/} - {/* APY*/} - {/* Total Liquidity*/} - {/* */} - {/* */} - {/* {FarmData.contents.map((content: any, index: number) =>*/} - {/* index === 0 ? (*/} - {/* */} - {/* ) : null*/} - {/* )}*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* /!* special *!/*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* Please Migrate your LP token farming from farming V1 to*/} - {/* this V2*/} - {/* */} - {/* */} - - {/* */} - {/* */} - {/* Go to farming V1*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* Deposit*/} - {/* Earn*/} - {/* APY*/} - {/* Total Liquidity*/} - {/* LP Locked*/} - {/* */} - {/* */} - - {/* {loadingLP ? (*/} - {/* */} - {/* {new Array(4).fill("1").map((item, index) => {*/} - {/* return (*/} - {/* */} - {/* */} - {/* {new Array(5).fill("1").map((item, index) => {*/} - {/* return (*/} - {/* */} - {/* */} - {/* */} - {/* );*/} - {/* })}*/} - {/* */} - {/* */} - {/* );*/} - {/* })}*/} - {/* */} - {/* ) : // */} - {/* keyword &&*/} - {/* searchResults.searchResult === undefined ? null : keyword &&*/} - {/* searchResults.searchResult !== undefined ? (*/} - {/* newSearchSection.newSearchResult === undefined ? (*/} - {/* searchResults.searchResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* ) : (*/} - {/* newSearchSection.newSearchResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* )*/} - {/* ) : searchResults.filterResult !== undefined ? (*/} - {/* newSearchSection.newFilterResult === undefined ? (*/} - {/* searchResults.filterResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* ) : (*/} - {/* newSearchSection.newFilterResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* )*/} - {/* ) : searchResults.filterResult === undefined ? (*/} - {/* recentFarms === undefined ? (*/} - {/* newLP.contents?.map((content: any, index: number) => (*/} - {/* */} - {/* ))*/} - {/* ) : (*/} - {/* recentFarms.map((content: any, index: number) => (*/} - {/* */} - {/* ))*/} - {/* )*/} - {/* ) : null}*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* Deposit*/} - {/* Earn*/} - {/* APY*/} - {/* Total Liquidity*/} - {/* LP Locked*/} - {/* */} - {/* */} - - {/* {loadingLP ? (*/} - {/* */} - {/* {new Array(4).fill("1").map((item, index) => {*/} - {/* return (*/} - {/* */} - {/* */} - {/* {new Array(4).fill("1").map((item, index) => {*/} - {/* return (*/} - {/* */} - {/* */} - {/* */} - {/* );*/} - {/* })}*/} - {/* */} - {/* */} - {/* );*/} - {/* })}*/} - {/* */} - {/* ) : keyword &&*/} - {/* searchResults.searchResult === undefined ? null : keyword &&*/} - {/* searchResults.searchResult !== undefined ? (*/} - {/* newSearchSection.newSearchResult === undefined ? (*/} - {/* searchResults.searchResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* ) : (*/} - {/* newSearchSection.newSearchResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* )*/} - {/* ) : searchResults.filterResult !== undefined ? (*/} - {/* newSearchSection.newFilterResult === undefined ? (*/} - {/* searchResults.filterResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* ) : (*/} - {/* newSearchSection.newFilterResult.map(*/} - {/* (content: any, index: number) => (*/} - {/* */} - {/* )*/} - {/* )*/} - {/* )*/} - {/* ) : searchResults.filterResult === undefined ? (*/} - {/* recentFarms === undefined ? (*/} - {/* newLP.contents?.map((content: any, index: number) => (*/} - {/* */} - {/* ))*/} - {/* ) : (*/} - {/* recentFarms.map((content: any, index: number) => (*/} - {/* */} - {/* ))*/} - {/* )*/} - {/* ) : null}*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/**/} - + { parseFloat(ethers.utils.formatUnits(RGPBallance)) * rgpPrice; const yeaRate = await specialPool.YEAR_RATE(); - //this is temporal handleUpdateSpecialPool([ From 51252f06e85cc6736e66c46d4b09140982d96ad3 Mon Sep 17 00:00:00 2001 From: Fakorede Damilola Date: Mon, 24 Oct 2022 10:55:19 +0100 Subject: [PATCH 2/9] changes --- src/pages/AddLiquidity/index.tsx | 2 +- src/pages/FarmingV2/ShowNewFarm.tsx | 4 +- .../FarmingV2/ShowProductFarmDetails.tsx | 2 +- src/pages/FarmingV2/ShowYieldFarmDetails.tsx | 10 +- src/pages/FarmingV2/YieldFarm.tsx | 7 +- src/pages/FarmingV2/index.tsx | 35 ++- src/pages/Pool/index.tsx | 2 +- src/pages/RemoveLiquidity/Remove.tsx | 2 +- src/pages/Swap/components/sendToken/index.tsx | 2 +- src/state/LPFarm/hooks.ts | 10 +- src/state/farm/actions.ts | 21 -- src/state/farm/hooks.ts | 10 - src/state/farm/index.ts | 43 ---- src/state/farm/reducer.ts | 195 -------------- src/state/farming/action.ts | 33 --- src/state/farming/hooks.ts | 239 ------------------ src/state/farming/reducer.ts | 140 ---------- src/state/index.ts | 6 +- src/state/newFarming/action.ts | 4 + src/state/newFarming/hooks.ts | 3 +- src/state/newFarming/reducer.ts | 62 +++-- src/state/newfarm/actions.ts | 3 + src/state/newfarm/hooks.ts | 53 ++-- src/state/newfarm/reducer.ts | 87 ++++++- src/state/{farm => newfarm}/types.ts | 0 src/state/nft/actions.ts | 5 - src/state/types.ts | 2 +- src/utils/hooks/useGetFarmData.ts | 103 +------- src/utils/hooks/useGetNewFarms.ts | 2 +- src/utils/utilsFunctions.ts | 2 +- 30 files changed, 217 insertions(+), 872 deletions(-) delete mode 100644 src/state/farm/actions.ts delete mode 100644 src/state/farm/hooks.ts delete mode 100644 src/state/farm/index.ts delete mode 100644 src/state/farm/reducer.ts delete mode 100644 src/state/farming/action.ts delete mode 100644 src/state/farming/hooks.ts delete mode 100644 src/state/farming/reducer.ts rename src/state/{farm => newfarm}/types.ts (100%) diff --git a/src/pages/AddLiquidity/index.tsx b/src/pages/AddLiquidity/index.tsx index 55efa732..1f3aec19 100644 --- a/src/pages/AddLiquidity/index.tsx +++ b/src/pages/AddLiquidity/index.tsx @@ -55,7 +55,7 @@ import { useUserGasPricePercentage, useUpdateUserGasPreference, } from "../../state/gas/hooks"; -import { clearSearchResult } from "../../state/farming/action"; +import { clearSearchResult } from "../../state/newFarming/action"; import { GFailedTransaction, GSuccessfullyTransaction, diff --git a/src/pages/FarmingV2/ShowNewFarm.tsx b/src/pages/FarmingV2/ShowNewFarm.tsx index b48ac615..12d5a48b 100644 --- a/src/pages/FarmingV2/ShowNewFarm.tsx +++ b/src/pages/FarmingV2/ShowNewFarm.tsx @@ -69,15 +69,13 @@ import { } from "../../utils/addresses"; import {clearInputInfo, convertFromWei, convertToNumber} from "../../utils"; import {useRGPBalance} from "../../utils/hooks/useBalances"; -import {updateFarmAllowances} from "../../state/farm/actions"; +import { updateFarmAllowances } from "../../state/newfarm/actions"; import {useActiveWeb3React} from "../../utils/hooks/useActiveWeb3React"; import Joyride from "react-joyride"; import {steps} from "../../components/Onboarding/YieldSteps"; import {Contract} from "@ethersproject/contracts"; import {calculateGas} from "../Swap/components/sendToken"; import {useUserGasPricePercentage} from "../../state/gas/hooks"; - -import {useFetchYieldFarmDetails, useUpdateFarm} from "../../state/newfarm/hooks"; import {useNewYieldFarmDetails, useUpdateNewFarm} from "../../state/LPFarm/hooks"; import { GButtonClicked, diff --git a/src/pages/FarmingV2/ShowProductFarmDetails.tsx b/src/pages/FarmingV2/ShowProductFarmDetails.tsx index 58a5563a..7c45b0e7 100644 --- a/src/pages/FarmingV2/ShowProductFarmDetails.tsx +++ b/src/pages/FarmingV2/ShowProductFarmDetails.tsx @@ -37,7 +37,7 @@ import { } from "../../utils/addresses"; import { clearInputInfo, convertFromWei, convertToNumber } from "../../utils"; import { useRGPBalance } from "../../utils/hooks/useBalances"; -import { updateFarmProductAllowances } from "../../state/farm/actions"; +import { updateFarmProductAllowances } from "../../state/newfarm/actions"; import { useActiveWeb3React } from "../../utils/hooks/useActiveWeb3React"; import { Contract } from "@ethersproject/contracts"; import { formatAmount, getERC20Token } from "../../utils/utilsFunctions"; diff --git a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx index 7b0da429..c882c44a 100644 --- a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx +++ b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx @@ -32,7 +32,6 @@ import {DARK_THEME, farmSection} from "./index"; import {addToast} from "../../components/Toast/toastSlice"; import {useDispatch, useSelector} from "react-redux"; import {setOpenModal, TrxState} from "../../state/application/reducer"; -import { setLoadingState } from "../../state/farm/actions"; import {ExplorerDataType, getExplorerLink} from "../../utils/getExplorerLink"; import { MasterChefV2Contract, @@ -51,7 +50,7 @@ import { } from "../../utils/addresses"; import {clearInputInfo, convertFromWei, convertToNumber} from "../../utils"; import {useRGPBalance} from "../../utils/hooks/useBalances"; -import {updateFarmAllowances} from "../../state/farm/actions"; +import { updateFarmAllowances } from "../../state/newfarm/actions"; import {useActiveWeb3React} from "../../utils/hooks/useActiveWeb3React"; import Joyride from "react-joyride"; import {steps} from "../../components/Onboarding/YieldSteps"; @@ -144,7 +143,7 @@ const ShowYieldFarmDetails = ({ const [loading, setLoading] = useState(true); // const data = useGetFarmData(reload, setReload); - +console.log({content},"jjjdjjdjjdj") const {loadingState} = useUpdateFarm({reload, setReload, content}); @@ -234,10 +233,11 @@ useEffect(()=>{ const checkForApproval = async () => { const rgp = await rigelToken(RGP[chainId as number], library); const rgpApproval = await poolAllowance(rgp); + console.log({content}) if (content.deposit === "RGP" && Number(content.id) === 1) { const specialPoolV1Approval = await specialPoolV1Allowance(rgp); changeApprovalButton(true, specialPoolV1Approval); - } else if (content.deposit === "RGP" && Number(content.id) === 13) { + } else if (content.deposit === "RGP" && Number(content.id) === 0) { const specialPoolV2Approval = await specialPoolV2Allowance(rgp); @@ -386,7 +386,7 @@ useEffect(()=>{ await RGPSpecialPoolV1Approval(); setApproveValueForOtherToken(true); setApproveValueForRGP(true); - } else if (content.deposit === "RGP" && Number(content.id) === 13) { + } else if (content.deposit === "RGP" && Number(content.id) === 0) { await RGPSpecialPoolV2Approval(); setApproveValueForOtherToken(true); setApproveValueForRGP(true); diff --git a/src/pages/FarmingV2/YieldFarm.tsx b/src/pages/FarmingV2/YieldFarm.tsx index e3c48f28..d8654e7a 100644 --- a/src/pages/FarmingV2/YieldFarm.tsx +++ b/src/pages/FarmingV2/YieldFarm.tsx @@ -69,6 +69,7 @@ const YieldFarm = ({ section: string; contractID: number; }) => { + console.log({content,content2}) const mode = useColorModeValue(LIGHT_THEME, DARK_THEME); const { chainId, library } = useWeb3React(); const active = chainId && library; @@ -80,7 +81,7 @@ const YieldFarm = ({ const symbolName = params.split("/"); const selectedField = useSelector( - (state: State) => state.farming.selectedField + (state: RootState) => state.newFarming.selectedField ); const selectedBSC = selectedField === farmSection.NEW_LP; const selected = @@ -104,8 +105,8 @@ const YieldFarm = ({ const totalLiquidityValue = () => { if (farmDataLoading) return ; - if (content.totalLiquidity) { - return ` ${formatAmount(content.totalLiquidity)}`; + if (content?.totalLiquidity) { + return ` ${formatAmount(content?.totalLiquidity)}`; } }; diff --git a/src/pages/FarmingV2/index.tsx b/src/pages/FarmingV2/index.tsx index 57a2d717..f607c39a 100644 --- a/src/pages/FarmingV2/index.tsx +++ b/src/pages/FarmingV2/index.tsx @@ -40,7 +40,7 @@ import { ChevronDownIcon, HamburgerIcon, SearchIcon } from "@chakra-ui/icons"; import { useDispatch, useSelector } from "react-redux"; import bigNumber from "bignumber.js"; -import { useFarms } from "../../state/farm/hooks"; +import { useFarms } from "../../state/newfarm/hooks"; import { shortenCode } from "../../utils"; import { RootState } from "../../state"; import { SupportedChainId } from "../../constants/chains"; @@ -54,22 +54,30 @@ import CryptoJS from "crypto-js"; import { useUpdateUserGasPreference } from "../../state/gas/hooks"; import Filter from "../../components/Farming/Modals/Filter"; import { filterFarms } from "../../utils/utilsFunctions"; -import { farmStateInterface } from "../../state/farm/reducer"; -import { +import { farmStateInterface } from "../../state/newfarm/reducer"; +// import { +// useClearFarm, +// useFarmSearch, +// useFilterFarms, +// usePrevious, +// useSearch, +// useSearchResults, +// } from "../../state/farming/hooks"; +import { useClearFarm, useFarmSearch, useFilterFarms, usePrevious, useSearch, useSearchResults, -} from "../../state/farming/hooks"; +} from "../../state/newFarming/hooks"; import FarmTab from "./FarmTab"; import FarmHeader from "./FarmHeader"; -import { - clearSearchResult, +import { clearSearchResult, updateSearchResult, updateSelectedField, -} from "../../state/farming/action"; + clearAllFarms +} from "../../state/newFarming/action"; import { useGetFarmData } from "../../utils/hooks/useGetFarmData"; import { useGetNewFarms } from "../../utils/hooks/useGetNewFarms"; @@ -82,7 +90,6 @@ import { } from "../../components/G-analytics/gFarming"; import { ZERO_ADDRESS } from "../../constants"; import { State } from "../../state/types"; -import { clearAllFarms } from "../../state/newFarming/action"; export const BIG_TEN = new bigNumber(10); export const V1 = "v1"; @@ -146,7 +153,7 @@ export function Index() { const filter = useSearch(); useClearFarm(); - const selector = useSelector((state: State) => state.farming.selectedField); + const selector = useSelector((state: RootState) => state.newFarming.selectedField); const [searchedDataResult] = useFarmSearch({ keyword, @@ -211,12 +218,12 @@ export function Index() { const data = useFarmData(); const newLP = useNewLPData(); - const farms = useSelector((state) => state.farming.content); - const recentFarms = useSelector((state) => state.newFarming.content); - const searchSection = useSelector((state) => state.farming); - const newSearchSection = useSelector((state) => state.newFarming); + const farms = useSelector((state:RootState) => state.newFarming.content); + const recentFarms = useSelector((state:RootState) => state.newFarming.content); + const searchSection = useSelector((state:RootState) => state.newFarming); + const newSearchSection = useSelector((state:RootState) => state.newFarming); - const { specialPool } = useSelector((state) => state.newfarm); + const { specialPool } = useSelector((state:RootState) => state.newfarm); console.log({specialPool}) diff --git a/src/pages/Pool/index.tsx b/src/pages/Pool/index.tsx index 9ab86772..a7355739 100644 --- a/src/pages/Pool/index.tsx +++ b/src/pages/Pool/index.tsx @@ -14,7 +14,7 @@ import Joyride from "react-joyride"; import { tourSteps } from "../../components/Onboarding/LiquiditySteps"; import WelcomeModal from "../../components/Onboarding/WelcomeModal"; import { useUpdateUserGasPreference } from "../../state/gas/hooks"; -import { clearSearchResult } from "../../state/farming/action"; +import { clearSearchResult } from "../../state/newFarming/action"; import { useDispatch } from "react-redux"; import { useActiveWeb3React } from "../../utils/hooks/useActiveWeb3React"; import { GClickedAddLiquidity, GClickedAddNewLiquidity } from "../../components/G-analytics/gLiquidity"; diff --git a/src/pages/RemoveLiquidity/Remove.tsx b/src/pages/RemoveLiquidity/Remove.tsx index b2bdda9b..29d4fced 100644 --- a/src/pages/RemoveLiquidity/Remove.tsx +++ b/src/pages/RemoveLiquidity/Remove.tsx @@ -45,7 +45,7 @@ import { useUpdateUserGasPreference, useUserGasPricePercentage, } from "../../state/gas/hooks"; -import { clearSearchResult } from "../../state/farming/action"; +import { clearSearchResult } from "../../state/newFarming/action"; import { GFailedTransaction, GSuccessfullyTransaction } from "../../components/G-analytics/gIndex"; const Remove = () => { diff --git a/src/pages/Swap/components/sendToken/index.tsx b/src/pages/Swap/components/sendToken/index.tsx index c005c318..15f7e480 100644 --- a/src/pages/Swap/components/sendToken/index.tsx +++ b/src/pages/Swap/components/sendToken/index.tsx @@ -55,7 +55,7 @@ import { useUpdateUserGasPreference } from "../../../../state/gas/hooks"; import { useUserGasPricePercentage } from "../../../../state/gas/hooks"; import { Web3Provider } from "@ethersproject/providers"; import NetworkModal from "./../../../../components/Navbar/modals/networkModal"; -import { clearSearchResult } from "../../../../state/farming/action"; +import { clearSearchResult } from "../../../../state/newFarming/action"; import { GButtonClick, GFailedTransaction, diff --git a/src/state/LPFarm/hooks.ts b/src/state/LPFarm/hooks.ts index 48254e48..23922361 100644 --- a/src/state/LPFarm/hooks.ts +++ b/src/state/LPFarm/hooks.ts @@ -32,7 +32,7 @@ import {RootState} from "../index"; import {farmSection} from "../../pages/FarmingV2"; export const useNewLPData = (): farmDataInterface => { - const farms = useSelector((state: State) => state.lpfarm); + const farms = useSelector((state: RootState) => state.lpfarm); return farms; }; @@ -93,9 +93,9 @@ export const useUpdateNewFarm = ({ content, contractID, section }: updateFarmInterface) => { const data = useNewLPData(); - const searchSection = useSelector((state) => state.newFarming); + const searchSection = useSelector((state:RootState) => state.newFarming); - const selectedField = useSelector((state: State) => state.farming.selectedField); + const selectedField = useSelector((state: RootState) => state.newFarming.selectedField); const selected = selectedField === farmSection.SECOND_NEW_LP; const mainLP = selectedField === farmSection.NEW_LP; @@ -412,14 +412,14 @@ interface FetchYieldFarmDetails { export const useNewYieldFarmDetails = ({content, section, loading, setLoading, contractID}: FetchYieldFarmDetails) => { const data = useNewLPData(); - const searchSection = useSelector((state) => state.newFarming); + const searchSection = useSelector((state:RootState) => state.newFarming); const { account, chainId, library } = useWeb3React(); // const [loading, setLoading] = useState(true); const trxState = useSelector((state) => state.application.modal?.trxState); const stateChanged : boolean = trxState === 2; - const selectedField = useSelector((state: State) => state.farming.selectedField); + const selectedField = useSelector((state: RootState) => state.newFarming.selectedField); const selected = selectedField === farmSection.SECOND_NEW_LP; const mainLP = selectedField === farmSection.NEW_LP; diff --git a/src/state/farm/actions.ts b/src/state/farm/actions.ts deleted file mode 100644 index 1be9f785..00000000 --- a/src/state/farm/actions.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { createAction } from '@reduxjs/toolkit' - -export interface valuenterface { - reserves0?: any - reserves1?: any, - symbol0?: any, - symbol1?: any -} - - - -export const changeFarmingContent = createAction<{ value: valuenterface }>('farm/changeFarmingContent'); -export const updateTotalLiquidity = createAction<{ liquidity: any, apy: any, deposit: string}[]>('farm/updateTotalLiquidity'); -export const updateFarmProductLiquidity = createAction<{ liquidity: any, deposit: string}[]>('farm/updateFarmProductLiquidity'); -export const updateTokenStaked = createAction<{ staked: any, earned: any,symbol?:string }[]>('farm/updateTokenStaked'); -export const updateProductStaked = createAction<{ staked: any, }[]>('farm/updateProductStaked'); -export const updateFarmAllowances = createAction('farm/updateFarmAllowances'); -export const updateFarmProductAllowances = createAction('farm/updateFarmProductAllowances'); -export const updateFarmBalances = createAction('farm/updateFarmBalances'); -export const updatePoolId = createAction('farm/updatePoolId'); -export const setLoadingState = createAction('farm/setLoadingState'); diff --git a/src/state/farm/hooks.ts b/src/state/farm/hooks.ts deleted file mode 100644 index a37f2976..00000000 --- a/src/state/farm/hooks.ts +++ /dev/null @@ -1,10 +0,0 @@ - -import { State } from '../types' -import {farmStateInterface} from './reducer' -import { useSelector } from 'react-redux' - - -export const useFarms = (): farmStateInterface => { - const farms = useSelector((state: State) => state.farms) - return farms -} diff --git a/src/state/farm/index.ts b/src/state/farm/index.ts deleted file mode 100644 index 5e89d790..00000000 --- a/src/state/farm/index.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { createSlice } from '@reduxjs/toolkit' -import farmsConfig from '../../utils/constants/farms' -import { isArchivedPid } from '../../utils/helpers/farmHelpers' - -const noAccountFarmConfig = farmsConfig.map((farm) => ({ - ...farm, - userData: { - allowance: '0', - tokenBalance: '0', - stakedBalance: '0', - earnings: '0', - }, -})) - -const initialState = { - data: noAccountFarmConfig, - loadArchivedFarmsData: false, - userDataLoaded: false, -} - -export const nonArchivedFarms = farmsConfig.filter(({ pid }) => !isArchivedPid(pid)) - -// Async thunks - - - - -export const farmsSlice = createSlice({ - name: 'Farms', - initialState, - reducers: { - setLoadArchivedFarmsData: (state, action) => { - const loadArchivedFarmsData = action.payload - state.loadArchivedFarmsData = loadArchivedFarmsData - }, - }, - -}) - -// Actions -export const { setLoadArchivedFarmsData } = farmsSlice.actions - -export default farmsSlice.reducer diff --git a/src/state/farm/reducer.ts b/src/state/farm/reducer.ts deleted file mode 100644 index 0347a442..00000000 --- a/src/state/farm/reducer.ts +++ /dev/null @@ -1,195 +0,0 @@ -import { createReducer } from "@reduxjs/toolkit"; -import { - changeFarmingContent, - updateTokenStaked, - updateTotalLiquidity, - updateFarmAllowances, - updateFarmProductAllowances, - updateFarmBalances, - updatePoolId, - updateFarmProductLiquidity, - updateProductStaked, - setLoadingState -} from "./actions"; - -export interface farmStateInterface { - loadingValue?: boolean; - error?: any; - contents: Array<{ - id: string; - img: string; - deposit: string; - earn: string; - ARYValue: any; - type?: string; - totalLiquidity: any; - tokensStaked: Array; - RGPEarned?: string; - availableToken: string; - inflationPerDay?: number; - tokenPrice?: number; - totalVolumePerPool?: number; - farmingFee?: number; - pId?: number; - poolAllowance?: any; - poolVersion?: string; - }>; - productFarm?: any -} - -export const initialState: farmStateInterface = { - loadingValue: false, - error: null, - contents: [ - // { - // id: "1", - // img: "rgp.svg", - // // deposit: 'RGP', - // deposit: "RGP", - // earn: "RGP", - // type: "RGP", - // ARYValue: "0", - // totalLiquidity: "1223", - // tokensStaked: ["RGP", "0"], - // RGPEarned: "0", - // availableToken: "", - // inflationPerDay: 0, - // tokenPrice: 0, - // totalVolumePerPool: 0, - // farmingFee: 0, - // pId: 0, - // poolAllowance: "", - // }, - { - id: "13", - img: "rgp.svg", - // deposit: 'RGP', - deposit: "RGP", - earn: "RGP", - type: "RGP", - ARYValue: "0", - totalLiquidity: "", //"1223", - tokensStaked: ["RGP", "0"], - RGPEarned: "0", - availableToken: "", - inflationPerDay: 0, - tokenPrice: 0, - totalVolumePerPool: 0, - farmingFee: 0, - pId: 10793, - poolAllowance: "", - poolVersion: "2", - }, - ], - productFarm :[ - { - feature:"AutoTrade", - percentageProfitShare:"25%", - profitTimeLine:"6 months", - totalLiquidity:"", - estimatedTotalProfit:"1774000", - deposit: "RGP", - pid:93903, - poolAllowance: "", - type:"AT", - RGPStaked:"" - } - ] -}; - -export default createReducer(initialState, (builder) => - builder - .addCase(changeFarmingContent, (state, action) => { - const id = `${action.payload.value.symbol0}-${action.payload.value.symbol1}`; - let current = state.contents.findIndex((obj) => obj.deposit === id); - - if (current >= 0) { - state.contents[current].totalLiquidity = - parseInt(action.payload.value.reserves1) + - parseInt(action.payload.value.reserves0); - } - }) - - .addCase(updateTotalLiquidity, (state, action) => { - const totalLiquidity = action.payload; - console.log("totalLiquidity", totalLiquidity); - totalLiquidity.forEach((item, index) => { - state.contents[index].totalLiquidity = item.liquidity; - state.contents[index].ARYValue = item.apy; - state.contents[index].deposit = item.deposit; - }); - }) - .addCase(updateFarmProductLiquidity, (state, action) => { - const totalLiquidity = action.payload; - - totalLiquidity.forEach((item, index) => { - state.productFarm[index].totalLiquidity = item.liquidity; - // state.productFarm[index].ARYValue = item.apy; - state.productFarm[index].deposit = item.deposit; - }); - }) - - .addCase(updateTokenStaked, (state, action) => { - console.log(action.payload) - const stakedToken = action.payload; - // stakedToken.forEach((item, index) => { - // state.contents[index].tokensStaked = [ - // state.contents[index].tokensStaked[0], - // item.staked, - // ]; - // state.contents[index].RGPEarned = item.earned; - // }); - let index =state.contents.findIndex((item)=>item?.poolVersion ==="2") - state.contents[index].tokensStaked = [ - state.contents[index].tokensStaked[0], - stakedToken[0].staked, - ]; - state.contents[index].RGPEarned = stakedToken[0].earned; - }) - .addCase(updateProductStaked, (state, action) => { - const stakedToken = action.payload; - console.log({stakedToken}) - state.productFarm[0].RGPStaked = stakedToken[0].staked - // stakedToken.forEach((item, index) => { - // state.contents[index].tokensStaked = [ - // state.contents[index].tokensStaked[0], - // item.staked, - // ]; - // state.contents[index].RGPEarned = item.earned; - // }); - }) - - .addCase(updateFarmAllowances, (state, action) => { - const allowances = action.payload; - console.log(allowances.length,state.contents.length,"iieii") - allowances.forEach((item, index) => { - state.contents[index].poolAllowance = item; - }); - }) - - .addCase(updateFarmProductAllowances, (state, action) => { - const allowances = action.payload; - console.log({allowances}) - allowances.forEach((item, index) => { - state.productFarm[index].poolAllowance = item; - }); - }) - - .addCase(updateFarmBalances, (state, action) => { - const balances = action.payload; - let index =state.contents.findIndex((item)=>item?.poolVersion ==="2") - - state.contents[index].availableToken = balances[0]; - }) - - .addCase(updatePoolId, (state, action) => { - const poolIds = action.payload; - poolIds.forEach((item, index) => { - state.contents[index].pId = item; - }); - }) - .addCase(setLoadingState, (state, action) => { - - state.loadingValue = !state.loadingValue; - }) -); diff --git a/src/state/farming/action.ts b/src/state/farming/action.ts deleted file mode 100644 index f573cfd6..00000000 --- a/src/state/farming/action.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { createAction } from "@reduxjs/toolkit"; -import { farmStateInterface } from "../farm/reducer"; - -export const updateSearchResult = createAction<{ - farmData: [] | undefined; -}>("farming/updateSearchResult"); - -export const updateNewSearchResult = createAction<{ - farmData: [] | undefined; -}>("farming/updateNewSearchResult"); - -export const updateFilterResult = createAction<{ - farmData: [] | undefined; -}>("farming/updateFilterResult"); - -export const updateNewFilterResult = createAction<{ - farmData: [] | undefined; -}>("farming/updateNewFilterResult"); - -export const clearSearchResult = createAction("farming/clearSearchResult"); - -export const updateYieldFarmDetails = createAction<{ value: any[] }>( - "farming/updateYieldFarmDetails" -); -export const updateProductFarmDetails = createAction<{ value: any[] }>( - "farming/updateProductFarmDetails" -); - -export const updateSelectedField = createAction<{ value: any }>( - "farming/updateSelectedField" -); - -export const clearAllFarms = createAction("farming/clearAllFarms"); diff --git a/src/state/farming/hooks.ts b/src/state/farming/hooks.ts deleted file mode 100644 index a4fa5793..00000000 --- a/src/state/farming/hooks.ts +++ /dev/null @@ -1,239 +0,0 @@ -import { useState, useMemo, useCallback, useEffect, useRef } from "react"; -import { useDispatch, useSelector } from "react-redux"; -import { - updateSearchResult, - clearSearchResult, - updateFilterResult, - clearAllFarms, -} from "./action"; -import { useFarms } from "../farm/hooks"; -import { useFarmData } from "../newfarm/hooks"; -import { useActiveWeb3React } from "../../utils/hooks/useActiveWeb3React"; -import { useWeb3React } from "@web3-react/core"; - -interface FilterFarms { - newestToOldest: boolean; - min: number; - max: number; - setSavedChanges: React.Dispatch>; - saveChanges: boolean; -} - -export const useSearch = () => { - const farms = useSelector((state: State) => state.farming.filterResult); - return farms; -}; - -export const useSearchResults = () => { - const farms = useSelector((state: State) => state.farming); - return farms; -}; - -export const useFilterFarms = ({ - newestToOldest, - min, - max, - setSavedChanges, - saveChanges, -}: FilterFarms) => { - const farmData = useFarms(); - const farms = useFarmData(); - const { chainId } = useActiveWeb3React(); - const dispatch = useDispatch(); - - const handleUpdateSearch = useCallback( - (searchResult) => { - dispatch( - updateFilterResult({ - farmData: searchResult, - }) - ); - }, - [dispatch] - ); - - useMemo(() => { - if (!newestToOldest && saveChanges) { - let dataArray = [...farms?.contents]; - - const arrayLength = dataArray.length; - // const firstItem = dataArray.splice(0, 1); - // const lastItem = dataArray.splice( - // chainId === 80001 || - // chainId === 137 || - // chainId === 42261 || - // chainId === 42262 - // ? 3 - // : arrayLength - 2, - // chainId === 80001 || - // chainId === 137 || - // chainId === 42261 || - // chainId === 42262 - // ? 10 - // : 1 - // ); - - console.log(dataArray); - - const searchResult = dataArray.filter( - (item, idx) => item.APY > min && item.APY < max - ); - const editSearch = [...searchResult]; - console.log(editSearch); - - handleUpdateSearch(editSearch); - setSavedChanges(false); - } else if (newestToOldest && saveChanges) { - let dataArray = [...farms.contents]; - - let normal = [...farmData.contents]; - let resortedArray = dataArray.reverse(); - const arrayLength = dataArray.length; - // const firstItem = dataArray.splice( - // 0, - // chainId === 80001 || - // chainId === 137 || - // chainId === 42261 || - // chainId === 42262 - // ? 9 - // : 1 - // ); - // const lastItem = dataArray.splice(dataArray.length - 1, 1); - const searchResult = dataArray.filter( - (item) => item.APY > min && item.APY < max - ); - const editSearch = [...searchResult]; - - handleUpdateSearch(editSearch); - setSavedChanges(false); - } - }, [newestToOldest, saveChanges]); -}; - -interface Args { - keyword: string; - previousKeyword: string; - searchData: []; -} - -export const useFarmSearch = ({ - keyword, - previousKeyword, - searchData, -}: Args) => { - const FarmData = useFarms(); - const farms = useFarmData(); - const [searchedDataResult, setSearchedDataResult] = useState(undefined); - const dispatch = useDispatch(); - const { chainId } = useActiveWeb3React(); - // const searchData = useSearch(); - - const handleUpdateSearch = useCallback( - (searchResult) => { - dispatch( - updateSearchResult({ - farmData: searchResult, - }) - ); - }, - [dispatch] - ); - - const clearResult = useCallback(() => { - dispatch(clearSearchResult()); - }, [dispatch]); - - useMemo(() => { - if (keyword) { - let word = keyword.split("-"); - - if (searchData) { - let searchResultArray = []; - - const dataArray = [...searchData]; - const resultArray = dataArray.filter( - (item) => item.deposit.search(keyword) !== -1 - ); - const secondResultSearch = - word.length >= 2 && resultArray.length === 0 - ? dataArray.filter( - (item) => item.deposit.search(word[1] + "-" + word[0]) !== -1 - ) - : undefined; - - if (resultArray.length !== 0) { - searchResultArray.push(resultArray); - } else { - searchResultArray.push(secondResultSearch); - } - setSearchedDataResult(searchResultArray[0]); - - // handleUpdateSearch(searchResultArray[0]); - } else if (farms.contents) { - let searchResultArray = []; - const dataArray = [...farms.contents]; - const arrayLength = dataArray.length; - // const firstItem = dataArray.splice(0, 1); - // const lastItem = dataArray.splice( - // chainId === 80001 || - // chainId === 137 || - // chainId === 42261 || - // chainId === 42262 - // ? 3 - // : arrayLength - 2, - // chainId === 80001 || - // chainId === 137 || - // chainId === 42261 || - // chainId === 42262 - // ? 10 - // : 1 - // ); - const resultArray = dataArray.filter( - (item) => item.deposit.search(keyword) !== -1 - ); - const secondResultSearch = - word.length >= 2 && resultArray.length === 0 - ? dataArray.filter( - (item) => item.deposit.search(word[1] + "-" + word[0]) !== -1 - ) - : undefined; - - if (resultArray.length !== 0) { - searchResultArray.push(resultArray); - } else { - searchResultArray.push(secondResultSearch); - } - console.log("farms", farms); - setSearchedDataResult(searchResultArray[0]); - } - } else { - setSearchedDataResult(undefined); - } - }, [keyword, searchData]); - - return [searchedDataResult]; -}; - -export function usePrevious(value: any) { - const ref = useRef(); - useEffect(() => { - ref.current = value; //assign the value of ref to the argument - }, [value]); //this code will run when the value of 'value' changes - return ref.current; //in the end, return the current ref value. -} - -export const useClearFarm = () => { - const data = useFarmData(); - const { chainId } = useWeb3React(); - const dispatch = useDispatch(); - - const handleUpdateFarms = useCallback(() => { - dispatch(clearAllFarms()); - }, [dispatch]); - - useMemo(() => { - if (chainId !== data.chainId) { - handleUpdateFarms(); - } - }, [chainId]); -}; diff --git a/src/state/farming/reducer.ts b/src/state/farming/reducer.ts deleted file mode 100644 index 662a32d4..00000000 --- a/src/state/farming/reducer.ts +++ /dev/null @@ -1,140 +0,0 @@ -import {createReducer} from "@reduxjs/toolkit"; -import { - clearAllFarms, - clearSearchResult, - updateFilterResult, - updateNewFilterResult, - updateNewSearchResult, - updateProductFarmDetails, - updateSearchResult, - updateSelectedField, - updateYieldFarmDetails -} from "./action"; - enum farmSection { - LIQUIDITY, - STAKING, - PRODUCT_FARM, - NEW_LP, - SECOND_NEW_LP, -} - -export interface FarmingSearchState { - searchResult: [] | undefined; - filterResult: [] | undefined; - newFilterResult: [] | undefined; - newSearchResult: [] | undefined; - content: - | Array<{ - id: number; - img: string; - deposit: string; - earn: string; - type: string; - totalLiquidity: number; - APY: number; - tokenStaked: string[]; - RGPEarned: string; - availableToken: string; - allowance: string; - address: string; - }> - | undefined; - productFarm: - | Array<{ - feature:string, - percentageProfitShare:string, - profitTimeLine:string, - totalLiquidity:string, - estimatedTotalProfit:string, - deposit: string, - pid:number, - poolAllowance: string, - type:string, - tokenStaked:string - }> - | undefined; - selectedField: farmSection -} - -const initialState: FarmingSearchState = { - searchResult: undefined, - newSearchResult: undefined, - filterResult: undefined, - newFilterResult: undefined, - content: undefined, - productFarm:undefined, - selectedField: farmSection.LIQUIDITY -}; - -export default createReducer(initialState, (builder) => - builder - .addCase(updateSearchResult, (farming, { payload: { farmData } }) => { - return { - ...farming, - searchResult: farmData, - }; - }) - - .addCase(updateNewSearchResult, (farming, { payload: { farmData } }) => { - return { - ...farming, - newSearchResult: farmData, - }; - }) - - .addCase(clearAllFarms, (farming, { payload }) => { - return { - ...farming, - newSearchResult: undefined, - newFilterResult: undefined, - content: undefined, - }; - }) - - .addCase(updateNewFilterResult, (farming, { payload: { farmData } }) => { - return { - ...farming, - newFilterResult: farmData, - }; - }) - - .addCase(updateYieldFarmDetails, (farming, { payload: { value } }) => { - // const farms = action.payload.farmData; - if (value !== undefined) { - return { - ...farming, - content: value, - }; - } - }) - .addCase(updateProductFarmDetails, (farming, { payload: { value } }) => { - // const farms = action.payload.farmData; - if (value !== undefined) { - return { - ...farming, - productFarm: value, - }; - } - }) - - .addCase(updateFilterResult, (farming, { payload: { farmData } }) => { - return { - ...farming, - filterResult: farmData, - }; - }) - .addCase(clearSearchResult, (farming, {}) => { - return { - ...farming, - searchResult: undefined, - filterResult: undefined, - }; - }) - .addCase(updateSelectedField, (farming, {payload: { value }}) => { - return { - ...farming, - selectedField: value - - }; - }) -); diff --git a/src/state/index.ts b/src/state/index.ts index b2144d11..b2915956 100644 --- a/src/state/index.ts +++ b/src/state/index.ts @@ -9,9 +9,8 @@ import user from "./user/reducer"; import blockReducer from "./block"; import transactions from "./transaction/reducer"; import mint from "./mint/reducer"; -import farms from "./farm/reducer"; import gas from "./gas/reducer"; -import farming from "./farming/reducer"; +// import farming from "./farming/reducer"; import newfarm from "./newfarm/reducer"; import lpfarm from "./LPFarm/reducer"; import newFarming from "./newFarming/reducer"; @@ -34,9 +33,8 @@ const store = configureStore({ lists, - farms, gas, - farming, + // farming, newfarm, lpfarm, newFarming, diff --git a/src/state/newFarming/action.ts b/src/state/newFarming/action.ts index b03f5f14..ca7a1b9d 100644 --- a/src/state/newFarming/action.ts +++ b/src/state/newFarming/action.ts @@ -16,6 +16,10 @@ export const updateNewFilterResult = createAction<{ farmData: [] | undefined; }>("newFarming/updateNewFilterResult"); +export const updateSelectedField = createAction<{ value: any }>( + "farming/updateSelectedField" +); + export const clearSearchResult = createAction("newFarming/clearSearchResult"); export const updateYieldFarmDetails = createAction<{ value: any[] }>( diff --git a/src/state/newFarming/hooks.ts b/src/state/newFarming/hooks.ts index fdc46198..e4bf27a8 100644 --- a/src/state/newFarming/hooks.ts +++ b/src/state/newFarming/hooks.ts @@ -6,7 +6,8 @@ import { updateFilterResult, clearAllFarms, } from "./action"; -import { useFarms } from "../farm/hooks"; +import { useFarmData } from "../newfarm/hooks"; +import { useFarms } from "../newfarm/hooks"; import { useNewLPData } from "../LPFarm/hooks"; import { useActiveWeb3React } from "../../utils/hooks/useActiveWeb3React"; import { useWeb3React } from "@web3-react/core"; diff --git a/src/state/newFarming/reducer.ts b/src/state/newFarming/reducer.ts index 5efb299b..435945be 100644 --- a/src/state/newFarming/reducer.ts +++ b/src/state/newFarming/reducer.ts @@ -7,9 +7,17 @@ import { updateNewSearchResult, updateProductFarmDetails, updateSearchResult, + updateSelectedField, updateYieldFarmDetails } from "./action"; +enum farmSection { + LIQUIDITY, + STAKING, + PRODUCT_FARM, + NEW_LP, + SECOND_NEW_LP, +} export interface FarmingSearchState { searchResult: [] | undefined; filterResult: [] | undefined; @@ -32,20 +40,23 @@ export interface FarmingSearchState { LPLocked: number; }> | undefined; - productFarm: - | Array<{ - feature:string, - percentageProfitShare:string, - profitTimeLine:string, - totalLiquidity:string, - estimatedTotalProfit:string, - deposit: string, - pid:number, - poolAllowance: string, - type:string, - tokenStaked:string - }> - | undefined; + productFarm: { + feature:string, + percentageProfitShare:string, + profitTimeLine:string, + totalLiquidity:string, + estimatedTotalProfit:string, + deposit: string, + pid:number, + poolAllowance: string, + type:string, + tokenStaked:string + RGPStaked:string + }[]; + + selectedField: farmSection + // productFarm:any + } const initialState: FarmingSearchState = { @@ -54,7 +65,21 @@ const initialState: FarmingSearchState = { filterResult: undefined, newFilterResult: undefined, content: undefined, - productFarm:undefined + selectedField: farmSection.LIQUIDITY, + productFarm:[{ + feature:"AutoTrade", + percentageProfitShare:"25%", + profitTimeLine:"6 months", + totalLiquidity:"", + estimatedTotalProfit:"1774000", + deposit: "RGP", + pid:93903, + poolAllowance: "", + type:"AT", + RGPStaked:"", + tokenStaked:"" + }], + // selectedField: farmSection.LIQUIDITY }; export default createReducer(initialState, (builder) => @@ -98,6 +123,13 @@ export default createReducer(initialState, (builder) => }; } }) + .addCase(updateSelectedField, (farming, {payload: { value }}) => { + return { + ...farming, + selectedField: value + + }; + }) .addCase(updateProductFarmDetails, (farming, { payload: { value } }) => { // const farms = action.payload.farmData; if (value !== undefined) { diff --git a/src/state/newfarm/actions.ts b/src/state/newfarm/actions.ts index 27f57e40..982f83a4 100644 --- a/src/state/newfarm/actions.ts +++ b/src/state/newfarm/actions.ts @@ -16,6 +16,9 @@ export const updateChainId = createAction<{ value: number }>( "newfarm/updateChainId" ); +export const updateFarmAllowances = createAction('newfarm/updateFarmAllowances'); +export const updateFarmProductAllowances = createAction('newfarm/updateFarmProductAllowances'); + export const updateAllowance = createAction<{ value: any; }>("newfarm/updateAllowance"); diff --git a/src/state/newfarm/hooks.ts b/src/state/newfarm/hooks.ts index b83227fa..348bba6e 100644 --- a/src/state/newfarm/hooks.ts +++ b/src/state/newfarm/hooks.ts @@ -1,5 +1,5 @@ import { State } from "../types"; -import { farmDataInterface } from "./reducer"; +import { farmDataInterface, farmStateInterface } from "./reducer"; import { useSelector } from "react-redux"; import { useEffect, useMemo, useState, useCallback } from "react"; import { useDispatch } from "react-redux"; @@ -25,18 +25,20 @@ import { import { getERC20Token } from "../../utils/utilsFunctions"; import { ethers } from "ethers"; import { updateFarms } from "./actions"; -import { + +import { updateFilterResult, - updateSearchResult, - updateYieldFarmDetails, - updateNewFilterResult, - updateNewSearchResult, - updateProductFarmDetails, -} from "../farming/action"; + updateSearchResult, + updateYieldFarmDetails, + updateNewFilterResult, + updateNewSearchResult, + updateProductFarmDetails, + } from "../newFarming/action"; import Web3 from "web3"; +import { RootState } from ".."; export const useFarmData = (): farmDataInterface => { - const farms = useSelector((state: State) => state.newfarm); + const farms = useSelector((state: RootState) => state.newfarm); return farms; }; @@ -54,19 +56,26 @@ interface updateFarmInterface { totalLiquidity: number; APY: number; address: string; - }; - section: string; - address: string; + } | any; + section?: string; + address?: string; } +export const useFarms = (): farmStateInterface => { + const farms = useSelector((state: RootState) => state.newFarming) + console.log({farms}) + return farms +} + + export const useUpdateFarm = ({ reload, setReload, content, - section, address + section }: updateFarmInterface) => { const data = useFarmData(); - const searchSection = useSelector((state) => state.farming); + const searchSection = useSelector((state:RootState) => state.newFarming); const { account, chainId, library } = useWeb3React(); const [loadingState, setLoadingState] = useState(false); @@ -204,7 +213,6 @@ export const useUpdateFarm = ({ console.log(err); } }; - const calculateLiquidityAndApy = async (reward: number | undefined) => { try { const masterchef = await MasterChefV2Contract( @@ -349,7 +357,7 @@ interface FetchYieldFarmDetails { totalLiquidity: number; APY: number; address: string; - }; + } | any; section: string; loading: boolean; setLoading: React.Dispatch>; @@ -362,7 +370,7 @@ export const useFetchYieldFarmDetails = ({ setLoading }: FetchYieldFarmDetails) => { const data = useFarmData(); - const searchSection = useSelector((state) => state.farming); + const searchSection = useSelector((state:RootState) => state.newFarming); const { account, chainId, library } = useWeb3React(); // const [loading, setLoading] = useState(true); @@ -438,11 +446,7 @@ export const useFetchYieldFarmDetails = ({ getERC20Token(token0Address, library), getERC20Token(token1Address, library), ]); - const [symbol0, symbol1] = await Promise.all([ - token0Contract.symbol(), - token1Contract.symbol(), - ]); - + const [decimal0, decimal1] = await Promise.all([ token0Contract.decimals(), token1Contract.decimals(), @@ -604,7 +608,7 @@ export const useFetchYieldFarmDetails = ({ section === "search" ? searchSection.newSearchResult !== undefined ? [...searchSection.newSearchResult] - : [...searchSection.searchResult] + : [...searchSection?.searchResult] : section === "filter" ? searchSection.newFilterResult !== undefined ? [...searchSection.newFilterResult] @@ -626,7 +630,6 @@ export const useFetchYieldFarmDetails = ({ newArray[index] = updatedFarm; - console.log("updatedd", newArray); handleUpdateFarms(newArray); @@ -668,7 +671,6 @@ const getUserValue = async ()=> { productFarm.userData(account), ]); const tokenStaked = await FarmTokenBalance.tokenQuantity - console.log({tokenStaked},tokenStaked.toString(),Web3.utils.fromWei(tokenStaked.toString())) return { feature:"AutoTrade", @@ -701,7 +703,6 @@ export const useUpdateProductFarm = ({ section, }: updateFarmInterface) => { const data = useFarmData(); - const searchSection = useSelector((state) => state.farming); const { account, chainId, library } = useWeb3React(); const [loadingState, setLoadingState] = useState(true); diff --git a/src/state/newfarm/reducer.ts b/src/state/newfarm/reducer.ts index 99ccac26..f9411f83 100644 --- a/src/state/newfarm/reducer.ts +++ b/src/state/newfarm/reducer.ts @@ -1,12 +1,13 @@ import { createReducer } from "@reduxjs/toolkit"; import { stat } from "fs"; -import farm from "../farm"; import { updateAllowance, updateFarms, updateLoadingState, updateSpecialPool, updateChainId, + updateFarmAllowances, + updateFarmProductAllowances, } from "./actions"; export interface farmDataInterface { @@ -44,15 +45,81 @@ export interface farmDataInterface { address: string; }> | undefined; + productFarm: { + feature:string, + percentageProfitShare:string, + profitTimeLine:string, + totalLiquidity:string, + estimatedTotalProfit:string, + deposit: string, + pid:number, + poolAllowance: string, + type:string, + tokenStaked:string + RGPStaked:string + }[] +} +export interface farmStateInterface { + loadingValue?: boolean; + error?: any; + contents: Array<{ + id: string; + img: string; + deposit: string; + earn: string; + ARYValue: any; + type?: string; + totalLiquidity: any; + tokensStaked: Array; + RGPEarned?: string; + availableToken: string; + inflationPerDay?: number; + tokenPrice?: number; + totalVolumePerPool?: number; + farmingFee?: number; + pId?: number; + poolAllowance?: any; + poolVersion?: string; + }>; + productFarm: { + feature:string, + percentageProfitShare:string, + profitTimeLine:string, + totalLiquidity:string, + estimatedTotalProfit:string, + deposit: string, + pid:number, + poolAllowance: string, + type:string, + tokenStaked:string + RGPStaked:string + }[] } - const initialState: farmDataInterface = { loading: false, contents: undefined, specialPool: undefined, chainId: 56, + productFarm :[ + { + feature:"AutoTrade", + percentageProfitShare:"25%", + profitTimeLine:"6 months", + totalLiquidity:"", + estimatedTotalProfit:"1774000", + deposit: "RGP", + pid:93903, + poolAllowance: "", + type:"AT", + RGPStaked:"", + tokenStaked:"" + } + ] }; + + + export default createReducer(initialState, (builder) => builder .addCase(updateFarms, (state, action) => { @@ -65,6 +132,7 @@ export default createReducer(initialState, (builder) => }; } }) + .addCase(updateSpecialPool, (state, action) => { const farms = action.payload.value; @@ -85,6 +153,21 @@ export default createReducer(initialState, (builder) => chainId: chainId, }; }) + .addCase(updateFarmAllowances, (state, action) => { + const allowances = action.payload; + console.log(allowances.length,allowances) + // allowances.forEach((item, index) => { + // state?.contents[index].poolAllowance = item; + // }); + }) + + .addCase(updateFarmProductAllowances, (state, action) => { + const allowances = action.payload; + console.log({allowances}) + allowances.forEach((item, index) => { + state.productFarm[index].poolAllowance = item; + }); + }) // .addCase(updateSpecialPool, (state, action) => { // const farms = action.payload.value; diff --git a/src/state/farm/types.ts b/src/state/newfarm/types.ts similarity index 100% rename from src/state/farm/types.ts rename to src/state/newfarm/types.ts diff --git a/src/state/nft/actions.ts b/src/state/nft/actions.ts index d1b4e27d..a56e087a 100644 --- a/src/state/nft/actions.ts +++ b/src/state/nft/actions.ts @@ -4,8 +4,3 @@ import { createAction } from '@reduxjs/toolkit' export const updateNftData = createAction<{ name: string, image: string, id: number}[]>('nft/updateNftData'); - -// export const updateTokenStaked = createAction<{ staked: any, earned: any }[]>('farm/updateTokenStaked'); -// export const updateFarmAllowances = createAction('farm/updateFarmAllowances'); -// export const updateFarmBalances = createAction('farm/updateFarmBalances'); -// export const updatePoolId = createAction('farm/updatePoolId'); diff --git a/src/state/types.ts b/src/state/types.ts index a8c75245..9efbc645 100644 --- a/src/state/types.ts +++ b/src/state/types.ts @@ -1,4 +1,4 @@ -import { SerializedFarmsState } from "./farm/types"; +import { SerializedFarmsState } from './newfarm/types'; import { TokenInfo, TokenList, Tags } from '@uniswap/token-lists' import {Token} from "@uniswap/sdk"; diff --git a/src/utils/hooks/useGetFarmData.ts b/src/utils/hooks/useGetFarmData.ts index b2df8371..5a246230 100644 --- a/src/utils/hooks/useGetFarmData.ts +++ b/src/utils/hooks/useGetFarmData.ts @@ -329,105 +329,6 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { } }; - // const calculateLiquidityAndApy = async ( - // address: string, - // pid?: number, - // reward?: number, - // Lp?: boolean - // ) => { - // try { - // const masterchef = await MasterChefV2Contract( - // MASTERCHEFV2ADDRESSES[ChainId as number], - // lib - // ); - // const LPInstance = await LiquidityPairInstance(address, lib); - // const reserves = await getLpTokenReserve(address); - // const totalRGP = reserves - // ? RGPADDRESSES[ChainId as number] === reserves.tokenAddress0 - // ? reserves.reserves0.toString() - // : reserves.reserves1.toString() - // : "1"; - - // const totalStable = reserves - // ? BUSD[ChainId as number] === reserves.tokenAddress0 || - // USDT[ChainId as number] === reserves.tokenAddress0 || - // USDC[ChainId as number] === reserves.tokenAddress0 - // ? ethers.utils.formatUnits( - // reserves.reserves0.toString(), - // reserves.decimals0 - // ) - // : ethers.utils.formatUnits( - // reserves.reserves1.toString(), - // reserves.decimals1 - // ) - // : "1"; - // const rgpPrice = await calculateRigelPrice(); - // const [token0, token1] = await Promise.all([ - // getERC20Token(reserves && reserves.tokenAddress0, lib), - // getERC20Token(reserves && reserves.tokenAddress1, lib), - // ]); - - // const [symbol0, symbol1] = await Promise.all([ - // token0.symbol(), - // token1.symbol(), - // ]); - - // const totalLiquidity = - // symbol0 === "BUSD" || - // symbol1 === "BUSD" || - // symbol0 === "USDT" || - // symbol1 === "USDT" || - // symbol0 === "USDC" || - // symbol1 === "USDC" - // ? parseFloat(totalStable) * 2 - // : parseFloat(ethers.utils.formatEther(totalRGP)) * rgpPrice * 2; - - // const [poolInfo, totalAllocPoint] = await Promise.all([ - // masterchef.poolInfo(pid), - // masterchef.totalAllocPoint(), - // ]); - // const allocPoint = await poolInfo.allocPoint; - // const poolReward = - // (parseFloat(allocPoint.toString()) / - // parseFloat(totalAllocPoint.toString())) * - // reward; - // const APY = (rgpPrice * poolReward * 365 * 100) / totalLiquidity; - // const [tokenEarned, userInfo, FarmTokenBalance, allowance] = - // await Promise.all([ - // masterchef.pendingRigel(pid, account), - // masterchef.userInfo(pid, account), - // LPInstance.balanceOf(account), - // LPInstance.allowance( - // account, - // MASTERCHEFV2ADDRESSES[ChainId as number] - // ), - // ]); - // const tokenStaked = await userInfo.amount; - - // return { - // id: pid, - // img: "rgp.svg", - // deposit: `${await formatSymbol(symbol0)}-${await formatSymbol( - // symbol1 - // )}`, - // earn: "RGP", - // type: "LP", - // totalLiquidity, - // APY, - // tokenStaked: [ - // `${await formatSymbol(symbol0)}-${await formatSymbol(symbol1)}`, - // ethers.utils.formatEther(tokenStaked.toString()), - // ], - // RGPEarned: ethers.utils.formatEther(tokenEarned.toString()), - // availableToken: ethers.utils.formatEther(FarmTokenBalance.toString()), - // poolAllowance: ethers.utils.formatEther(allowance.toString()), - // address: address, - // }; - // } catch (err) { - // console.log(err); - // } - // }; - const loopFarms = async (LpAddress: any[], rgpPrice: number | undefined) => { const data = []; @@ -481,6 +382,7 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { const RGPLiquidity = parseFloat(ethers.utils.formatUnits(RGPBallance)) * rgpPrice; + const yeaRate = await specialPool.YEAR_RATE(); //this is temporal @@ -494,7 +396,8 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { type: "RGP", ARYValue: ethers.utils.formatUnits(yeaRate), totalLiquidity: RGPLiquidity, - tokensStaked: ["RGP", "0"], + // main issue 206432 + tokensStaked: ["RGP", "300000"], RGPEarned: "0", availableToken: "", inflationPerDay: 0, diff --git a/src/utils/hooks/useGetNewFarms.ts b/src/utils/hooks/useGetNewFarms.ts index cf5bc6e8..cecfc3a0 100644 --- a/src/utils/hooks/useGetNewFarms.ts +++ b/src/utils/hooks/useGetNewFarms.ts @@ -35,7 +35,7 @@ export const useGetNewFarms = ( const { library } = useWeb3React(); const [loadingLP, setLoading] = useState(true); const selectedField = useSelector( - (state) => state.farming.selectedField + (state) => state.newFarming.selectedField ); const selected = selectedField === farmSection.SECOND_NEW_LP; const [LPData, setLPData] = useState< diff --git a/src/utils/utilsFunctions.ts b/src/utils/utilsFunctions.ts index a1fcd821..4772271b 100644 --- a/src/utils/utilsFunctions.ts +++ b/src/utils/utilsFunctions.ts @@ -6,7 +6,7 @@ import detectEthereumProvider from "@metamask/detect-provider"; import { ethers } from "ethers"; import { escapeRegExp } from "."; import { inputRegex } from "../components/Farming/Modals/Filter"; -import { farmStateInterface } from "../state/farm/reducer"; +import { farmStateInterface } from "../state/newfarm/reducer"; import { useSelector } from "react-redux"; import { useCallback, useEffect, useMemo, useState } from "react"; import { RootState } from "../state"; From 8dd264a5fe59bd5843068f32979ee3490902c4ed Mon Sep 17 00:00:00 2001 From: Fakorede Damilola Date: Wed, 26 Oct 2022 13:00:14 +0100 Subject: [PATCH 3/9] changes --- src/pages/FarmingV2/ShowYieldFarmDetails.tsx | 10 ++-------- src/pages/FarmingV2/YieldFarm.tsx | 1 - src/state/newfarm/hooks.ts | 2 +- src/utils/hooks/useBalances.ts | 10 +++++----- src/utils/hooks/useGetFarmData.ts | 19 +++++++++++++++---- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx index c882c44a..ea01e041 100644 --- a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx +++ b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx @@ -143,12 +143,10 @@ const ShowYieldFarmDetails = ({ const [loading, setLoading] = useState(true); // const data = useGetFarmData(reload, setReload); -console.log({content},"jjjdjjdjjdj") const {loadingState} = useUpdateFarm({reload, setReload, content}); useFetchYieldFarmDetails({content, section, setLoading, loading}); - console.log({content}) //const {loadingFarm} = useUpdateNewFarm({reload, setReload, content}); @@ -194,7 +192,6 @@ useEffect(()=>{ checkEnoughApproval(content.poolAllowance,content.availableToken) },[depositTokenValue]) useEffect(() => { - console.log({content}) const poolAllowance = async (contract: Contract) => { if (account) { const rgpApproval = await contract.allowance( @@ -225,7 +222,6 @@ useEffect(()=>{ account, RGPSPECIALPOOLADDRESSES2[chainId as number] ); - console.log({rgpApproval}) return !(rgpApproval.toString() <= 0); } }; @@ -233,7 +229,6 @@ useEffect(()=>{ const checkForApproval = async () => { const rgp = await rigelToken(RGP[chainId as number], library); const rgpApproval = await poolAllowance(rgp); - console.log({content}) if (content.deposit === "RGP" && Number(content.id) === 1) { const specialPoolV1Approval = await specialPoolV1Allowance(rgp); changeApprovalButton(true, specialPoolV1Approval); @@ -245,7 +240,6 @@ useEffect(()=>{ } else { const pool = await smartSwapLPTokenPoolTwo(content.address, library); const approvalForRGPBNB = await poolAllowance(pool); - console.log({approvalForRGPBNB,rgpApproval}) changeApprovalButton(approvalForRGPBNB, rgpApproval); } }; @@ -381,7 +375,6 @@ useEffect(()=>{ const checkUser = async (val :string) => { alert(1) - console.log({content}) if (content.deposit === "RGP" && Number(content.id) === 1) { await RGPSpecialPoolV1Approval(); setApproveValueForOtherToken(true); @@ -630,7 +623,7 @@ useEffect(()=>{ if (account) { if (val === "RGP" && Number(content.id) === 1) { await RGPUnstake(val); - } else if (val === "RGP" && Number(content.id) === 13) { + } else if (val === "RGP" && Number(content.id) === 0) { await RGPUnstakeV2(val); } else { tokensWithdrawal(content.id,val); @@ -1241,6 +1234,7 @@ useEffect(()=>{ RGPSPECIALPOOLADDRESSES2[chainId as number], library ); + alert(1) const { format1, format2, format3 } = await calculateGas( userGasPricePercentage, library, diff --git a/src/pages/FarmingV2/YieldFarm.tsx b/src/pages/FarmingV2/YieldFarm.tsx index d8654e7a..6c344100 100644 --- a/src/pages/FarmingV2/YieldFarm.tsx +++ b/src/pages/FarmingV2/YieldFarm.tsx @@ -69,7 +69,6 @@ const YieldFarm = ({ section: string; contractID: number; }) => { - console.log({content,content2}) const mode = useColorModeValue(LIGHT_THEME, DARK_THEME); const { chainId, library } = useWeb3React(); const active = chainId && library; diff --git a/src/state/newfarm/hooks.ts b/src/state/newfarm/hooks.ts index 348bba6e..4325e119 100644 --- a/src/state/newfarm/hooks.ts +++ b/src/state/newfarm/hooks.ts @@ -63,7 +63,7 @@ interface updateFarmInterface { export const useFarms = (): farmStateInterface => { const farms = useSelector((state: RootState) => state.newFarming) - console.log({farms}) + // console.log({farms}) return farms } diff --git a/src/utils/hooks/useBalances.ts b/src/utils/hooks/useBalances.ts index d0dc2e6c..24609f24 100644 --- a/src/utils/hooks/useBalances.ts +++ b/src/utils/hooks/useBalances.ts @@ -71,7 +71,7 @@ export const useRGPBalance = () => { useEffect(() => { const getBalance = async () => { if (account) { - try { + // try { const token = await getERC20Token( RGPADDRESSES[chainId as number], library @@ -80,10 +80,10 @@ export const useRGPBalance = () => { setRGPBalance( parseFloat(ethers.utils.formatEther(balance)).toFixed(4) ); - } catch (err) { - setRGPBalance(""); - console.log(err); - } + // } catch (err) { + // setRGPBalance(""); + // console.log(err); + // } } }; diff --git a/src/utils/hooks/useGetFarmData.ts b/src/utils/hooks/useGetFarmData.ts index 5a246230..57c91165 100644 --- a/src/utils/hooks/useGetFarmData.ts +++ b/src/utils/hooks/useGetFarmData.ts @@ -27,9 +27,11 @@ import { import { RootState } from "../../state"; import { SupportedChainId } from "../../constants/chains"; +import { useActiveWeb3React } from "./useActiveWeb3React"; +import { useRGPBalance } from "./useBalances"; export const useGetFarmData = (reload?: boolean, setReload?: any) => { - const { library } = useWeb3React(); + const { library,account } = useActiveWeb3React(); const [loadingState, setLoading] = useState(true); const [farmdata, setFarmData] = useState< Array<{ @@ -45,6 +47,7 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { address: string; }> >([]); + const [RGPBalance] = useRGPBalance(); const dispatch = useDispatch(); const ChainId = useSelector((state) => state.chainId.chainId); @@ -379,6 +382,14 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { RGPSPECIALPOOLADDRESSES2[ChainId as number] ); + const RGPStaked = await specialPool.userInfo(account); +console.log("n3kkkkkkkkkkkkkkkkkk") + const RGPStakedValue = ethers.utils.formatUnits(RGPStaked._amountStaked, 18); + const RGPUserReward = ethers.utils.formatUnits(RGPStaked._userReward, 18); + const availableToken = ethers.utils.formatUnits(RGPBallance, 18); + + console.log({RGPStakedValue,RGPUserReward,availableToken,RGPBalance}) + const RGPLiquidity = parseFloat(ethers.utils.formatUnits(RGPBallance)) * rgpPrice; @@ -397,9 +408,9 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { ARYValue: ethers.utils.formatUnits(yeaRate), totalLiquidity: RGPLiquidity, // main issue 206432 - tokensStaked: ["RGP", "300000"], - RGPEarned: "0", - availableToken: "", + tokensStaked: ["RGP", parseFloat(RGPStakedValue).toFixed(4)], + RGPEarned: parseFloat(RGPUserReward).toFixed(4), + availableToken:RGPBalance, inflationPerDay: 0, tokenPrice: 0, totalVolumePerPool: 0, From 35fbd51b01d0922a7edb6de25afa3488175fd0d7 Mon Sep 17 00:00:00 2001 From: Fakorede Damilola Date: Fri, 28 Oct 2022 08:46:37 +0100 Subject: [PATCH 4/9] changes --- src/pages/Swap/AutoTime.tsx | 2 +- src/pages/Swap/InstantSwap.tsx | 2 +- src/pages/Swap/SetPrice.tsx | 2 +- src/pages/Swap/components/history/History.tsx | 4 ++-- src/utils/hooks/useAccountHistory.ts | 2 +- src/utils/hooks/useMarketHistory.ts | 2 +- src/utils/hooks/useOpenOrders.ts | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pages/Swap/AutoTime.tsx b/src/pages/Swap/AutoTime.tsx index 91da45ac..020462c6 100644 --- a/src/pages/Swap/AutoTime.tsx +++ b/src/pages/Swap/AutoTime.tsx @@ -517,7 +517,7 @@ const setQuantityValue =() =>{ }) ); const changeFrequencyToday = changeFrequencyTodays(selectedFrequency)// - const response = await fetch(`https://autoswap-server.herokuapp.com/auto/add`, { + const response = await fetch(`http://localhost:7000/auto/add`, { method: "POST", mode: "cors", cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached diff --git a/src/pages/Swap/InstantSwap.tsx b/src/pages/Swap/InstantSwap.tsx index c3273485..6f44d31e 100644 --- a/src/pages/Swap/InstantSwap.tsx +++ b/src/pages/Swap/InstantSwap.tsx @@ -520,7 +520,7 @@ const handleMaxInput = async () => { if (response && value) { - const response = await fetch(`https://autoswap-server.herokuapp.com/auto/instant`, { + const response = await fetch(`http://localhost:7000/auto/instant`, { method: "POST", mode: "cors", cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached diff --git a/src/pages/Swap/SetPrice.tsx b/src/pages/Swap/SetPrice.tsx index 6b524320..baaf5a5f 100644 --- a/src/pages/Swap/SetPrice.tsx +++ b/src/pages/Swap/SetPrice.tsx @@ -83,7 +83,7 @@ const SetPrice = () => { oppositeAmount } = useDerivedSwapInfo(); - const [URL, setURL] = useState("https://autoswap-server.herokuapp.com")//https://autoswap-server.herokuapp.com + const [URL, setURL] = useState("http://localhost:7000")//http://localhost:7000 const [transactionSigned, setTransactionSigned] = useState(false) const [disableInput, setDisableInput] = useState(true) const [initialFromPrice, setInitialFromPrice] = useState("") diff --git a/src/pages/Swap/components/history/History.tsx b/src/pages/Swap/components/history/History.tsx index 5c803e70..c051fb28 100644 --- a/src/pages/Swap/components/history/History.tsx +++ b/src/pages/Swap/components/history/History.tsx @@ -36,7 +36,7 @@ const History = () => { useEffect( () => { - setSocket(io("https://autoswap-server.herokuapp.com"));//https://autoswap-server.herokuapp.com + setSocket(io("http://localhost:7000"));//http://localhost:7000 }, [] @@ -50,7 +50,7 @@ const History = () => { const [notification, setNotification] = useState(0); const location = useLocation().pathname; const [address, setAddress] = useState(""); - const [URL, setURL] = useState("https://autoswap-server.herokuapp.com")//https://autoswap-server.herokuapp.com + const [URL, setURL] = useState("http://localhost:7000")//http://localhost:7000 const [showOrder, setShowOrder] = useState(false); const [type, setType] = useState(""); diff --git a/src/utils/hooks/useAccountHistory.ts b/src/utils/hooks/useAccountHistory.ts index 451566a6..c0bec056 100644 --- a/src/utils/hooks/useAccountHistory.ts +++ b/src/utils/hooks/useAccountHistory.ts @@ -104,7 +104,7 @@ const useAccountHistory = (socket:any) => { const [historyData, setHistoryData] = useState({} as any); const [stateAccount, setStateAccount] = useState(account) const [locationData, setLocationData] = useState("swap") - const [URL, setURL] = useState("https://autoswap-server.herokuapp.com")// + const [URL, setURL] = useState("http://localhost:7000")// const dispatch =useDispatch() const [contractAddress, setContractAddress] = useState(SMARTSWAPROUTER[chainId as number]) const tokenList = async (addressName: string) => { diff --git a/src/utils/hooks/useMarketHistory.ts b/src/utils/hooks/useMarketHistory.ts index d504a892..51721517 100644 --- a/src/utils/hooks/useMarketHistory.ts +++ b/src/utils/hooks/useMarketHistory.ts @@ -38,7 +38,7 @@ const useMarketHistory = (socket:any) => { const [marketHistoryData, setMarketHistoryData] = useState({} as any); const [stateAccount, setStateAccount] = useState(account) const [locationData, setLocationData] = useState("swap") - const [URL, setURL] = useState("https://autoswap-server.herokuapp.com")// + const [URL, setURL] = useState("http://localhost:7000")// const [contractAddress, setContractAddress] = useState(SMARTSWAPROUTER[chainId as number]) const api = APIENDPOINT[chainId as number]; diff --git a/src/utils/hooks/useOpenOrders.ts b/src/utils/hooks/useOpenOrders.ts index c27ebb35..c4cee88e 100644 --- a/src/utils/hooks/useOpenOrders.ts +++ b/src/utils/hooks/useOpenOrders.ts @@ -37,7 +37,7 @@ const useOpenOrders = (socket:any) => { const [openOrderData, setopenOrderData] = useState({} as any); const [stateAccount, setStateAccount] = useState(account) const [locationData, setLocationData] = useState("swap") - const [URL, setURL] = useState("https://autoswap-server.herokuapp.com") + const [URL, setURL] = useState("http://localhost:7000") const [contractAddress, setContractAddress] = useState(SMARTSWAPROUTER[chainId as number]) const refreshPage = useSelector((state: RootState) => state.transactions.refresh); const location = useLocation().pathname; From b025c3bdcc0102c4f32a266f6d397488cca0b103 Mon Sep 17 00:00:00 2001 From: Fakorede Damilola Date: Fri, 28 Oct 2022 13:29:32 +0100 Subject: [PATCH 5/9] changes --- src/pages/FarmingV2/ShowNewFarm.tsx | 21 ++++++++------------ src/pages/FarmingV2/ShowYieldFarmDetails.tsx | 15 +++++++------- src/utils/hooks/useGetFarmData.ts | 2 +- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/pages/FarmingV2/ShowNewFarm.tsx b/src/pages/FarmingV2/ShowNewFarm.tsx index 12d5a48b..ab3e42cc 100644 --- a/src/pages/FarmingV2/ShowNewFarm.tsx +++ b/src/pages/FarmingV2/ShowNewFarm.tsx @@ -237,7 +237,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section if (content.deposit === "RGP" && Number(content.id) === 1) { const specialPoolV1Approval = await specialPoolV1Allowance(rgp); changeApprovalButton(true, specialPoolV1Approval); - } else if (content.deposit === "RGP" && Number(content.id) === 13) { + } else if (content.deposit === "RGP" && content.id === "special") { const specialPoolV2Approval = await specialPoolV2Allowance(rgp); changeApprovalButton(true, specialPoolV2Approval); } else { @@ -380,12 +380,12 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section await RGPSpecialPoolV1Approval(); setApproveValueForOtherToken(true); setApproveValueForRGP(true); - } else if (content.deposit === "RGP" && Number(content.id) === 13) { + } else if (content.deposit === "RGP" && content.id === "special") { await RGPSpecialPoolV2Approval(); setApproveValueForOtherToken(true); setApproveValueForRGP(true); } else { - const pool = await smartSwapLPTokenPoolTwo(content.address, library); + const pool = await smartSwapLPTokenPoolTwo(content?.address, library); if (!approveValueForOtherToken && !approveValueForRGP) { await RGPApproval(); await LPApproval(pool,content.deposit); @@ -874,7 +874,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section }) ); } - } else if (id === 10793) { + } else if (id === "special") { const specialPool = await RGPSpecialPool2( RGPSPECIALPOOLADDRESSES2[chainId as number], library @@ -1100,7 +1100,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section GFarmingSuccessTransaction("farming", "stake", val,"v2") setDeposited(true); setReload(true); - setContentId(content.deposit === "RGP" ? undefined : content.id); + // setContentId(content.deposit === "RGP" ? undefined : content.id); // callRefreshFarm(confirmations, status); } } catch (error: any) { @@ -1746,8 +1746,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section _hover={{ color: "white" }} disabled={parseFloat(content.RGPEarned) <= 0} onClick={() => { - harvestTokens( - content.deposit === "RGP" ? content.pId : content.id + harvestTokens(content.id ); }} className={"harvest"} @@ -1958,9 +1957,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section _hover={{ color: "white" }} disabled={parseFloat(content.RGPEarned) <= 0} onClick={() => { - harvestTokens( - content.deposit === "RGP" ? content.pId : content.id - ); + harvestTokens(content.id); }} className={"harvest"} > @@ -1997,9 +1994,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section _hover={{ color: "white" }} disabled={parseFloat(content.RGPEarned) <= 0} onClick={() => { - harvestTokens( - content.deposit === "RGP" ? content.pId : content.id - ); + harvestTokens(content.id); }} className={"harvest"} > diff --git a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx index ea01e041..4d363d9f 100644 --- a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx +++ b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx @@ -176,6 +176,7 @@ const ShowYieldFarmDetails = ({ } }; useEffect(()=>{ + console.log({content}) const checkEnoughApproval = (allowance: any, balance: any) => { // console.log("checkEnoughApproval",allowance.toString(),balance); if (allowance && balance) { @@ -786,7 +787,7 @@ useEffect(()=>{ }) ); } - } else if (id === 10793) { + } else if (id === "special") { const specialPool = await RGPSpecialPool2( RGPSPECIALPOOLADDRESSES2[chainId as number], library @@ -1043,7 +1044,7 @@ useEffect(()=>{ if (account) { if (val === "RGP" && Number(content.id) === 1) { await RGPuseStake(); - } else if (val === "RGP" && Number(content.id) === 13) { + } else if (val === "RGP" && content.id=== "special") { await RGPuseStakeV2(); } else { LPDeposit(content.id,val); @@ -1632,7 +1633,7 @@ useEffect(()=>{ disabled={parseFloat(content.RGPEarned) <= 0} onClick={() => { harvestTokens( - content.deposit === "RGP" ? content.pId : content.id + content.id ); }} className={"harvest"} @@ -1671,7 +1672,7 @@ useEffect(()=>{ disabled={parseFloat(content.RGPEarned) <= 0} onClick={() => { harvestTokens( - content.deposit === "RGP" ? content.pId : content.id + content.id ); }} className={"harvest"} @@ -1883,7 +1884,7 @@ useEffect(()=>{ disabled={parseFloat(content.RGPEarned) <= 0} onClick={() => { harvestTokens( - content.deposit === "RGP" ? content.pId : content.id + content.id ); }} className={"harvest"} @@ -1921,9 +1922,7 @@ useEffect(()=>{ _hover={{ color: "white" }} disabled={parseFloat(content.RGPEarned) <= 0} onClick={() => { - harvestTokens( - content.deposit === "RGP" ? content.pId : content.id - ); + harvestTokens(content.id); }} className={"harvest"} > diff --git a/src/utils/hooks/useGetFarmData.ts b/src/utils/hooks/useGetFarmData.ts index 57c91165..abfff158 100644 --- a/src/utils/hooks/useGetFarmData.ts +++ b/src/utils/hooks/useGetFarmData.ts @@ -399,7 +399,7 @@ console.log("n3kkkkkkkkkkkkkkkkkk") handleUpdateSpecialPool([ { - id: "0", + id: "special", img: "rgp.svg", // deposit: 'RGP', deposit: "RGP", From cdb26438fd0f21f763b104c2b26356326f34f895 Mon Sep 17 00:00:00 2001 From: Fakorede Damilola Date: Sat, 29 Oct 2022 13:27:19 +0100 Subject: [PATCH 6/9] changes --- src/pages/FarmingV2/ShowYieldFarmDetails.tsx | 6 +++--- src/state/newfarm/hooks.ts | 1 - src/utils/hooks/useGetFarmData.ts | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx index 4d363d9f..feed180c 100644 --- a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx +++ b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx @@ -233,7 +233,7 @@ useEffect(()=>{ if (content.deposit === "RGP" && Number(content.id) === 1) { const specialPoolV1Approval = await specialPoolV1Allowance(rgp); changeApprovalButton(true, specialPoolV1Approval); - } else if (content.deposit === "RGP" && Number(content.id) === 0) { + } else if (content.deposit === "RGP" && content.id=== "special") { const specialPoolV2Approval = await specialPoolV2Allowance(rgp); @@ -380,7 +380,7 @@ useEffect(()=>{ await RGPSpecialPoolV1Approval(); setApproveValueForOtherToken(true); setApproveValueForRGP(true); - } else if (content.deposit === "RGP" && Number(content.id) === 0) { + } else if (content.deposit === "RGP" && content.id === "special") { await RGPSpecialPoolV2Approval(); setApproveValueForOtherToken(true); setApproveValueForRGP(true); @@ -624,7 +624,7 @@ useEffect(()=>{ if (account) { if (val === "RGP" && Number(content.id) === 1) { await RGPUnstake(val); - } else if (val === "RGP" && Number(content.id) === 0) { + } else if (val === "RGP" && content.id === "special") { await RGPUnstakeV2(val); } else { tokensWithdrawal(content.id,val); diff --git a/src/state/newfarm/hooks.ts b/src/state/newfarm/hooks.ts index 4325e119..476234f6 100644 --- a/src/state/newfarm/hooks.ts +++ b/src/state/newfarm/hooks.ts @@ -5,7 +5,6 @@ import { useEffect, useMemo, useState, useCallback } from "react"; import { useDispatch } from "react-redux"; import { updateAllowance } from "./actions"; import { useWeb3React } from "@web3-react/core"; -import { useGetFarmData } from "../../utils/hooks/useGetFarmData"; import { id } from "ethers/lib/utils"; import { MasterChefV2Contract, diff --git a/src/utils/hooks/useGetFarmData.ts b/src/utils/hooks/useGetFarmData.ts index abfff158..8ac8a9be 100644 --- a/src/utils/hooks/useGetFarmData.ts +++ b/src/utils/hooks/useGetFarmData.ts @@ -377,6 +377,7 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { RGPSPECIALPOOLADDRESSES2[ChainId as number], lib ); + console.log("here....") const rgp = await getERC20Token(RGPADDRESSES[ChainId as number], lib); const RGPBallance = await rgp.balanceOf( RGPSPECIALPOOLADDRESSES2[ChainId as number] From fa63840be91e9ba954e900a251a6113404ea0286 Mon Sep 17 00:00:00 2001 From: Fakorede Damilola Date: Sun, 30 Oct 2022 20:40:21 +0000 Subject: [PATCH 7/9] half way --- src/pages/FarmingV2/ShowNewFarm.tsx | 28 +++---- .../FarmingV2/ShowProductFarmDetails.tsx | 4 +- src/pages/FarmingV2/ShowYieldFarmDetails.tsx | 22 +++--- src/pages/FarmingV2/YieldFarm.tsx | 2 +- src/pages/FarmingV2/mock.ts | 12 +-- src/state/LPFarm/actions.ts | 4 - src/state/LPFarm/reducer.ts | 41 ---------- src/state/newFarming/action.ts | 4 + src/state/newFarming/hooks.ts | 5 +- src/state/newFarming/reducer.ts | 58 ++++++++++++++ src/state/newfarm/reducer.ts | 76 ++++++++++++------- src/utils/hooks/useBalances.ts | 1 + src/utils/hooks/useGetFarmData.ts | 15 ++-- 13 files changed, 155 insertions(+), 117 deletions(-) diff --git a/src/pages/FarmingV2/ShowNewFarm.tsx b/src/pages/FarmingV2/ShowNewFarm.tsx index ab3e42cc..1c46d24d 100644 --- a/src/pages/FarmingV2/ShowNewFarm.tsx +++ b/src/pages/FarmingV2/ShowNewFarm.tsx @@ -96,7 +96,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section img: string; ARYValue: string; lpSymbol: string; - tokensStaked: string[]; + tokenStaked: string[]; availableToken: string; deposit: string; poolAllowance: any; @@ -620,7 +620,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section return; } else if ( Number(content.poolVersion) === 2 && - parseFloat(content.tokensStaked[1]) <= 0 && + parseFloat(content.tokenStaked[1]) <= 0 && Number(depositTokenValue) < Number(minimumStakeAmount) ) { setDepositInputHasError(true); @@ -665,9 +665,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section if ( parseFloat(unstakeToken) > parseFloat( - content.deposit === "RGP" - ? content.tokensStaked[1] - : content.tokenStaked[1] + content.tokenStaked[1] ) ) { setInputHasError(true); @@ -683,11 +681,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section GButtonClicked(`max_button for ${input}`,content.deposit,"v2") setDepositTokenValue(content.availableToken); } else if (input === "unstake") { - setUnstakeToken( - content.deposit === "RGP" - ? content.tokensStaked[1] - : content.tokenStaked[1] - ); + setUnstakeToken(content.tokenStaked[1]); } } catch (e) { console.log( @@ -1593,11 +1587,11 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section > - {parseFloat(content.tokensStaked[1]).toFixed(4)} + {parseFloat(content.tokenStaked[1]).toFixed(4)} @@ -1871,7 +1865,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section parseFloat( content.type !== "RGP" ? content.tokenStaked[1] - : content.tokensStaked[1] + : content.tokenStaked[1] ) <= 0 } padding='10px 40px' @@ -2510,7 +2504,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section {`${ content.type === "RGP" - ? content.tokensStaked[1] + ? content.tokenStaked[1] : content.tokenStaked[1] } ${content.deposit} Staked `} diff --git a/src/pages/FarmingV2/ShowProductFarmDetails.tsx b/src/pages/FarmingV2/ShowProductFarmDetails.tsx index 7c45b0e7..674a6962 100644 --- a/src/pages/FarmingV2/ShowProductFarmDetails.tsx +++ b/src/pages/FarmingV2/ShowProductFarmDetails.tsx @@ -679,11 +679,11 @@ return ( > {/* - {parseFloat(content.tokensStaked[1]).toFixed(4)} + {parseFloat(content.tokenStaked[1]).toFixed(4)} */} {content.RGPStaked} diff --git a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx index feed180c..57303585 100644 --- a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx +++ b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx @@ -86,7 +86,7 @@ const ShowYieldFarmDetails = ({ img: string; ARYValue: string; lpSymbol: string; - tokensStaked: string[]; + tokenStaked: string[]; availableToken: string; deposit: string; poolAllowance: any; @@ -533,7 +533,7 @@ useEffect(()=>{ return; } else if ( Number(content.poolVersion) === 2 && - parseFloat(content.tokensStaked[1]) <= 0 && + parseFloat(content.tokenStaked[1]) <= 0 && Number(depositTokenValue) < Number(minimumStakeAmount) ) { setDepositInputHasError(true); @@ -579,7 +579,7 @@ useEffect(()=>{ parseFloat(unstakeToken) > parseFloat( content.deposit === "RGP" - ? content.tokensStaked[1] + ? content.tokenStaked[1] : content.tokenStaked[1] ) ) { @@ -598,7 +598,7 @@ useEffect(()=>{ } else if (input === "unstake") { setUnstakeToken( content.deposit === "RGP" - ? content.tokensStaked[1] + ? content.tokenStaked[1] : content.tokenStaked[1] ); } @@ -1518,11 +1518,11 @@ useEffect(()=>{ > - {parseFloat(content.tokensStaked[1]).toFixed(4)} + {parseFloat(content.tokenStaked[1]).toFixed(4)} { disabled={ approveValueForRGP && approveValueForOtherToken && - parseFloat(content.tokensStaked[1]) <= 0 + parseFloat(content.tokenStaked[1]) <= 0 } padding='10px 40px' cursor='pointer' @@ -1762,7 +1762,7 @@ useEffect(()=>{ label={ content?.type !== "RGP" ? content?.tokenStaked[1] - : content.tokensStaked[1] + : content.tokenStaked[1] } bg='gray.300' color='black' @@ -1770,7 +1770,7 @@ useEffect(()=>{ {parseFloat( content.type !== "RGP" ? content?.tokenStaked[1] - : content.tokensStaked[1] + : content.tokenStaked[1] ).toFixed(4)} @@ -1797,7 +1797,7 @@ useEffect(()=>{ parseFloat( content.type !== "RGP" ? content.tokenStaked[1] - : content.tokensStaked[1] + : content.tokenStaked[1] ) <= 0 } padding='10px 40px' @@ -2420,7 +2420,7 @@ useEffect(()=>{ {`${ content.type === "RGP" - ? content.tokensStaked[1] + ? content.tokenStaked[1] : content.tokenStaked[1] } ${content.deposit} Staked `} diff --git a/src/pages/FarmingV2/YieldFarm.tsx b/src/pages/FarmingV2/YieldFarm.tsx index 6c344100..bfbe5d81 100644 --- a/src/pages/FarmingV2/YieldFarm.tsx +++ b/src/pages/FarmingV2/YieldFarm.tsx @@ -40,7 +40,7 @@ const YieldFarm = ({ img: string; ARYValue: string; lpSymbol: string; - tokensStaked: string[]; + tokenStaked: string[]; availableToken: string; deposit: string; poolAllowance: any; diff --git a/src/pages/FarmingV2/mock.ts b/src/pages/FarmingV2/mock.ts index e5c615d7..5cc243bb 100644 --- a/src/pages/FarmingV2/mock.ts +++ b/src/pages/FarmingV2/mock.ts @@ -6,7 +6,7 @@ export const contents = [ ARYValue: "30,000", earn: "RGP", lpSymbol: "RGB", - tokensStaked: ["RGP", "2"], + tokenStaked: ["RGP", "2"], availableToken: "3.747948393", }, { @@ -16,7 +16,7 @@ export const contents = [ ARYValue: "30,000", earn: "RGP", lpSymbol: "RGB - BNB", - tokensStaked: ["RGP-BNB", "3"], + tokenStaked: ["RGP-BNB", "3"], availableToken: "3.747948393", }, { @@ -26,7 +26,7 @@ export const contents = [ ARYValue: "30,000", earn: "RGP", lpSymbol: "RBG - BUSD", - tokensStaked: ["RGP-BUSD", "0"], + tokenStaked: ["RGP-BUSD", "0"], availableToken: "3.747948393", }, { @@ -36,7 +36,7 @@ export const contents = [ ARYValue: "30,000", earn: "RGP", lpSymbol: "RGP - ETH", - tokensStaked: ["RGP-ETH", "0"], + tokenStaked: ["RGP-ETH", "0"], availableToken: "3.747948393", }, { @@ -46,7 +46,7 @@ export const contents = [ ARYValue: "30,000", earn: "RGP", lpSymbol: "RGP - AXD", - tokensStaked: ["RGP-AXD", "0"], + tokenStaked: ["RGP-AXD", "0"], availableToken: "3.747948393", }, { @@ -56,7 +56,7 @@ export const contents = [ ARYValue: "30,000", earn: "RGP", lpSymbol: "RGP - POL", - tokensStaked: ["RGP-POL", "0"], + tokenStaked: ["RGP-POL", "0"], availableToken: "3.747948393", }, ]; diff --git a/src/state/LPFarm/actions.ts b/src/state/LPFarm/actions.ts index 941c469b..9bbf6bad 100644 --- a/src/state/LPFarm/actions.ts +++ b/src/state/LPFarm/actions.ts @@ -4,10 +4,6 @@ export const updateFarms = createAction<{ value: any[] }>( "lpfarm/updateFarms" ); -export const updateSpecialPool = createAction<{ value: any[] }>( - "lpfarm/updateSpecialPool" -); - export const updateLoadingState = createAction<{ value: boolean }>( "lpfarm/updateLoadingState" ); diff --git a/src/state/LPFarm/reducer.ts b/src/state/LPFarm/reducer.ts index c3ec8496..23d9da27 100644 --- a/src/state/LPFarm/reducer.ts +++ b/src/state/LPFarm/reducer.ts @@ -2,7 +2,6 @@ import { createReducer } from "@reduxjs/toolkit"; import { updateFarms, updateLoadingState, - updateSpecialPool, updateChainId, } from "./actions"; @@ -26,28 +25,11 @@ export interface farmDataInterface { | undefined; loading: boolean; chainId: number | undefined; - specialPool: - | Array<{ - id: number; - img: string; - deposit: string; - earn: string; - type: string; - totalLiquidity: number; - APY: number; - tokenStaked: string[]; - RGPEarned: string; - availableToken: string; - allowance: string; - address: string; - }> - | undefined; } const initialState: farmDataInterface = { loading: false, contents: undefined, - specialPool: undefined, chainId: undefined, }; @@ -64,17 +46,6 @@ export default createReducer(initialState, (builder) => } }) - .addCase(updateSpecialPool, (state, action) => { - const farms = action.payload.value; - if (farms !== undefined) { - return { - ...state, - specialPool: farms, - loading: false, - }; - } - }) - .addCase(updateChainId, (state, action) => { const chainId = action.payload.value; @@ -83,18 +54,6 @@ export default createReducer(initialState, (builder) => chainId: chainId, }; }) - - // .addCase(updateSpecialPool, (state, action) => { - // const farms = action.payload.value; - // if (farms !== undefined) { - // return { - // ...state, - // specialPool: farms, - // loading: false, - // }; - // } - // }) - .addCase(updateLoadingState, (state, action) => { if (state.contents !== undefined) { return { diff --git a/src/state/newFarming/action.ts b/src/state/newFarming/action.ts index ca7a1b9d..e1499610 100644 --- a/src/state/newFarming/action.ts +++ b/src/state/newFarming/action.ts @@ -22,6 +22,10 @@ export const updateSelectedField = createAction<{ value: any }>( export const clearSearchResult = createAction("newFarming/clearSearchResult"); +export const updateSpecialPool = createAction<{ value: any[] }>( + "newfarm/updateSpecialPool" + ); + export const updateYieldFarmDetails = createAction<{ value: any[] }>( "newFarming/updateYieldFarmDetails" ); diff --git a/src/state/newFarming/hooks.ts b/src/state/newFarming/hooks.ts index e4bf27a8..c8d426b1 100644 --- a/src/state/newFarming/hooks.ts +++ b/src/state/newFarming/hooks.ts @@ -11,6 +11,7 @@ import { useFarms } from "../newfarm/hooks"; import { useNewLPData } from "../LPFarm/hooks"; import { useActiveWeb3React } from "../../utils/hooks/useActiveWeb3React"; import { useWeb3React } from "@web3-react/core"; +import { RootState } from ".."; interface FilterFarms { newestToOldest: boolean; @@ -21,12 +22,12 @@ interface FilterFarms { } export const useSearch = () => { - const farms = useSelector((state: State) => state.newFarming.filterResult); + const farms = useSelector((state: RootState) => state.newFarming.filterResult); return farms; }; export const useSearchResults = () => { - const farms = useSelector((state: State) => state.newFarming); + const farms = useSelector((state: RootState) => state.newFarming); return farms; }; diff --git a/src/state/newFarming/reducer.ts b/src/state/newFarming/reducer.ts index 435945be..d689c88c 100644 --- a/src/state/newFarming/reducer.ts +++ b/src/state/newFarming/reducer.ts @@ -8,6 +8,7 @@ import { updateProductFarmDetails, updateSearchResult, updateSelectedField, + updateSpecialPool, updateYieldFarmDetails } from "./action"; @@ -40,6 +41,27 @@ export interface FarmingSearchState { LPLocked: number; }> | undefined; + specialPool: + | Array<{ + id: number | string; + img: string; + deposit: string; + earn: string; + type: string; + totalLiquidity: number | string; + tokenStaked: string[]; + RGPEarned: string; + availableToken: string; + ARYValue: number | string; + inflationPerDay: number | string; + tokenPrice: number; + totalVolumePerPool: number; + farmingFee: number; + pId:number; + poolAllowance: string; + poolVersion:string; + }> + | undefined; productFarm: { feature:string, percentageProfitShare:string, @@ -65,6 +87,29 @@ const initialState: FarmingSearchState = { filterResult: undefined, newFilterResult: undefined, content: undefined, + specialPool: [ + { + id: "special", + img: "rgp.svg", + // deposit: 'RGP', + deposit: "RGP", + earn: "RGP", + type: "RGP", + ARYValue:0, + totalLiquidity: "", + // main issue 206432 + tokenStaked: ["RGP",""], + RGPEarned: "", + availableToken: "", + inflationPerDay: 0, + tokenPrice: 0, + totalVolumePerPool: 0, + farmingFee: 0, + pId: 10793, + poolAllowance: "", + poolVersion: "2", + } + ], selectedField: farmSection.LIQUIDITY, productFarm:[{ feature:"AutoTrade", @@ -140,6 +185,19 @@ export default createReducer(initialState, (builder) => } }) + .addCase(updateSpecialPool, (state, action) => { + console.log({action},action.payload) + const farms = action.payload.value; + console.log({farms}) + if (farms !== undefined) { + return { + ...state, + specialPool: farms, + loading: false, + }; + } + }) + .addCase(updateFilterResult, (farming, { payload: { farmData } }) => { return { ...farming, diff --git a/src/state/newfarm/reducer.ts b/src/state/newfarm/reducer.ts index f9411f83..b08966da 100644 --- a/src/state/newfarm/reducer.ts +++ b/src/state/newfarm/reducer.ts @@ -29,22 +29,27 @@ export interface farmDataInterface { | undefined; loading: boolean; chainId: number; - specialPool: - | Array<{ - id: number; - img: string; - deposit: string; - earn: string; - type: string; - totalLiquidity: number; - APY: number; - tokenStaked: string[]; - RGPEarned: string; - availableToken: string; - allowance: string; - address: string; - }> - | undefined; + // specialPool: + // | Array<{ + // id: number | string; + // img: string; + // deposit: string; + // earn: string; + // type: string; + // totalLiquidity: number | string; + // tokenStaked: string[]; + // RGPEarned: string; + // availableToken: string; + // ARYValue: number | string; + // inflationPerDay: number | string; + // tokenPrice: number; + // totalVolumePerPool: number; + // farmingFee: number; + // pId:number; + // poolAllowance: string; + // poolVersion:string; + // }> + // | undefined; productFarm: { feature:string, percentageProfitShare:string, @@ -70,7 +75,7 @@ export interface farmStateInterface { ARYValue: any; type?: string; totalLiquidity: any; - tokensStaked: Array; + tokenStaked: Array; RGPEarned?: string; availableToken: string; inflationPerDay?: number; @@ -98,7 +103,29 @@ export interface farmStateInterface { const initialState: farmDataInterface = { loading: false, contents: undefined, - specialPool: undefined, + // specialPool: [ + // { + // id: "special", + // img: "rgp.svg", + // // deposit: 'RGP', + // deposit: "RGP", + // earn: "RGP", + // type: "RGP", + // ARYValue:0, + // totalLiquidity: "", + // // main issue 206432 + // tokenStaked: ["RGP",""], + // RGPEarned: "", + // availableToken: "", + // inflationPerDay: 0, + // tokenPrice: 0, + // totalVolumePerPool: 0, + // farmingFee: 0, + // pId: 10793, + // poolAllowance: "", + // poolVersion: "2", + // } + // ], chainId: 56, productFarm :[ { @@ -123,6 +150,7 @@ const initialState: farmDataInterface = { export default createReducer(initialState, (builder) => builder .addCase(updateFarms, (state, action) => { + console.log(action.payload) const farms = action.payload.value; if (farms !== undefined) { return { @@ -135,7 +163,9 @@ export default createReducer(initialState, (builder) => .addCase(updateSpecialPool, (state, action) => { + console.log({action},action.payload) const farms = action.payload.value; + console.log({farms}) if (farms !== undefined) { return { ...state, @@ -169,16 +199,6 @@ export default createReducer(initialState, (builder) => }); }) - // .addCase(updateSpecialPool, (state, action) => { - // const farms = action.payload.value; - // if (farms !== undefined) { - // return { - // ...state, - // specialPool: farms, - // loading: false, - // }; - // } - // }) .addCase(updateLoadingState, (state, action) => { if (state.contents !== undefined) { diff --git a/src/utils/hooks/useBalances.ts b/src/utils/hooks/useBalances.ts index 24609f24..14157200 100644 --- a/src/utils/hooks/useBalances.ts +++ b/src/utils/hooks/useBalances.ts @@ -77,6 +77,7 @@ export const useRGPBalance = () => { library ); const balance = await token.balanceOf(account); + console.log({balance},balance.toString()) setRGPBalance( parseFloat(ethers.utils.formatEther(balance)).toFixed(4) ); diff --git a/src/utils/hooks/useGetFarmData.ts b/src/utils/hooks/useGetFarmData.ts index 8ac8a9be..f9ea7a49 100644 --- a/src/utils/hooks/useGetFarmData.ts +++ b/src/utils/hooks/useGetFarmData.ts @@ -48,6 +48,7 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { }> >([]); const [RGPBalance] = useRGPBalance(); + console.log({RGPBalance},"kkkkkkkkkkkkkkkkkkkkkkk") const dispatch = useDispatch(); const ChainId = useSelector((state) => state.chainId.chainId); @@ -56,6 +57,7 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { const handleUpdateFarms = useCallback( (value) => { + console.log({value}) dispatch(updateFarms({ value })); }, [dispatch] @@ -63,7 +65,9 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { const handleUpdateSpecialPool = useCallback( (value) => { - dispatch(updateSpecialPool({ value })); + console.log({ value }, "value"); + alert(3) + dispatch(updateSpecialPool({value})); }, [dispatch] ); @@ -382,18 +386,19 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { const RGPBallance = await rgp.balanceOf( RGPSPECIALPOOLADDRESSES2[ChainId as number] ); - + console.log({RGPBallance}) const RGPStaked = await specialPool.userInfo(account); console.log("n3kkkkkkkkkkkkkkkkkk") + const RGPStakedValue = ethers.utils.formatUnits(RGPStaked._amountStaked, 18); const RGPUserReward = ethers.utils.formatUnits(RGPStaked._userReward, 18); const availableToken = ethers.utils.formatUnits(RGPBallance, 18); - console.log({RGPStakedValue,RGPUserReward,availableToken,RGPBalance}) + console.log({RGPStakedValue,RGPUserReward,availableToken}) const RGPLiquidity = parseFloat(ethers.utils.formatUnits(RGPBallance)) * rgpPrice; - + alert(123) const yeaRate = await specialPool.YEAR_RATE(); //this is temporal @@ -409,7 +414,7 @@ console.log("n3kkkkkkkkkkkkkkkkkk") ARYValue: ethers.utils.formatUnits(yeaRate), totalLiquidity: RGPLiquidity, // main issue 206432 - tokensStaked: ["RGP", parseFloat(RGPStakedValue).toFixed(4)], + tokenStaked: ["RGP", parseFloat(RGPStakedValue).toFixed(4)], RGPEarned: parseFloat(RGPUserReward).toFixed(4), availableToken:RGPBalance, inflationPerDay: 0, From e26d434f9360e00a7dc407a2416db6242a18f6f1 Mon Sep 17 00:00:00 2001 From: Fakorede Damilola Date: Tue, 1 Nov 2022 02:15:43 +0000 Subject: [PATCH 8/9] changes --- src/pages/FarmingV2/ShowYieldFarmDetails.tsx | 20 +------ src/pages/FarmingV2/index.tsx | 4 +- src/state/newfarm/actions.ts | 3 - src/state/newfarm/reducer.ts | 61 +------------------- src/utils/hooks/useGetFarmData.ts | 27 ++++----- 5 files changed, 19 insertions(+), 96 deletions(-) diff --git a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx index 57303585..5e97195c 100644 --- a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx +++ b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx @@ -142,23 +142,14 @@ const ShowYieldFarmDetails = ({ const [contentid, setContentId] = useState(undefined); const [loading, setLoading] = useState(true); - // const data = useGetFarmData(reload, setReload); - const {loadingState} = useUpdateFarm({reload, setReload, content}); useFetchYieldFarmDetails({content, section, setLoading, loading}); - //const {loadingFarm} = useUpdateNewFarm({reload, setReload, content}); - - // useNewYieldFarmDetails({content, section, setLoading, loading}); - - - const closeModal = () => { GButtonIntialized("close unstaked",content.deposit,"v2") modal2Disclosure.onClose(); }; - // useUpdate(reload, setReload, contentid, setContentId); const [userGasPricePercentage] = useUserGasPricePercentage(); const handleSetReferralField = () => { if (showReferrerField === true && URLReferrerAddress === "") { @@ -176,9 +167,8 @@ const ShowYieldFarmDetails = ({ } }; useEffect(()=>{ - console.log({content}) const checkEnoughApproval = (allowance: any, balance: any) => { - // console.log("checkEnoughApproval",allowance.toString(),balance); + console.log({allowance,balance}) if (allowance && balance) { let approve = parseFloat(allowance) >= parseFloat(depositTokenValue); @@ -596,11 +586,7 @@ useEffect(()=>{ GButtonClicked(`max_button for ${input}`,content.deposit,"v2") setDepositTokenValue(content.availableToken); } else if (input === "unstake") { - setUnstakeToken( - content.deposit === "RGP" - ? content.tokenStaked[1] - : content.tokenStaked[1] - ); + setUnstakeToken(content.tokenStaked[1]); } } catch (e) { console.log( @@ -1273,8 +1259,6 @@ useEffect(()=>{ ); refreshSpecialData() - // dispatch the getTokenStaked action from here when data changes - // callRefreshFarm(confirmations, status); } catch (error:any) { GFarmingFailedTransaction("special pool", "unstake", error.message, "RGP","v2") dispatch( diff --git a/src/pages/FarmingV2/index.tsx b/src/pages/FarmingV2/index.tsx index f607c39a..688fa42f 100644 --- a/src/pages/FarmingV2/index.tsx +++ b/src/pages/FarmingV2/index.tsx @@ -209,7 +209,7 @@ export function Index() { const { account, chainId, library } = useActiveWeb3React(); const dispatch = useDispatch(); const FarmData = useFarms(); - const { farmdata, loadingState } = useGetFarmData(); + const { farmdata, loadingState } = useGetFarmData(refreshSpecialPool); const { LPData, loadingLP } = useGetNewFarms( selected === farmSection.SECOND_NEW_LP ? 2 : 1 ); @@ -223,7 +223,7 @@ export function Index() { const searchSection = useSelector((state:RootState) => state.newFarming); const newSearchSection = useSelector((state:RootState) => state.newFarming); - const { specialPool } = useSelector((state:RootState) => state.newfarm); + const { specialPool } = useSelector((state:RootState) => state.newFarming); console.log({specialPool}) diff --git a/src/state/newfarm/actions.ts b/src/state/newfarm/actions.ts index 982f83a4..0b77a301 100644 --- a/src/state/newfarm/actions.ts +++ b/src/state/newfarm/actions.ts @@ -4,9 +4,6 @@ export const updateFarms = createAction<{ value: any[] }>( "newfarm/updateFarms" ); -export const updateSpecialPool = createAction<{ value: any[] }>( - "newfarm/updateSpecialPool" -); export const updateLoadingState = createAction<{ value: boolean }>( "newfarm/updateLoadingState" diff --git a/src/state/newfarm/reducer.ts b/src/state/newfarm/reducer.ts index b08966da..5d72d0d8 100644 --- a/src/state/newfarm/reducer.ts +++ b/src/state/newfarm/reducer.ts @@ -4,7 +4,6 @@ import { updateAllowance, updateFarms, updateLoadingState, - updateSpecialPool, updateChainId, updateFarmAllowances, updateFarmProductAllowances, @@ -29,27 +28,6 @@ export interface farmDataInterface { | undefined; loading: boolean; chainId: number; - // specialPool: - // | Array<{ - // id: number | string; - // img: string; - // deposit: string; - // earn: string; - // type: string; - // totalLiquidity: number | string; - // tokenStaked: string[]; - // RGPEarned: string; - // availableToken: string; - // ARYValue: number | string; - // inflationPerDay: number | string; - // tokenPrice: number; - // totalVolumePerPool: number; - // farmingFee: number; - // pId:number; - // poolAllowance: string; - // poolVersion:string; - // }> - // | undefined; productFarm: { feature:string, percentageProfitShare:string, @@ -103,29 +81,6 @@ export interface farmStateInterface { const initialState: farmDataInterface = { loading: false, contents: undefined, - // specialPool: [ - // { - // id: "special", - // img: "rgp.svg", - // // deposit: 'RGP', - // deposit: "RGP", - // earn: "RGP", - // type: "RGP", - // ARYValue:0, - // totalLiquidity: "", - // // main issue 206432 - // tokenStaked: ["RGP",""], - // RGPEarned: "", - // availableToken: "", - // inflationPerDay: 0, - // tokenPrice: 0, - // totalVolumePerPool: 0, - // farmingFee: 0, - // pId: 10793, - // poolAllowance: "", - // poolVersion: "2", - // } - // ], chainId: 56, productFarm :[ { @@ -160,21 +115,7 @@ export default createReducer(initialState, (builder) => }; } }) - - - .addCase(updateSpecialPool, (state, action) => { - console.log({action},action.payload) - const farms = action.payload.value; - console.log({farms}) - if (farms !== undefined) { - return { - ...state, - specialPool: farms, - loading: false, - }; - } - }) - + .addCase(updateChainId, (state, action) => { const chainId = action.payload.value; diff --git a/src/utils/hooks/useGetFarmData.ts b/src/utils/hooks/useGetFarmData.ts index f9ea7a49..9929fbfa 100644 --- a/src/utils/hooks/useGetFarmData.ts +++ b/src/utils/hooks/useGetFarmData.ts @@ -22,8 +22,9 @@ import { updateChainId, updateFarms, updateLoadingState, - updateSpecialPool, + // updateSpecialPool, } from "../../state/newfarm/actions"; +import { updateSpecialPool } from "../../state/newFarming/action"; import { RootState } from "../../state"; import { SupportedChainId } from "../../constants/chains"; @@ -47,8 +48,6 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { address: string; }> >([]); - const [RGPBalance] = useRGPBalance(); - console.log({RGPBalance},"kkkkkkkkkkkkkkkkkkkkkkk") const dispatch = useDispatch(); const ChainId = useSelector((state) => state.chainId.chainId); @@ -57,7 +56,6 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { const handleUpdateFarms = useCallback( (value) => { - console.log({value}) dispatch(updateFarms({ value })); }, [dispatch] @@ -65,8 +63,6 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { const handleUpdateSpecialPool = useCallback( (value) => { - console.log({ value }, "value"); - alert(3) dispatch(updateSpecialPool({value})); }, [dispatch] @@ -383,22 +379,27 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { ); console.log("here....") const rgp = await getERC20Token(RGPADDRESSES[ChainId as number], lib); + + const balance = await rgp.balanceOf(account); + console.log({balance},balance.toString()) + const bal= parseFloat(ethers.utils.formatEther(balance)).toFixed(4) const RGPBallance = await rgp.balanceOf( RGPSPECIALPOOLADDRESSES2[ChainId as number] ); console.log({RGPBallance}) const RGPStaked = await specialPool.userInfo(account); -console.log("n3kkkkkkkkkkkkkkkkkk") const RGPStakedValue = ethers.utils.formatUnits(RGPStaked._amountStaked, 18); const RGPUserReward = ethers.utils.formatUnits(RGPStaked._userReward, 18); - const availableToken = ethers.utils.formatUnits(RGPBallance, 18); - - console.log({RGPStakedValue,RGPUserReward,availableToken}) + const allowance = await rgp.allowance( + account, + RGPSPECIALPOOLADDRESSES2[ChainId as number] + ); + const allowanceValue = ethers.utils.formatUnits(allowance, 18); + console.log({allowanceValue}) const RGPLiquidity = parseFloat(ethers.utils.formatUnits(RGPBallance)) * rgpPrice; - alert(123) const yeaRate = await specialPool.YEAR_RATE(); //this is temporal @@ -416,13 +417,13 @@ console.log("n3kkkkkkkkkkkkkkkkkk") // main issue 206432 tokenStaked: ["RGP", parseFloat(RGPStakedValue).toFixed(4)], RGPEarned: parseFloat(RGPUserReward).toFixed(4), - availableToken:RGPBalance, + availableToken:bal, inflationPerDay: 0, tokenPrice: 0, totalVolumePerPool: 0, farmingFee: 0, pId: 10793, - poolAllowance: "", + poolAllowance: allowanceValue, poolVersion: "2", }, ]); From 192ca77355f37f744a899acf2c823887f68458ee Mon Sep 17 00:00:00 2001 From: Fakorede Damilola Date: Wed, 2 Nov 2022 09:15:22 +0100 Subject: [PATCH 9/9] changes --- .../TransactionStateModal.tsx | 2 +- src/pages/FarmingV2/ShowYieldFarmDetails.tsx | 24 +++++++------------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/components/Modals/TransactionsModal/TransactionStateModal.tsx b/src/components/Modals/TransactionsModal/TransactionStateModal.tsx index f89d18b7..2cd94f4d 100644 --- a/src/components/Modals/TransactionsModal/TransactionStateModal.tsx +++ b/src/components/Modals/TransactionsModal/TransactionStateModal.tsx @@ -83,7 +83,7 @@ const TransactionStateModal: React.FC = () => { {modalDetails?.trxState === TrxState.TransactionSuccessful ? - "Transaction Succesful" : + "Transaction Successful" : modalDetails?.trxState === TrxState.WaitingForConfirmation ? modalDetails?.text ?? " Waiting for Confirmation" : modalDetails?.trxState === TrxState.TransactionFailed ? diff --git a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx index 5e97195c..64959715 100644 --- a/src/pages/FarmingV2/ShowYieldFarmDetails.tsx +++ b/src/pages/FarmingV2/ShowYieldFarmDetails.tsx @@ -365,7 +365,6 @@ useEffect(()=>{ }; const checkUser = async (val :string) => { - alert(1) if (content.deposit === "RGP" && Number(content.id) === 1) { await RGPSpecialPoolV1Approval(); setApproveValueForOtherToken(true); @@ -1131,7 +1130,6 @@ useEffect(()=>{ await fetchTransactionData(data); GFarmingSuccessTransaction("special pool", "stake", "RGP","v2") //122 - refreshSpecialData() dispatch( setOpenModal({ @@ -1139,6 +1137,8 @@ useEffect(()=>{ message: `Successfully staked ${depositTokenValue} RGP `, }) ); + + // refreshSpecialData() // callRefreshFarm(confirmations, status); setReload(true); } catch (error:any) { @@ -1190,7 +1190,6 @@ useEffect(()=>{ : ethers.utils.parseUnits(format3, 9).toString(), } ); - const { confirmations, status } = await fetchTransactionData(data); GFarmingSuccessTransaction("special pool", "unstake", "RGP","v1") dispatch( setOpenModal({ @@ -1199,6 +1198,7 @@ useEffect(()=>{ }) ); refreshSpecialData() + // setReload(true) // dispatch the getTokenStaked action from here when data changes // callRefreshFarm(confirmations, status); } catch (e:any) { @@ -1221,7 +1221,6 @@ useEffect(()=>{ RGPSPECIALPOOLADDRESSES2[chainId as number], library ); - alert(1) const { format1, format2, format3 } = await calculateGas( userGasPricePercentage, library, @@ -1401,16 +1400,16 @@ useEffect(()=>{