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

Remove fallbacks for old Nexus versions #796

Merged
merged 1 commit into from
Aug 17, 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 .changelog/796.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove fallbacks for old Nexus versions
18 changes: 1 addition & 17 deletions src/app/components/ContractVerificationIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { COLORS } from '../../../styles/theme/colors'
import Link from '@mui/material/Link'
import Typography from '@mui/material/Typography'
import Skeleton from '@mui/material/Skeleton'
import { Runtime, RuntimeAccount } from '../../../oasis-nexus/api'
import { SearchScope } from '../../../types/searchScope'
import { useGetRuntimeAccountsAddress } from '../../../oasis-nexus/api'
import { RuntimeAccount } from '../../../oasis-nexus/api'

type VerificationStatus = 'verified' | 'unverified'

Expand Down Expand Up @@ -116,17 +114,3 @@ export const VerificationIcon: FC<{ address_eth: string; verified: boolean; noLi
</>
)
}

export const DelayedContractVerificationIcon: FC<{
scope: SearchScope
contractOasisAddress: string
noLink?: boolean | undefined
}> = ({ scope, contractOasisAddress, noLink }) => {
const accountQuery = useGetRuntimeAccountsAddress(
scope.network,
scope.layer as Runtime,
contractOasisAddress,
)

return <ContractVerificationIcon account={accountQuery.data?.data} noLink={noLink} />
}
8 changes: 2 additions & 6 deletions src/app/components/Tokens/TokenDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TokenLink } from './TokenLink'
import { CopyToClipboard } from '../CopyToClipboard'
import { AccountLink } from '../Account/AccountLink'
import { DashboardLink } from '../../pages/ParatimeDashboardPage/DashboardLink'
import { DelayedContractVerificationIcon, VerificationIcon } from '../ContractVerificationIcon'
import { VerificationIcon } from '../ContractVerificationIcon'
import Box from '@mui/material/Box'
import { COLORS } from '../../../styles/theme/colors'
import { TokenTypeTag } from './TokenList'
Expand Down Expand Up @@ -55,11 +55,7 @@ export const TokenDetails: FC<{
</dd>
<dt>{t('contract.verification.title')}</dt>
<dd>
{token.is_verified === undefined ? ( // Workaround for old Nexus versions. TODO: remove when new version of Nexus has been deployed everywhere.
<DelayedContractVerificationIcon scope={token} contractOasisAddress={token.contract_addr} />
) : (
<VerificationIcon address_eth={token.eth_contract_addr} verified={token.is_verified} />
)}
<VerificationIcon address_eth={token.eth_contract_addr} verified={token.is_verified} />
</dd>

<dt>{t(isMobile ? 'tokens.holdersCount_short' : 'tokens.holdersCount')}</dt>
Expand Down
27 changes: 9 additions & 18 deletions src/app/components/Tokens/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { TablePaginationProps } from '../Table/TablePagination'
import { AccountLink } from '../Account/AccountLink'
import { TokenLink } from './TokenLink'
import { CopyToClipboard } from '../CopyToClipboard'
import {
DelayedContractVerificationIcon,
VerificationIcon,
verificationIconBoxHeight,
} from '../ContractVerificationIcon'
import { VerificationIcon, verificationIconBoxHeight } from '../ContractVerificationIcon'
import Box from '@mui/material/Box'
import {
getTokenTypeDescription,
Expand All @@ -30,13 +26,16 @@ type TokensProps = {
pagination: false | TablePaginationProps
}

export const TokenTypeTag: FC<{ tokenType: EvmTokenType; sx?: SxProps }> = ({ tokenType, sx = {} }) => {
export const TokenTypeTag: FC<{ tokenType: EvmTokenType | undefined; sx?: SxProps }> = ({
tokenType,
sx = {},
}) => {
const { t } = useTranslation()
return (
<Box
sx={{
background: tokenBackgroundColor[tokenType],
border: `1px solid ${tokenBorderColor[tokenType]}`,
background: tokenBackgroundColor[tokenType ?? 'missing'],
border: `1px solid ${tokenBorderColor[tokenType ?? 'missing']}`,
display: 'inline-block',
borderRadius: 2,
py: 1,
Expand All @@ -51,7 +50,7 @@ export const TokenTypeTag: FC<{ tokenType: EvmTokenType; sx?: SxProps }> = ({ to
<Typography component="span">{getTokenTypeDescription(t, tokenType)}</Typography>
&nbsp;
<Typography component="span" color={COLORS.grayMedium}>
{t('common.parentheses', { subject: getTokenTypeStrictName(t, tokenType) })}
{t('common.parentheses', { subject: getTokenTypeStrictName(t, tokenType ?? 'missing') })}
</Typography>
</Box>
)
Expand Down Expand Up @@ -120,15 +119,7 @@ export const TokenList = (props: TokensProps) => {
width: '100%',
}}
>
{token.is_verified === undefined ? ( // Workaround for old Nexus versions. TODO: remove when new version of Nexus has been deployed everywhere.
<DelayedContractVerificationIcon
scope={token}
contractOasisAddress={token.contract_addr}
noLink
/>
) : (
<VerificationIcon address_eth={token.eth_contract_addr} verified={token.is_verified} noLink />
)}
<VerificationIcon address_eth={token.eth_contract_addr} verified={token.is_verified} noLink />
</Box>
),
},
Expand Down
64 changes: 2 additions & 62 deletions src/app/components/Tokens/TokenTransfers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import { TokenTransferIcon } from './TokenTransferIcon'
import { RoundedBalance } from '../RoundedBalance'
import { useScreenSize } from '../../hooks/useScreensize'
import { fromBaseUnits, getEthAccountAddressFromBase64 } from '../../utils/helpers'
import Skeleton from '@mui/material/Skeleton'
import { TokenLink } from './TokenLink'
import { PlaceholderLabel } from '../../utils/PlaceholderLabel'
import { useTokenWithBase64Address } from './hooks'
import { TokenTypeTag } from './TokenList'
import { parseEvmEvent } from '../../utils/parseEvmEvent'

Expand All @@ -41,43 +39,6 @@ type TableRuntimeEvent = RuntimeEvent & {
markAsNew?: boolean
}

/**
* This is a wrapper around EventBalance which is able to load the referenced token for extra data
*/
const DelayedEventBalance: FC<{
event: RuntimeEvent
tickerAsLink?: boolean | undefined
}> = ({ event, tickerAsLink }) => {
const { t } = useTranslation()
const { isLoading, isError, token } = useTokenWithBase64Address(event, event.body.address)

if (isLoading) {
return <Skeleton variant="text" />
}
if (isError || !token) {
if (process.env.NODE_ENV !== 'production') {
console.log('Event:', JSON.stringify(event, null, ' '))
throw new Error("Can't identify token for this event! (See console.)")
}
return t('common.missing')
}

return (
<EventBalance
event={{
...event,
evm_token: {
...(event.evm_token ?? {}),
type: token.type,
decimals: token.decimals,
symbol: token.symbol,
},
}}
tickerAsLink={tickerAsLink}
/>
)
}

/**
* This is a wrapper around RoundedBalance which is able to display event balance properly, based on the token type
*/
Expand Down Expand Up @@ -130,19 +91,6 @@ export const EventBalance: FC<{
}
}

const DelayedTokenTransferTokenType: FC<{ event: RuntimeEvent }> = ({ event }) => {
const { t } = useTranslation()
const { isLoading, isError, token } = useTokenWithBase64Address(event, event.body.address)

if (isLoading) {
return <Skeleton variant="text" />
}
if (isError || !token) {
return t('common.missing')
}
return <TokenTypeTag tokenType={token.type} />
}

type TokenTransfersProps = {
transfers?: TableRuntimeEvent[]
/**
Expand Down Expand Up @@ -262,23 +210,15 @@ export const TokenTransfers: FC<TokenTransfersProps> = ({
? [
{
key: 'tokenType',
content: transfer.evm_token?.type ? (
<TokenTypeTag tokenType={transfer.evm_token.type} />
) : (
<DelayedTokenTransferTokenType event={transfer} />
),
content: <TokenTypeTag tokenType={transfer.evm_token!.type} />,
align: TableCellAlign.Center,
},
]
: []),
{
key: 'value',
align: TableCellAlign.Right,
content: transfer.evm_token?.type ? (
<EventBalance event={transfer} tickerAsLink={differentTokens} />
) : (
<DelayedEventBalance event={transfer} tickerAsLink={differentTokens} />
),
content: <EventBalance event={transfer} tickerAsLink={differentTokens} />,
},
],
highlight: transfer.markAsNew,
Expand Down
23 changes: 1 addition & 22 deletions src/app/pages/AccountDetailsPage/AccountTokensCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
getTokenTypeStrictName,
} from '../../../types/tokens'
import { SearchScope } from '../../../types/searchScope'
import Skeleton from '@mui/material/Skeleton'
import { AccountDetailsContext } from './index'
import { getPreciseNumberFormat } from '../../../locales/getPreciseNumberFormat'

Expand All @@ -31,19 +30,6 @@ type AccountTokensCardProps = AccountDetailsContext & {

export const accountTokenContainerId = 'tokens'

export const DelayedContractLink: FC<{ scope: SearchScope; oasisAddress: string }> = ({
scope,
oasisAddress,
}) => {
const { isLoading, account: contract } = useAccount(scope, oasisAddress)

if (isLoading) {
return <Skeleton variant={'text'} />
}

return <ContractLink scope={scope} address={contract?.address_eth ?? oasisAddress} />
}

export const ContractLink: FC<{ scope: SearchScope; address: string }> = ({ scope, address }) => {
return (
<Box sx={{ display: 'flex', alignContent: 'center' }}>
Expand Down Expand Up @@ -85,14 +71,7 @@ export const AccountTokensCard: FC<AccountTokensCardProps> = ({ scope, address,
{
content: (
<LinkableDiv id={item.token_contract_addr_eth ?? item.token_contract_addr}>
{item.token_contract_addr_eth === undefined ? ( // TODO remove temporal workaround when latest Nexus is deployed
<DelayedContractLink scope={scope} oasisAddress={item.token_contract_addr} />
) : (
<ContractLink
scope={scope}
address={item.token_contract_addr_eth ?? item.token_contract_addr}
/>
)}
<ContractLink scope={scope} address={item.token_contract_addr_eth ?? item.token_contract_addr} />
</LinkableDiv>
),
key: 'hash',
Expand Down
8 changes: 2 additions & 6 deletions src/app/pages/TokenDashboardPage/TokenDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useScreenSize } from '../../hooks/useScreensize'
import { useTranslation } from 'react-i18next'
import { AccountLink } from '../../components/Account/AccountLink'
import { CopyToClipboard } from '../../components/CopyToClipboard'
import { DelayedContractVerificationIcon, VerificationIcon } from '../../components/ContractVerificationIcon'
import { VerificationIcon } from '../../components/ContractVerificationIcon'
import { getNameForTicker, Ticker } from '../../../types/ticker'
import { DelayedContractCreatorInfo } from '../../components/Account/ContractCreatorInfo'
import CardContent from '@mui/material/CardContent'
Expand Down Expand Up @@ -51,11 +51,7 @@ export const TokenDetailsCard: FC<{ scope: SearchScope; address: string }> = ({

<dt>{t('contract.verification.title')}</dt>
<dd>
{token.is_verified === undefined ? ( // Workaround for old Nexus versions. TODO: remove when new version of Nexus has been deployed everywhere.
<DelayedContractVerificationIcon scope={token} contractOasisAddress={token.contract_addr} />
) : (
<VerificationIcon address_eth={token.eth_contract_addr} verified={token.is_verified} />
)}
<VerificationIcon address_eth={token.eth_contract_addr} verified={token.is_verified} />
</dd>

<dt>{t('common.type')} </dt>
Expand Down
16 changes: 2 additions & 14 deletions src/app/pages/TokenDashboardPage/TokenTitleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Typography from '@mui/material/Typography'
import { COLORS } from '../../../styles/theme/colors'
import { useTokenInfo } from './hook'
import Skeleton from '@mui/material/Skeleton'
import { DelayedContractVerificationIcon, VerificationIcon } from '../../components/ContractVerificationIcon'
import { VerificationIcon } from '../../components/ContractVerificationIcon'
import { AccountLink } from '../../components/Account/AccountLink'
import Box from '@mui/material/Box'
import { CopyToClipboard } from '../../components/CopyToClipboard'
Expand Down Expand Up @@ -67,19 +67,7 @@ export const TokenTitleCard: FC<{ scope: SearchScope; address: string }> = ({ sc
alignItems: 'center',
}}
>
{token.is_verified === undefined ? ( // Workaround for old Nexus versions. TODO: remove when new version of Nexus has been deployed everywhere.
<DelayedContractVerificationIcon
scope={token}
contractOasisAddress={token.contract_addr}
noLink
/>
) : (
<VerificationIcon
address_eth={token.eth_contract_addr}
verified={token.is_verified}
noLink
/>
)}
<VerificationIcon address_eth={token.eth_contract_addr} verified={token.is_verified} noLink />
<AccountLink scope={token} address={token.eth_contract_addr || token.contract_addr} />
<CopyToClipboard value={token.eth_contract_addr || token.contract_addr} />
</Box>
Expand Down
2 changes: 1 addition & 1 deletion src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const routes: RouteObject[] = [
element: <TokensPage />,
},
{
path: `token/:address`, // This is a temporal workaround, until we have the required dedicated functionality for tokens
path: `token/:address`,
element: <TokenDashboardPage />,
loader: addressParamLoader,
children: [
Expand Down
18 changes: 12 additions & 6 deletions src/types/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@ import { TFunction } from 'i18next'
import { exhaustedTypeWarning } from './errors'
import { COLORS } from '../styles/theme/colors'

export const getTokenTypeDescription = (t: TFunction, tokenType: EvmTokenType): string => {
switch (tokenType) {
export const getTokenTypeDescription = (t: TFunction, tokenType: EvmTokenType | undefined): string => {
switch (tokenType ?? 'missing') {
case 'missing':
return t('common.missing')
case 'ERC20':
return t('common.token')
case 'ERC721':
return t('common.nft')
default:
exhaustedTypeWarning('Unknown token type', tokenType)
exhaustedTypeWarning('Unknown token type', tokenType as any)
return '???'
}
}

export const tokenBackgroundColor: Record<EvmTokenType, string> = {
export const tokenBackgroundColor: Record<EvmTokenType | 'missing', string> = {
missing: COLORS.errorIndicatorBackground,
ERC20: COLORS.brandMedium15,
ERC721: COLORS.pink15,
}

export const tokenBorderColor: Record<EvmTokenType, string> = {
export const tokenBorderColor: Record<EvmTokenType | 'missing', string> = {
missing: COLORS.pink,
ERC20: COLORS.brandMedium,
ERC721: COLORS.pink,
}
Expand All @@ -37,8 +41,10 @@ export const getTokenTypePluralDescription = (t: TFunction, tokenType: EvmTokenT
}
}

export const getTokenTypeStrictName = (t: TFunction, tokenType: EvmTokenType): string => {
export const getTokenTypeStrictName = (t: TFunction, tokenType: EvmTokenType | 'missing'): string => {
switch (tokenType) {
case 'missing':
return t('common.missing')
case 'ERC20':
return t('account.ERC20')
case 'ERC721':
Expand Down