diff --git a/package.json b/package.json index 08df7824a1..4ab9b5de78 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@pushprotocol/ledgerlive": "latest", "@pushprotocol/restapi": "0.0.1-alpha.50", "@pushprotocol/socket": "latest", - "@pushprotocol/uiweb": "0.0.1-alpha.22", + "@pushprotocol/uiweb": "0.0.1-alpha.25", "@reduxjs/toolkit": "^1.7.1", "@testing-library/dom": "^9.0.1", "@testing-library/jest-dom": "^4.2.4", diff --git a/src/App.tsx b/src/App.tsx index d72546ebab..6bbc62d87e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,6 +10,7 @@ import { DarkModeSwitch } from 'react-toggle-dark-mode'; import styled, { createGlobalStyle, ThemeProvider } from 'styled-components'; import ReactGA from 'react-ga'; import * as dotenv from 'dotenv'; +import { PushAPI } from '@pushprotocol/restapi'; // Internal Compoonents import InitState from 'components/InitState'; @@ -31,6 +32,7 @@ import { resetChannelCreationSlice } from 'redux/slices/channelCreationSlice'; import { resetAdminSlice } from 'redux/slices/adminSlice'; import Navigation from 'structure/Navigation'; import { ErrorContext } from './contexts/ErrorContext' +import { resetUserSlice, setUserPushSDKInstance } from 'redux/slices/userSlice'; // Internal Configs import { appConfig } from 'config'; @@ -79,6 +81,9 @@ export default function App() { const [currentTime, setcurrentTime] = React.useState(0); const {authError, setAuthError } = useContext(ErrorContext); const updateOnboardTheme = useUpdateTheme(); + const { userPushSDKInstance } = useSelector((state: any) => { + return state.user; + }); const { run, stepIndex, tutorialContinous } = useSelector((state: any) => state.userJourney); // const location = useLocation(); @@ -102,8 +107,29 @@ export default function App() { dispatch(resetCanSendSlice()); dispatch(resetChannelCreationSlice()); dispatch(resetAdminSlice()); + dispatch(resetUserSlice()); }, [account]); + useEffect(() => { + const librarySigner = provider?.getSigner(account); + if(!account || !librarySigner || !appConfig?.appEnv || userPushSDKInstance) return; + + const initializePushSDK = async () => { + try { + const userInstance = await PushAPI.initialize(librarySigner, { + env: appConfig.appEnv, // defaults to staging + account: account + }); + + dispatch(setUserPushSDKInstance(userInstance)); + } catch (error) { + // Handle initialization error + } + }; + + initializePushSDK(); +}, [account, provider]); + // console.log(isActive, chainId, account); // handle logic to reconnect in response to certain events from the provider const { allowedChain } = useInactiveListener(); diff --git a/src/assets/checkmark.svg b/src/assets/checkmark.svg new file mode 100644 index 0000000000..73535c7bf6 --- /dev/null +++ b/src/assets/checkmark.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/components/StepsTransactionModal.tsx b/src/components/StepsTransactionModal.tsx new file mode 100644 index 0000000000..bed6c8f948 --- /dev/null +++ b/src/components/StepsTransactionModal.tsx @@ -0,0 +1,180 @@ +import React from 'react'; +import { ReactComponent as Close } from 'assets/chat/group-chat/close.svg'; +import { ButtonV2, H2V2, ItemHV2, ItemVV2, SpanV2 } from './reusables/SharedStylingV2'; +import styled from 'styled-components'; +import Globals from 'config/Globals'; +import { LOADER_SPINNER_TYPE } from './reusables/loaders/LoaderSpinner'; +import Spinner from './reusables/spinners/SpinnerUnit'; +import { ReactComponent as CheckMark } from 'assets/checkmark.svg'; + +const StepsTransactionModal = ({ onClose, InnerComponentProps }) => { + + const { + currentTransactionNo, + totalTransactionNo, + transactionSteps, + transactionText, + setCurrentTransactionNo, + setTotalTransactionNo, + setTransactionSteps, + claimRewards, + unstakeTokensPaginated, + } = InnerComponentProps; + + const handleClose = () => { + setTransactionSteps(0); + onClose(); + } + + const retryClaimingRewards = async () => { + setTransactionSteps(0); + setTotalTransactionNo(0); + setCurrentTransactionNo(0); + if(transactionText?.includes('Unstaking')){ + unstakeTokensPaginated(); + }else{ + claimRewards(); + } + } + + return ( + + + {totalTransactionNo ? ( + <> + + handleClose()} + style={{ cursor: 'pointer' }} + /> + + + + {transactionSteps === 0 && ( + <> + + + + + + + Please sign transaction {" "} + {currentTransactionNo}/{totalTransactionNo} + + + Processing your request + + + + + {transactionText} + + + + + Confirm the request in your wallet + + + + + )} + + {transactionSteps === 1 && ( + + + + + Transaction Error + + + User denied the transaction signature. + + + + + Retry + + + )} + + {transactionSteps === 2 && ( + + + + + + + + Transactions Successful + + + You have claimed all the rewards. + + + + + + + Close + + + + + )} + + ) : ( + + + )} + + + + + + + + + + + + ); +}; + +export default StepsTransactionModal; + +const Container = styled(ItemVV2)` + + min-width:493px; + padding:32px 24px; + + +` + +const FilledButton = styled(ButtonV2)` + min-width:200px; + background: #D53A94; + border: 1px solid #D53A94; + border-radius: 8px; + padding: 12px; + font-size: 16px; + line-height: 141%; + letter-spacing: -0.03em; + color: #FFFFFF; + cursor:pointer; + & > div{ + display:block; + } + + @media(max-width:600px){ + font-size: 14px; + } + +`; \ No newline at end of file diff --git a/src/components/chat/w2wChat/groupChat/createGroup/CreateGroupModalContent.tsx b/src/components/chat/w2wChat/groupChat/createGroup/CreateGroupModalContent.tsx index ef71fe305e..275f61b838 100644 --- a/src/components/chat/w2wChat/groupChat/createGroup/CreateGroupModalContent.tsx +++ b/src/components/chat/w2wChat/groupChat/createGroup/CreateGroupModalContent.tsx @@ -24,6 +24,9 @@ import { fetchInbox } from 'helpers/w2w/user'; import { profilePicture } from 'config/W2WConfig'; import { useAccount, useDeviceWidthCheck } from 'hooks'; import { device } from 'config/Globals'; +import { CreateGroupModal } from "@pushprotocol/uiweb"; +import { ChatUIProvider } from '@pushprotocol/uiweb'; + export const CreateGroupModalContent = ({ onClose, onConfirm: createGroup, toastObject }: ModalInnerComponentType) => { const [createGroupState, setCreateGroupState] = React.useState(1); @@ -40,6 +43,7 @@ export const CreateGroupModalContent = ({ onClose, onConfirm: createGroup, toast const createGroupToast = useToast(); const isMobile = useDeviceWidthCheck(600); + const handlePrevious = () => { setCreateGroupState(1); }; @@ -133,34 +137,8 @@ export const CreateGroupModalContent = ({ onClose, onConfirm: createGroup, toast }; return ( - - - {createGroupState == 1 && ( - - )} - {createGroupState == 2 && ( - - )} + + handleClose()} /> ); diff --git a/src/components/dropdowns/ManageNotifSettingDropdown.tsx b/src/components/dropdowns/ManageNotifSettingDropdown.tsx index 00348ececb..63b1eb8463 100644 --- a/src/components/dropdowns/ManageNotifSettingDropdown.tsx +++ b/src/components/dropdowns/ManageNotifSettingDropdown.tsx @@ -3,7 +3,7 @@ import React, { useContext, useMemo, useState } from "react"; // External Packages import styled, { css, useTheme } from "styled-components"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; // Internal Components import { DropdownBtnHandler } from "./DropdownBtnHandler"; @@ -107,7 +107,9 @@ const ManageNotifSettingDropdown: React.FC = (o } = options; const [isOpen, setIsOpen] = useState(false); const { chainId } = useAccount(); - const { userPushSDKInstance } = useContext(AppContext); + const { userPushSDKInstance } = useSelector((state: any) => { + return state.user; + }); const dispatch = useDispatch(); const channelSetting = useMemo(() => { diff --git a/src/components/dropdowns/OptinNotifSettingDropdown.tsx b/src/components/dropdowns/OptinNotifSettingDropdown.tsx index e145c1d136..0a5b26ec3d 100644 --- a/src/components/dropdowns/OptinNotifSettingDropdown.tsx +++ b/src/components/dropdowns/OptinNotifSettingDropdown.tsx @@ -5,7 +5,7 @@ import React, { useContext, useMemo, useState } from "react"; import Switch from 'react-switch'; import Slider from 'react-input-slider'; import styled, { css, useTheme } from "styled-components"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; // Internal Components import { DropdownBtnHandler } from "./DropdownBtnHandler"; @@ -136,7 +136,9 @@ const OptinNotifSettingDropdown: React.FC = (opt const { children, channelDetail, setLoading, onSuccessOptin } = options; const { chainId } = useAccount(); - const { userPushSDKInstance } = useContext(AppContext); + const { userPushSDKInstance } = useSelector((state: any) => { + return state.user; + }); const [isOpen, setIsOpen] = useState(false); const dispatch = useDispatch(); diff --git a/src/components/dropdowns/UpdateNotifSettingDropdown.tsx b/src/components/dropdowns/UpdateNotifSettingDropdown.tsx index 18272d4f72..68f6e2847f 100644 --- a/src/components/dropdowns/UpdateNotifSettingDropdown.tsx +++ b/src/components/dropdowns/UpdateNotifSettingDropdown.tsx @@ -5,7 +5,7 @@ import React, { useContext, useState } from "react"; import Switch from 'react-switch'; import Slider from 'react-input-slider'; import styled, { css, useTheme } from "styled-components"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; // Internal Components import { DropdownBtnHandler } from "./DropdownBtnHandler"; @@ -145,7 +145,9 @@ const UpdateNotifSettingDropdown: React.FC = ({ const [isOpen, setIsOpen] = useState(false); const { chainId } = useAccount(); - const { userPushSDKInstance } = useContext(AppContext); + const { userPushSDKInstance } = useSelector((state: any) => { + return state.user; + }); const dispatch = useDispatch(); const onCoreNetwork = chainId === appConfig.coreContractChain; diff --git a/src/components/yield/YieldPushFeeV3.tsx b/src/components/yield/YieldPushFeeV3.tsx index b36803e15e..93ad256f06 100644 --- a/src/components/yield/YieldPushFeeV3.tsx +++ b/src/components/yield/YieldPushFeeV3.tsx @@ -24,12 +24,13 @@ import { useAccount, useDeviceWidthCheck } from 'hooks'; import Tooltip from 'components/reusables/tooltip/Tooltip'; import { device } from 'config/Globals'; import { useClickAway } from 'react-use'; +import StepsTransactionModal from 'components/StepsTransactionModal'; const YieldPushFeeV3 = ({ userDataPush, getUserDataPush, PUSHPoolstats, - getPUSHPoolStats + getPUSHPoolStats, }) => { const { account, provider } = useAccount(); @@ -39,27 +40,21 @@ const YieldPushFeeV3 = ({ const [unstakeErrorMessage, setUnstakeErrorMessage] = useState(null); const [withdrawErrorMessage, setWithdrawErrorMessage] = useState(null); + const [currentTransactionNo, setCurrentTransactionNo] = useState(0); + const [totalTransactionNo, setTotalTransactionNo] = useState(0); + const [transactionSteps, setTransactionSteps] = useState(0); + + const [transactionText, setTransactionText] = useState(''); + const pushFeeToast = useToast(); const theme = useTheme(); - const withdrawAmountTokenFarmAutomatic = async () => { - if (txInProgressWithdraw) { - return; - } - setTxInProgressWithdraw(true); - const unstakeAmount = formatTokens(userDataPush?.userStaked); - - if (unstakeAmount == 0) { - setUnstakeErrorMessage("Nothing to unstake, You need to stake first"); - setTxInProgressWithdraw(false); - return - } + // Checking if the address is Delegated or not + const checkDelegateAddress = async (pushCoreV2) => { var signer = provider.getSigner(account); - let pushToken = new ethers.Contract(addresses.pushToken, abis.pushToken, signer); - let pushCoreV2 = new ethers.Contract(addresses.pushCoreV2, abis.pushCoreV2, signer); const isAddressDelegated = await pushToken.holderDelegation( account, @@ -86,6 +81,7 @@ const YieldPushFeeV3 = ({ /> ), }); + return true; } catch (error) { console.log("Error in delegating", error) pushFeeToast.showMessageToast({ @@ -95,65 +91,31 @@ const YieldPushFeeV3 = ({ getToastIcon: (size) => , }); setTxInProgressWithdraw(false); - return; + return false; } + } else { + return true; } - const tx = pushCoreV2.unstake(); - tx.then(async (tx) => { - pushFeeToast.showLoaderToast({ loaderMessage: 'Unstaking! Waiting for Confirmation...' }); + } - try { - await provider.waitForTransaction(tx.hash); - pushFeeToast.showMessageToast({ - toastTitle: 'Success', - toastMessage: 'Transaction Completed!', - toastType: 'SUCCESS', - getToastIcon: (size) => ( - - ), - }); + const getLastClaimedBlock = async (pushCoreV2) => { + const userFeesInfo = await pushCoreV2.userFeesInfo(account); + const lastClaimedBlock = userFeesInfo.lastClaimedBlock; - getPUSHPoolStats(); - getUserDataPush(); - setTxInProgressWithdraw(false); + if (lastClaimedBlock.toNumber() !== 0) { + const genesisEpoch = await pushCoreV2.genesisEpoch(); + const epochDuration = await pushCoreV2.epochDuration(); - } catch (e) { - console.log("Error", e) - pushFeeToast.showMessageToast({ - toastTitle: 'Error', - toastMessage: `Transaction Failed! (" +${e.name}+ ")`, - toastType: 'ERROR', - getToastIcon: (size) => , - }); + const epochNumberGap = (lastClaimedBlock - genesisEpoch) / epochDuration; - setTxInProgressWithdraw(false); - } - }).catch((err) => { - console.log("Error: ", err) - const unstakeErrorMessage = err.reason.includes("PushCoreV2::unstake:"); - const harvestErrorMessage = err.reason.includes("PushCoreV2::harvestPaginated:"); - if(unstakeErrorMessage || harvestErrorMessage){ - setUnstakeErrorMessage("PUSH cannot be unstaked until current epoch is over."); - } else { - let errorMessage = err.reason.slice(err.reason.indexOf('::') + 1); - errorMessage = errorMessage.replace('unstake:', ''); - pushFeeToast.showMessageToast({ - toastTitle: 'Error', - toastMessage: `${errorMessage}`, - toastType: 'ERROR', - getToastIcon: (size) => , - }); - } - setTxInProgressWithdraw(false); - }); - }; + return epochNumberGap; + + } + } - const massClaimRewardsTokensAll = async () => { + const claimRewards = async () => { if (txInProgressClaimRewards) { return; } @@ -168,58 +130,158 @@ const YieldPushFeeV3 = ({ } var signer = provider.getSigner(account); - - let pushToken = new ethers.Contract(addresses.pushToken, abis.pushToken, signer); let pushCoreV2 = new ethers.Contract(addresses.pushCoreV2, abis.pushCoreV2, signer); + + const currentEpoch = PUSHPoolstats?.currentEpochNumber; + const batchSize = 14; + + const isAddressDelegate = await checkDelegateAddress(pushCoreV2); + setTxInProgressClaimRewards(false); + if (!isAddressDelegate) { + return; + } - const isAddressDelegated = await pushToken.holderDelegation( - account, - pushCoreV2.address - ) + let _tillEpoch = 1; + _tillEpoch = await getLastClaimedBlock(pushCoreV2); - //First we will delegate the pushCoreV2 address then we will proceed further - if (!isAddressDelegated) { - try { - const tx = await pushToken.setHolderDelegation( - pushCoreV2.address, - 'true' - ) - pushFeeToast.showLoaderToast({ loaderMessage: 'Delegating!!Waiting for Confirmation...' }); - await provider.waitForTransaction(tx.hash); - pushFeeToast.showMessageToast({ - toastTitle: 'Success', - toastMessage: 'Transaction Completed!', - toastType: 'SUCCESS', - getToastIcon: (size) => ( - - ), - }); - } catch (error) { + openTransactionModal(); - pushFeeToast.showMessageToast({ - toastTitle: 'Error', - toastMessage: `Transaction failed`, - toastType: 'ERROR', - getToastIcon: (size) => , - }); + let totalTransactionNumber = 0; + if (currentEpoch - _tillEpoch < batchSize) { + totalTransactionNumber = Math.ceil((currentEpoch - _tillEpoch) / batchSize); + } else { + totalTransactionNumber = Math.floor((currentEpoch - _tillEpoch) / batchSize); + } + + setTotalTransactionNo(totalTransactionNumber); + + console.log("Total transaction number", totalTransactionNumber, _tillEpoch, currentEpoch); + if (totalTransactionNumber == 0) { + return; + } + + // Making a single function for claiming rewards Modal + await RewardsPaginated(totalTransactionNumber, _tillEpoch, pushCoreV2, batchSize); + + getUserDataPush(); + setTransactionSteps(2); + setCurrentTransactionNo(0); + + }; + + const RewardsPaginated = async (totalTransactionNumber, _tillEpoch, pushCoreV2, batchSize) => { + + const currentEpoch = PUSHPoolstats?.currentEpochNumber; + + let transactionNumber = 0; + for (let i = 0; i < totalTransactionNumber; i++) { + + let lastEpoch = _tillEpoch; + _tillEpoch += batchSize; + + let temp = Math.min(_tillEpoch, currentEpoch - 1); + + setTransactionText(`Claiming the rewards from Epoch ${lastEpoch} to ${temp} `); + + const tx = pushCoreV2.harvestPaginated(temp, { + gasLimit: 910000 + }); + + await tx.then(async (tx) => { + + try { + pushFeeToast.showLoaderToast({ loaderMessage: 'Waiting for confirmation' }); + await provider.waitForTransaction(tx.hash); + + pushFeeToast.showMessageToast({ + toastTitle: 'Success', + toastMessage: 'Transaction Completed!', + toastType: 'SUCCESS', + getToastIcon: (size) => ( + + ), + }); + + transactionNumber++; + setCurrentTransactionNo(transactionNumber); + + } catch (error) { + console.log("Error in the transaction", tx); + return; + } + + + }).catch((error) => { + console.log("Error in claiming the reward", error); + setTransactionText(''); setTxInProgressWithdraw(false); - return; - } + getUserDataPush(); + setTransactionSteps(1); + setCurrentTransactionNo(0); + throw error; + }) + + } + } + const unstakeTokensPaginated = async () => { + if (txInProgressWithdraw) { + return; + } + + setTxInProgressWithdraw(true); + const unstakeAmount = formatTokens(userDataPush?.userStaked); + + if (unstakeAmount == 0) { + setUnstakeErrorMessage("Nothing to unstake, You need to stake first"); + setTxInProgressWithdraw(false); + return + } + + var signer = provider.getSigner(account); + let pushCoreV2 = new ethers.Contract(addresses.pushCoreV2, abis.pushCoreV2, signer); + + // Checking if the address is delegated or not + const isAddressDelegate = await checkDelegateAddress(pushCoreV2); + + console.log("Is Address delegate", isAddressDelegate); + setTxInProgressClaimRewards(false); + if (!isAddressDelegate) { + return; } - const tx = pushCoreV2.harvestAll(); + const currentEpoch = PUSHPoolstats?.currentEpochNumber; + const batchSize = 14; + + let _tillEpoch = 0; + _tillEpoch = await getLastClaimedBlock(pushCoreV2); + + console.log("Last Claimed Block", _tillEpoch, currentEpoch); + // Modal for displaying transactions + openTransactionModal(); + + const totalTransactionNumber = Math.ceil((currentEpoch - _tillEpoch) / batchSize); + setTotalTransactionNo(totalTransactionNumber); + + console.log("Totlal transaction Number", totalTransactionNumber, _tillEpoch) + + if (totalTransactionNumber > 1) { + await RewardsPaginated(totalTransactionNumber - 1, _tillEpoch, pushCoreV2, batchSize); + } + + setTransactionText("Unstaking Your Push Tokens. Please wait...") + + const tx = pushCoreV2.unstake(); tx.then(async (tx) => { + pushFeeToast.showLoaderToast({ loaderMessage: 'Unstaking! Waiting for Confirmation...' }); try { - pushFeeToast.showLoaderToast({ loaderMessage: '!Waiting for Confirmation...' }); await provider.waitForTransaction(tx.hash); - pushFeeToast.showMessageToast({ toastTitle: 'Success', toastMessage: 'Transaction Completed!', @@ -232,27 +294,44 @@ const YieldPushFeeV3 = ({ ), }); + getPUSHPoolStats(); getUserDataPush(); - setTxInProgressClaimRewards(false); + setTxInProgressWithdraw(false); + setTransactionSteps(2); + setCurrentTransactionNo(0); + } catch (e) { + console.log("Error", e) pushFeeToast.showMessageToast({ toastTitle: 'Error', - toastMessage: `Transaction failed`, + toastMessage: `Transaction Failed! (" +${e.name}+ ")`, toastType: 'ERROR', getToastIcon: (size) => , }); + setTransactionText(''); + setTxInProgressWithdraw(false); - setTxInProgressClaimRewards(false); } }).catch((err) => { - pushFeeToast.showMessageToast({ - toastTitle: 'Error', - toastMessage: `Transaction failed`, - toastType: 'ERROR', - getToastIcon: (size) => , - }); - - setTxInProgressClaimRewards(false); + console.log("Error: ", err) + const unstakeErrorMessage = err.reason.includes("PushCoreV2::unstake:"); + const harvestErrorMessage = err.reason.includes("PushCoreV2::harvestPaginated:"); + if(unstakeErrorMessage || harvestErrorMessage){ + setUnstakeErrorMessage("PUSH cannot be unstaked until current epoch is over."); + } else { + let errorMessage = err.reason.slice(err.reason.indexOf('::') + 1); + errorMessage = errorMessage.replace('unstake:', ''); + pushFeeToast.showMessageToast({ + toastTitle: 'Error', + toastMessage: `${errorMessage}`, + toastType: 'ERROR', + getToastIcon: (size) => , + }); + } + setTxInProgressWithdraw(false); + getUserDataPush(); + setTransactionSteps(1); + setCurrentTransactionNo(0); }); }; @@ -271,6 +350,14 @@ const YieldPushFeeV3 = ({ const stakingModalToast = useToast(); const isMobile = useDeviceWidthCheck(600); + const { + isModalOpen: isTransactionModalOpen, + showModal: openTransactionModal, + ModalComponent: TransactionModal, + } = useModalBlur(); + + + return ( + { }} + modalPadding="0px" + modalPosition={MODAL_POSITION.ON_ROOT} + /> + {/* Top Section */} {PUSHPoolstats ? ( @@ -501,26 +607,26 @@ const YieldPushFeeV3 = ({ ToolTipTitle={"You can unstake once epoch 2 ends."} ButtonTitle={"Unstake PUSH"} /> - : - formatTokens(userDataPush?.userStaked) === 0 || unstakeErrorMessage !== null ? - : - - {txInProgressWithdraw ? - () : - "Unstake $PUSH" - } - + formatTokens(userDataPush?.userStaked) === 0 || unstakeErrorMessage !== null ? + + : + + {txInProgressWithdraw ? + () : + "Unstake $PUSH" + } + } @@ -552,7 +658,7 @@ const YieldPushFeeV3 = ({ background={'transparent'} color={theme.activeButtonText} cursor='pointer' - onClick={massClaimRewardsTokensAll} + onClick={claimRewards} > {txInProgressClaimRewards ? () : diff --git a/src/config/config-dev.js b/src/config/config-dev.js index 778a9d8a3a..57e26d8c1e 100644 --- a/src/config/config-dev.js +++ b/src/config/config-dev.js @@ -106,6 +106,7 @@ export const addresses = { yieldFarmLP: "0x576c46b328433AaDcb9d9cDd81E0A92852bb0B6F", // yieldFarmLP: "0x13ac63901c8fD5797939099553582951fAbAFDE3", pushCoreV2: "0x23346b732d56d34ec4e890419fbfb8548216a799", + // pushCoreV2: "0x0E76e9776CB192f5840B357780efB325885073FF", uniV2LPToken: "0x698839247E5b83572fFF6ccdcf386CC37e60bEf5", pushToken: "0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33", diff --git a/src/contexts/AppContext.tsx b/src/contexts/AppContext.tsx index 347afb1a74..06a9ac2486 100644 --- a/src/contexts/AppContext.tsx +++ b/src/contexts/AppContext.tsx @@ -1,21 +1,15 @@ // React + Web3 Essentials import useModalBlur from "hooks/useModalBlur"; -import React,{createContext,useEffect,useMemo,useState} from "react"; +import React,{createContext, useState} from "react"; -// External Packages -import { PushAPI } from "@pushprotocol/restapi"; // Internal Components import { AppContextType, Web3NameListType } from "types/context" -import { appConfig } from "config"; -import { useAccount } from "hooks"; export const AppContext = createContext(null); const AppContextProvider=({children})=>{ const [web3NameList,setWeb3NameList]=useState({}); - const [userPushSDKInstance, setUserPushSDKInstance] = useState(null); - const {account, provider} = useAccount(); const [SnapState, setSnapState] = useState(1); const { @@ -24,31 +18,10 @@ const AppContextProvider=({children})=>{ ModalComponent: MetamaskPushSnapModalComponent, } = useModalBlur(); - useEffect(() => { - const librarySigner = provider?.getSigner(account); - if(!account || !librarySigner || !appConfig?.appEnv) return; - - const initializePushSDK = async () => { - try { - const userInstance = await PushAPI.initialize(librarySigner, { - env: appConfig.appEnv, // defaults to staging - account: account - }); - - setUserPushSDKInstance(userInstance); - } catch (error) { - // Handle initialization error - } - }; - - initializePushSDK(); - }, [account, appConfig?.appEnv, provider]); - return( = nextFromEpoch)) { return Helpers.toBN(0); } @@ -229,9 +232,12 @@ export class CoreV2Reward { let rewards = Helpers.toBN(0); for (let i = nextFromEpoch; i <= _tillEpoch; i++) { const claimableReward = this.calculateEpochRewards(i); + console.log("Epoch Number", i , "ClaimableReward",claimableReward,parseFloat(ethers.utils.formatEther(claimableReward))); rewards = rewards.add(claimableReward); } + console.log("Available for claiming reward",rewards,parseFloat(ethers.utils.formatEther(rewards))); + return rewards; } diff --git a/src/helpers/pushStaking/src/constants.ts b/src/helpers/pushStaking/src/constants.ts index 1e0baaa345..c863afa7d9 100644 --- a/src/helpers/pushStaking/src/constants.ts +++ b/src/helpers/pushStaking/src/constants.ts @@ -5,6 +5,6 @@ export const Constants = { }, }, - // epochDuration: 100, epochDuration: 21 * 7156, + // epochDuration: 50, }; diff --git a/src/hooks/useAccount.tsx b/src/hooks/useAccount.tsx index 06028ab319..6d29a0309d 100644 --- a/src/hooks/useAccount.tsx +++ b/src/hooks/useAccount.tsx @@ -20,6 +20,10 @@ export const useAccount = () => { return wallet && wallet.accounts.length > 0 ? true : false }, [wallet]); + const account = useMemo(() => { + return wallet && wallet.accounts.length > 0 ? ethers.utils.getAddress(wallet.accounts[0].address) : undefined; + }, [wallet]); + return { wallet, connecting, @@ -29,7 +33,7 @@ export const useAccount = () => { setWalletModules, setPrimaryWallet, provider, - account: wallet && wallet.accounts.length > 0 ? ethers.utils.getAddress(wallet.accounts[0].address) : undefined, + account: account, chainId: connectedChain ? Number(connectedChain.id) : undefined, isActive, setChain, diff --git a/src/modules/chat/ChatModule.tsx b/src/modules/chat/ChatModule.tsx index 21903a6ea2..2900ed2cad 100644 --- a/src/modules/chat/ChatModule.tsx +++ b/src/modules/chat/ChatModule.tsx @@ -30,7 +30,7 @@ import { VideoCallContext } from 'contexts/VideoCallContext'; import { caip10ToWallet } from 'helpers/w2w'; import * as w2wHelper from 'helpers/w2w/'; import { checkIfGroup, rearrangeMembers } from 'helpers/w2w/groupChat'; -import { useAccount, useDeviceWidthCheck, useSDKSocket } from 'hooks'; +import { useAccount,useDeviceWidthCheck, useSDKSocket } from 'hooks'; import useModalBlur, { MODAL_POSITION } from 'hooks/useModalBlur'; import useToast from 'hooks/useToast'; import ChatBoxSection from 'sections/chat/ChatBoxSection'; @@ -43,6 +43,7 @@ import { checkIfIntent, getUpdatedChatAndIntent, getUpdatedGroupInfo } from 'hel import { appConfig } from 'config'; import GLOBALS, { device, globalsMargin } from 'config/Globals'; import { fetchIntent } from 'helpers/w2w/user'; +import { ChatUIProvider } from '@pushprotocol/uiweb'; export const ToastPosition: ToastOptions = { position: 'top-right', @@ -58,8 +59,8 @@ export const Context = React.createContext(null); // Create Header function Chat({ chatid }) { - const { account, chainId } = useAccount(); - const { getUser, connectedUser, setConnectedUser, blockedLoading, setBlockedLoading, displayQR, setDisplayQR } = + const { account, chainId, provider } = useAccount(); + const { getUser, pgpPvtKey,connectedUser, setConnectedUser, blockedLoading, setBlockedLoading, displayQR, setDisplayQR } = useContext(ChatUserContext); const { videoCallData } = useContext(VideoCallContext); @@ -77,6 +78,7 @@ function Chat({ chatid }) { const [activeTab, setCurrentTab] = useState(0); const [userShouldBeSearched, setUserShouldBeSearched] = useState(false); const [filteredUserData, setFilteredUserData] = useState([]); + const [signerData, setSignerData] = useState(); const isMobile = useDeviceWidthCheck(600); const queryClient = new QueryClient({}); @@ -274,11 +276,14 @@ const getUpdatedGroup = async(groupInfo) => { showModal: showCreateGroupModal, ModalComponent: CreateGroupModalComponent, } = useModalBlur(); + // const { pgpPvtKey } = useContext(ChatUserContext); const connectUser = async (): Promise => { const caip10:string = w2wHelper.walletToCAIP10({account}); - + const signer = await provider.getSigner(); + setSignerData(signer); + console.log(signer, 'kkkk') if(connectedUser?.wallets?.toLowerCase() !== caip10?.toLowerCase()){ await getUser(); @@ -392,8 +397,13 @@ const getUpdatedGroup = async(groupInfo) => { } }; + useEffect(() => { + console.log(account, connectedUser?.privateKey, "kkkk") + }, [account, connectedUser?.privateKey]) + return ( + {!isLoading ? ( @@ -513,6 +523,7 @@ const getUpdatedGroup = async(groupInfo) => { /> )} + ); } diff --git a/src/modules/yield/YieldFarmingModuleV2.tsx b/src/modules/yield/YieldFarmingModuleV2.tsx index 09621b415a..7a88cf5e52 100644 --- a/src/modules/yield/YieldFarmingModuleV2.tsx +++ b/src/modules/yield/YieldFarmingModuleV2.tsx @@ -33,7 +33,7 @@ const YieldFarmingModuleV2 = () => { const { account, chainId, switchChain} = useAccount(); - const handleChainChange = ()=>{ + const handleChainChange = () => { const chainIdToPass = appConfig.allowedNetworks[0]; @@ -41,7 +41,7 @@ const YieldFarmingModuleV2 = () => { switchChain(chainIdToPass); } -} + } useEffect(() => { diff --git a/src/redux/slices/userSlice.ts b/src/redux/slices/userSlice.ts new file mode 100644 index 0000000000..783c7c2329 --- /dev/null +++ b/src/redux/slices/userSlice.ts @@ -0,0 +1,29 @@ +// External Packages +import { PushAPI } from "@pushprotocol/restapi"; +import { createSlice, PayloadAction } from "@reduxjs/toolkit"; + +export interface IUserSliceState { + userPushSDKInstance: PushAPI +} + +const initialState: IUserSliceState = { + userPushSDKInstance: null +}; + +export const userSlice = createSlice({ + name: "user", + initialState, + reducers: { + resetUserSlice: () => initialState, + setUserPushSDKInstance: (state, action: PayloadAction) => { + state.userPushSDKInstance = action.payload; + } + }, +}); + +export const { + resetUserSlice, + setUserPushSDKInstance +} = userSlice.actions; + +export default userSlice.reducer; diff --git a/src/redux/store.js b/src/redux/store.js index b01a70d264..bf6096bf37 100644 --- a/src/redux/store.js +++ b/src/redux/store.js @@ -10,6 +10,7 @@ import notificationReducer from './slices/notificationSlice'; import canSendNotification from "./slices/sendNotificationSlice"; import spamReducer from './slices/spamSlice'; import userJourneyReducer from './slices/userJourneySlice'; +import userReducer from "./slices/userSlice"; const rootReducer = combineReducers({ contracts: contractReducer, @@ -20,6 +21,7 @@ const rootReducer = combineReducers({ spam: spamReducer, userJourney: userJourneyReducer, canSend:canSendNotification, + user: userReducer }); const store = configureStore({ diff --git a/src/sections/yield/NewYieldFarming.tsx b/src/sections/yield/NewYieldFarming.tsx index ccefb14514..7912f74167 100644 --- a/src/sections/yield/NewYieldFarming.tsx +++ b/src/sections/yield/NewYieldFarming.tsx @@ -17,6 +17,8 @@ import { useAccount } from 'hooks'; // Internal Configs import { abis, addresses } from 'config'; +import useModalBlur, { MODAL_POSITION } from 'hooks/useModalBlur'; +import StepsTransactionModal from 'components/StepsTransactionModal'; const NewYieldFarming = ( { setActiveTab } @@ -58,7 +60,7 @@ const NewYieldFarming = ( }, [yieldFarmingLP]); const getUserDataPush = React.useCallback(async () => { - const [pushPoolStats,userDataPush] = await YieldFarmingDataStoreV2.instance.getUserDataPUSH(provider); + const [pushPoolStats, userDataPush] = await YieldFarmingDataStoreV2.instance.getUserDataPUSH(provider); setPUSHPoolStats({ ...pushPoolStats }); setUserDataPush({ ...userDataPush }); @@ -116,18 +118,19 @@ const NewYieldFarming = ( getPUSHPoolStats(); }, [account]); - - + return ( <> + + - + diff --git a/src/types/context.ts b/src/types/context.ts index 576bf0a74a..4568411c0d 100644 --- a/src/types/context.ts +++ b/src/types/context.ts @@ -7,7 +7,6 @@ export interface Web3NameListType { export interface AppContextType { web3NameList: Web3NameListType; setWeb3NameList: (ens: Web3NameListType) => void; - userPushSDKInstance: PushAPI; MetamaskPushSnapModalComponent:any, showMetamaskPushSnap:any, SnapState:number, diff --git a/yarn.lock b/yarn.lock index 2faf6deeb2..78212d0dc6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5425,7 +5425,7 @@ __metadata: "@pushprotocol/ledgerlive": latest "@pushprotocol/restapi": 0.0.1-alpha.50 "@pushprotocol/socket": latest - "@pushprotocol/uiweb": 0.0.1-alpha.21 + "@pushprotocol/uiweb": 0.0.1-alpha.24 "@reduxjs/toolkit": ^1.7.1 "@testing-library/dom": ^6.12.2 "@testing-library/jest-dom": ^4.2.4 @@ -5688,9 +5688,9 @@ __metadata: languageName: node linkType: hard -"@pushprotocol/uiweb@npm:0.0.1-alpha.21": - version: 0.0.1-alpha.21 - resolution: "@pushprotocol/uiweb@npm:0.0.1-alpha.21" +"@pushprotocol/uiweb@npm:0.0.1-alpha.24": + version: 0.0.1-alpha.24 + resolution: "@pushprotocol/uiweb@npm:0.0.1-alpha.24" dependencies: "@livekit/components-react": ^1.2.2 "@livekit/components-styles": ^1.0.6 @@ -5711,7 +5711,9 @@ __metadata: html-react-parser: ^1.4.13 livekit-client: ^1.13.3 moment: ^2.29.4 + react-easy-crop: ^4.1.4 react-icons: ^4.10.1 + react-image-file-resizer: ^0.4.7 react-toastify: ^9.1.3 react-twitter-embed: ^4.0.4 uuid: ^9.0.1 @@ -5720,8 +5722,8 @@ __metadata: "@pushprotocol/socket": ^0.5.0 axios: ^0.27.2 react: ">=16.8.0" - styled-components: ^5.3.5 - checksum: 23dd20717311fc9f24e45f55b944db36e74f616ff787c7a91ccda4bc324471532a073a332600e8b63612f5b399b3609dfa780e0ca12e8206482e7596d32409c3 + styled-components: ^6.0.8 + checksum: e8ec5fe961cb90fdfc37a771753f19e136f043b38bd911f9c22817da5bb1b553cf2e70387644444454e04e83c4ac63091b80839c32a16c9a567f8ae951a32e06 languageName: node linkType: hard