Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evm tokens section updates #104

Merged
merged 5 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/components/Account/ShowMoreTokensLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const StyledLink = styled(RouterLink)(({ theme }) => ({
color: COLORS.brandDark,
fontWeight: 600,
textDecoration: 'none',
whiteSpace: 'nowrap',
marginLeft: theme.spacing(4),
}))

Expand Down
51 changes: 29 additions & 22 deletions src/app/components/Account/TokenPills.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { useHref } from 'react-router-dom'
import Link from '@mui/material/Link'
import Chip from '@mui/material/Chip'
import Typography from '@mui/material/Typography'
import { ShowMoreTokensLink } from './ShowMoreTokensLink'
Expand All @@ -9,38 +11,43 @@ type TokenPillsProps = {
tokens: Token[]
}

const prioritizedTokensSymbols = ['ROSE', 'WROSE', 'ETH']

export const TokenPills: FC<TokenPillsProps> = ({ tokens }) => {
const { t } = useTranslation()

if (!tokens) {
if (!tokens?.length) {
return <Typography sx={{ opacity: '0.5' }}>{t('account.noTokens')}</Typography>
}

const prioritizedPills = tokens?.filter(
item => item.token_symbol && prioritizedTokensSymbols.includes(item.token_symbol),
)
const numberOfMissingPills = prioritizedTokensSymbols.length - prioritizedPills.length
const additionalPills = numberOfMissingPills
? tokens
.filter(item => !item.token_symbol || !prioritizedTokensSymbols.includes(item.token_symbol))
.slice(0, numberOfMissingPills)
: []
const pills = [...prioritizedPills, ...additionalPills]
const pills = tokens.slice(0, 3)

return (
<>
{pills.map(item => (
<Chip
key={item.token_contract_addr}
sx={{ mr: 2 }}
label={`${item.balance} ${item.token_name}`}
variant="outlined"
color="tertiary"
/>
<Pill key={item.token_contract_addr} pill={item} />
))}

<ShowMoreTokensLink tokens={tokens} pills={pills} />
</>
)
}

type PillProps = {
pill: Token
}

export const Pill: FC<PillProps> = ({ pill }) => {
const href = `${useHref(pill.token_type === 'ERC20' ? 'tokens/erc-20' : 'tokens/erc-721')}#${
pill.token_contract_addr
}`

return (
<Chip
clickable
color="tertiary"
component={Link}
href={href}
key={pill.token_contract_addr}
label={`${pill.balance} ${pill.token_name}`}
sx={{ mr: 2 }}
variant="outlined"
/>
)
}
2 changes: 1 addition & 1 deletion src/app/components/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const Account: FC<AccountProps> = ({ account, roseFiatValue }) => {
</dd>
</>
)}
<dt>{t('account.tokens')}</dt>
<dt>{t('account.evmTokens')}</dt>
<dd>
<TokenPills tokens={account.runtime_evm_balances} />
</dd>
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/Blocks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const Blocks = (props: BlocksProps) => {
]
: []),
],
markAsNew: block.markAsNew,
highlight: block.markAsNew,
}))

return (
Expand Down
12 changes: 6 additions & 6 deletions src/app/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ const backgroundColorAnimation = keyframes`
const backgroundColorAnimationDuration = `${Math.max(500, REFETCH_INTERVAL - 2000)}ms`

type StyledTableRowProps = MuiTableRowProps & {
markAsNew?: boolean
highlight?: boolean
}

const StyledTableRow = styled(TableRow, {
shouldForwardProp: prop => prop !== 'markAsNew',
shouldForwardProp: prop => prop !== 'highlight',
})<StyledTableRowProps>(
({ markAsNew }) => css`
${markAsNew &&
({ highlight }) => css`
${highlight &&
css`
animation-name: ${backgroundColorAnimation};
animation-duration: ${backgroundColorAnimationDuration};
Expand All @@ -71,7 +71,7 @@ type TableCellProps = {
export type TableRowProps = {
key: string
data: TableCellProps[]
markAsNew?: boolean
highlight?: boolean
}

export type TableColProps = {
Expand Down Expand Up @@ -137,7 +137,7 @@ export const Table: FC<TableProps> = ({
<SkeletonTableRows rowsNumber={rowsNumber} columnsNumber={columns.length} />
)}
{rows?.map(row => (
<StyledTableRow key={row.key} markAsNew={row.markAsNew}>
<StyledTableRow key={row.key} highlight={row.highlight}>
{row.data.map((cell, index) => (
<TableCell
key={cell.key}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/Transactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const Transactions: FC<TransactionProps> = ({ isLoading, limit, paginatio
key: 'value',
},
],
markAsNew: transaction.markAsNew,
highlight: transaction.markAsNew,
}))

return (
Expand Down
10 changes: 9 additions & 1 deletion src/app/pages/AccountDetailsPage/TokensCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { useLoaderData } from 'react-router-dom'
import { useLocation } from 'react-router-dom'
import Box from '@mui/material/Box'
import Card from '@mui/material/Card'
import CardHeader from '@mui/material/CardHeader'
import CardContent from '@mui/material/CardContent'
Expand All @@ -18,6 +20,7 @@ type TokensCardProps = {
export const TokensCard: FC<TokensCardProps> = ({ type }) => {
const { t } = useTranslation()
const address = useLoaderData() as string
const locationHash = useLocation().hash.replace('#', '')
const tokenLabel = t(`account.${type}`)
const tokenListLabel = t('account.tokensListTitle', { token: tokenLabel })
const tableColumns = [
Expand All @@ -38,7 +41,11 @@ export const TokensCard: FC<TokensCardProps> = ({ type }) => {
key: 'name',
},
{
content: <CopyToClipboard value={item.token_contract_addr} />,
content: (
<Box id={item.token_contract_addr}>
<CopyToClipboard value={item.token_contract_addr} />
</Box>
),
key: 'hash',
},
{
Expand All @@ -52,6 +59,7 @@ export const TokensCard: FC<TokensCardProps> = ({ type }) => {
key: 'ticker',
},
],
highlight: item.token_contract_addr === locationHash,
}))

return (
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"noTokens": "This account holds no tokens",
"showMore": "+ {{counter}} more",
"title": "Account",
"tokens": "Tokens",
"evmTokens": "EVM tokens",
"tokensListTitle": "{{token}} Tokens",
"transactionsListTitle": "Account Transactions"
},
Expand Down