From 54f9dad5977689e31758f1497bef5b2cad9487f6 Mon Sep 17 00:00:00 2001 From: Sam Sweet Date: Wed, 27 Aug 2025 12:17:41 -0400 Subject: [PATCH 1/4] Fix display value on erc20 --- src/frontend/utils/calculateValue.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/frontend/utils/calculateValue.ts b/src/frontend/utils/calculateValue.ts index 257d090..0cc39de 100644 --- a/src/frontend/utils/calculateValue.ts +++ b/src/frontend/utils/calculateValue.ts @@ -28,7 +28,9 @@ 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 && !isNaN(parseInt(tokenTx.contractInfo.decimals)) + ? parseInt(tokenTx.contractInfo.decimals) + : 18 return tokenTx.tokenValue === '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' ? 'unlimited' From e1523c78aca1a6ab48f3a66420063b073f223a88 Mon Sep 17 00:00:00 2001 From: Sam Sweet Date: Wed, 27 Aug 2025 12:19:52 -0400 Subject: [PATCH 2/4] debug logging --- src/frontend/utils/calculateValue.ts | 29 +++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/frontend/utils/calculateValue.ts b/src/frontend/utils/calculateValue.ts index 0cc39de..59a7f0a 100644 --- a/src/frontend/utils/calculateValue.ts +++ b/src/frontend/utils/calculateValue.ts @@ -27,25 +27,40 @@ export const calculateTokenValue = ( fullValue = true ): string => { try { + console.log('calculateTokenValue - Input:', { tokenTx, txType, tokenId, fullValue }) + if (txType === TokenType.ERC_20 || txType === TokenType.EVM_Internal) { + console.log('calculateTokenValue - ERC20/EVM_Internal branch') + console.log('calculateTokenValue - contractInfo:', tokenTx.contractInfo) + console.log('calculateTokenValue - tokenValue:', tokenTx.tokenValue) + const decimalsValue = tokenTx.contractInfo.decimals && !isNaN(parseInt(tokenTx.contractInfo.decimals)) ? parseInt(tokenTx.contractInfo.decimals) : 18 + + console.log('calculateTokenValue - decimalsValue:', decimalsValue) - return tokenTx.tokenValue === '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' - ? 'unlimited' - : fullValue - ? utils.formatUnits(tokenTx.tokenValue, decimalsValue) - : roundTokenValue(utils.formatUnits(tokenTx.tokenValue, decimalsValue)) + if (tokenTx.tokenValue === '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') { + console.log('calculateTokenValue - unlimited value detected') + return 'unlimited' + } + + console.log('calculateTokenValue - attempting formatUnits with:', tokenTx.tokenValue, decimalsValue) + const formatted = utils.formatUnits(tokenTx.tokenValue, decimalsValue) + console.log('calculateTokenValue - formatUnits result:', formatted) + + return fullValue ? formatted : roundTokenValue(formatted) // : round(web3.utils.fromWei(tokenTx.tokenValue, "ether")); } else if (txType === TokenType.ERC_721) { + console.log('calculateTokenValue - ERC721 branch') return tokenTx.tokenEvent === 'Approval For All' ? tokenTx.tokenValue === '0x0000000000000000000000000000000000000000000000000000000000000001' ? 'True' : 'False' : shortTokenValue(web3.utils.hexToNumberString(tokenTx.tokenValue)) } else if (txType === TokenType.ERC_1155) { + console.log('calculateTokenValue - ERC1155 branch') return tokenTx.tokenEvent === 'Approval For All' ? tokenTx.tokenValue === '0x0000000000000000000000000000000000000000000000000000000000000001' ? 'True' @@ -56,7 +71,11 @@ export const calculateTokenValue = ( ? shortTokenValue(web3.utils.hexToNumberString(tokenTx.tokenValue.substring(0, 66))) : shortTokenValue(web3.utils.hexToNumberString('0x' + tokenTx.tokenValue.substring(66, 130))) } + + console.log('calculateTokenValue - No matching token type, txType:', txType) } catch (e) { + console.error('calculateTokenValue - Error caught:', e) + console.error('calculateTokenValue - Error stack:', e.stack) return 'error in calculating tokenValue' } return 'error in calculating tokenValue' From 72de61e466d709e51c66fb55165b2edab0cb25c7 Mon Sep 17 00:00:00 2001 From: Sam Sweet Date: Wed, 27 Aug 2025 12:23:06 -0400 Subject: [PATCH 3/4] fix ethers formatUnits change --- src/frontend/utils/calculateValue.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frontend/utils/calculateValue.ts b/src/frontend/utils/calculateValue.ts index 59a7f0a..c546328 100644 --- a/src/frontend/utils/calculateValue.ts +++ b/src/frontend/utils/calculateValue.ts @@ -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' @@ -46,7 +46,7 @@ export const calculateTokenValue = ( } console.log('calculateTokenValue - attempting formatUnits with:', tokenTx.tokenValue, decimalsValue) - const formatted = utils.formatUnits(tokenTx.tokenValue, decimalsValue) + const formatted = formatUnits(tokenTx.tokenValue, decimalsValue) console.log('calculateTokenValue - formatUnits result:', formatted) return fullValue ? formatted : roundTokenValue(formatted) From d4d6fd4131f986aa127d706acc0a940d3bd0bb74 Mon Sep 17 00:00:00 2001 From: Sam Sweet Date: Wed, 27 Aug 2025 12:24:54 -0400 Subject: [PATCH 4/4] remove debug logs --- src/frontend/utils/calculateValue.ts | 29 +++++----------------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/src/frontend/utils/calculateValue.ts b/src/frontend/utils/calculateValue.ts index c546328..7db6ba1 100644 --- a/src/frontend/utils/calculateValue.ts +++ b/src/frontend/utils/calculateValue.ts @@ -27,40 +27,25 @@ export const calculateTokenValue = ( fullValue = true ): string => { try { - console.log('calculateTokenValue - Input:', { tokenTx, txType, tokenId, fullValue }) - if (txType === TokenType.ERC_20 || txType === TokenType.EVM_Internal) { - console.log('calculateTokenValue - ERC20/EVM_Internal branch') - console.log('calculateTokenValue - contractInfo:', tokenTx.contractInfo) - console.log('calculateTokenValue - tokenValue:', tokenTx.tokenValue) - const decimalsValue = tokenTx.contractInfo.decimals && !isNaN(parseInt(tokenTx.contractInfo.decimals)) ? parseInt(tokenTx.contractInfo.decimals) : 18 - - console.log('calculateTokenValue - decimalsValue:', decimalsValue) - if (tokenTx.tokenValue === '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') { - console.log('calculateTokenValue - unlimited value detected') - return 'unlimited' - } - - console.log('calculateTokenValue - attempting formatUnits with:', tokenTx.tokenValue, decimalsValue) - const formatted = formatUnits(tokenTx.tokenValue, decimalsValue) - console.log('calculateTokenValue - formatUnits result:', formatted) - - return fullValue ? formatted : roundTokenValue(formatted) + return tokenTx.tokenValue === '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' + ? 'unlimited' + : fullValue + ? formatUnits(tokenTx.tokenValue, decimalsValue) + : roundTokenValue(formatUnits(tokenTx.tokenValue, decimalsValue)) // : round(web3.utils.fromWei(tokenTx.tokenValue, "ether")); } else if (txType === TokenType.ERC_721) { - console.log('calculateTokenValue - ERC721 branch') return tokenTx.tokenEvent === 'Approval For All' ? tokenTx.tokenValue === '0x0000000000000000000000000000000000000000000000000000000000000001' ? 'True' : 'False' : shortTokenValue(web3.utils.hexToNumberString(tokenTx.tokenValue)) } else if (txType === TokenType.ERC_1155) { - console.log('calculateTokenValue - ERC1155 branch') return tokenTx.tokenEvent === 'Approval For All' ? tokenTx.tokenValue === '0x0000000000000000000000000000000000000000000000000000000000000001' ? 'True' @@ -71,11 +56,7 @@ export const calculateTokenValue = ( ? shortTokenValue(web3.utils.hexToNumberString(tokenTx.tokenValue.substring(0, 66))) : shortTokenValue(web3.utils.hexToNumberString('0x' + tokenTx.tokenValue.substring(66, 130))) } - - console.log('calculateTokenValue - No matching token type, txType:', txType) } catch (e) { - console.error('calculateTokenValue - Error caught:', e) - console.error('calculateTokenValue - Error stack:', e.stack) return 'error in calculating tokenValue' } return 'error in calculating tokenValue'