Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions dapp/src/hooks/usePositionStats.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { useAcreContext } from "#/acre-react/hooks"
import { queryKeysFactory } from "#/constants"
import { useQuery } from "@tanstack/react-query"
import { useMemo } from "react"
import useActivities from "./useActivities"
import useBitcoinPosition from "./useBitcoinPosition"

export default function usePositionStats() {
const { acre, isInitialized, isConnected } = useAcreContext()
const { data, isLoading } = useActivities()
const { data: position, isLoading: isLoadingBitcoinPosition } =
useBitcoinPosition()

return useQuery({
queryKey: [...queryKeysFactory.userKeys.positionStats()],
queryFn: async () => {
if (!acre) throw new Error("Acre SDK not available")
const positionStats = useMemo(() => {
if (!data || !position) return undefined

const currentBalance = await acre.account.estimatedBitcoinBalance()
const withdrawals = await acre.account.getWithdrawals()
const deposits = await acre.account.getDeposits()
const currentBalance = position.estimatedBitcoinBalance
const withdrawals = data.filter((activity) => activity.type === "withdraw")
const deposits = data.filter((activity) => activity.type === "deposit")

const sumOfWithdrawals = withdrawals.reduce(
(sum, withdrawal) => sum + withdrawal.amount,
0n,
)
const sumOfDeposits = deposits.reduce(
(sum, deposit) => sum + deposit.amount,
0n,
)
const sumOfWithdrawals = withdrawals.reduce(
(sum, withdrawal) => sum + withdrawal.amount,
0n,
)
const sumOfDeposits = deposits.reduce(
(sum, deposit) => sum + deposit.amount,
0n,
)

const earned = currentBalance + sumOfWithdrawals - sumOfDeposits
const earned = currentBalance + sumOfWithdrawals - sumOfDeposits

return { deposited: currentBalance, earned: earned < 0n ? 0n : earned }
},
enabled: isInitialized && isConnected && !!acre,
})
return { deposited: sumOfDeposits, earned: earned < 0n ? 0n : earned }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to clarify with Product the actual intention of the deposited value to be shown. Currently the user can deposit and withdraw in the loop, and their BTC Deposited value will be growing, while they are looping the same deposit amont.

@r-czajkowski r-czajkowski Nov 29, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated to:

"BTC deposited" ==> net active BTC deposits. (total aggregate # of BTC that has been deposited by the user) - (total aggregate BTC withdrawals).

48d1c90

}, [data, position])

return { data: positionStats, isLoading, isLoadingBitcoinPosition }
}
2 changes: 1 addition & 1 deletion dapp/src/pages/DashboardPage/BTCDepositedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function BTCDepositedCard(props: BTCDepositedCardProps) {
return (
<BitcoinAmountFeaturedMetricsCard
icon={IconCurrencyBitcoin}
label="Current Balance"
label="BTC Deposited"
{...props}
/>
)
Expand Down
25 changes: 16 additions & 9 deletions dapp/src/pages/DashboardPage/PositionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { featureFlags } from "#/constants"
import { IconClockHour5Filled } from "@tabler/icons-react"
import TooltipIcon from "#/components/shared/TooltipIcon"
import { activitiesUtils } from "#/utils"
import CurrencyBalance from "#/components/shared/CurrencyBalance"
import CurrencyBalanceWithConversion from "#/components/shared/CurrencyBalanceWithConversion"
import AcreTVLMessage from "./AcreTVLMessage"

const isWithdrawalFlowEnabled = featureFlags.WITHDRAWALS_ENABLED
Expand All @@ -40,7 +40,7 @@ const buttonStyles: ButtonProps = {

export default function PositionDetails() {
const { data: bitcoinPosition } = useBitcoinPosition()
const shares = bitcoinPosition?.sharesBalance ?? 0n
const bitcoinAmount = bitcoinPosition?.estimatedBitcoinBalance ?? 0n

const openDepositModal = useTransactionModal(ACTION_FLOW_TYPES.STAKE)
const openWithdrawModal = useTransactionModal(ACTION_FLOW_TYPES.UNSTAKE)
Expand All @@ -62,7 +62,7 @@ export default function PositionDetails() {
<VStack alignItems="start" spacing={0}>
{/* TODO: Component should be moved to `CardHeader` */}
<HStack>
<Text size="md">Your Acre balance</Text>
<Text size="md">Account Summary</Text>
{activitiesUtils.hasPendingDeposits(activities ?? []) && (
<TooltipIcon
icon={IconClockHour5Filled}
Expand All @@ -73,12 +73,19 @@ export default function PositionDetails() {
</HStack>
<UserDataSkeleton>
<VStack alignItems="start" spacing={0}>
<CurrencyBalance
amount={shares}
currency="acrebtc"
size="4xl"
letterSpacing="-0.075rem" // -1.2px
color="text.primary"
<CurrencyBalanceWithConversion
from={{
amount: bitcoinAmount,
currency: "bitcoin",
size: "4xl",
letterSpacing: "-0.075rem", // -1.2px
color: "text.primary",
}}
to={{
currency: "usd",
color: "text.tertiary",
fontWeight: "medium",
}}
/>
</VStack>
</UserDataSkeleton>
Expand Down
Loading