-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render acre point data only when fetched
- Loading branch information
1 parent
199689b
commit 99578ac
Showing
4 changed files
with
108 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
dapp/src/pages/DashboardPage/AcrePointsCard/LabelWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React, { ReactNode } from "react" | ||
import { VStack } from "@chakra-ui/react" | ||
|
||
export default function LabelWrapper({ children }: { children: ReactNode }) { | ||
return ( | ||
<VStack px={4} py={5} spacing={0} rounded="lg" bg="gold.100"> | ||
{children} | ||
</VStack> | ||
) | ||
} |
88 changes: 88 additions & 0 deletions
88
dapp/src/pages/DashboardPage/AcrePointsCard/UserPointsLabel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from "react" | ||
import { TextMd } from "#/components/shared/Typography" | ||
import { Button, HStack, VStack } from "@chakra-ui/react" | ||
import { numberToLocaleString } from "#/utils" | ||
import { useAcrePointsData, useClaimPoints, useUserPointsData } from "#/hooks" | ||
import Spinner from "#/components/shared/Spinner" | ||
import TooltipIcon from "#/components/shared/TooltipIcon" | ||
import useDebounce from "#/hooks/useDebounce" | ||
import { ONE_SEC_IN_MILLISECONDS } from "#/constants" | ||
import LabelWrapper from "./LabelWrapper" | ||
import { NextDropTimestampLabel } from "./AcrePointsLabel" | ||
|
||
// TODO: Update `Button` component theme | ||
const COLOR_BUTTON_LABEL = "#FBF7EC" | ||
const COLOR_BUTTON_BACKGROUND = "#33A321" | ||
|
||
function ClaimableBalanceLabel() { | ||
const { mutate: claimPoints } = useClaimPoints() | ||
const { data: userPointsData } = useUserPointsData() | ||
const debouncedClaimPoints = useDebounce(claimPoints, ONE_SEC_IN_MILLISECONDS) | ||
|
||
const claimableBalance = userPointsData?.claimableBalance || 0 | ||
const formattedClaimablePointsAmount = numberToLocaleString(claimableBalance) | ||
|
||
if (claimableBalance <= 0) return null | ||
|
||
return ( | ||
<Button | ||
mt={5} | ||
onClick={debouncedClaimPoints} | ||
w="full" | ||
colorScheme="green" | ||
bgColor={COLOR_BUTTON_BACKGROUND} | ||
color={COLOR_BUTTON_LABEL} | ||
fontWeight="semibold" | ||
size="lg" | ||
> | ||
Claim {formattedClaimablePointsAmount} PTS | ||
</Button> | ||
) | ||
} | ||
|
||
function CalculationInProgressLabel() { | ||
const { data } = useUserPointsData() | ||
|
||
return ( | ||
<VStack spacing={4}> | ||
{!data?.claimableBalance && ( | ||
<TextMd color="grey.500">Please wait...</TextMd> | ||
)} | ||
<HStack spacing={0}> | ||
<Spinner mr={3} size="sm" /> | ||
<TextMd>Your drop is being prepared.</TextMd> | ||
<TooltipIcon | ||
label={` | ||
We need some time to calculate your points. It may take up to 30 minutes. | ||
${data?.claimableBalance ? "You can still claim points from previous drops." : ""} | ||
`} | ||
maxW={72} | ||
/> | ||
</HStack> | ||
</VStack> | ||
) | ||
} | ||
|
||
export default function UserPointsLabel() { | ||
const { data: acrePointsData } = useAcrePointsData() | ||
const { data: userPointsData } = useUserPointsData() | ||
|
||
if (acrePointsData || userPointsData?.isEligible) { | ||
if (acrePointsData?.isCalculationInProgress) | ||
return ( | ||
<LabelWrapper> | ||
<CalculationInProgressLabel /> | ||
<ClaimableBalanceLabel /> | ||
</LabelWrapper> | ||
) | ||
|
||
return ( | ||
<LabelWrapper> | ||
<NextDropTimestampLabel /> | ||
<ClaimableBalanceLabel /> | ||
</LabelWrapper> | ||
) | ||
} | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters