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 @@ import { formatUnits, zeroAddress, type Hex } from 'viem'

import type { TransakConfig } from '../../contexts/CheckoutModal.js'
import type { Collectible, CreditCardProviders } from '../../contexts/SelectPaymentModal.js'
import { getCurrencyCode, TRANSAK_PROXY_ADDRESS } from '../../utils/transak.js'
import { getCurrencyCode, getTransakProxyAddress } from '../../utils/transak.js'
import { useTransakWidgetUrl } from '../useTransakWidgetUrl.js'
const TRANSAK_IFRAME_ID = 'credit-card-payment-transak-iframe'

Expand Down Expand Up @@ -87,9 +87,10 @@ export const useCreditCardPayment = ({
// this is a weird hack so that credit card integrations are as simple as possible and should work 99% of the time
// If an issue arises, the user can override the calldata in the transak settings

const transakProxyAddress = getTransakProxyAddress(network?.chainId || 137) || ''
const calldataWithProxy =
transakConfig?.callDataOverride ??
txData.replace(recipientAddress.toLowerCase().substring(2), TRANSAK_PROXY_ADDRESS.toLowerCase().substring(2))
txData.replace(recipientAddress.toLowerCase().substring(2), transakProxyAddress.substring(2))

const price = Number(formatUnits(BigInt(totalPriceRaw), Number(currencyDecimals || 18)))

Expand Down
28 changes: 26 additions & 2 deletions packages/checkout/src/utils/transak.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { ChainId } from '@0xsequence/network'
import { zeroAddress } from 'viem'

export const TRANSAK_PROXY_ADDRESS = '0x4a598b7ec77b1562ad0df7dc64a162695ce4c78a'

interface CountriesResult {
response: Country[]
}
Expand Down Expand Up @@ -48,3 +46,29 @@ export const getCurrencyCode = ({ chainId, currencyAddress, defaultCurrencyCode

return foundCurrencyAddress || defaultCurrencyCode
}

interface ProxyByChainId {
[key: number]: string
}

const chainIdToProxyAddressMapping: ProxyByChainId = {
[ChainId.MAINNET]: '0xab88cd272863b197b48762ea283f24a13f6586dd'.toLowerCase(),
[ChainId.SEPOLIA]: '0xD84aC4716A082B1F7eCDe9301aA91A7c4B62ECd7'.toLowerCase(),
[ChainId.POLYGON]: '0x4A598B7eC77b1562AD0dF7dc64a162695cE4c78A'.toLowerCase(),
[ChainId.POLYGON_AMOY]: '0xCB9bD5aCD627e8FcCf9EB8d4ba72AEb1Cd8Ff5EF'.toLowerCase(),
[ChainId.BSC]: '0x4A598B7eC77b1562AD0dF7dc64a162695cE4c78A'.toLowerCase(),
[ChainId.BSC_TESTNET]: '0x0E9539455944BE8a307bc43B0a046613a1aD6732'.toLowerCase(),
[ChainId.ARBITRUM]: '0x4A598B7eC77b1562AD0dF7dc64a162695cE4c78A'.toLowerCase(),
[ChainId.ARBITRUM_SEPOLIA]: '0x489F56e3144FF03A887305839bBCD20FF767d3d1'.toLowerCase(),
[ChainId.OPTIMISM]: '0x4A598B7eC77b1562AD0dF7dc64a162695cE4c78A'.toLowerCase(),
[ChainId.OPTIMISM_SEPOLIA]: '0xCB9bD5aCD627e8FcCf9EB8d4ba72AEb1Cd8Ff5EF'.toLowerCase(),
[ChainId.IMMUTABLE_ZKEVM]: '0x8b83dE7B20059864C479640CC33426935DC5F85b'.toLowerCase(),
[ChainId.IMMUTABLE_ZKEVM_TESTNET]: '0x489F56e3144FF03A887305839bBCD20FF767d3d1'.toLowerCase(),
[ChainId.BASE]: '0x8b83dE7B20059864C479640CC33426935DC5F85b'.toLowerCase(),
[ChainId.BASE_SEPOLIA]: '0xCB9bD5aCD627e8FcCf9EB8d4ba72AEb1Cd8Ff5EF'.toLowerCase()
}

export const getTransakProxyAddress = (chainId: number): string | undefined => {
const proxyAddress = chainIdToProxyAddressMapping[chainId]
return proxyAddress
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useTransactionStatusModal
} from '../hooks/index.js'
import { useTransakWidgetUrl } from '../hooks/useTransakWidgetUrl.js'
import { getCurrencyCode, TRANSAK_PROXY_ADDRESS } from '../utils/transak.js'
import { getCurrencyCode, getTransakProxyAddress } from '../utils/transak.js'

interface PendingCreditTransactionProps {
skipOnCloseCallback: () => void
Expand Down Expand Up @@ -83,11 +83,13 @@ export const PendingCreditCardTransactionTransak = ({ skipOnCloseCallback }: Pen
// this is a weird hack so that credit card integrations are as simple as possible and should work 99% of the time
// If an issue arises, the user can override the calldata in the transak settings

const transakProxyAddress = getTransakProxyAddress(network?.chainId || 137) || ''

const calldataWithProxy =
transakConfig?.callDataOverride ??
creditCardCheckout.calldata.replace(
creditCardCheckout.recipientAddress.toLowerCase().substring(2),
TRANSAK_PROXY_ADDRESS.toLowerCase().substring(2)
transakProxyAddress.substring(2)
)

const price = Number(formatUnits(BigInt(creditCardCheckout.currencyQuantity), Number(creditCardCheckout.currencyDecimals)))
Expand Down