Skip to content
Open
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
10 changes: 5 additions & 5 deletions src/frontend/account/AccountDetail/useAccountDetailHook.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useState } from 'react'
import { api, PATHS } from '../../api'
import { Account, AccountType, ContractType, Token, Transaction, TransactionSearchType } from '../../../types'
import { BigNumberish, utils } from 'ethers'
import { BigNumberish, formatUnits } from 'ethers'

interface detailProps {
id: string
Expand Down Expand Up @@ -83,12 +83,12 @@ export const useAccountDetailHook = ({ id, txType }: detailProps): AccountDetail
(accounts && accounts.length > 0 && accounts[0].accountId)
) {
const { tokens } = await getToken()
if (tokens.length > 0) {
if (tokens && tokens.length > 0) {
tokens.forEach(
(item: { contractType: ContractType; contractInfo: { decimals: string }; balance: BigNumberish }) => {
(item: { contractType: ContractType; contractInfo: { decimals: string } | null; balance: BigNumberish }) => {
if (item.contractType === ContractType.ERC_20) {
const decimalsValue = item.contractInfo.decimals ? parseInt(item.contractInfo.decimals) : 18
item.balance = utils.formatUnits(item.balance, decimalsValue)
const decimalsValue = item.contractInfo?.decimals ? parseInt(item.contractInfo.decimals) : 18
item.balance = formatUnits(item.balance, decimalsValue)
}
}
)
Expand Down
9 changes: 7 additions & 2 deletions src/frontend/account/TokenDropdown/TokenDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ export const TokenDropdown: React.FC<TokenDropdownProps> = (props) => {
<input placeholder="Search for Token Name" className={styles.search} ref={inputRef} />
<div className={styles.item}>
<div className={styles.label}>
ERC-20 Tokens <span>(1)</span>
ERC-20 Tokens <span>({tokens.length})</span>
</div>
<SortButton isUp={isSortUp} onSort={() => setIsSortUp(!isSortUp)} />
</div>
{
tokens && tokens.length > 0 ? (
tokens?.map((row, index) => (
<MenuItem key={index} label={row.balance} label2={row?.contractInfo.name} className={styles.menuItem} />
<MenuItem
key={index}
label={row.balance}
label2={row?.contractInfo?.name || row.contractAddress}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Ensure that row.contractInfo is not null before accessing name to avoid potential runtime errors if contractInfo is null. This prevents possible crashes when rendering the dropdown. [possible issue, importance: 7]

Suggested change
label2={row?.contractInfo?.name || row.contractAddress}
label2={row?.contractInfo && row.contractInfo.name ? row.contractInfo.name : row.contractAddress}

className={styles.menuItem}
/>
))
) : (
<div className={styles.empty}>No Tokens Found!</div>
Expand Down
14 changes: 5 additions & 9 deletions src/frontend/token/Token.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { useRouter } from 'next/router'
import { utils } from 'ethers'
import { formatUnits } from 'ethers'

import { AnchorLink, Button, ContentLayout, CopyButton, Spacer, Tab, Table, Pagination } from '../components'
import { DetailCard } from '../account/DetailCard'
Expand Down Expand Up @@ -59,8 +59,7 @@ export const Token: React.FC = () => {
{val
? transactionType === TransactionSearchType.ERC_721
? val
: utils
.formatUnits(
: formatUnits(
val as number,
account?.contractInfo?.decimals ? parseInt(account?.contractInfo?.decimals) : 18
)
Expand Down Expand Up @@ -157,8 +156,7 @@ export const Token: React.FC = () => {
{
key: 'Max Total Supply :',
value: account?.contractInfo?.totalSupply
? utils
.formatUnits(
? formatUnits(
account?.contractInfo?.totalSupply,
account?.contractInfo?.decimals ? parseInt(account?.contractInfo?.decimals) : 18
)
Expand All @@ -178,8 +176,7 @@ export const Token: React.FC = () => {
{
key: 'Max Total Supply :',
value: account?.contractInfo?.totalSupply
? utils
.formatUnits(
? formatUnits(
account?.contractInfo?.totalSupply,
account?.contractInfo?.decimals ? parseInt(account?.contractInfo?.decimals) : 18
)
Expand Down Expand Up @@ -220,8 +217,7 @@ export const Token: React.FC = () => {
{tokenBalance
? transactionType === TransactionSearchType.ERC_721
? tokenBalance
: utils
.formatUnits(
: formatUnits(
tokenBalance,
account?.contractInfo?.decimals ? parseInt(account?.contractInfo?.decimals) : 18
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const Ovewview: React.FC<OvewviewProps> = ({ transaction }) => {
<span>For</span>
<div>{calculateTokenValue(item, item.tokenType, undefined, true)}&nbsp;</div>
<Link href={`/account/${item.contractAddress}`} className={styles.anchor}>
{item.tokenType === TokenType.EVM_Internal ? 'SHM' : item.contractInfo.name || item.contractAddress}
{item.tokenType === TokenType.EVM_Internal ? 'SHM' : item.contractInfo?.name || item.contractAddress}
</Link>
</div>
))}
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/utils/calculateValue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import web3 from 'web3'
import { utils } from 'ethers'
import { formatUnits } from 'ethers'
import { TokenTx, TokenType, TransactionType } from '../../types'
import BN from 'bn.js'
import { fromWeiNoTrailingComma } from './fromWeiNoTrailingComma'
Expand Down Expand Up @@ -28,13 +28,13 @@ export const calculateTokenValue = (
): string => {
try {
if (txType === TokenType.ERC_20 || txType === TokenType.EVM_Internal) {
const decimalsValue = tokenTx.contractInfo.decimals ? parseInt(tokenTx.contractInfo.decimals) : 18
const decimalsValue = tokenTx.contractInfo?.decimals ? parseInt(tokenTx.contractInfo.decimals) : 18

return tokenTx.tokenValue === '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
? 'unlimited'
: fullValue
? utils.formatUnits(tokenTx.tokenValue, decimalsValue)
: roundTokenValue(utils.formatUnits(tokenTx.tokenValue, decimalsValue))
? formatUnits(tokenTx.tokenValue, decimalsValue)
: roundTokenValue(formatUnits(tokenTx.tokenValue, decimalsValue))

// : round(web3.utils.fromWei(tokenTx.tokenValue, "ether"));
} else if (txType === TokenType.ERC_721) {
Expand Down
4 changes: 2 additions & 2 deletions src/storage/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ export async function queryTokensByAddress(address: string, detail = false): Pro
if (accountExist && accountExist.contractType) {
filterTokens.push({
contractAddress: contractAddress,
contractInfo: accountExist.contractInfo,
contractType: accountExist.contractType,
contractInfo: accountExist?.contractInfo || null,
contractType: accountExist?.contractType || null,
Comment on lines +269 to +270
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Returning null for contractType may cause issues if downstream code expects a valid contract type. Consider only including tokens with a valid contractType to avoid propagating invalid data. [possible issue, importance: 6]

Suggested change
contractInfo: accountExist?.contractInfo || null,
contractType: accountExist?.contractType || null,
if (accountExist && accountExist.contractType) {
filterTokens.push({
contractAddress: contractAddress,
contractInfo: accountExist?.contractInfo || null,
contractType: accountExist.contractType,
balance: tokenValue,
})
}

balance: tokenValue,
})
}
Expand Down
Loading