-
-
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
462 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,60 @@ | ||
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 type NftType = 'ERC721' | 'ERC1155'; | ||
|
||
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> | ||
); | ||
}; |
58 changes: 58 additions & 0 deletions
58
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,58 @@ | ||
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, NftType } from 'src/utils/wallet/nftUtils'; | ||
import { getNetwork } from '@suite-common/wallet-config'; | ||
|
||
type NftsTableProps = { | ||
selectedAccount: SelectedAccountLoaded; | ||
searchQuery: string; | ||
type?: NftType; | ||
verified?: boolean; | ||
}; | ||
|
||
const HiddenNftsTable = ({ selectedAccount, searchQuery, type, verified }: NftsTableProps) => { | ||
const { account } = selectedAccount; | ||
const network = getNetwork(account.symbol); | ||
const nftDefinitions = useSelector(state => selectNftDefinitions(state, account.symbol)); | ||
const filteredTokens = filterNftTokens(account?.tokens || []); | ||
const nfts = getNfts({ tokens: filteredTokens, symbol: account.symbol, nftDefinitions }); | ||
|
||
const hiddenNfts = verified | ||
? nfts.hiddenVerified | ||
: [...nfts.hiddenVerified, ...nfts.hiddenUnverified]; | ||
|
||
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> | ||
{hiddenNfts.map(nft => ( | ||
<NftsRow | ||
nft={nft} | ||
key={nft.contract} | ||
type="ERC721" | ||
hidden | ||
network={network} | ||
/> | ||
))} | ||
</Table.Body> | ||
</Table> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default HiddenNftsTable; |
74 changes: 74 additions & 0 deletions
74
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,74 @@ | ||
import { Network } from '@suite-common/wallet-config'; | ||
import { DefinitionType, tokenDefinitionsActions } from '@suite-common/token-definitions'; | ||
import { TokenManagementAction } from '@suite-common/token-definitions'; | ||
import { Token } from '@trezor/blockchain-link-types/src/blockbook-api'; | ||
import { Button, Table } from '@trezor/components'; | ||
import { Translation } from 'src/components/suite'; | ||
|
||
import { NftType } from 'src/utils/wallet/nftUtils'; | ||
|
||
import { useDispatch } from 'src/hooks/suite'; | ||
|
||
type NftsRowProps = { | ||
nft: Token; | ||
type: NftType; | ||
hidden?: boolean; | ||
network: Network; | ||
}; | ||
|
||
const NftsRow = ({ nft, type, hidden, network }: NftsRowProps) => { | ||
const dispatch = useDispatch(); | ||
|
||
return ( | ||
<Table.Row> | ||
<Table.Cell colSpan={1}>{nft.name}</Table.Cell> | ||
<Table.Cell align="left"> | ||
{(type === 'ERC721' && nft.ids?.map(id => id.toString()).join(', ')) || ''} | ||
{(type === 'ERC1155' && | ||
nft.multiTokenValues?.map(value => value.id?.toString()).join(', ')) || | ||
''} | ||
</Table.Cell> | ||
<Table.Cell colSpan={1} align="right"> | ||
{hidden ? ( | ||
<Button | ||
icon="show" | ||
onClick={() => { | ||
dispatch( | ||
tokenDefinitionsActions.setTokenStatus({ | ||
networkSymbol: network.symbol, | ||
contractAddress: nft.contract || '', | ||
status: TokenManagementAction.SHOW, | ||
type: DefinitionType.NFT, | ||
}), | ||
); | ||
}} | ||
variant="tertiary" | ||
size="small" | ||
> | ||
<Translation id="TR_UNHIDE_TOKEN" /> | ||
</Button> | ||
) : ( | ||
<Button | ||
icon="eyeSlash" | ||
onClick={() => { | ||
dispatch( | ||
tokenDefinitionsActions.setTokenStatus({ | ||
networkSymbol: network.symbol, | ||
contractAddress: nft.contract || '', | ||
status: TokenManagementAction.HIDE, | ||
type: DefinitionType.NFT, | ||
}), | ||
); | ||
}} | ||
variant="tertiary" | ||
size="small" | ||
> | ||
<Translation id="TR_HIDE_TOKEN" /> | ||
</Button> | ||
)} | ||
</Table.Cell> | ||
</Table.Row> | ||
); | ||
}; | ||
|
||
export default NftsRow; |
Oops, something went wrong.