Skip to content

Commit

Permalink
Merge pull request #542 from oasisprotocol/csillag/follow-api-changes
Browse files Browse the repository at this point in the history
Follow indexer api changes
  • Loading branch information
csillag authored Jun 16, 2023
2 parents 5755458 + 3a3b71f commit 788a7e4
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 70 deletions.
1 change: 1 addition & 0 deletions .changelog/542.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove explorer support for token types dropped by indexer, incl. ERC721
15 changes: 2 additions & 13 deletions src/app/components/Account/ShowMoreTokensLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,15 @@ export const ShowMoreTokensLink: FC<ShowMoreTokensLinkProps> = ({ account, token
EvmTokenType.ERC20,
accountTokenContainerId,
)
const erc721Link = RouteUtils.getAccountTokensRoute(
account,
account.address_eth ?? account.address,
EvmTokenType.ERC721,
accountTokenContainerId,
)

const additionalTokensCounter = tokens.length - pills.length

if (!additionalTokensCounter) {
return null
}

// link to ERC20 tab otherwise if there are only ERC721 tokens not included in pills link to the ERC721
const pillsSymbols = new Set(pills.map(({ token_contract_addr }) => token_contract_addr))
const showMoreItems = tokens.filter(({ token_contract_addr }) => !pillsSymbols.has(token_contract_addr))
const hasERC20 = showMoreItems.some(item => item.token_type === EvmTokenType.ERC20)
const targetShowMoreLink = hasERC20 ? erc20link : erc721Link

return (
<StyledLink to={targetShowMoreLink} color="inherit">
<StyledLink to={erc20link} color="inherit">
{t('account.showMore', { counter: additionalTokensCounter })}
</StyledLink>
)
Expand Down
29 changes: 2 additions & 27 deletions src/app/components/Account/__tests__/ShowMoreTokensLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ const mockedToken2: Token = {
token_decimals: 18,
}

const mockedToken3: Token = {
balance: '0.012345',
token_contract_addr: 'oasis1qrg90d4qlelg5zg4q4sd4y0z8j2lpjpvuspzjly3',
token_name: 'ERC721',
token_symbol: 'ERC721',
token_type: EvmTokenType.ERC721,
token_decimals: 18,
}

const mockedToken4: Token = {
balance: '1123.5',
token_contract_addr: 'oasis1qrg90d4qlelg5zg4q4sd4y0z8j2lpjpvuspzjly4',
Expand All @@ -61,31 +52,15 @@ describe('ShowMoreTokensLink', () => {
renderWithProviders(
<ShowMoreTokensLink
account={mockedAccount}
tokens={[mockedToken1, mockedToken2, mockedToken3, mockedToken4]}
tokens={[mockedToken1, mockedToken2, mockedToken4]}
pills={[mockedToken1]}
/>,
)

expect(screen.getByText('+ 3 more')).toBeInTheDocument()
expect(screen.getByText('+ 2 more')).toBeInTheDocument()
expect(screen.getByRole('link')).toHaveAttribute(
'href',
'/mainnet/emerald/address/oasis1qrvha284gfztn7wwq6z50c86ceu28jp7csqhpx9t/tokens/erc-20#tokens',
)
})

it('should render ERC721 link if there is no ERC20 token', () => {
renderWithProviders(
<ShowMoreTokensLink
account={mockedAccount}
tokens={[mockedToken1, mockedToken2, mockedToken3]}
pills={[mockedToken1, mockedToken2]}
/>,
)

expect(screen.getByText('+ 1 more')).toBeInTheDocument()
expect(screen.getByRole('link')).toHaveAttribute(
'href',
'/mainnet/emerald/address/oasis1qrvha284gfztn7wwq6z50c86ceu28jp7csqhpx9t/tokens/erc-721#tokens',
)
})
})
7 changes: 2 additions & 5 deletions src/app/pages/AccountDetailsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ export const AccountDetailsPage: FC = () => {

const showErc20 = showEmptyAccountDetails || !!account?.tokenBalances[EvmTokenType.ERC20].length
const erc20Link = useHref(`tokens/erc-20#${accountTokenContainerId}`)
const showErc721 = showEmptyAccountDetails || !!account?.tokenBalances[EvmTokenType.ERC721].length
const erc721Link = useHref(`tokens/erc-721#${accountTokenContainerId}`)
const showTxs = showEmptyAccountDetails || showErc20 || showErc721 || !!account?.stats.num_txns
const showTxs = showEmptyAccountDetails || showErc20 || !!account?.stats.num_txns
const txLink = useHref('')

const showDetails = showTxs || showErc20 || showErc721
const showDetails = showTxs || showErc20

return (
<PageLayout>
Expand All @@ -48,7 +46,6 @@ export const AccountDetailsPage: FC = () => {
tabs={[
{ label: t('common.transactions'), to: txLink, visible: showTxs },
{ label: t('account.ERC20'), to: erc20Link, visible: showErc20 },
{ label: t('account.ERC721'), to: erc721Link, visible: showErc721 },
]}
/>
)}
Expand Down
3 changes: 0 additions & 3 deletions src/app/utils/route-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ export abstract class RouteUtils {
) => {
const map: Record<EvmTokenType, string | undefined> = {
ERC20: `${this.getAccountRoute(scope, account)}/tokens/erc-20`,
ERC721: `${this.getAccountRoute(scope, account)}/tokens/erc-721`,
ERC1155: undefined,
OasisSdk: undefined,
}
const tokenRoutes = map[tokenType]
if (!tokenRoutes) throw new Error('Unexpected token type')
Expand Down
1 change: 0 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"emptyTokenList": "This account holds no {{token}} tokens.",
"emptyTransactionList": "There are no transactions on record for this account.",
"ERC20": "ERC-20",
"ERC721": "ERC-721",
"noTokens": "This account holds no tokens",
"showMore": "+ {{counter}} more",
"title": "Account",
Expand Down
3 changes: 0 additions & 3 deletions src/oasis-indexer/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ function wrapWithNetwork<P extends Array<any>, Q>(f: (...args: P) => Q): (net: N

export const groupAccountTokenBalances = (account: Omit<RuntimeAccount, 'tokenBalances'>): RuntimeAccount => {
const tokenBalances: Record<generated.EvmTokenType, generated.RuntimeEvmBalance[]> = {
ERC1155: [],
ERC20: [],
ERC721: [],
OasisSdk: [],
}
account.evm_balances.forEach(balance => {
if (balance.token_type) tokenBalances[balance.token_type].push(balance)
Expand Down
35 changes: 27 additions & 8 deletions src/oasis-indexer/generated/api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ export const routes: RouteObject[] = [
element: <TokensCard type="ERC20" />,
loader: addressParamLoader,
},
{
path: 'tokens/erc-721',
element: <TokensCard type="ERC721" />,
loader: addressParamLoader,
},
],
},
{
Expand All @@ -110,11 +105,6 @@ export const routes: RouteObject[] = [
element: <TokensCard type="ERC20" />,
loader: addressParamLoader,
},
{
path: 'tokens/erc-721',
element: <TokensCard type="ERC721" />,
loader: addressParamLoader,
},
],
},
],
Expand Down

0 comments on commit 788a7e4

Please sign in to comment.