Skip to content

Commit

Permalink
my vaults filter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vnaysngh-mudrex committed Jun 5, 2024
1 parent 1a0c981 commit babf713
Showing 1 changed file with 5 additions and 54 deletions.
59 changes: 5 additions & 54 deletions src/pages/Vaults/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,59 +314,6 @@ function PromotionalBanner({ noDecorations = false }) {
}

const noop = () => {}
interface UserBalanceProps {
tokenAddress: string
vaultAddress: string
tokenPrice: number | undefined
getResult?: ({ vaultAddress, balance }: UserBalanceResultParams) => void
}
const UserBalance: React.FC<UserBalanceProps> = ({
tokenAddress,
vaultAddress,
tokenPrice,
getResult = () => {},
}: UserBalanceProps) => {
const { address, isConnected } = useAccountDetails()
const {
data: userBalanceData,
isLoading: isUserBalanceLoading,
isError: isUserBalanceError,
isSuccess: isUserBalanceSuccess,
} = useBalance({
token: tokenAddress,
address,
watch: true,
})
let result
const balanceInUsd = Number(userBalanceData?.formatted ?? 0) * (tokenPrice ?? 0)
const balance =
userBalanceData && Number(userBalanceData?.formatted) > 0 ? Number(userBalanceData?.formatted).toFixed(6) : 0
useEffect(() => {
if (isConnected && isUserBalanceSuccess) {
getResult({ vaultAddress, balance: Number(balance) })
}
}, [userBalanceData, isUserBalanceSuccess, isConnected])

switch (true) {
case !isConnected:
case isUserBalanceError: {
result = formatUsdPrice(0)
break
}
case isUserBalanceLoading: {
result = '...'
break
}
case isUserBalanceSuccess: {
result = formatUsdPrice(balanceInUsd)
break
}
default: {
result = formatUsdPrice(0)
}
}
return <span>{balance}</span>
}

interface ListItemProps {
index: number
Expand Down Expand Up @@ -407,13 +354,17 @@ const ListItem = ({ index, vaultAddress, vaultData, getUserBalance = noop }: Lis
currency1.logoURI = vaultData.token1.logoURI

//calculating total shares usd value
const { totalToken0Amount, totalToken1Amount } = useUserShares(
const { totalShares, totalToken0Amount, totalToken1Amount } = useUserShares(
vaultAddress,
null,
currency0 ?? undefined,
currency1 ?? undefined
)

useEffect(() => {
getUserBalance({ vaultAddress, balance: totalShares })
}, [vaultAddress, totalShares])

const separatedFiatValueofLiquidity = useQuery({
queryKey: ['fiat_value', totalToken0Amount, totalToken1Amount],
queryFn: async () => {
Expand Down

0 comments on commit babf713

Please sign in to comment.