diff --git a/packages/plugins/RedPacket/src/SiteAdaptor/Conditions/index.tsx b/packages/plugins/RedPacket/src/SiteAdaptor/Conditions/index.tsx index 5c5e6385f0c..eafdbbb7b97 100644 --- a/packages/plugins/RedPacket/src/SiteAdaptor/Conditions/index.tsx +++ b/packages/plugins/RedPacket/src/SiteAdaptor/Conditions/index.tsx @@ -1,11 +1,15 @@ -import { Icons } from '@masknet/icons' -import { MaskColors, makeStyles } from '@masknet/theme' -import { FireflyRedPacketAPI } from '@masknet/web3-providers/types' -import { Box, IconButton, Typography, type BoxProps } from '@mui/material' import { Trans } from '@lingui/react/macro' +import { Icons } from '@masknet/icons' +import { WalletRelatedTypes } from '@masknet/plugin-redpacket' import { TokenIcon } from '@masknet/shared' -import { isZero } from '@masknet/web3-shared-base' import { NetworkPluginID } from '@masknet/shared-base' +import { LoadingBase, 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' +import { Box, IconButton, Link, Typography, type BoxProps } from '@mui/material' +import { useQuery } from '@tanstack/react-query' +import { memo } from 'react' import { formatTokenAmount } from '../helpers/formatTokenAmount.js' const useStyles = makeStyles()((theme, _, refs) => ({ @@ -68,7 +72,6 @@ const useStyles = makeStyles()((theme, _, refs) => ({ gap: theme.spacing(1), [`& .${refs.assetName}`]: { lineHeight: '18px', - height: 36, }, }, asset: { @@ -93,7 +96,7 @@ const useStyles = makeStyles()((theme, _, refs) => ({ height: 24, marginRight: '0px !important', }, - unsatisfied: { + results: { position: 'absolute', left: 12, bottom: 12, @@ -101,6 +104,11 @@ const useStyles = makeStyles()((theme, _, refs) => ({ backgroundColor: 'rgba(255, 53, 69, 0.2)', borderRadius: 4, padding: 6, + '&:empty': { + display: 'none', + }, + }, + unsatisfied: { color: theme.palette.maskColor.white, fontSize: 12, fontWeight: 700, @@ -114,13 +122,28 @@ interface Props extends BoxProps { onClose?(): void } -export function Conditions({ onClose, statusList, unsatisfied = true, ...props }: Props) { +const StrategyType = FireflyRedPacketAPI.StrategyType +const PlatformType = FireflyRedPacketAPI.PlatformType + +export const Conditions = memo(function Conditions({ onClose, statusList, unsatisfied = true, ...props }: Props) { const { classes, cx } = useStyles() - const tokenPayloads = statusList.find((x) => x.type === FireflyRedPacketAPI.StrategyType.tokens)?.payload + const tokenPayloads = statusList.find((x) => x.type === StrategyType.tokens)?.payload const tokenPayload = tokenPayloads?.[0] const quantity = tokenPayload ? formatTokenAmount(tokenPayload.amount, tokenPayload.decimals) : '' - const collectionPayloads = statusList.find((x) => x.type === FireflyRedPacketAPI.StrategyType.nftOwned)?.payload + const collectionPayloads = statusList.find((x) => x.type === StrategyType.nftOwned)?.payload + const walletUnsatisfied = statusList + .filter((x) => WalletRelatedTypes.includes(x.type)) + .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({ + queryKey: ['twitter-user', 'by-profile-id', followPayload?.profileId], + queryFn: () => (followPayload?.profileId ? FireflyTwitter.getUserInfoById(followPayload?.profileId) : null), + select: (data) => data?.legacy.screen_name, + }) return ( @@ -183,15 +206,38 @@ export function Conditions({ onClose, statusList, unsatisfied = true, ...props } : null} - {unsatisfied ? - - Your wallet does not meet the eligibility criteria for claiming. - - : null} +
+ {followUnsatisfied ? + isLoading ? + + + + : twitterHandle ? + + {followPayload ? + + You need to follow{' '} + + @{twitterHandle} + + + : You need to follow the creator of the lucky drop.} + + : null + : null} + {walletUnsatisfied ? + + Your wallet does not meet the eligibility criteria for claiming. + + : null} +
onClose?.()} aria-label="Close">
) -} +}) diff --git a/packages/plugins/RedPacket/src/SiteAdaptor/SolanaRedPacket/SolanaRedPacketFrame.tsx b/packages/plugins/RedPacket/src/SiteAdaptor/SolanaRedPacket/SolanaRedPacketFrame.tsx index 02d58a7be26..f201ec17b13 100644 --- a/packages/plugins/RedPacket/src/SiteAdaptor/SolanaRedPacket/SolanaRedPacketFrame.tsx +++ b/packages/plugins/RedPacket/src/SiteAdaptor/SolanaRedPacket/SolanaRedPacketFrame.tsx @@ -15,7 +15,12 @@ export function SolanaRedPacketFrame({ payload }: Omit@", ["twitterHandle"], ""], + "ty2gt9": ["You need to follow the creator of the lucky drop."], "aFJrEy": ["You need to hold any of the following NFTs in your wallet."], "0lBTmP": ["You need to hold any of the following tokens."], "WKG5E8": ["You need to hold at least ", ["quantity"], " of any of the following tokens."], diff --git a/packages/plugins/RedPacket/src/locale/en-US.po b/packages/plugins/RedPacket/src/locale/en-US.po index 64d449b549f..0131c1ca98a 100644 --- a/packages/plugins/RedPacket/src/locale/en-US.po +++ b/packages/plugins/RedPacket/src/locale/en-US.po @@ -987,6 +987,14 @@ msgstr "" msgid "You haven't created any NFT lucky drop yet. Try to create one and share fortune with your friends." msgstr "" +#: src/SiteAdaptor/Conditions/index.tsx +msgid "You need to follow <0>@{twitterHandle}" +msgstr "" + +#: src/SiteAdaptor/Conditions/index.tsx +msgid "You need to follow the creator of the lucky drop." +msgstr "" + #: src/SiteAdaptor/Conditions/index.tsx msgid "You need to hold any of the following NFTs in your wallet." msgstr "" diff --git a/packages/plugins/RedPacket/src/locale/ja-JP.json b/packages/plugins/RedPacket/src/locale/ja-JP.json index 07e67b58b1b..c212d23e81f 100644 --- a/packages/plugins/RedPacket/src/locale/ja-JP.json +++ b/packages/plugins/RedPacket/src/locale/ja-JP.json @@ -303,6 +303,8 @@ "zEZe86": [ "You haven't created any NFT lucky drop yet. Try to create one and share fortune with your friends." ], + "Jnjbl3": ["You need to follow <0>@", ["twitterHandle"], ""], + "ty2gt9": ["You need to follow the creator of the lucky drop."], "aFJrEy": ["You need to hold any of the following NFTs in your wallet."], "0lBTmP": ["You need to hold any of the following tokens."], "WKG5E8": ["You need to hold at least ", ["quantity"], " of any of the following tokens."], diff --git a/packages/plugins/RedPacket/src/locale/ja-JP.po b/packages/plugins/RedPacket/src/locale/ja-JP.po index c4b7e33646f..53468023157 100644 --- a/packages/plugins/RedPacket/src/locale/ja-JP.po +++ b/packages/plugins/RedPacket/src/locale/ja-JP.po @@ -992,6 +992,14 @@ msgstr "" msgid "You haven't created any NFT lucky drop yet. Try to create one and share fortune with your friends." msgstr "" +#: src/SiteAdaptor/Conditions/index.tsx +msgid "You need to follow <0>@{twitterHandle}" +msgstr "" + +#: src/SiteAdaptor/Conditions/index.tsx +msgid "You need to follow the creator of the lucky drop." +msgstr "" + #: src/SiteAdaptor/Conditions/index.tsx msgid "You need to hold any of the following NFTs in your wallet." msgstr "" diff --git a/packages/plugins/RedPacket/src/locale/ko-KR.json b/packages/plugins/RedPacket/src/locale/ko-KR.json index 9e620c79b0b..0dc158c6b27 100644 --- a/packages/plugins/RedPacket/src/locale/ko-KR.json +++ b/packages/plugins/RedPacket/src/locale/ko-KR.json @@ -302,6 +302,8 @@ "zEZe86": [ "You haven't created any NFT lucky drop yet. Try to create one and share fortune with your friends." ], + "Jnjbl3": ["You need to follow <0>@", ["twitterHandle"], ""], + "ty2gt9": ["You need to follow the creator of the lucky drop."], "aFJrEy": ["You need to hold any of the following NFTs in your wallet."], "0lBTmP": ["You need to hold any of the following tokens."], "WKG5E8": ["You need to hold at least ", ["quantity"], " of any of the following tokens."], diff --git a/packages/plugins/RedPacket/src/locale/ko-KR.po b/packages/plugins/RedPacket/src/locale/ko-KR.po index bec1d736dc2..63759596480 100644 --- a/packages/plugins/RedPacket/src/locale/ko-KR.po +++ b/packages/plugins/RedPacket/src/locale/ko-KR.po @@ -992,6 +992,14 @@ msgstr "" msgid "You haven't created any NFT lucky drop yet. Try to create one and share fortune with your friends." msgstr "" +#: src/SiteAdaptor/Conditions/index.tsx +msgid "You need to follow <0>@{twitterHandle}" +msgstr "" + +#: src/SiteAdaptor/Conditions/index.tsx +msgid "You need to follow the creator of the lucky drop." +msgstr "" + #: src/SiteAdaptor/Conditions/index.tsx msgid "You need to hold any of the following NFTs in your wallet." msgstr "" diff --git a/packages/plugins/RedPacket/src/locale/zh-CN.json b/packages/plugins/RedPacket/src/locale/zh-CN.json index 95b9f82c54d..784e6105d8e 100644 --- a/packages/plugins/RedPacket/src/locale/zh-CN.json +++ b/packages/plugins/RedPacket/src/locale/zh-CN.json @@ -302,6 +302,8 @@ "zEZe86": [ "You haven't created any NFT lucky drop yet. Try to create one and share fortune with your friends." ], + "Jnjbl3": ["You need to follow <0>@", ["twitterHandle"], ""], + "ty2gt9": ["You need to follow the creator of the lucky drop."], "aFJrEy": ["You need to hold any of the following NFTs in your wallet."], "0lBTmP": ["You need to hold any of the following tokens."], "WKG5E8": ["You need to hold at least ", ["quantity"], " of any of the following tokens."], diff --git a/packages/plugins/RedPacket/src/locale/zh-CN.po b/packages/plugins/RedPacket/src/locale/zh-CN.po index 4ddc01d7103..5734913000b 100644 --- a/packages/plugins/RedPacket/src/locale/zh-CN.po +++ b/packages/plugins/RedPacket/src/locale/zh-CN.po @@ -992,6 +992,14 @@ msgstr "" msgid "You haven't created any NFT lucky drop yet. Try to create one and share fortune with your friends." msgstr "" +#: src/SiteAdaptor/Conditions/index.tsx +msgid "You need to follow <0>@{twitterHandle}" +msgstr "" + +#: src/SiteAdaptor/Conditions/index.tsx +msgid "You need to follow the creator of the lucky drop." +msgstr "" + #: src/SiteAdaptor/Conditions/index.tsx msgid "You need to hold any of the following NFTs in your wallet." msgstr "" diff --git a/packages/plugins/RedPacket/src/locale/zh-TW.json b/packages/plugins/RedPacket/src/locale/zh-TW.json index 91a81b334b3..6f179754de6 100644 --- a/packages/plugins/RedPacket/src/locale/zh-TW.json +++ b/packages/plugins/RedPacket/src/locale/zh-TW.json @@ -302,6 +302,8 @@ "zEZe86": [ "You haven't created any NFT lucky drop yet. Try to create one and share fortune with your friends." ], + "Jnjbl3": ["You need to follow <0>@", ["twitterHandle"], ""], + "ty2gt9": ["You need to follow the creator of the lucky drop."], "aFJrEy": ["You need to hold any of the following NFTs in your wallet."], "0lBTmP": ["You need to hold any of the following tokens."], "WKG5E8": ["You need to hold at least ", ["quantity"], " of any of the following tokens."], diff --git a/packages/plugins/RedPacket/src/locale/zh-TW.po b/packages/plugins/RedPacket/src/locale/zh-TW.po index f315e9af0cd..e34414b113c 100644 --- a/packages/plugins/RedPacket/src/locale/zh-TW.po +++ b/packages/plugins/RedPacket/src/locale/zh-TW.po @@ -992,6 +992,14 @@ msgstr "" msgid "You haven't created any NFT lucky drop yet. Try to create one and share fortune with your friends." msgstr "" +#: src/SiteAdaptor/Conditions/index.tsx +msgid "You need to follow <0>@{twitterHandle}" +msgstr "" + +#: src/SiteAdaptor/Conditions/index.tsx +msgid "You need to follow the creator of the lucky drop." +msgstr "" + #: src/SiteAdaptor/Conditions/index.tsx msgid "You need to hold any of the following NFTs in your wallet." msgstr ""