Skip to content

Commit 9c33abd

Browse files
authored
Feat/update swap api hooks (#418)
* feat: swap api hooks update * update args * update new api version * format * added swap options to custom checkout & checks for funds * fix: skip native balance check for non-main currency also * renamed hook and added ts doc * fix test & wallet widget + add slippage bps prop * pnpm install * switch to prod version for @0xsequence/api * remove console.logs
1 parent c5fd715 commit 9c33abd

File tree

33 files changed

+5525
-5297
lines changed

33 files changed

+5525
-5297
lines changed

examples/components/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
".": "./src/index.ts"
55
},
66
"dependencies": {
7-
"@radix-ui/react-popover": "^1.0.7",
8-
"typescript": "^5.8.2"
7+
"@radix-ui/react-popover": "^1.1.11",
8+
"typescript": "^5.8.3"
99
},
1010
"peerDependencies": {
1111
"@0xsequence/design-system": "2.1.6",

examples/next/package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,30 @@
1010
"typecheck": "tsc --noEmit"
1111
},
1212
"dependencies": {
13-
"@0xsequence/design-system": "2.1.6",
14-
"@0xsequence/network": ">= 2.3.7",
1513
"@0xsequence/checkout": "workspace:*",
1614
"@0xsequence/connect": "workspace:*",
15+
"@0xsequence/design-system": "2.1.6",
1716
"@0xsequence/hooks": "workspace:*",
17+
"@0xsequence/network": "^2.3.10",
18+
"@0xsequence/waas": "^2.3.10",
1819
"@0xsequence/wallet-widget": "workspace:*",
19-
"@0xsequence/waas": ">= 2.3.7",
20-
"@tailwindcss/postcss": "^4.0.6",
21-
"@tanstack/react-query": "^5.62.0",
20+
"@tailwindcss/postcss": "^4.1.4",
21+
"@tanstack/react-query": "^5.74.11",
2222
"example-shared-components": "workspace:*",
2323
"next": "14.2.3",
24-
"react": "^19.0.0",
25-
"react-dom": "^19.0.0",
26-
"tailwindcss": "^4.0.6",
27-
"viem": "^2.28.0",
28-
"wagmi": "^2.15.0"
24+
"react": "^19.1.0",
25+
"react-dom": "^19.1.0",
26+
"tailwindcss": "^4.1.4",
27+
"viem": "^2.28.1",
28+
"wagmi": "^2.15.1"
2929
},
3030
"devDependencies": {
31-
"@types/node": "^20.12.12",
32-
"@types/react": "^19.0.10",
33-
"@types/react-dom": "^19.0.4",
34-
"eslint": "^8",
31+
"@types/node": "^20.17.32",
32+
"@types/react": "^19.1.2",
33+
"@types/react-dom": "^19.1.3",
34+
"eslint": "^8.57.1",
3535
"eslint-config-next": "14.2.3",
36-
"postcss": "^8.5.1",
37-
"typescript": "^5.8.2"
36+
"postcss": "^8.5.3",
37+
"typescript": "^5.8.3"
3838
}
3939
}

examples/react/package.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@
1414
"@0xsequence/checkout": "workspace:*",
1515
"@0xsequence/connect": "workspace:*",
1616
"@0xsequence/design-system": "2.1.6",
17-
"@0xsequence/network": ">= 2.3.7",
18-
"@0xsequence/wallet-widget": "workspace:*",
19-
"@0xsequence/immutable-connector": "workspace:*",
2017
"@0xsequence/hooks": "workspace:*",
21-
"@0xsequence/waas": ">= 2.3.7",
22-
"@imtbl/config": "^2.1.2",
23-
"@imtbl/sdk": "^2.1.2",
24-
"@tanstack/react-query": "^5.62.0",
18+
"@0xsequence/immutable-connector": "workspace:*",
19+
"@0xsequence/network": "^2.3.10",
20+
"@0xsequence/waas": "^2.3.10",
21+
"@0xsequence/wallet-widget": "workspace:*",
22+
"@imtbl/config": "^2.2.0",
23+
"@imtbl/sdk": "^2.2.0",
24+
"@tanstack/react-query": "^5.74.11",
2525
"clsx": "^2.1.1",
2626
"example-shared-components": "workspace:*",
27-
"motion": "^12.3.1",
28-
"react": "^19.0.0",
29-
"react-dom": "^19.0.0",
30-
"react-router-dom": "^7.3.0",
31-
"tailwindcss": "^4.0.6",
32-
"typescript": "^5.8.2",
33-
"viem": "^2.28.0",
34-
"wagmi": "^2.15.0"
27+
"motion": "^12.9.2",
28+
"react": "^19.1.0",
29+
"react-dom": "^19.1.0",
30+
"react-router-dom": "^7.5.3",
31+
"tailwindcss": "^4.1.4",
32+
"typescript": "^5.8.3",
33+
"viem": "^2.28.1",
34+
"wagmi": "^2.15.1"
3535
},
3636
"devDependencies": {
37-
"@tailwindcss/postcss": "^4.0.6",
38-
"@types/node": "^20.12.12",
39-
"@types/react": "^19.0.10",
40-
"@types/react-dom": "^19.0.4",
41-
"@vitejs/plugin-react": "^4.3.0",
37+
"@tailwindcss/postcss": "^4.1.4",
38+
"@types/node": "^20.17.32",
39+
"@types/react": "^19.1.2",
40+
"@types/react-dom": "^19.1.3",
41+
"@vitejs/plugin-react": "^4.4.1",
4242
"postcss": "^8.5.3",
43-
"vite": "^5.2.11",
43+
"vite": "^5.4.19",
4444
"vite-plugin-node-polyfills": "^0.21.0",
45-
"vite-plugin-svgr": "^4.2.0",
45+
"vite-plugin-svgr": "^4.3.0",
4646
"vite-tsconfig-paths": "^4.3.2"
4747
}
4848
}

examples/react/src/components/Connected.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,17 @@ export const Connected = () => {
320320

321321
const onClickSwap = () => {
322322
const chainId = 137
323-
const currencyAddress = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359'
324-
const currencyAmount = '20000'
323+
const toTokenAddress = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359'
324+
const toTokenAmount = '200000'
325325
const data = encodeFunctionData({ abi: parseAbi(['function demo()']), functionName: 'demo', args: [] })
326326

327327
const swapModalSettings: SwapModalSettings = {
328328
onSuccess: () => {
329329
console.log('swap successful!')
330330
},
331331
chainId,
332-
currencyAddress,
333-
currencyAmount,
332+
toTokenAddress,
333+
toTokenAmount,
334334
postSwapTransactions: [
335335
{
336336
to: '0x37470dac8a0255141745906c972e414b1409b470',
@@ -360,7 +360,7 @@ export const Connected = () => {
360360
const currencyAddress = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359'
361361
const salesContractAddress = '0xe65b75eb7c58ffc0bf0e671d64d0e1c6cd0d3e5b'
362362
const collectionAddress = '0xdeb398f41ccd290ee5114df7e498cf04fac916cb'
363-
const price = '20000'
363+
const price = '200000'
364364
const contractId = '674eb5613d739107bbd18ed2'
365365

366366
const chainId = 137
@@ -392,6 +392,7 @@ export const Connected = () => {
392392
chain: chainId,
393393
price,
394394
targetContractAddress: salesContractAddress,
395+
enableMainCurrencyPayment: true,
395396
recipientAddress: address,
396397
currencyAddress,
397398
collectionAddress,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ export const CustomCheckout = () => {
159159
<div className="flex flex-col gap-2">
160160
{cryptoPayment.cryptoOptions.data.map(option => (
161161
<CryptoOption
162-
key={option.currencyAddress}
163-
currencyName={option.currencyName}
162+
key={option.address}
163+
currencyName={option.name}
164164
chainId={option.chainId}
165165
symbol={option.symbol}
166166
price={option.totalPriceDisplay}
167167
onClick={() => {
168-
cryptoPayment.purchaseAction.setSelectedCurrencyAddress(option.currencyAddress)
168+
cryptoPayment.purchaseAction.setSelectedCurrencyAddress(option.address)
169169
}}
170170
isSelected={option.isSelected}
171171
showInsufficientFundsWarning={option.isInsufficientFunds}

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,26 @@
3535
"devDependencies": {
3636
"@0xsequence/connect": "workspace:*",
3737
"@arethetypeswrong/cli": "^0.17.4",
38-
"@changesets/changelog-github": "^0.5.0",
39-
"@changesets/cli": "^2.25.2",
40-
"@eslint/js": "^9.22.0",
41-
"@types/node": "^20.12.12",
42-
"@types/react": "^19.0.10",
43-
"@types/react-dom": "^19.0.4",
44-
"eslint": "^9.22.0",
45-
"eslint-plugin-import": "^2.29.1",
38+
"@changesets/changelog-github": "^0.5.1",
39+
"@changesets/cli": "^2.29.2",
40+
"@eslint/js": "^9.25.1",
41+
"@types/node": "^20.17.32",
42+
"@types/react": "^19.1.2",
43+
"@types/react-dom": "^19.1.3",
44+
"eslint": "^9.25.1",
45+
"eslint-plugin-import": "^2.31.0",
4646
"eslint-plugin-react-hooks": "^5.2.0",
47-
"ethers": "^6.13.0",
47+
"ethers": "^6.13.7",
4848
"husky": "^9.1.7",
49-
"prettier": "^3.2.5",
50-
"react": "^19.0.0",
51-
"react-dom": "^19.0.0",
52-
"rimraf": "^5.0.7",
49+
"prettier": "^3.5.3",
50+
"react": "^19.1.0",
51+
"react-dom": "^19.1.0",
52+
"rimraf": "^5.0.10",
5353
"turbo": "2.0.1",
54-
"typescript": "^5.8.2",
55-
"typescript-eslint": "^8.26.1",
56-
"viem": "^2.28.0",
57-
"wagmi": "^2.15.0"
54+
"typescript": "^5.8.3",
55+
"typescript-eslint": "^8.31.1",
56+
"viem": "^2.28.1",
57+
"wagmi": "^2.15.1"
5858
},
5959
"resolutions": {},
6060
"packageManager": "[email protected]"

packages/checkout/package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@
3131
},
3232
"dependencies": {
3333
"@0xsequence/design-system": "2.1.6",
34-
"@0xsequence/marketplace": "^2.1.3",
3534
"@0xsequence/hooks": "workspace:*",
35+
"@0xsequence/marketplace": "^2.3.10",
36+
"motion": "^12.9.2",
3637
"pako": "^2.1.0",
37-
"qrcode.react": "^4.0.1",
38+
"qrcode.react": "^4.2.0",
3839
"react-copy-to-clipboard": "^5.1.0",
39-
"timeago-react": "^3.0.6",
40-
"motion": "^12.3.1"
40+
"timeago-react": "^3.0.7"
4141
},
4242
"peerDependencies": {
4343
"0xsequence": ">= 2.3.7",
44-
"@0xsequence/api": ">=2.3.7",
44+
"@0xsequence/api": "2.3.11",
45+
"@0xsequence/connect": "workspace:*",
4546
"@0xsequence/indexer": ">= 2.3.7",
4647
"@0xsequence/metadata": ">= 2.3.7",
4748
"@0xsequence/network": ">= 2.3.7",
48-
"@0xsequence/connect": "workspace:*",
4949
"@0xsequence/waas": ">= 2.3.7",
5050
"@tanstack/react-query": ">= 5",
5151
"ethers": ">= 6.13.0",
@@ -56,14 +56,14 @@
5656
},
5757
"devDependencies": {
5858
"@0xsequence/connect": "workspace:*",
59-
"@tanstack/react-query": "^5.62.0",
59+
"@tanstack/react-query": "^5.74.11",
6060
"@types/pako": "^2.0.3",
6161
"@types/react-copy-to-clipboard": "^5.0.7",
62-
"ethers": "^6.13.0",
63-
"react": "^19.0.0",
64-
"react-dom": "^19.0.0",
65-
"viem": "^2.28.0",
66-
"vite": "^5.2.11",
67-
"wagmi": "^2.15.0"
62+
"ethers": "^6.13.7",
63+
"react": "^19.1.0",
64+
"react-dom": "^19.1.0",
65+
"viem": "^2.28.1",
66+
"vite": "^5.4.19",
67+
"wagmi": "^2.15.1"
6868
}
6969
}

packages/checkout/src/contexts/SelectPaymentModal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface SelectPaymentSettings {
4747
customProviderCallback?: (onSuccess: (txHash: string) => void, onError: (error: Error) => void, onClose: () => void) => void
4848
supplementaryAnalyticsInfo?: SupplementaryAnalyticsInfo
4949
skipNativeBalanceCheck?: boolean
50+
slippageBps?: number
5051
nativeTokenAddress?: string
5152
}
5253

packages/checkout/src/contexts/SwapModal.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ interface Transaction {
1212

1313
export interface SwapModalSettings {
1414
chainId: number
15-
currencyAddress: string
16-
currencyAmount: string
15+
toTokenAddress: string
16+
toTokenAmount: string
17+
slippageBps?: number
1718
title?: string
1819
description?: string
1920
disableMainCurrency?: boolean

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface UseCheckoutUIArgs {
1919
targetContractAddress: string
2020
txData: Hex
2121
transactionConfirmations?: number
22+
slippageBps?: number
2223
creditCardProvider?: CreditCardProviders
2324
transakConfig?: TransakConfig
2425
onSuccess?: (txHash: string) => void
@@ -43,6 +44,7 @@ export const useCheckoutUI = ({
4344
transactionConfirmations,
4445
creditCardProvider,
4546
transakConfig,
47+
slippageBps,
4648
onSuccess,
4749
onError
4850
}: UseCheckoutUIArgs): UseCheckoutUIReturn => {
@@ -138,7 +140,8 @@ export const useCheckoutUI = ({
138140
isLoadingTokenMetadatas,
139141
errorTokenMetadata,
140142
isLoadingCurrencyInfo,
141-
errorCurrencyInfo
143+
errorCurrencyInfo,
144+
slippageBps
142145
})
143146

144147
return {

0 commit comments

Comments
 (0)