Skip to content

Commit 246a36b

Browse files
feat: use trails nftTransfer prop for automatic NFT bundling
1 parent a65511b commit 246a36b

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

pnpm-lock.yaml

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
}
6161
},
6262
"dependencies": {
63-
"0xtrails": "^0.9.6",
63+
"0xtrails": "file:../../trails-nft-auto-bundle/packages/0xtrails/0xtrails-0.9.6.tgz",
6464
"@databeat/tracker": "^0.9.3",
6565
"@tailwindcss/cli": "^4.1.18",
6666
"@xstate/store": "catalog:",

sdk/src/react/ui/modals/BuyModal/components/BuyModalContent.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const BuyModalContent = () => {
3535
marketOrder,
3636
collectible,
3737
buyStep,
38+
nftTransfer,
3839
isLoading,
3940
collection,
4041
checkoutMode,
@@ -146,6 +147,7 @@ export const BuyModalContent = () => {
146147
toToken={currencyAddress}
147148
toCalldata={buyStep.data}
148149
toAmount={formattedAmount}
150+
nftTransfer={nftTransfer}
149151
renderInline={true}
150152
theme="dark"
151153
mode="pay"

sdk/src/react/ui/modals/BuyModal/internal/buyModalContext.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { ContractType, type Hash } from '@0xsequence/api-client';
22
import { useSupportedChains } from '0xtrails';
3+
import type { NFTTransfer } from '0xtrails';
34
import { type Chain, formatUnits } from 'viem';
5+
import { useAccount } from 'wagmi';
46
import { TransactionType } from '../../../../_internal';
57
import { useConfig } from '../../../../hooks';
68
import { useBuyTransaction } from '../../../../hooks/transactions/useBuyTransaction';
@@ -19,6 +21,7 @@ export function useBuyModalContext() {
1921
const { close } = useBuyModal();
2022
const transactionStatusModal = useTransactionStatusModal();
2123
const { supportedChains, isLoadingChains } = useSupportedChains();
24+
const { address: userWalletAddress } = useAccount();
2225

2326
const {
2427
collectible,
@@ -34,16 +37,18 @@ export function useBuyModalContext() {
3437
refetchQueries,
3538
} = useBuyModalData();
3639

40+
const contractType =
41+
collection?.type === ContractType.ERC1155
42+
? ContractType.ERC1155
43+
: ContractType.ERC721;
44+
3745
const transactionData = useBuyTransaction({
3846
modalProps,
3947
primarySalePrice: {
4048
amount: primarySaleItem?.priceAmount,
4149
currencyAddress: primarySaleItem?.currencyAddress,
4250
},
43-
contractType:
44-
collection?.type === ContractType.ERC1155
45-
? ContractType.ERC1155
46-
: ContractType.ERC721,
51+
contractType,
4752
});
4853
const steps = transactionData.data?.steps;
4954
const canBeUsedWithTrails =
@@ -60,6 +65,23 @@ export function useBuyModalContext() {
6065

6166
const buyStep = steps?.find((step) => step.id === 'buy');
6267

68+
const nftTransfer: NFTTransfer | null = (() => {
69+
if (!isMarket || !marketOrder || !userWalletAddress || marketOrder.tokenId === undefined) {
70+
return null;
71+
}
72+
73+
const baseTransfer = {
74+
contract: marketOrder.collectionContractAddress,
75+
tokenId: marketOrder.tokenId,
76+
recipient: userWalletAddress,
77+
};
78+
79+
if (contractType === ContractType.ERC1155) {
80+
return { ...baseTransfer, type: 'ERC1155' as const, amount: 1n };
81+
}
82+
return { ...baseTransfer, type: 'ERC721' as const };
83+
})();
84+
6385
const checkoutMode = determineCheckoutMode({
6486
checkoutModeConfig,
6587
isChainSupported,
@@ -133,6 +155,7 @@ export function useBuyModalContext() {
133155
marketOrder,
134156
isShop,
135157
buyStep,
158+
nftTransfer,
136159
isLoading,
137160
checkoutMode,
138161
formattedAmount,

0 commit comments

Comments
 (0)