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/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..1c46d24d 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, @@ -98,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; @@ -239,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 { @@ -382,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); @@ -622,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); @@ -667,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); @@ -685,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( @@ -876,7 +868,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 @@ -1102,7 +1094,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) { @@ -1595,11 +1587,11 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section > - {parseFloat(content.tokensStaked[1]).toFixed(4)} + {parseFloat(content.tokenStaked[1]).toFixed(4)} { - harvestTokens( - content.deposit === "RGP" ? content.pId : content.id + harvestTokens(content.id ); }} className={"harvest"} @@ -1839,7 +1830,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section label={ content?.type !== "RGP" ? content?.tokenStaked[1] - : content.tokensStaked[1] + : content.tokenStaked[1] } bg='gray.300' color='black' @@ -1847,7 +1838,7 @@ const ShowNewFarm = ({content, wallet, URLReferrerAddress, LoadingState, section {parseFloat( content.type !== "RGP" ? content?.tokenStaked[1] - : content.tokensStaked[1] + : content.tokenStaked[1] ).toFixed(4)} @@ -1874,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' @@ -1960,9 +1951,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"} > @@ -1999,9 +1988,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"} > @@ -2517,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 58a5563a..674a6962 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"; @@ -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 ce865f25..64959715 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"; @@ -87,7 +86,7 @@ const ShowYieldFarmDetails = ({ img: string; ARYValue: string; lpSymbol: string; - tokensStaked: string[]; + tokenStaked: string[]; availableToken: string; deposit: string; poolAllowance: any; @@ -143,24 +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 === "") { @@ -179,7 +168,7 @@ const ShowYieldFarmDetails = ({ }; useEffect(()=>{ 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); @@ -224,7 +213,6 @@ useEffect(()=>{ account, RGPSPECIALPOOLADDRESSES2[chainId as number] ); - console.log({rgpApproval}) return !(rgpApproval.toString() <= 0); } }; @@ -235,7 +223,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) === 13) { + } else if (content.deposit === "RGP" && content.id=== "special") { const specialPoolV2Approval = await specialPoolV2Allowance(rgp); @@ -243,7 +231,6 @@ useEffect(()=>{ } else { const pool = await smartSwapLPTokenPoolTwo(content.address, library); const approvalForRGPBNB = await poolAllowance(pool); - console.log({approvalForRGPBNB,rgpApproval}) changeApprovalButton(approvalForRGPBNB, rgpApproval); } }; @@ -382,7 +369,7 @@ useEffect(()=>{ 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); @@ -535,7 +522,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); @@ -581,7 +568,7 @@ useEffect(()=>{ parseFloat(unstakeToken) > parseFloat( content.deposit === "RGP" - ? content.tokensStaked[1] + ? content.tokenStaked[1] : content.tokenStaked[1] ) ) { @@ -598,11 +585,7 @@ useEffect(()=>{ 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( @@ -626,7 +609,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" && content.id === "special") { await RGPUnstakeV2(val); } else { tokensWithdrawal(content.id,val); @@ -789,7 +772,7 @@ useEffect(()=>{ }) ); } - } else if (id === 10793) { + } else if (id === "special") { const specialPool = await RGPSpecialPool2( RGPSPECIALPOOLADDRESSES2[chainId as number], library @@ -1046,7 +1029,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); @@ -1147,7 +1130,6 @@ useEffect(()=>{ await fetchTransactionData(data); GFarmingSuccessTransaction("special pool", "stake", "RGP","v2") //122 - refreshSpecialData() dispatch( setOpenModal({ @@ -1155,6 +1137,8 @@ useEffect(()=>{ message: `Successfully staked ${depositTokenValue} RGP `, }) ); + + // refreshSpecialData() // callRefreshFarm(confirmations, status); setReload(true); } catch (error:any) { @@ -1206,7 +1190,6 @@ useEffect(()=>{ : ethers.utils.parseUnits(format3, 9).toString(), } ); - const { confirmations, status } = await fetchTransactionData(data); GFarmingSuccessTransaction("special pool", "unstake", "RGP","v1") dispatch( setOpenModal({ @@ -1215,6 +1198,7 @@ useEffect(()=>{ }) ); refreshSpecialData() + // setReload(true) // dispatch the getTokenStaked action from here when data changes // callRefreshFarm(confirmations, status); } catch (e:any) { @@ -1274,8 +1258,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( @@ -1418,16 +1400,16 @@ useEffect(()=>{ */} - {/* */} - {/* */} - {/* */} - - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/* 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}*/} - {/* */} - {/* */} - {/* */} - {/* */} - {/* */} - {/**/} - + { diff --git a/src/pages/Swap/AutoTime.tsx b/src/pages/Swap/AutoTime.tsx index 66a28a0f..97f014c4 100644 --- a/src/pages/Swap/AutoTime.tsx +++ b/src/pages/Swap/AutoTime.tsx @@ -559,7 +559,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 55365c4c..71e9aedd 100644 --- a/src/pages/Swap/InstantSwap.tsx +++ b/src/pages/Swap/InstantSwap.tsx @@ -566,7 +566,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/pages/Swap/components/sendToken/index.tsx b/src/pages/Swap/components/sendToken/index.tsx index 0784873d..73ec0f6a 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/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/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/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/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..e1499610 100644 --- a/src/state/newFarming/action.ts +++ b/src/state/newFarming/action.ts @@ -16,8 +16,16 @@ export const updateNewFilterResult = createAction<{ farmData: [] | undefined; }>("newFarming/updateNewFilterResult"); +export const updateSelectedField = createAction<{ value: any }>( + "farming/updateSelectedField" +); + 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 fdc46198..c8d426b1 100644 --- a/src/state/newFarming/hooks.ts +++ b/src/state/newFarming/hooks.ts @@ -6,10 +6,12 @@ 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"; +import { RootState } from ".."; interface FilterFarms { newestToOldest: boolean; @@ -20,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 5efb299b..d689c88c 100644 --- a/src/state/newFarming/reducer.ts +++ b/src/state/newFarming/reducer.ts @@ -7,9 +7,18 @@ import { updateNewSearchResult, updateProductFarmDetails, updateSearchResult, + updateSelectedField, + updateSpecialPool, updateYieldFarmDetails } from "./action"; +enum farmSection { + LIQUIDITY, + STAKING, + PRODUCT_FARM, + NEW_LP, + SECOND_NEW_LP, +} export interface FarmingSearchState { searchResult: [] | undefined; filterResult: [] | undefined; @@ -32,20 +41,44 @@ 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; + 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, + 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 +87,44 @@ const initialState: FarmingSearchState = { filterResult: undefined, newFilterResult: undefined, content: undefined, - productFarm: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", + 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 +168,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) { @@ -108,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/actions.ts b/src/state/newfarm/actions.ts index 27f57e40..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" @@ -16,6 +13,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..476234f6 100644 --- a/src/state/newfarm/hooks.ts +++ b/src/state/newfarm/hooks.ts @@ -1,11 +1,10 @@ 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"; import { updateAllowance } from "./actions"; import { useWeb3React } from "@web3-react/core"; -import { useGetFarmData } from "../../utils/hooks/useGetFarmData"; import { id } from "ethers/lib/utils"; import { MasterChefV2Contract, @@ -25,18 +24,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 +55,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 +212,6 @@ export const useUpdateFarm = ({ console.log(err); } }; - const calculateLiquidityAndApy = async (reward: number | undefined) => { try { const masterchef = await MasterChefV2Contract( @@ -349,7 +356,7 @@ interface FetchYieldFarmDetails { totalLiquidity: number; APY: number; address: string; - }; + } | any; section: string; loading: boolean; setLoading: React.Dispatch>; @@ -362,7 +369,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 +445,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 +607,7 @@ export const useFetchYieldFarmDetails = ({ section === "search" ? searchSection.newSearchResult !== undefined ? [...searchSection.newSearchResult] - : [...searchSection.searchResult] + : [...searchSection?.searchResult] : section === "filter" ? searchSection.newFilterResult !== undefined ? [...searchSection.newFilterResult] @@ -626,7 +629,6 @@ export const useFetchYieldFarmDetails = ({ newArray[index] = updatedFarm; - console.log("updatedd", newArray); handleUpdateFarms(newArray); @@ -668,7 +670,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 +702,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..5d72d0d8 100644 --- a/src/state/newfarm/reducer.ts +++ b/src/state/newfarm/reducer.ts @@ -1,12 +1,12 @@ 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 { @@ -28,34 +28,84 @@ 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; + 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; + tokenStaked: 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) => { + console.log(action.payload) const farms = action.payload.value; if (farms !== undefined) { return { @@ -65,18 +115,7 @@ 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; @@ -85,17 +124,22 @@ 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; - // if (farms !== undefined) { - // return { - // ...state, - // specialPool: farms, - // loading: false, - // }; - // } - // }) .addCase(updateLoadingState, (state, action) => { if (state.contents !== undefined) { 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/useAccountHistory.ts b/src/utils/hooks/useAccountHistory.ts index d245262b..cde819e4 100644 --- a/src/utils/hooks/useAccountHistory.ts +++ b/src/utils/hooks/useAccountHistory.ts @@ -109,7 +109,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/useBalances.ts b/src/utils/hooks/useBalances.ts index 77809e39..8a1b1da7 100644 --- a/src/utils/hooks/useBalances.ts +++ b/src/utils/hooks/useBalances.ts @@ -72,19 +72,27 @@ export const useRGPBalance = () => { useEffect(() => { const getBalance = async () => { if (account) { - try { + // try { const token = await getERC20Token( RGPADDRESSES[chainId as number], library ); const balance = await token.balanceOf(account); + console.log({balance},balance.toString()) setRGPBalance( parseFloat(ethers.utils.formatEther(balance)).toFixed(4) ); +<<<<<<< HEAD + // } catch (err) { + // setRGPBalance(""); + // console.log(err); + // } +======= } catch (err) { setRGPBalance(""); console.log(err,"iruruuru"); } +>>>>>>> develop } }; diff --git a/src/utils/hooks/useGetFarmData.ts b/src/utils/hooks/useGetFarmData.ts index 998f0116..9929fbfa 100644 --- a/src/utils/hooks/useGetFarmData.ts +++ b/src/utils/hooks/useGetFarmData.ts @@ -22,14 +22,17 @@ 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"; +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<{ @@ -60,7 +63,7 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { const handleUpdateSpecialPool = useCallback( (value) => { - dispatch(updateSpecialPool({ value })); + dispatch(updateSpecialPool({value})); }, [dispatch] ); @@ -329,105 +332,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 = []; @@ -473,21 +377,36 @@ 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 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); + const RGPStakedValue = ethers.utils.formatUnits(RGPStaked._amountStaked, 18); + const RGPUserReward = ethers.utils.formatUnits(RGPStaked._userReward, 18); + 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; const yeaRate = await specialPool.YEAR_RATE(); - //this is temporal handleUpdateSpecialPool([ { - id: "0", + id: "special", img: "rgp.svg", // deposit: 'RGP', deposit: "RGP", @@ -495,15 +414,16 @@ export const useGetFarmData = (reload?: boolean, setReload?: any) => { type: "RGP", ARYValue: ethers.utils.formatUnits(yeaRate), totalLiquidity: RGPLiquidity, - tokensStaked: ["RGP", "0"], - RGPEarned: "0", - availableToken: "", + // main issue 206432 + tokenStaked: ["RGP", parseFloat(RGPStakedValue).toFixed(4)], + RGPEarned: parseFloat(RGPUserReward).toFixed(4), + availableToken:bal, inflationPerDay: 0, tokenPrice: 0, totalVolumePerPool: 0, farmingFee: 0, pId: 10793, - poolAllowance: "", + poolAllowance: allowanceValue, poolVersion: "2", }, ]); 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/hooks/useMarketHistory.ts b/src/utils/hooks/useMarketHistory.ts index 1b2f56cf..13462d63 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 81d7023c..1cf335bd 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; diff --git a/src/utils/utilsFunctions.ts b/src/utils/utilsFunctions.ts index cc92144b..16808561 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";