-
-
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
14 changed files
with
675 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,52 @@ | ||
import { Banner, Column, H3 } from '@trezor/components'; | ||
import { SelectedAccountLoaded } from '@suite-common/wallet-types'; | ||
import NftsTable from './NftsTable/NftsTable'; | ||
import { Translation } from 'src/components/suite'; | ||
|
||
type NftsTableProps = { | ||
selectedAccount: SelectedAccountLoaded; | ||
searchQuery: string; | ||
}; | ||
|
||
const HiddenNfts = ({ selectedAccount, searchQuery }: NftsTableProps) => { | ||
return ( | ||
<Column gap={24} alignItems="stretch"> | ||
<NftsTable | ||
selectedAccount={selectedAccount} | ||
searchQuery={searchQuery} | ||
type="ERC721" | ||
shown={false} | ||
verified={true} | ||
/> | ||
<NftsTable | ||
selectedAccount={selectedAccount} | ||
searchQuery={searchQuery} | ||
type="ERC1155" | ||
shown={false} | ||
verified={true} | ||
/> | ||
<H3> | ||
<Translation id="TR_COLLECTIONS_UNRECOGNIZED_BY_TREZOR" /> | ||
</H3> | ||
<Banner variant="warning" icon> | ||
<Translation id="TR_NFT_UNRECOGNIZED_BY_TREZOR_TOOLTIP" /> | ||
</Banner> | ||
<NftsTable | ||
selectedAccount={selectedAccount} | ||
searchQuery={searchQuery} | ||
type="ERC721" | ||
shown={false} | ||
verified={false} | ||
/> | ||
<NftsTable | ||
selectedAccount={selectedAccount} | ||
searchQuery={searchQuery} | ||
type="ERC1155" | ||
shown={false} | ||
verified={false} | ||
/> | ||
</Column> | ||
); | ||
}; | ||
|
||
export default HiddenNfts; |
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,87 @@ | ||
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 + nfts.shownUnverified.length || undefined | ||
} | ||
isRounded | ||
typographyStyle="hint" | ||
/> | ||
<NavigationItem | ||
nameId="TR_HIDDEN" | ||
isActive={routeName === 'wallet-nfts-hidden'} | ||
icon="hide" | ||
goToRoute="wallet-nfts-hidden" | ||
preserveParams | ||
iconSize="mediumLarge" | ||
itemsCount={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> | ||
); | ||
}; |
Oops, something went wrong.