Skip to content

Commit c958440

Browse files
committed
added crypto options
1 parent 11e701f commit c958440

File tree

5 files changed

+36
-27
lines changed

5 files changed

+36
-27
lines changed

examples/react/src/components/Connected.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ import React, { type ComponentProps, useEffect } from 'react'
2424
import { encodeFunctionData, formatUnits, parseAbi, toHex } from 'viem'
2525
import { useAccount, useChainId, usePublicClient, useSendTransaction, useWalletClient, useWriteContract } from 'wagmi'
2626

27-
import { CustomCheckout } from './CustomCheckout'
28-
2927
import { sponsoredContractAddresses } from '../config'
3028
import { messageToSign } from '../constants'
3129
import { ERC_1155_SALE_CONTRACT } from '../constants/erc1155-sale-contract'
3230
import { abi } from '../constants/nft-abi'
31+
import { CustomCheckout } from './CustomCheckout'
3332
import { delay, getCheckoutSettings, getOrderbookCalldata } from '../utils'
3433

3534
// append ?debug to url to enable debug mode

examples/react/src/components/CustomCheckout/index.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Text, Button, Spinner, NetworkImage, Image } from '@0xsequence/design-system'
2-
import React, { useMemo } from 'react'
31
import { useCheckoutUI, CreditCardProviders } from '@0xsequence/checkout'
42
import { CryptoOption } from '@0xsequence/connect'
3+
import { Text, Button, Spinner, NetworkImage, Image } from '@0xsequence/design-system'
4+
import { useState } from 'react'
55
import { encodeFunctionData, toHex } from 'viem'
66
import { useAccount } from 'wagmi'
7+
78
import { ERC_1155_SALE_CONTRACT } from '../../constants/erc1155-sale-contract'
89

910
export const CustomCheckout = () => {
@@ -121,6 +122,7 @@ export const CustomCheckout = () => {
121122
}
122123

123124
const CreditCardPayment = () => {
125+
const [showCreditCardPayment, setShowCreditCardPayment] = useState(false)
124126
if (creditCardPayment.isLoading) {
125127
return <Spinner />
126128
}
@@ -132,12 +134,16 @@ export const CustomCheckout = () => {
132134
const CreditCardIframe = creditCardPayment.data?.CreditCardIframe
133135
const EventListener = creditCardPayment.data?.EventListener
134136

135-
return (
136-
<div>
137-
<CreditCardIframe />
138-
<EventListener />
139-
</div>
140-
)
137+
if (showCreditCardPayment) {
138+
return (
139+
<div>
140+
<CreditCardIframe />
141+
<EventListener />
142+
</div>
143+
)
144+
}
145+
146+
return <Button onClick={() => setShowCreditCardPayment(true)}>Show Credit Card Payment</Button>
141147
}
142148

143149
const CryptoPayment = () => {

packages/checkout/src/hooks/useCheckoutUI/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { TransakConfig } from '../../contexts/CheckoutModal'
66
import { Collectible, CreditCardProviders } from '../../contexts/SelectPaymentModal'
77

88
import { useCreditCardPayment, type UseCreditCardPaymentReturn } from './useCreditCardPayment'
9-
import { useOrderSummary, type UseOrderSummaryReturn } from './useOrderSummary'
109
import { useCryptoPayment, type UseCryptoPaymentReturn } from './useCryptoPayment'
10+
import { useOrderSummary, type UseOrderSummaryReturn } from './useOrderSummary'
1111

1212
interface UseCheckoutUIArgs {
1313
chain: string | number

packages/checkout/src/hooks/useCheckoutUI/useCryptoPayment.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { useState } from 'react'
66
import { Hex, encodeFunctionData, formatUnits, zeroAddress } from 'viem'
77
import { usePublicClient, useAccount, useReadContract, useWalletClient } from 'wagmi'
88

9-
import { Collectible } from '../../contexts/SelectPaymentModal'
109
import { ERC_20_CONTRACT_ABI } from '../../constants/abi'
10+
import { Collectible } from '../../contexts/SelectPaymentModal'
11+
1112
export interface UseCryptoPaymentArgs {
1213
chain: string | number
1314
currencyAddress: string
@@ -150,18 +151,22 @@ export const useCryptoPayment = ({
150151
significantDigits: 6
151152
})
152153

153-
const mainCurrencyOption = {
154-
chainId,
155-
currencyAddress,
156-
currencyName: currencyInfo?.name || 'unknown',
157-
totalPriceRaw: totalPriceRaw,
158-
decimals: currencyDecimals || 18,
159-
totalPriceDisplay: priceDisplay,
160-
currrencyLogoUrl: currencyInfo?.logoURI,
161-
symbol: currencySymbol || '',
162-
isInsufficientFunds: Number(mainCurrencyBalance) < Number(totalPriceRaw),
163-
isSelected: compareAddress(currencyAddress, selectedCurrencyAddress || '')
164-
}
154+
const mainCurrencyOption = currencyBalanceIsLoading
155+
? [
156+
{
157+
chainId,
158+
currencyAddress,
159+
currencyName: currencyInfo?.name || 'unknown',
160+
totalPriceRaw: totalPriceRaw,
161+
decimals: currencyDecimals || 18,
162+
totalPriceDisplay: priceDisplay,
163+
currrencyLogoUrl: currencyInfo?.logoURI,
164+
symbol: currencySymbol || '',
165+
isInsufficientFunds: Number(mainCurrencyBalance) < Number(totalPriceRaw),
166+
isSelected: compareAddress(currencyAddress, selectedCurrencyAddress || '')
167+
}
168+
]
169+
: []
165170

166171
const swapOptions = swapPrices.map(swapPrice => {
167172
const swapQuotePriceFormatted = formatUnits(BigInt(swapPrice.price.price), swapPrice.info?.decimals || 18)
@@ -350,8 +355,8 @@ export const useCryptoPayment = ({
350355

351356
return {
352357
cryptoOptions: {
353-
data: [mainCurrencyOption, ...swapOptions],
354-
isLoading: isLoadingCurrencyInfo || swapPricesIsLoading,
358+
data: [...mainCurrencyOption, ...swapOptions],
359+
isLoading: isLoadingCurrencyInfo || swapPricesIsLoading || currencyBalanceIsLoading,
355360
error: errorCurrencyInfo || swapPricesError
356361
},
357362
purchaseAction: {

packages/checkout/src/hooks/useCheckoutUI/useOrderSummary.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export const useOrderSummary = ({
5656
currencyAddress,
5757
totalPriceRaw,
5858
collectible,
59-
collectionAddress,
6059
currencyInfo,
6160
tokenMetadatas,
6261
dataCollectionInfo,

0 commit comments

Comments
 (0)