1
- import { getTokenSymbol , validateEnsName } from '@/utils'
2
- import { isAddress } from 'viem'
1
+ import { getTokenSymbol , validateEnsName , getTokenDecimals } from '@/utils'
2
+ import { isAddress , formatUnits } from 'viem'
3
3
4
4
// Constants
5
5
const PINTA_MERCHANTS : Record < string , string > = {
@@ -114,7 +114,9 @@ export const parseEip681 = (
114
114
const params = new URLSearchParams ( '?' + queryString )
115
115
116
116
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
118
120
return {
119
121
address,
120
122
chainId,
@@ -127,7 +129,12 @@ export const parseEip681 = (
127
129
if ( functionName . toLowerCase ( ) === 'transfer' ) {
128
130
const tokenAddress = address
129
131
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
131
138
return {
132
139
address : recipientAddress ,
133
140
chainId,
0 commit comments