Skip to content

Commit

Permalink
fixup! fixup! refactor: select nfts
Browse files Browse the repository at this point in the history
  • Loading branch information
swkatmask committed Jan 3, 2025
1 parent e58eb60 commit 904493d
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 928 deletions.
2 changes: 1 addition & 1 deletion packages/icons/general/Clear.dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/icons/general/Clear.light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions packages/icons/icon-generated-as-jsx.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions packages/plugins/RedPacket/src/SiteAdaptor/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { History } from './views/History.js'
import { HistoryDetail } from './views/HistoryDetail.js'
import { NftHistory } from './views/NftHistory.js'
import { NftRedPacketConfirm } from './views/NftRedPacketConfirm.js'
import { SelectNft } from './views/SelectNft.js'
import { SelectCollectibles } from './views/SelectCollectibles.js'

export function RedPacketRoutes() {
Expand All @@ -19,7 +18,6 @@ export function RedPacketRoutes() {
<Route path={RoutePaths.CreateNftRedPacket} element={<CreateNftRedPacket />} />
</Route>
<Route path={RoutePaths.CustomCover} element={<CustomCover />} />
<Route path={RoutePaths.SelectNft} element={<SelectNft />} />
<Route path={RoutePaths.SelectCollectibles} element={<SelectCollectibles />} />
<Route path={RoutePaths.History}>
<Route index element={<History />} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Icons } from '@masknet/icons'
import { RoutePaths } from '@masknet/plugin-redpacket'
import { TokenIcon } from '@masknet/shared'
import { makeStyles } from '@masknet/theme'
import type { Web3Helper } from '@masknet/web3-helpers'
import { useWeb3Utils } from '@masknet/web3-hooks-base'
import { SourceType, type NonFungibleCollection } from '@masknet/web3-shared-base'
import { ChainId, type SchemaType } from '@masknet/web3-shared-evm'
import { SourceType } from '@masknet/web3-shared-base'
import { ChainId } from '@masknet/web3-shared-evm'
import { Box, Typography, type BoxProps } from '@mui/material'
import { useNavigate } from 'react-router-dom'

Expand Down Expand Up @@ -73,13 +74,11 @@ const useStyles = makeStyles()((theme) => ({

export interface CollectionSelectPanelProps extends BoxProps {
chainId?: ChainId
onContractChange: (contract: NonFungibleCollection<ChainId, SchemaType>) => void
balance: number
collection: NonFungibleCollection<ChainId, SchemaType> | null | undefined
collection?: Web3Helper.NonFungibleCollectionAll
}

export function CollectionSelectPanel({
onContractChange,
collection,
chainId = ChainId.Mainnet,
balance,
Expand Down
78 changes: 78 additions & 0 deletions packages/plugins/RedPacket/src/SiteAdaptor/components/NFTCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Icons } from '@masknet/icons'
import { AssetPreviewer } from '@masknet/shared'
import { makeStyles } from '@masknet/theme'
import type { Web3Helper } from '@masknet/web3-helpers'
import { formatTokenId } from '@masknet/web3-shared-evm'
import { Typography } from '@mui/material'
import { memo } from 'react'

const useStyles = makeStyles()((theme) => {
return {
removeButton: {
position: 'absolute',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
top: 3,
right: 3,
overflow: 'hidden',
cursor: 'pointer',
color: 'rgba(255, 53, 69, 1)',
},
fallbackImage: {
minHeight: '0 !important',
maxWidth: 'none',
width: 64,
height: 64,
},
preview: {
height: 'auto',
aspectRatio: '1 / 1',
borderRadius: 8,
overflow: 'hidden',
},
card: {
width: 86,
position: 'relative',
borderRadius: 8,
overflow: 'hidden',
backgroundColor: theme.palette.maskColor.input,
},
cardName: {
height: 24,
fontSize: 12,
fontWeight: 700,
color: theme.palette.maskColor.main,
padding: theme.spacing(0.5),
boxSizing: 'border-box',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
},
}
})

interface NFTCardProps {
token: Web3Helper.NonFungibleAssetAll
onRemove: (token: Web3Helper.NonFungibleAssetAll) => void
}

export const NFTCard = memo(function NFTCard(props: NFTCardProps) {
const { token, onRemove } = props
const { classes } = useStyles()
return (
<div className={classes.card}>
<AssetPreviewer
url={token.metadata?.mediaURL || token.metadata?.imageURL}
classes={{
fallbackImage: classes.fallbackImage,
root: classes.preview,
}}
/>
<Typography className={classes.cardName} color="textSecondary">
{formatTokenId(token.tokenId, 2)}
</Typography>
<Icons.Clear size={20} className={classes.removeButton} onClick={() => onRemove(token)} />
</div>
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { DURATION, PRESET_THEMES, RED_PACKET_DEFAULT_SHARES } from '../../constants.js'
import { NFTSelectOption, type OrderedERC721Token } from '../../types.js'
import type { RedPacketSettings } from '../hooks/useCreateCallback.js'
import type { Web3Helper } from '@masknet/web3-helpers'

export enum ConditionType {
Crypto = 'Crypto',
Expand Down Expand Up @@ -61,14 +62,14 @@ interface RedPacketContextOptions {
// NFT
nftGasOption: GasConfig | undefined
setNftGasOption: Dispatch<SetStateAction<GasConfig | undefined>>
selectedNfts: OrderedERC721Token[]
setSelectedNfts: Dispatch<SetStateAction<OrderedERC721Token[]>>
selectedNfts: Web3Helper.NonFungibleAssetAll[]
setSelectedNfts: Dispatch<SetStateAction<Web3Helper.NonFungibleAssetAll[]>>
myNfts: OrderedERC721Token[]
setMyNfts: Dispatch<SetStateAction<OrderedERC721Token[]>>
selectOption: NFTSelectOption | undefined
setSelectOption: Dispatch<SetStateAction<NFTSelectOption>>
collection: NonFungibleCollection<ChainId, SchemaType> | undefined
setCollection: Dispatch<SetStateAction<NonFungibleCollection<ChainId, SchemaType> | undefined>>
collection: Web3Helper.NonFungibleCollectionAll | undefined
setCollection: Dispatch<SetStateAction<Web3Helper.NonFungibleCollectionAll | undefined>>
}
export const RedPacketContext = createContext<RedPacketContextOptions>({
gasOption: undefined,
Expand Down Expand Up @@ -165,7 +166,7 @@ export const RedPacketProvider = memo(function RedPacketProvider({ children }: P

// NFT
const [nftGasOption, setNftGasOption] = useState<GasConfig>()
const [selectedNfts, setSelectedNfts] = useState<OrderedERC721Token[]>([])
const [selectedNfts, setSelectedNfts] = useState<Web3Helper.NonFungibleAssetAll[]>([])
const [myNfts, setMyNfts] = useState<OrderedERC721Token[]>([])
const [selectOption, setSelectOption] = useState<NFTSelectOption>(NFTSelectOption.Partial)
const [collection, setCollection] = useState<NonFungibleCollection<ChainId, SchemaType>>()
Expand Down
Loading

0 comments on commit 904493d

Please sign in to comment.