-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
6 changed files
with
129 additions
and
28 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
66 changes: 66 additions & 0 deletions
66
packages/suite/src/components/suite/FormattedNftAmount.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,66 @@ | ||
import { WalletAccountTransaction } from '@wallet-types/index'; | ||
import React from 'react'; | ||
|
||
import styled from 'styled-components'; | ||
import { SignValue } from '@suite-common/suite-types'; | ||
import { HiddenPlaceholder } from './HiddenPlaceholder'; | ||
import { Sign } from './Sign'; | ||
import { TrezorLink } from '@suite-components'; | ||
import { useSelector } from '@suite-hooks/useSelector'; | ||
|
||
const Container = styled.span` | ||
max-width: 100%; | ||
display: flex; | ||
`; | ||
|
||
const Symbol = styled.span` | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
`; | ||
|
||
const StyledTrezorLink = styled(TrezorLink)` | ||
color: ${({ theme }) => theme.TYPE_GREEN}; | ||
text-decoration: underline; | ||
`; | ||
|
||
interface FormattedNftAmountProps { | ||
transfer: WalletAccountTransaction['tokens'][number]; | ||
signValue?: SignValue; | ||
className?: string; | ||
useLink?: boolean; | ||
} | ||
|
||
export const FormattedNftAmount = ({ | ||
transfer, | ||
signValue, | ||
className, | ||
useLink, | ||
}: FormattedNftAmountProps) => { | ||
const id = // use 0 index, haven't found an example where multiTokenValues.length > 1 | ||
transfer.standard === 'ERC1155' && transfer.multiTokenValues?.length | ||
? transfer.multiTokenValues[0].id | ||
: transfer.amount; | ||
|
||
const { selectedAccount } = useSelector(state => state.wallet); | ||
const { network } = selectedAccount; | ||
const explorerUrl = `${network?.explorer.tx.replace('tx', 'nft')}/${transfer.address}/${id}`; | ||
|
||
return ( | ||
<HiddenPlaceholder> | ||
<Container className={className}> | ||
{!!signValue && <Sign value={signValue} />} | ||
|
||
<span>ID </span> | ||
|
||
{useLink ? ( | ||
<StyledTrezorLink href={explorerUrl}>{id}</StyledTrezorLink> | ||
) : ( | ||
<span>{id}</span> | ||
)} | ||
|
||
<Symbol> {transfer.symbol}</Symbol> | ||
</Container> | ||
</HiddenPlaceholder> | ||
); | ||
}; |
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