Skip to content

Commit

Permalink
fix: adjust follow condition
Browse files Browse the repository at this point in the history
  • Loading branch information
swkatmask committed Jan 24, 2025
1 parent 3bfb040 commit f182dd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
43 changes: 17 additions & 26 deletions packages/plugins/RedPacket/src/SiteAdaptor/Conditions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Icons } from '@masknet/icons'
import { WalletRelatedTypes } from '@masknet/plugin-redpacket'
import { TokenIcon } from '@masknet/shared'
import { NetworkPluginID } from '@masknet/shared-base'
import { LoadingBase, MaskColors, makeStyles } from '@masknet/theme'
import { MaskColors, makeStyles } from '@masknet/theme'
import { FireflyTwitter } from '@masknet/web3-providers'
import { FireflyRedPacketAPI } from '@masknet/web3-providers/types'
import { isZero } from '@masknet/web3-shared-base'
Expand Down Expand Up @@ -117,15 +117,14 @@ const useStyles = makeStyles<void, 'assetName'>()((theme, _, refs) => ({
}))

interface Props extends BoxProps {
unsatisfied?: boolean
statusList: FireflyRedPacketAPI.ClaimStrategyStatus[]
onClose?(): void
}

const StrategyType = FireflyRedPacketAPI.StrategyType
const PlatformType = FireflyRedPacketAPI.PlatformType

export const Conditions = memo(function Conditions({ onClose, statusList, unsatisfied = true, ...props }: Props) {
export const Conditions = memo(function Conditions({ onClose, statusList, ...props }: Props) {
const { classes, cx } = useStyles()
const tokenPayloads = statusList.find((x) => x.type === StrategyType.tokens)?.payload
const tokenPayload = tokenPayloads?.[0]
Expand All @@ -137,9 +136,8 @@ export const Conditions = memo(function Conditions({ onClose, statusList, unsati
.some((x) => (typeof x.result === 'boolean' ? !x.result : !x.result.hasPassed))
const followStatus = statusList.find((x) => x.type === StrategyType.profileFollow)
const followPayload = followStatus?.payload.find((x) => x.platform === PlatformType.twitter)
const followUnsatisfied = followStatus?.result === false

const { data: twitterHandle, isLoading } = useQuery({
const { data: twitterHandle } = useQuery({
queryKey: ['twitter-user', 'by-profile-id', followPayload?.profileId],
queryFn: () => (followPayload?.profileId ? FireflyTwitter.getUserInfoById(followPayload?.profileId) : null),
select: (data) => data?.legacy.screen_name,
Expand All @@ -151,6 +149,20 @@ export const Conditions = memo(function Conditions({ onClose, statusList, unsati
<Trans>Who can claim?</Trans>
</Typography>
<div className={classes.content}>
{followPayload ?
<div className={classes.section}>
<Typography className={classes.sectionTitle}>
{twitterHandle ?
<Trans>
You need to follow{' '}
<Link href={`https://twitter.com/${twitterHandle}`} target="_blank" color="inherit">
@{twitterHandle}
</Link>
</Trans>
: <Trans>You need to follow the creator of the lucky drop.</Trans>}
</Typography>
</div>
: null}
{tokenPayloads?.length ?
<div className={classes.section}>
<Typography className={classes.sectionTitle}>
Expand Down Expand Up @@ -207,27 +219,6 @@ export const Conditions = memo(function Conditions({ onClose, statusList, unsati
</div>
: null}
<div className={classes.results}>
{followUnsatisfied ?
isLoading ?
<Typography className={classes.unsatisfied}>
<LoadingBase size={16} />
</Typography>
: twitterHandle ?
<Typography className={classes.unsatisfied}>
{followPayload ?
<Trans>
You need to follow{' '}
<Link
href={`https://twitter.com/${twitterHandle}`}
target="_blank"
color="inherit">
@{twitterHandle}
</Link>
</Trans>
: <Trans>You need to follow the creator of the lucky drop.</Trans>}
</Typography>
: null
: null}
{walletUnsatisfied ?
<Typography className={classes.unsatisfied}>
<Trans>Your wallet does not meet the eligibility criteria for claiming.</Trans>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ export const RedPacket = memo(function RedPacket({ payload, currentPluginID }: R
{cover ?
<Grow in={showRequirements} timeout={250}>
<Conditions
unsatisfied={unsatisfied}
statusList={claimStrategyStatus?.claimStrategyStatus ?? EMPTY_LIST}
className={classes.conditions}
onClose={() => setShowRequirements(false)}
Expand Down

0 comments on commit f182dd6

Please sign in to comment.