Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('parseEip681', () => {
const result = parseEip681(url)
expect(result).toEqual({
address: '0xfb6916095ca1df60bb79Ce92ce3ea74c37c5d359',
amount: '2.014e18',
amount: '2.014',
tokenSymbol: 'ETH',
})
})
Expand All @@ -17,7 +17,7 @@ describe('parseEip681', () => {
expect(result).toEqual({
address: '0xfb6916095ca1df60bb79Ce92ce3ea74c37c5d359',
chainId: '42',
amount: '1.5e18',
amount: '1.5',
tokenSymbol: 'ETH',
})
})
Expand All @@ -28,7 +28,7 @@ describe('parseEip681', () => {
const result = parseEip681(url)
expect(result).toEqual({
address: '0x8e23ee67d1332ad560396262c48ffbb01f93d052',
amount: '1',
amount: '0.000001',
tokenAddress: '0x89205a3a3b2a69de6dbf7f01ed13b2108b2c43e7',
})
})
Expand All @@ -44,7 +44,7 @@ describe('parseEip681', () => {
const result = parseEip681(url)
expect(result).toEqual({
address: '0xfb6916095ca1df60bb79Ce92ce3ea74c37c5d359',
amount: '1e18',
amount: '1',
tokenSymbol: 'ETH',
})
})
Expand Down
15 changes: 11 additions & 4 deletions src/components/Global/DirectSendQR/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getTokenSymbol, validateEnsName } from '@/utils'
import { isAddress } from 'viem'
import { getTokenSymbol, validateEnsName, getTokenDecimals } from '@/utils'
import { isAddress, formatUnits } from 'viem'

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

if (!functionName) {
const value = params.get('value') || undefined
const rawValue = params.get('value') || undefined
const weiValue = rawValue ? BigInt(Number(rawValue)) : undefined
const value = weiValue ? formatUnits(weiValue, 18) : undefined
return {
address,
chainId,
Expand All @@ -127,7 +129,12 @@ export const parseEip681 = (
if (functionName.toLowerCase() === 'transfer') {
const tokenAddress = address
const recipientAddress = params.get('address') || ''
const amount = params.get('uint256') || undefined
const rawAmount = params.get('uint256') || undefined
// Amount may be in scientific notation, so we need to convert it
const atomicAmount = rawAmount ? BigInt(Number(rawAmount)) : undefined
const amount = atomicAmount
? formatUnits(atomicAmount, getTokenDecimals(tokenAddress, chainId) ?? 6)
: undefined
return {
address: recipientAddress,
chainId,
Expand Down
31 changes: 14 additions & 17 deletions src/utils/__mocks__/peanut-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ export const CHAIN_DETAILS = {
},
}

export const TOKEN_DETAILS = {
1: {
ETH: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
address: '0x0000000000000000000000000000000000000000',
},
},
11155111: {
ETH: {
name: 'Sepolia Ether',
symbol: 'ETH',
decimals: 18,
address: '0x0000000000000000000000000000000000000000',
},
export const TOKEN_DETAILS = [
{
chainId: '1',
name: 'Ethereum',
tokens: [
{
address: '0x0000000000000000000000000000000000000000',
name: 'Ether',
symbol: 'ETH',
decimals: 18,
logoURI: 'https://github.com/raw/spothq/cryptocurrency-icons/master/svg/color/eth.svg',
},
],
},
}
]
Loading