-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
392 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { isTokenDefinitionKnown, TokenDefinition } from '@suite-common/token-definitions'; | ||
import { isNftMatchesSearch, filterNftTokens } from '@suite-common/wallet-utils'; | ||
import { NetworkSymbol, getNetworkFeatures } from '@suite-common/wallet-config'; | ||
import { Token } from '@trezor/blockchain-link-types/src/blockbook-api'; | ||
|
||
type GetNfts = { | ||
tokens: Token[]; | ||
symbol: NetworkSymbol; | ||
nftDefinitions?: TokenDefinition; | ||
searchQuery?: string; | ||
}; | ||
|
||
export const getNfts = ({ tokens, symbol, nftDefinitions, searchQuery }: GetNfts) => { | ||
// filter out NFT tokens until we implement them | ||
const nfts = filterNftTokens(tokens); | ||
|
||
const hasNftDefinitions = getNetworkFeatures(symbol).includes('nft-definitions'); | ||
|
||
const shownVerified: Token[] = []; | ||
const shownUnverified: Token[] = []; | ||
const hiddenVerified: Token[] = []; | ||
const hiddenUnverified: Token[] = []; | ||
|
||
nfts.forEach(token => { | ||
const isKnown = isTokenDefinitionKnown(nftDefinitions?.data, symbol, token.contract || ''); | ||
const isHidden = nftDefinitions?.hide.includes(token.contract || ''); | ||
const isShown = nftDefinitions?.show.includes(token.contract || ''); | ||
|
||
const query = searchQuery ? searchQuery.trim().toLowerCase() : ''; | ||
|
||
if (searchQuery && !isNftMatchesSearch(token, query)) return; | ||
|
||
const pushToArray = (arrayVerified: Token[], arrayUnverified: Token[]) => { | ||
if (isKnown) { | ||
arrayVerified.push(token); | ||
} else { | ||
arrayUnverified.push(token); | ||
} | ||
}; | ||
|
||
if (isShown) { | ||
pushToArray(shownVerified, shownUnverified); | ||
} else if (hasNftDefinitions && !isKnown) { | ||
pushToArray(hiddenVerified, hiddenUnverified); | ||
} else if (isHidden) { | ||
pushToArray(hiddenVerified, hiddenUnverified); | ||
} else { | ||
pushToArray(shownVerified, shownUnverified); | ||
} | ||
}); | ||
|
||
return { | ||
shownVerified, | ||
shownUnverified, | ||
hiddenVerified, | ||
hiddenUnverified, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Dispatch, SetStateAction, useEffect, useState } from 'react'; | ||
|
||
import { SelectedAccountLoaded } from '@suite-common/wallet-types'; | ||
import { selectNftDefinitions } from '@suite-common/token-definitions'; | ||
import { spacings } from '@trezor/theme'; | ||
import { Row } from '@trezor/components'; | ||
|
||
import { useSelector } from 'src/hooks/suite'; | ||
import { NavigationItem } from 'src/components/suite/layouts/SuiteLayout/Sidebar/NavigationItem'; | ||
import { getNfts } from 'src/utils/wallet/nftUtils'; | ||
import { selectRouteName } from 'src/reducers/suite/routerReducer'; | ||
import { SearchAction } from 'src/components/wallet/SearchAction'; | ||
import { filterNftTokens } from '@suite-common/wallet-utils'; | ||
|
||
interface NftsNavigationProps { | ||
selectedAccount: SelectedAccountLoaded; | ||
searchQuery: string; | ||
setSearchQuery: Dispatch<SetStateAction<string>>; | ||
} | ||
|
||
export const NftsNavigation = ({ | ||
selectedAccount, | ||
searchQuery, | ||
setSearchQuery, | ||
}: NftsNavigationProps) => { | ||
const { account } = selectedAccount; | ||
|
||
const [isExpanded, setExpanded] = useState(false); | ||
|
||
const routeName = useSelector(selectRouteName); | ||
|
||
const nftDefinitions = useSelector(state => | ||
selectNftDefinitions(state, selectedAccount.account.symbol), | ||
); | ||
|
||
const filteredTokens = filterNftTokens(account.tokens || []); | ||
|
||
const nfts = getNfts({ tokens: filteredTokens, symbol: account.symbol, nftDefinitions }); | ||
|
||
useEffect(() => { | ||
setSearchQuery(''); | ||
setExpanded(false); | ||
}, [account.symbol, account.index, account.accountType, setSearchQuery]); | ||
|
||
return ( | ||
<Row alignItems="center" justifyContent="space-between" margin={{ bottom: spacings.md }}> | ||
<Row alignItems="center" gap={spacings.xxs}> | ||
<NavigationItem | ||
nameId="TR_NAV_NFTS" | ||
isActive={routeName === 'wallet-nfts'} | ||
icon="tokens" | ||
goToRoute="wallet-nfts" | ||
preserveParams | ||
iconSize="mediumLarge" | ||
itemsCount={nfts.shownVerified.length || undefined} | ||
isRounded | ||
typographyStyle="hint" | ||
/> | ||
<NavigationItem | ||
nameId="TR_HIDDEN" | ||
isActive={routeName === 'wallet-nfts-hidden'} | ||
icon="hide" | ||
goToRoute="wallet-nfts-hidden" | ||
preserveParams | ||
iconSize="mediumLarge" | ||
itemsCount={nfts.hiddenVerified.length || undefined} | ||
isRounded | ||
typographyStyle="hint" | ||
/> | ||
</Row> | ||
<Row> | ||
<SearchAction | ||
tooltipText="TR_TOKENS_SEARCH_TOOLTIP" | ||
placeholder="TR_SEARCH_TOKENS" | ||
isExpanded={isExpanded} | ||
searchQuery={searchQuery} | ||
setExpanded={setExpanded} | ||
setSearch={setSearchQuery} | ||
onSearch={setSearchQuery} | ||
data-testid="@wallet/accounts/search-icon" | ||
/> | ||
</Row> | ||
</Row> | ||
); | ||
}; |
44 changes: 44 additions & 0 deletions
44
packages/suite/src/views/wallet/nfts/NftsTable/HiddenNftsTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Card, Table } from '@trezor/components'; | ||
import { SelectedAccountLoaded } from '@suite-common/wallet-types'; | ||
import { Translation } from 'src/components/suite'; | ||
Check warning on line 3 in packages/suite/src/views/wallet/nfts/NftsTable/HiddenNftsTable.tsx GitHub Actions / Linting and formatting
|
||
import { filterNftTokens } from '@suite-common/wallet-utils'; | ||
import { selectNftDefinitions } from '@suite-common/token-definitions'; | ||
import NftsRow from './NftsRow'; | ||
Check warning on line 6 in packages/suite/src/views/wallet/nfts/NftsTable/HiddenNftsTable.tsx GitHub Actions / Linting and formatting
|
||
import { useSelector } from 'src/hooks/suite'; | ||
import { getNfts } from 'src/utils/wallet/nftUtils'; | ||
|
||
type NftsTableProps = { | ||
selectedAccount: SelectedAccountLoaded; | ||
searchQuery: string; | ||
}; | ||
|
||
const HiddenNftsTable = ({ selectedAccount, searchQuery }: NftsTableProps) => { | ||
const { account } = selectedAccount; | ||
const nftDefinitions = useSelector(state => selectNftDefinitions(state, account.symbol)); | ||
const filteredTokens = filterNftTokens(account?.tokens || []); | ||
const nfts = getNfts({ tokens: filteredTokens, symbol: account.symbol, nftDefinitions }); | ||
|
||
return ( | ||
<Card paddingType="none" overflow="hidden"> | ||
<Table> | ||
<Table.Header> | ||
<Table.Row> | ||
<Table.Cell> | ||
<Translation id="TR_COLLECTION" /> | ||
</Table.Cell> | ||
<Table.Cell colSpan={2}> | ||
<Translation id="TR_TOKENS" /> | ||
</Table.Cell> | ||
</Table.Row> | ||
</Table.Header> | ||
<Table.Body> | ||
{nfts.hiddenUnverified.map(nft => ( | ||
<NftsRow nft={nft} key={nft.contract} type="ERC721" /> | ||
))} | ||
</Table.Body> | ||
</Table> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default HiddenNftsTable; |
22 changes: 22 additions & 0 deletions
22
packages/suite/src/views/wallet/nfts/NftsTable/NftsRow.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Token } from '@trezor/blockchain-link-types/src/blockbook-api'; | ||
import { Table } from '@trezor/components'; | ||
|
||
import { NftType } from 'src/utils/wallet/nftUtils'; | ||
|
||
type NftsRowProps = { | ||
nft: Token; | ||
type: NftType; | ||
}; | ||
|
||
const NftsRow = ({ nft, type }: NftsRowProps) => { | ||
return ( | ||
<Table.Row> | ||
<Table.Cell>{nft.name}</Table.Cell> | ||
<Table.Cell colSpan={2}> | ||
{nft.ids?.map(id => id.toString()).join(', ') || ''} | ||
</Table.Cell> | ||
</Table.Row> | ||
); | ||
}; | ||
|
||
export default NftsRow; |
59 changes: 59 additions & 0 deletions
59
packages/suite/src/views/wallet/nfts/NftsTable/NftsTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { SelectedAccountLoaded } from '@suite-common/wallet-types'; | ||
import { Card, Column, Table, Text } from '@trezor/components'; | ||
import { selectNftDefinitions } from '@suite-common/token-definitions'; | ||
|
||
import { Translation } from 'src/components/suite/Translation'; | ||
import { useSelector } from 'src/hooks/suite'; | ||
import { getNfts } from 'src/utils/wallet/nftUtils'; | ||
|
||
import NftsRow from './NftsRow'; | ||
import { filterNftTokens } from '@suite-common/wallet-utils'; | ||
import { Token } from '@trezor/blockchain-link-types/src/blockbook-api'; | ||
|
||
type NftsTableProps = { | ||
selectedAccount: SelectedAccountLoaded; | ||
searchQuery: string; | ||
type: 'ERC721' | 'ERC1155'; | ||
}; | ||
|
||
const NftsTable = ({ selectedAccount, searchQuery, type }: NftsTableProps) => { | ||
const { account } = selectedAccount; | ||
const nftDefinitions = useSelector(state => selectNftDefinitions(state, account.symbol)); | ||
const filteredTokens = filterNftTokens(account?.tokens || []); | ||
const nfts = getNfts({ tokens: filteredTokens, symbol: account.symbol, nftDefinitions }); | ||
|
||
const filterNftsByType = (nfts: Token[]) => { | ||
return nfts.filter(nft => nft.type === type); | ||
}; | ||
|
||
const shownNfts = filterNftsByType([...nfts.shownVerified, ...nfts.shownUnverified]); | ||
|
||
return ( | ||
<Column width="100%" alignItems="start" gap={16}> | ||
<Text typographyStyle="titleSmall" align="left"> | ||
{type === 'ERC721' ? 'ERC721' : 'ERC1155'} | ||
</Text> | ||
<Card paddingType="none" overflow="hidden"> | ||
<Table> | ||
<Table.Header> | ||
<Table.Row> | ||
<Table.Cell> | ||
<Translation id="TR_COLLECTION" /> | ||
</Table.Cell> | ||
<Table.Cell colSpan={2}> | ||
<Translation id="TR_TOKENS" /> | ||
</Table.Cell> | ||
</Table.Row> | ||
</Table.Header> | ||
<Table.Body> | ||
{shownNfts.map(nft => ( | ||
<NftsRow nft={nft} key={nft.contract} type="ERC721" /> | ||
))} | ||
</Table.Body> | ||
</Table> | ||
</Card> | ||
</Column> | ||
); | ||
}; | ||
|
||
export default NftsTable; |
Oops, something went wrong.