Skip to content

Commit 57bd610

Browse files
committed
readme information
1 parent 31c4590 commit 57bd610

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

packages/checkout/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,56 @@ const MyComponent = () => {
254254
return <button onClick={onClick}>Add Funds</button>
255255
}
256256
```
257+
258+
## Custom Checkout UIs
259+
260+
Fully customized checkout UIs can be created with the `useCheckoutUI` hook. The hook will return three objects `orderSummary`, `creditCardPayment` and `cryptoPayment` which serve to create the order summary section, credit card payment section and crypto payment section of a checkout UI. API calls are done within the hook and all that if left to build is placing the information and actions.
261+
262+
Each section comes with its own loading, error and data states.
263+
264+
```js
265+
import { useCheckoutUI } from '@0xsequence/checkout'
266+
267+
const CustomCheckoutUI = () => {
268+
const checkoutUIParams = {
269+
collectible,
270+
chain: chainId,
271+
totalPriceRaw: price,
272+
targetContractAddress: salesContractAddress,
273+
recipientAddress: address || '',
274+
currencyAddress,
275+
collectionAddress,
276+
creditCardProvider: 'transak' as CreditCardProviders,
277+
transakConfig: {
278+
contractId,
279+
apiKey: '5911d9ec-46b5-48fa-a755-d59a715ff0cf'
280+
},
281+
onSuccess: (txnHash: string) => {
282+
console.log('success!', txnHash)
283+
},
284+
onError: (error: Error) => {
285+
console.error(error)
286+
},
287+
txData: purchaseTransactionData
288+
}
289+
290+
const { orderSummary, creditCardPayment, cryptoPayment } = useCheckoutUI(checkoutUIParams)
291+
292+
const isLoading = orderSummary.isLoading || creditCardPayment.isLoading || cryptoPayment.isLoading
293+
294+
const error = orderSummary.error || creditCardPayment.error || cryptoPayment.error
295+
296+
if (isLoading) {
297+
return <div>loading...</div>
298+
}
299+
if (error) {
300+
return <div>an error has occurred</div>
301+
}
302+
303+
return (
304+
<CustomOrderSummaryComponent data={orderSummary.data}>
305+
<CustomCreditCardComponent data={creditCardPayment.data}>
306+
<CustomCryptoPaymentComponent data={cryptoPayment.data} purchaseAction={cryptoPayment.purchaseAction}>
307+
)
308+
}
309+
```

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ export interface CollectibleItem {
3838
export interface UseOrderSummaryData {
3939
formattedCryptoPrice: string
4040
cryptoSymbol: string
41+
cryptoImageUrl?: string
4142
totalPriceFiat: string
4243
networkName: string
4344
networkImageUrl: string
44-
networkBadge: ReactNode
45+
NetworkBadge: ReactNode
4546
collectibleItem: CollectibleItem
4647
}
4748

@@ -71,6 +72,7 @@ export const useOrderSummary = ({
7172
const isNativeCurrency = compareAddress(currencyAddress, zeroAddress)
7273
const currencySymbol = isNativeCurrency ? network?.nativeToken.symbol : currencyInfo?.symbol
7374
const currencyDecimals = isNativeCurrency ? network?.nativeToken.decimals : currencyInfo?.decimals
75+
const cryptoImageUrl = isNativeCurrency ? network?.logoURI : currencyInfo?.logoURI
7476

7577
const {
7678
data: dataCoinPrices,
@@ -104,9 +106,10 @@ export const useOrderSummary = ({
104106
data = {
105107
formattedCryptoPrice: displayPrice,
106108
cryptoSymbol: currencySymbol || 'POL',
109+
cryptoImageUrl: cryptoImageUrl,
107110
networkName: network?.name || 'Polygon',
108111
networkImageUrl: networkImageUrl(network?.chainId || 137),
109-
networkBadge: <NetworkBadge chainId={chainId} />,
112+
NetworkBadge: <NetworkBadge chainId={chainId} />,
110113
totalPriceFiat: priceFiat,
111114
collectibleItem: {
112115
quantityRaw: collectible.quantity,

0 commit comments

Comments
 (0)