Skip to content

Commit ea8630e

Browse files
committed
fix: scientific notation in eip681 parsing
1 parent ee6e749 commit ea8630e

File tree

1 file changed

+11
-4
lines changed
  • src/components/Global/DirectSendQR

1 file changed

+11
-4
lines changed

src/components/Global/DirectSendQR/utils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getTokenSymbol, validateEnsName } from '@/utils'
2-
import { isAddress } from 'viem'
1+
import { getTokenSymbol, validateEnsName, getTokenDecimals } from '@/utils'
2+
import { isAddress, formatUnits } from 'viem'
33

44
// Constants
55
const PINTA_MERCHANTS: Record<string, string> = {
@@ -114,7 +114,9 @@ export const parseEip681 = (
114114
const params = new URLSearchParams('?' + queryString)
115115

116116
if (!functionName) {
117-
const value = params.get('value') || undefined
117+
const rawValue = params.get('value') || undefined
118+
const weiValue = rawValue ? BigInt(Number(rawValue)) : undefined
119+
const value = weiValue ? formatUnits(weiValue, 18) : undefined
118120
return {
119121
address,
120122
chainId,
@@ -127,7 +129,12 @@ export const parseEip681 = (
127129
if (functionName.toLowerCase() === 'transfer') {
128130
const tokenAddress = address
129131
const recipientAddress = params.get('address') || ''
130-
const amount = params.get('uint256') || undefined
132+
const rawAmount = params.get('uint256') || undefined
133+
// Amount may be in scientific notation, so we need to convert it
134+
const atomicAmount = rawAmount ? BigInt(Number(rawAmount)) : undefined
135+
const amount = atomicAmount
136+
? formatUnits(atomicAmount, getTokenDecimals(tokenAddress, chainId) ?? 6)
137+
: undefined
131138
return {
132139
address: recipientAddress,
133140
chainId,

0 commit comments

Comments
 (0)