From e1a74df50c48ace2700ade81260d4029a8dbb31b Mon Sep 17 00:00:00 2001 From: Linkie Link Date: Thu, 30 Jan 2025 10:12:20 +0100 Subject: [PATCH 1/2] fix: fixed rewards center and accountlist --- .../account/AccountList/AccountStats.tsx | 22 ++++++++++++++----- .../account/AccountList/Skeleton.tsx | 1 + src/components/header/RewardsCenter/index.tsx | 9 ++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/components/account/AccountList/AccountStats.tsx b/src/components/account/AccountList/AccountStats.tsx index bac3de547..21b1bdc92 100644 --- a/src/components/account/AccountList/AccountStats.tsx +++ b/src/components/account/AccountList/AccountStats.tsx @@ -7,16 +7,19 @@ import Button from 'components/common/Button' import { ArrowDownLine, ArrowUpLine, TrashBin } from 'components/common/Icons' import SwitchAutoLend from 'components/common/Switch/SwitchAutoLend' import useLendingMarketAssetsTableData from 'components/earn/lend/Table/useLendingMarketAssetsTableData' +import { BN_ZERO } from 'constants/math' +import { ORACLE_DENOM } from 'constants/oracle' import useAccount from 'hooks/accounts/useAccount' -import useWhitelistedAssets from 'hooks/assets/useWhitelistedAssets' +import useAssets from 'hooks/assets/useAssets' import useAstroLpAprs from 'hooks/astroLp/useAstroLpAprs' import useHealthComputer from 'hooks/health-computer/useHealthComputer' +import usePerpsMarketStates from 'hooks/perps/usePerpsMarketStates' import usePerpsVault from 'hooks/perps/usePerpsVault' import useVaultAprs from 'hooks/vaults/useVaultAprs' import useStore from 'store' +import { BNCoin } from 'types/classes/BNCoin' import { calculateAccountApy, calculateAccountBalanceValue } from 'utils/accounts' import { mergeBNCoinArrays } from 'utils/helpers' -import usePerpsMarketStates from 'hooks/perps/usePerpsMarketStates' interface Props { accountId: string @@ -26,22 +29,31 @@ interface Props { export default function AccountStats(props: Props) { const { accountId, isActive, setShowMenu } = props - const assets = useWhitelistedAssets() + const { data: assets } = useAssets() const { data: account } = useAccount(accountId) const { data: vaultAprs } = useVaultAprs() const { data: perpsVault } = usePerpsVault() const astroLpAprs = useAstroLpAprs() - const perpsMarketStates = usePerpsMarketStates() const positionBalance = useMemo( () => (!account ? null : calculateAccountBalanceValue(account, assets)), [account, assets], ) const { health, healthFactor } = useHealthComputer(account) + const accountBalanceValue = useMemo( + () => (!account ? BN_ZERO : calculateAccountBalanceValue(account, assets)), + [account, assets], + ) + + const coin = BNCoin.fromDenomAndBigNumber(ORACLE_DENOM, accountBalanceValue) const data = useBorrowMarketAssetsTableData() const borrowAssetsData = useMemo(() => data?.allAssets || [], [data]) + const { availableAssets: lendingAvailableAssets, accountLentAssets } = useLendingMarketAssetsTableData() + + const perpsMarketStates = usePerpsMarketStates() + const lendingAssetsData = useMemo( () => [...lendingAvailableAssets, ...accountLentAssets], [lendingAvailableAssets, accountLentAssets], @@ -49,7 +61,7 @@ export default function AccountStats(props: Props) { const apy = useMemo( () => !account - ? null + ? BN_ZERO : calculateAccountApy( account, borrowAssetsData, diff --git a/src/components/account/AccountList/Skeleton.tsx b/src/components/account/AccountList/Skeleton.tsx index 9f897d5f9..07af822da 100644 --- a/src/components/account/AccountList/Skeleton.tsx +++ b/src/components/account/AccountList/Skeleton.tsx @@ -22,6 +22,7 @@ export default function Skeleton(props: Props) { {positionBalance ? ( ) : ( diff --git a/src/components/header/RewardsCenter/index.tsx b/src/components/header/RewardsCenter/index.tsx index a916c38ce..3b111a0c8 100644 --- a/src/components/header/RewardsCenter/index.tsx +++ b/src/components/header/RewardsCenter/index.tsx @@ -42,9 +42,14 @@ export default function RewardsCenter(props: Props) { const { isAutoLendEnabledForCurrentAccount: isAutoLend } = useAutoLend() const { data: stakedAstroLpRewards } = useStakedAstroLpRewards() + const currentLpRewards = useMemo(() => { - if (stakedAstroLpRewards.length === 0) return [] - return stakedAstroLpRewards[0].rewards + let currentLpRewardsArray = [] as BNCoin[] + if (stakedAstroLpRewards.length === 0) return currentLpRewardsArray + stakedAstroLpRewards.forEach((stakeAstroLpReward) => { + currentLpRewardsArray = mergeBNCoinArrays(currentLpRewardsArray, stakeAstroLpReward.rewards) + }) + return currentLpRewardsArray }, [stakedAstroLpRewards]) const rewards = useMemo( From b30f5a29fa3d660edde13ca3e26061afd1e8bb2e Mon Sep 17 00:00:00 2001 From: Linkie Link Date: Thu, 30 Jan 2025 10:12:41 +0100 Subject: [PATCH 2/2] env: bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ce41b856e..a2908cbf1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mars-v2-frontend", - "version": "2.8.9", + "version": "2.8.10", "homepage": "./", "private": false, "license": "SEE LICENSE IN LICENSE FILE",