Skip to content

Commit

Permalink
fix: fw-438 show user claimed amount on cover
Browse files Browse the repository at this point in the history
  • Loading branch information
swkatmask committed Feb 26, 2024
1 parent cf7c176 commit 741181f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/plugins/RedPacket/src/SiteAdaptor/RedPacket/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,21 @@ export const RedPacket = memo(function RedPacket({ payload }: RedPacketProps) {
if (shareText) share?.(shareText, source ? source : undefined)
}, [shareText, source])

const outdated =
listOfStatus.includes(RedPacketStatus.empty) || (!canRefund && listOfStatus.includes(RedPacketStatus.expired))
const empty = listOfStatus.includes(RedPacketStatus.empty)
const outdated = empty || (!canRefund && listOfStatus.includes(RedPacketStatus.expired))
const claimed = listOfStatus.includes(RedPacketStatus.claimed)

const { classes } = useStyles({ outdated })

const { data } = useQuery({
enabled: !!availability && !!payload.rpid && !!token?.symbol,
queryKey: ['red-packet', 'theme-id', payload.rpid],
queryKey: ['red-packet', 'theme-id', payload.rpid, claimed],
queryFn: async () => {
const name = payload.sender.name
const data = await redPacketContract.methods.check_availability(payload.rpid).call({
// check availability is ok w/o account
from: account,
})

return FireflyRedPacket.getCoverUrlByRpid(
payload.rpid,
Expand All @@ -246,15 +251,15 @@ export const RedPacket = memo(function RedPacket({ payload }: RedPacketProps) {
payload.sender.message,
availability?.balance ?? payload.total,
toFixed(minus(payload.shares, availability?.claimed || 0)),
data.claimed_amount,
)
},
})

// the red packet can fetch without account
if (!availability || !token || !data?.url) return <LoadingStatus minHeight={148} />

const claimedOrEmpty =
listOfStatus.includes(RedPacketStatus.claimed) || listOfStatus.includes(RedPacketStatus.empty)
const claimedOrEmpty = claimed || empty

return (
<>
Expand Down
2 changes: 2 additions & 0 deletions packages/web3-providers/src/Firefly/RedPacket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class FireflyRedPacket {
message?: string,
remainingAmount?: string,
remainingShares?: string,
claimedAmount?: string,
) {
const url = urlcat(FIREFLY_ROOT_URL, 'v1/redpacket/themeById', {
rpid,
Expand All @@ -78,6 +79,7 @@ export class FireflyRedPacket {
message,
'remaining-amount': remainingAmount,
'remaining-shares': remainingShares,
'claimed-amount': claimedAmount,
}),
}
}
Expand Down

0 comments on commit 741181f

Please sign in to comment.