diff --git a/rair-front/src/components/Navigation/Menu.tsx b/rair-front/src/components/Navigation/Menu.tsx index 7420b671b..1ebc62205 100644 --- a/rair-front/src/components/Navigation/Menu.tsx +++ b/rair-front/src/components/Navigation/Menu.tsx @@ -14,6 +14,8 @@ import { BellIcon, CloseIconMobile, MenuIcon, + RairFavicon, + RairTokenLogo, VerifiedIcon } from '../../images'; import { @@ -270,6 +272,10 @@ const MenuNavigation: React.FC = ({ )}
{ + handleMessageAlert('profileEdit'); + toggleMenu('nav'); + }} className="mobileAikonWidget" style={{ backgroundColor: @@ -281,13 +287,9 @@ const MenuNavigation: React.FC = ({ className={`profile-user-balance ${ primaryColor === 'rhyno' ? 'rhyno' : '' }`}> -
- {isLoadingBalance ? ( - - ) : ( - userBalance - )} -
+ logo {currentChain && chainData[currentChain] && ( = ({ }) => { const hotDropsVar = import.meta.env.VITE_TESTNET; + const [userBalance, setUserBalance] = useState(''); + const [userRairBalance, setUserRairBalance] = useState( + BigNumber.from(0) + ); + const { userData } = useSelector((store) => store.userStore); + + const { web3TxHandler } = useWeb3Tx(); + + const { erc777Instance, currentChain } = useSelector< + RootState, + ContractsInitialType +>((store) => store.contractStore); + +const getBalance = useCallback(async () => { + if (currentUserAddress && erc777Instance?.provider) { + const balance = + await erc777Instance.provider.getBalance(currentUserAddress); + + if (balance) { + const result = utils.formatEther(balance); + const final = Number(result.toString())?.toFixed(2)?.toString(); + + setUserBalance(final); + } + } + // eslint-disable-next-line react-hooks/exhaustive-deps +}, [currentUserAddress, erc777Instance, userData]); + + const getUserRairBalance = useCallback(async () => { + if (!erc777Instance || userRairBalance?.gt(0)) { + return; + } + const result = await web3TxHandler(erc777Instance, 'balanceOf', [ + currentUserAddress + ]); + if (result?._isBigNumber) { + setUserRairBalance(result); + } + }, [erc777Instance, currentUserAddress, userRairBalance, web3TxHandler]); + const [copyEth, setCopyEth] = useState(false); const { logoutUser } = useConnectUser(); + useEffect(() => { + getBalance(); + }, [getBalance]) + + useEffect(() => { + getUserRairBalance(); + }, [getUserRairBalance]); + useEffect(() => { setCopyEth(false); @@ -80,71 +135,101 @@ const MobileNavigationList: React.FC = ({ className="nav-header-box-mobile" primaryColor={primaryColor} messageAlert={messageAlert}> - setMessageAlert('profile')}> - - -
  • - Personal Profile -
  • - +
    +
    +
    +
    +
    + {userBalance ? userBalance : 0.00} + {/* {isLoadingBalance ? : userBalance} */} +
    +
    + {currentChain && chainData[currentChain] && ( + logo + )} +
    +
    +
    +
    + {userRairBalance ? formatEther(userRairBalance) : 0.00} + {/* {isLoadingBalance ? : userBalance} */} +
    +
    + logo +
    +
    +
    +
    +
    +
    Exchange rate
    +
    50K RAIR/bETH
    +
    +
    + + + +
    +
    +
    +
    + {currentUserAddress && ( +
  • + Logout +
  • + )} ) : ( - {hotDropsVar !== 'true' && ( -
  • - - Token - -
  • - )} - {hotDropsVar !== 'true' ? ( -
  • - -
  • - ) : ( - <> -
  • - - Info - -
  • -
  • - - Collections - -
  • -
  • - - Hotties - -
  • -
  • - - Shop - -
  • - - )} {currentUserAddress && (
  • Logout diff --git a/rair-front/src/components/UserProfileSettings/PopUpSetting.tsx b/rair-front/src/components/UserProfileSettings/PopUpSetting.tsx index 7b6a4d460..00f9fc816 100644 --- a/rair-front/src/components/UserProfileSettings/PopUpSetting.tsx +++ b/rair-front/src/components/UserProfileSettings/PopUpSetting.tsx @@ -3,17 +3,20 @@ import { useCallback, useEffect, useRef, useState } from 'react'; import { useSelector } from 'react-redux'; import { useNavigate } from 'react-router-dom'; import { Popup } from 'reactjs-popup'; -import { utils } from 'ethers'; +import { BigNumber, utils } from 'ethers'; +import { formatEther } from 'ethers/lib/utils'; import { RootState } from '../../ducks'; import { ContractsInitialType } from '../../ducks/contracts/contracts.types'; // import { TUsersInitialState } from '../../ducks/users/users.types'; // React Redux types import useConnectUser from '../../hooks/useConnectUser'; -import { VerifiedIcon } from '../../images'; +import { RairFavicon, RairTokenLogo, VerifiedIcon } from '../../images'; import chainData from '../../utils/blockchainData'; import LoadingComponent from '../common/LoadingComponent'; +import { TooltipBox } from '../common/Tooltip/TooltipBox'; +import useWeb3Tx from './../../hooks/useWeb3Tx'; import EditMode from './EditMode/EditMode'; import defaultPictures from './images/defaultUserPictures.png'; import { @@ -33,6 +36,10 @@ const PopUpSettings = ({ showAlert, selectedChain, setTabIndexItems }) => { const [editMode, setEditMode] = useState(false); const [userBalance, setUserBalance] = useState(''); const [isLoadingBalance, setIsLoadingBalance] = useState(false); + const [userBalanceTrigger, setUserBalanceTrigger] = useState(false); + const [userRairBalance, setUserRairBalance] = useState( + BigNumber.from(0) + ); const hotdropsVar = import.meta.env.VITE_TESTNET; @@ -46,14 +53,29 @@ const PopUpSettings = ({ showAlert, selectedChain, setTabIndexItems }) => { const { logoutUser } = useConnectUser(); const { userData } = useSelector((store) => store.userStore); - const { erc777Instance, currentUserAddress, currentChain } = useSelector< + + const { currentUserAddress, erc777Instance, currentChain } = useSelector< RootState, ContractsInitialType - >((state) => state.contractStore); + >((store) => store.contractStore); - // const { loginType } = useSelector( - // (store) => store.userStore - // ); + const { web3TxHandler } = useWeb3Tx(); + + const getUserRairBalance = useCallback(async () => { + if (!erc777Instance || userRairBalance?.gt(0)) { + return; + } + const result = await web3TxHandler(erc777Instance, 'balanceOf', [ + currentUserAddress + ]); + if (result?._isBigNumber) { + setUserRairBalance(result); + } + }, [erc777Instance, currentUserAddress, userRairBalance, web3TxHandler]); + + useEffect(() => { + getUserRairBalance(); + }, [getUserRairBalance]); const onChangeEditMode = useCallback(() => { setEditMode((prev) => !prev); @@ -144,7 +166,6 @@ const PopUpSettings = ({ showAlert, selectedChain, setTabIndexItems }) => { return ( <>
  • setUserBalanceTrigger((prev) => !prev)} className={`profile-user-balance ${ primaryColor === '#dedede' ? 'rhyno' : '' }`}> -
    - {isLoadingBalance ? : userBalance} -
    + logo {chainData[currentChain] && ( logo )}
    setTriggerState((prev) => !prev)} className="profile-btn-img" style={{ height: '100%', @@ -214,6 +241,7 @@ const PopUpSettings = ({ showAlert, selectedChain, setTabIndexItems }) => { /> )}
    setTriggerState((prev) => !prev)} style={{ display: 'flex', width: '140px', @@ -248,6 +276,139 @@ const PopUpSettings = ({ showAlert, selectedChain, setTabIndexItems }) => { }}>
    + { + setUserBalanceTrigger(false); + }}> +
    +
    +
    +
    +
    + {isLoadingBalance ? ( + + ) : ( + userBalance + )} +
    +
    + {chainData[currentChain] && ( + logo + )} +
    +
    +
    +
    + {isLoadingBalance ? ( + + ) : ( + formatEther(userRairBalance) + )} +
    +
    + logo +
    +
    +
    +
    +
    +
    + Exchange rate +
    +
    + 50K RAIR/bETH +
    +
    +
    + + + +
    +
    +
    +
    +