Skip to content

Commit 09b22fc

Browse files
committed
added network icon to collectibles tile, fixed collections filter logic
1 parent 89641b2 commit 09b22fc

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

packages/wallet-widget/src/components/Filter/CollectionsFilter.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ListCardSelect } from '../ListCard/ListCardSelect'
88

99
export const CollectionsFilter = () => {
1010
const { selectedCollectionsObservable, selectedNetworks, selectedWallets, setSelectedCollections } = useSettings()
11+
const selectedCollections = selectedCollectionsObservable.get()
1112

1213
const { data: tokens } = useGetTokenBalancesSummary({
1314
chainIds: selectedNetworks,
@@ -22,6 +23,7 @@ export const CollectionsFilter = () => {
2223
.map(collection => {
2324
return {
2425
contractAddress: collection.contractAddress,
26+
chainId: collection.chainId,
2527
contractInfo: {
2628
name: collection.contractInfo?.name || '',
2729
logoURI: collection.contractInfo?.logoURI || ''
@@ -54,12 +56,17 @@ export const CollectionsFilter = () => {
5456
<ListCardSelect
5557
key={collection.contractAddress}
5658
isSelected={
57-
selectedCollectionsObservable.get().find(c => c.contractAddress === collection.contractAddress) !== undefined ||
58-
collections.length === 1
59+
selectedCollections.find(
60+
c => c.contractAddress === collection.contractAddress && c.chainId === collection.chainId
61+
) !== undefined
5962
}
6063
onClick={collections.length > 1 ? () => setSelectedCollections([collection]) : undefined}
6164
>
62-
<TokenImage src={collection.contractInfo?.logoURI} symbol={collection.contractInfo?.name} />
65+
<TokenImage
66+
src={collection.contractInfo?.logoURI}
67+
symbol={collection.contractInfo?.name}
68+
withNetwork={collection.chainId}
69+
/>
6370
<Text color="primary" fontWeight="medium" variant="normal">
6471
{collection.contractInfo?.name}
6572
</Text>

packages/wallet-widget/src/components/IconWrappers/MediaIconWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const MediaIconWrapper = ({
8787
height: `calc(${widthClassMap[size]} + 2px)`
8888
}}
8989
>
90-
<img src={icon} alt="icon" />
90+
<img src={icon} alt="icon" style={{ backgroundColor: 'lightgray' }} />
9191
</div>
9292
)}
9393
</>

packages/wallet-widget/src/components/SearchLists/CollectiblesList/CollectibleTile.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { useGetTokenMetadata } from '@0xsequence/hooks'
22

33
import { TokenBalanceWithPrice } from '../../../utils'
44
import { CollectibleTileImage } from '../../CollectibleTileImage'
5+
import { NetworkImage } from '@0xsequence/design-system'
6+
7+
const NETWORK_IMAGE_SIZE = '32px'
58

69
interface CollectibleTileProps {
710
balance: TokenBalanceWithPrice
@@ -22,8 +25,18 @@ export const CollectibleTile = ({ balance, onTokenClick }: CollectibleTileProps)
2225
const imageUrl = tokenMetadata?.[0]?.image
2326

2427
return (
25-
<div className="select-none cursor-pointer aspect-square" onClick={onClick}>
28+
<div className="select-none cursor-pointer aspect-square relative" onClick={onClick}>
2629
<CollectibleTileImage imageUrl={imageUrl} />
30+
<NetworkImage
31+
chainId={balance.chainId}
32+
className={`absolute z-1`}
33+
style={{
34+
width: NETWORK_IMAGE_SIZE,
35+
height: NETWORK_IMAGE_SIZE,
36+
right: '2px',
37+
bottom: '2px'
38+
}}
39+
/>
2740
</div>
2841
)
2942
}

packages/wallet-widget/src/hooks/useSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface MutableObservable<T> extends Observable<T> {
1010

1111
export interface SettingsCollection {
1212
contractAddress: string
13+
chainId: number
1314
contractInfo: {
1415
name: string
1516
logoURI: string

packages/wallet-widget/src/views/Home/IntegratedWallet/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,18 @@ export const IntegratedWallet = () => {
8585
const coinBalancesUnordered =
8686
tokenBalancesData?.filter(b => b.contractType === 'ERC20' || compareAddress(b.contractAddress, ethers.ZeroAddress)) || []
8787

88+
const isSingleCollectionSelected = selectedCollections.length === 1
89+
8890
const collectibleBalancesUnordered =
89-
tokenBalancesData?.filter(b => b.contractType === 'ERC721' || b.contractType === 'ERC1155') || []
91+
tokenBalancesData?.filter(token => {
92+
if (token.contractType !== 'ERC721' && token.contractType !== 'ERC1155') {
93+
return false
94+
}
95+
if (isSingleCollectionSelected) {
96+
return token.chainId === selectedCollections[0].chainId
97+
}
98+
return true
99+
}) || []
90100

91101
const { data: coinPrices = [], isPending: isCoinPricesPending } = useGetCoinPrices(
92102
coinBalancesUnordered.map(token => ({

packages/wallet-widget/src/views/Search/SearchCollectibles.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ export const SearchCollectibles = () => {
2525
}
2626
})
2727

28+
const isSingleCollectionSelected = selectedCollections.length === 1
29+
30+
const collectibleBalancesFiltered = tokenBalancesData.filter(token => {
31+
if (isSingleCollectionSelected) {
32+
return token.chainId === selectedCollections[0].chainId
33+
}
34+
return true
35+
})
36+
2837
const onHandleCollectibleClick = (balance: TokenBalanceWithPrice) => {
2938
setNavigation({
3039
location: 'collectible-details',
@@ -40,7 +49,7 @@ export const SearchCollectibles = () => {
4049
return (
4150
<div className="p-4 pt-2 w-full">
4251
<CollectiblesList
43-
tokenBalancesData={tokenBalancesData}
52+
tokenBalancesData={collectibleBalancesFiltered}
4453
isPendingTokenBalances={isPendingTokenBalances}
4554
onTokenClick={onHandleCollectibleClick}
4655
enableFilters={true}

0 commit comments

Comments
 (0)