Skip to content

Commit

Permalink
Merge branch 'main' into welcome-component
Browse files Browse the repository at this point in the history
  • Loading branch information
r-czajkowski authored Nov 8, 2024
2 parents ba5363e + d39606e commit fa3a21a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 14 deletions.
3 changes: 3 additions & 0 deletions dapp/src/hooks/useStatistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ const useStatistics = () => {
? 100
: Math.floor((bitcoinTvl / TOTAL_VALUE_LOCKED_CAP) * 100)

const remaining = isCapExceeded ? 0 : TOTAL_VALUE_LOCKED_CAP - bitcoinTvl

return {
tvl: {
progress,
value: bitcoinTvl,
usdValue: usdTvl,
isCapExceeded,
remaining,
},
}
}
Expand Down
45 changes: 45 additions & 0 deletions dapp/src/pages/DashboardPage/AcreTVLMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from "react"
import { Box, HStack, StackProps, VStack } from "@chakra-ui/react"
import { useAllActivitiesCount, useStatistics, useWallet } from "#/hooks"
import { BoltFilled } from "#/assets/icons"
import { TextMd } from "#/components/shared/Typography"
import { CurrencyBalance } from "#/components/shared/CurrencyBalance"

type AcreTVLMessageProps = Omit<StackProps, "children">

export default function AcreTVLMessage(props: AcreTVLMessageProps) {
const { tvl } = useStatistics()
const { isConnected } = useWallet()
const activitiesCount = useAllActivitiesCount()

const isFirstTimeUser = activitiesCount === 0

if (isConnected && !isFirstTimeUser && !tvl.isCapExceeded) {
return null
}

return (
<HStack align="start" spacing={1} color="grey.500" {...props}>
<BoltFilled color="orange.400" my={1} />
{tvl.isCapExceeded ? (
<VStack align="start" spacing={0}>
<TextMd fontWeight="semibold" color="grey.700">
Deposit cap reached!
</TextMd>
<TextMd>Stay tuned for the next deposit cycle.</TextMd>
</VStack>
) : (
<TextMd as="div">
<CurrencyBalance
amount={tvl.remaining}
currency="bitcoin"
shouldBeFormatted={false}
desiredDecimals={2}
color="grey.700"
/>
<Box as="span">&nbsp;remaining until deposit cap</Box>
</TextMd>
)}
</HStack>
)
}
49 changes: 35 additions & 14 deletions dapp/src/pages/DashboardPage/PositionDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React from "react"
import { CurrencyBalanceWithConversion } from "#/components/shared/CurrencyBalanceWithConversion"
import { useBitcoinPosition, useTransactionModal } from "#/hooks"
import {
useAllActivitiesCount,
useBitcoinPosition,
useTransactionModal,
useStatistics,
useWallet,
} from "#/hooks"
import { ACTION_FLOW_TYPES } from "#/types"
import {
Button,
Expand All @@ -14,6 +20,7 @@ import ArrivingSoonTooltip from "#/components/ArrivingSoonTooltip"
import UserDataSkeleton from "#/components/shared/UserDataSkeleton"
import { featureFlags } from "#/constants"
import { TextMd } from "#/components/shared/Typography"
import AcreTVLMessage from "./AcreTVLMessage"

const isWithdrawalFlowEnabled = featureFlags.WITHDRAWALS_ENABLED

Expand All @@ -33,6 +40,11 @@ export default function PositionDetails() {

const openDepositModal = useTransactionModal(ACTION_FLOW_TYPES.STAKE)
const openWithdrawModal = useTransactionModal(ACTION_FLOW_TYPES.UNSTAKE)
const activitiesCount = useAllActivitiesCount()

const { tvl } = useStatistics()

const { isConnected } = useWallet()

return (
<Flex w="100%" flexDirection="column" gap={5}>
Expand Down Expand Up @@ -76,24 +88,33 @@ export default function PositionDetails() {
</UserDataSkeleton>
</VStack>

<HStack w="full" justify="start" flexWrap="wrap" spacing={2}>
<HStack w="full" justify="start" flexWrap="wrap" spacing={5}>
<UserDataSkeleton>
<Button {...buttonStyles} onClick={openDepositModal}>
<Button
{...buttonStyles}
onClick={openDepositModal}
isDisabled={featureFlags.TVL_ENABLED && tvl.isCapExceeded}
>
Deposit
</Button>
</UserDataSkeleton>
<UserDataSkeleton>
<ArrivingSoonTooltip shouldDisplayTooltip={!isWithdrawalFlowEnabled}>
<Button
variant="outline"
{...buttonStyles}
onClick={openWithdrawModal}
isDisabled={!isWithdrawalFlowEnabled}
{isConnected && activitiesCount > 0 && (
<UserDataSkeleton ml={-3}>
<ArrivingSoonTooltip
shouldDisplayTooltip={!isWithdrawalFlowEnabled}
>
Withdraw
</Button>
</ArrivingSoonTooltip>
</UserDataSkeleton>
<Button
variant="outline"
{...buttonStyles}
onClick={openWithdrawModal}
isDisabled={!isWithdrawalFlowEnabled}
>
Withdraw
</Button>
</ArrivingSoonTooltip>
</UserDataSkeleton>
)}
{featureFlags.TVL_ENABLED && <AcreTVLMessage />}
</HStack>
</Flex>
)
Expand Down

0 comments on commit fa3a21a

Please sign in to comment.