Skip to content

Commit a86835c

Browse files
authored
fix: nft redpacket issues (#12161)
1 parent 3c5eb55 commit a86835c

File tree

19 files changed

+64
-66
lines changed

19 files changed

+64
-66
lines changed

packages/plugins/RedPacket/src/SiteAdaptor/NftRedPacket/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export function NftRedPacket({ payload, currentPluginID }: NftRedPacketProps) {
187187
creator={payload.senderName}
188188
asset={claimedAsset}
189189
collection={collection}
190+
chainId={payload.chainId}
190191
shares={availability.totalAmount}
191192
claimedCount={+availability.claimedAmount}
192193
total={availability.totalAmount}

packages/plugins/RedPacket/src/SiteAdaptor/components/CollectionSelectPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const useStyles = makeStyles()((theme) => ({
7474

7575
export interface CollectionSelectPanelProps extends BoxProps {
7676
chainId?: ChainId
77-
balance: number
77+
balance: string | null | undefined
7878
collection?: Web3Helper.NonFungibleCollectionAll
7979
}
8080

@@ -103,7 +103,7 @@ export function CollectionSelectPanel({
103103
null
104104
: <Typography className={classes.title} component="span">
105105
<Trans>
106-
Balance: <b>{balance ? balance : '0'}</b>
106+
Balance: <b>{balance || 0}</b>
107107
</Trans>
108108
</Typography>}
109109
</div>

packages/plugins/RedPacket/src/SiteAdaptor/components/NftRedPacketEnvelope.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import { NetworkPluginID } from '@masknet/shared-base'
55
import { makeStyles, ShadowRootTooltip, TextOverflowTooltip } from '@masknet/theme'
66
import type { Web3Helper } from '@masknet/web3-helpers'
77
import { useNetworks } from '@masknet/web3-hooks-base'
8-
import { SimpleHashResolveChainId } from '@masknet/web3-providers'
98
import type { SimpleHash } from '@masknet/web3-providers/types'
109
import { isZero, type NonFungibleAsset } from '@masknet/web3-shared-base'
11-
import { ChainId } from '@masknet/web3-shared-evm'
10+
import { type ChainId } from '@masknet/web3-shared-evm'
1211
import { Typography } from '@mui/material'
1312
import type { HTMLProps } from 'react'
1413

@@ -194,6 +193,7 @@ interface Props extends HTMLProps<HTMLDivElement> {
194193
message: string
195194
asset?: NonFungibleAsset<Web3Helper.ChainIdAll, Web3Helper.SchemaTypeAll> | null
196195
collection: SimpleHash.Collection | undefined
196+
chainId: ChainId
197197
shares?: number
198198
/** claimed entities */
199199
claimedCount: number
@@ -212,6 +212,7 @@ export function NftRedPacketEnvelope({
212212
message,
213213
asset,
214214
collection,
215+
chainId,
215216
shares = 1,
216217
claimedCount,
217218
total,
@@ -229,7 +230,6 @@ export function NftRedPacketEnvelope({
229230
const metadata = asset?.metadata
230231

231232
const pluginID = asset?.runtime || NetworkPluginID.PLUGIN_EVM
232-
const chainId = asset?.chainId || SimpleHashResolveChainId(collection?.chain) || ChainId.Mainnet
233233
const networks = useNetworks(pluginID)
234234
const network = networks.find((x) => x.chainId === asset?.chainId)
235235
const assetId = asset?.id ? `#${asset.id}`.replace(/^##/, '#') : ''

packages/plugins/RedPacket/src/SiteAdaptor/components/PreviewNftRedPacket.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { type HTMLProps } from 'react'
21
import { t } from '@lingui/core/macro'
3-
import { type NonFungibleAsset } from '@masknet/web3-shared-base'
4-
import type { FireflyRedPacketAPI, SimpleHash } from '@masknet/web3-providers/types'
52
import type { Web3Helper } from '@masknet/web3-helpers'
3+
import type { FireflyRedPacketAPI, SimpleHash } from '@masknet/web3-providers/types'
4+
import { type NonFungibleAsset } from '@masknet/web3-shared-base'
5+
import type { ChainId } from '@masknet/web3-shared-evm'
6+
import { type HTMLProps } from 'react'
67
import { NftRedPacketEnvelope } from './NftRedPacketEnvelope.js'
78

89
interface Props extends HTMLProps<HTMLDivElement> {
910
theme?: FireflyRedPacketAPI.ThemeGroupSettings
1011
message: string
1112
asset?: NonFungibleAsset<Web3Helper.ChainIdAll, Web3Helper.SchemaTypeAll>
1213
collection: SimpleHash.Collection | undefined
14+
chainId: ChainId
1315
creator: string
1416
totalShares: number
1517
}

packages/plugins/RedPacket/src/SiteAdaptor/hooks/useMyCollectionNfts.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/plugins/RedPacket/src/SiteAdaptor/views/CreateNftRedPacket.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
useEnvironmentContext,
1818
useNativeToken,
1919
useNativeTokenPrice,
20+
useNonFungibleTokenBalance,
2021
useSmartPayChainId,
2122
useWallet,
2223
} from '@masknet/web3-hooks-base'
@@ -31,7 +32,6 @@ import { MessageInput } from '../components/MessageInput.js'
3132
import { NFTCard } from '../components/NFTCard.js'
3233
import { useRedPacket } from '../contexts/RedPacketContext.js'
3334
import { useCreateNFTRedpacketGas } from '../hooks/useCreateNftRedpacketGas.js'
34-
import { useMyCollectionNfts } from '../hooks/useMyCollectionNfts.js'
3535

3636
const useStyles = makeStyles()((theme) => {
3737
return {
@@ -113,11 +113,10 @@ export function CreateNftRedPacket() {
113113
{ chainId },
114114
)
115115

116-
const { data: assets_ = EMPTY_LIST } = useMyCollectionNfts()
117-
118-
const assets = collection?.assets?.length ? collection.assets : assets_
119-
120-
const balance = collection?.balance ?? assets.length
116+
const { data: balance } = useNonFungibleTokenBalance(pluginID, collection?.address, {
117+
account,
118+
chainId,
119+
})
121120
const removeToken = useCallback((token: Web3Helper.NonFungibleAssetAll) => {
122121
setSelectedNfts((list) => list.filter((t) => t.tokenId !== token.tokenId))
123122
}, [])

packages/plugins/RedPacket/src/SiteAdaptor/views/NftRedPacketConfirm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ export function NftRedPacketConfirm() {
261261
totalShares={selectedNfts.length}
262262
asset={selectedNfts[0]}
263263
collection={simplehashCollection}
264+
chainId={chainId}
264265
theme={theme}
265266
/>
266267
</div>

packages/plugins/RedPacket/src/SiteAdaptor/views/SelectCollectibles.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function SelectCollectibles() {
6767
const noChanges = useMemo(() => {
6868
const pendingSet = new Set(pendingNfts.map((x) => [x.chainId, x.address, x.tokenId].join(':').toLowerCase()))
6969
const selectedSet = new Set(selectedNfts.map((x) => [x.chainId, x.address, x.tokenId].join(':').toLowerCase()))
70-
return pendingSet.difference(selectedSet).size === 0
70+
return pendingSet.difference(selectedSet).size === 0 && selectedSet.difference(pendingSet).size === 0
7171
}, [pendingNfts, selectedNfts])
7272

7373
const [pendingTokenCount, setPendingTokenCount] = useState(0)

packages/plugins/RedPacket/src/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export const NFT_DEFAULT_CHAINS = [
5050
ChainId.Arbitrum,
5151
ChainId.Avalanche,
5252
ChainId.Optimism,
53-
ChainId.Base,
5453
]
5554

5655
function createTheme(themeId: string, cover: string): FireflyRedPacketAPI.ThemeGroupSettings {

packages/plugins/RedPacket/src/locale/en-US.po

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)