@0xsequence/marketplace-sdk 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/dist/chunk-22NLQ3AS.js +3078 -0
  2. package/dist/chunk-22NLQ3AS.js.map +1 -0
  3. package/dist/chunk-3OHM45R3.js +1294 -0
  4. package/dist/chunk-3OHM45R3.js.map +1 -0
  5. package/dist/{chunk-MQR6SHXZ.js → chunk-4YU2UPYH.js} +58 -103
  6. package/dist/chunk-4YU2UPYH.js.map +1 -0
  7. package/dist/chunk-7NJETFMF.js +21 -0
  8. package/dist/chunk-7NJETFMF.js.map +1 -0
  9. package/dist/{chunk-UYRQ5MJQ.js → chunk-FUM4OGOQ.js} +4 -4
  10. package/dist/chunk-FUM4OGOQ.js.map +1 -0
  11. package/dist/{chunk-7OO74L2K.js → chunk-GJAKQ5Q3.js} +40 -1
  12. package/dist/chunk-GJAKQ5Q3.js.map +1 -0
  13. package/dist/chunk-MCI3KOSQ.js +2 -0
  14. package/dist/{chunk-BJE7AG6V.js → chunk-O7UQGT43.js} +698 -23
  15. package/dist/chunk-O7UQGT43.js.map +1 -0
  16. package/dist/{chunk-CSN7YD5Q.js → chunk-Q57TEA3Z.js} +20 -2
  17. package/dist/chunk-Q57TEA3Z.js.map +1 -0
  18. package/dist/{chunk-VEX7FDL6.js → chunk-SBVLWSRZ.js} +2 -2
  19. package/dist/{chunk-VEX7FDL6.js.map → chunk-SBVLWSRZ.js.map} +1 -1
  20. package/dist/{chunk-6S4FYXP6.js → chunk-SPW24Y7I.js} +40 -1
  21. package/dist/chunk-SPW24Y7I.js.map +1 -0
  22. package/dist/chunk-UISBTKFF.js +1 -0
  23. package/dist/{chunk-OUWB3FHZ.js → chunk-WA433WAJ.js} +9 -33
  24. package/dist/chunk-WA433WAJ.js.map +1 -0
  25. package/dist/{chunk-O5JXKTWP.js → chunk-WFE6OCYF.js} +4 -4
  26. package/dist/chunk-WFE6OCYF.js.map +1 -0
  27. package/dist/chunk-XX4EVWBF.js +1292 -0
  28. package/dist/chunk-XX4EVWBF.js.map +1 -0
  29. package/dist/chunk-Y7YO5TLE.js +53 -0
  30. package/dist/chunk-Y7YO5TLE.js.map +1 -0
  31. package/dist/index.css +1 -50
  32. package/dist/index.d.ts +3 -5
  33. package/dist/index.js +158 -73
  34. package/dist/index.js.map +1 -1
  35. package/dist/react/hooks/index.css +82 -0
  36. package/dist/react/hooks/index.css.map +1 -0
  37. package/dist/react/hooks/index.d.ts +401 -462
  38. package/dist/react/hooks/index.js +26 -6
  39. package/dist/react/index.css +56 -91
  40. package/dist/react/index.css.map +1 -1
  41. package/dist/react/index.d.ts +2 -2
  42. package/dist/react/index.js +32 -13
  43. package/dist/react/ui/components/index.css +86 -121
  44. package/dist/react/ui/components/index.css.map +1 -1
  45. package/dist/react/ui/components/index.d.ts +10 -4
  46. package/dist/react/ui/components/index.js +12 -11
  47. package/dist/react/ui/icons/index.js +3 -2
  48. package/dist/react/ui/icons/index.js.map +1 -1
  49. package/dist/react/ui/index.css +56 -91
  50. package/dist/react/ui/index.css.map +1 -1
  51. package/dist/react/ui/index.d.ts +29 -31
  52. package/dist/react/ui/index.js +14 -11
  53. package/dist/react/ui/modals/_internal/components/actionModal/index.js +5 -16
  54. package/dist/react/ui/modals/_internal/components/actionModal/index.js.map +1 -1
  55. package/dist/react/ui/styles/index.d.ts +1 -1
  56. package/dist/styles/index.css +1 -50
  57. package/dist/styles/index.css.map +1 -1
  58. package/dist/styles/index.d.ts +1 -5
  59. package/dist/styles/index.js +8 -10
  60. package/dist/utils/abi/index.d.ts +2 -0
  61. package/dist/utils/abi/index.js +21 -0
  62. package/dist/utils/abi/marketplace/index.d.ts +805 -0
  63. package/dist/utils/abi/marketplace/index.js +12 -0
  64. package/dist/utils/abi/{abi/token → token}/index.js +1 -2
  65. package/dist/utils/index.d.ts +5 -5
  66. package/dist/utils/index.js +12 -14
  67. package/package.json +17 -15
  68. package/src/react/_internal/transaction-machine/execute-transaction.ts +592 -0
  69. package/src/react/_internal/transaction-machine/useTransactionMachine.ts +66 -0
  70. package/src/react/hooks/index.ts +4 -0
  71. package/src/react/hooks/useBuyCollectable.tsx +38 -0
  72. package/src/react/hooks/useCancelOrder.tsx +38 -0
  73. package/src/react/hooks/useCheckoutOptions.tsx +9 -6
  74. package/src/react/hooks/useCreateListing.tsx +65 -0
  75. package/src/react/hooks/useGenerateBuyTransaction.tsx +71 -0
  76. package/src/react/hooks/useListListingsForCollectible.tsx +1 -1
  77. package/src/react/hooks/useMakeOffer.tsx +62 -0
  78. package/src/react/hooks/useRoyaltyPercentage.tsx +1 -1
  79. package/src/react/hooks/useSell.tsx +62 -0
  80. package/src/react/ui/components/_internals/action-button/ActionButton.tsx +107 -115
  81. package/src/react/ui/components/_internals/custom-select/CustomSelect.tsx +63 -0
  82. package/src/react/ui/components/_internals/custom-select/styles.css.ts +64 -0
  83. package/src/react/ui/components/collectible-card/CollectibleCard.tsx +127 -130
  84. package/src/react/ui/components/collectible-card/Footer.tsx +65 -58
  85. package/src/react/ui/icons/Bell.tsx +2 -2
  86. package/src/react/ui/index.ts +1 -0
  87. package/src/react/ui/modals/BuyModal/_store.ts +53 -0
  88. package/src/react/ui/modals/BuyModal/index.tsx +119 -0
  89. package/src/react/ui/modals/CreateListingModal/_store.ts +35 -312
  90. package/src/react/ui/modals/CreateListingModal/index.tsx +185 -126
  91. package/src/react/ui/modals/MakeOfferModal/_store.ts +34 -276
  92. package/src/react/ui/modals/MakeOfferModal/index.tsx +195 -136
  93. package/src/react/ui/modals/SellModal/_store.ts +29 -262
  94. package/src/react/ui/modals/SellModal/index.tsx +156 -121
  95. package/src/react/ui/modals/SuccessfulPurchaseModal/_store.ts +17 -3
  96. package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +3 -2
  97. package/src/react/ui/modals/TransferModal/index.tsx +9 -16
  98. package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +1 -0
  99. package/src/react/ui/modals/_internal/components/actionModal/ErrorModal.tsx +18 -0
  100. package/src/react/ui/modals/_internal/components/actionModal/LoadingModal.tsx +18 -0
  101. package/src/react/ui/modals/_internal/components/calendarPopover/index.tsx +1 -0
  102. package/src/react/ui/modals/_internal/components/calendarPopover/overrides.css +8 -0
  103. package/src/react/ui/modals/_internal/components/calendarPopover/styles.css.ts +10 -4
  104. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +10 -13
  105. package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +23 -9
  106. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +7 -18
  107. package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +17 -44
  108. package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +10 -8
  109. package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +14 -3
  110. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +4 -2
  111. package/src/react/ui/modals/_internal/components/transactionHeader/index.tsx +4 -4
  112. package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +4 -2
  113. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +13 -10
  114. package/src/react/ui/modals/_internal/types.ts +13 -0
  115. package/src/react/ui/modals/modal-provider.tsx +4 -2
  116. package/src/styles/index.ts +0 -2
  117. package/src/utils/abi/index.ts +2 -0
  118. package/src/utils/abi/marketplace/index.ts +3 -0
  119. package/src/utils/abi/marketplace/sequence-marketplace-v1.ts +463 -0
  120. package/src/utils/abi/marketplace/sequence-marketplace-v2.ts +802 -0
  121. package/src/utils/index.ts +2 -3
  122. package/src/utils/network.ts +4 -2
  123. package/tsconfig.tsbuildinfo +1 -1
  124. package/dist/chunk-6JWGELXL.js +0 -214
  125. package/dist/chunk-6JWGELXL.js.map +0 -1
  126. package/dist/chunk-6S4FYXP6.js.map +0 -1
  127. package/dist/chunk-7OO74L2K.js.map +0 -1
  128. package/dist/chunk-BCNFYVAL.js +0 -1
  129. package/dist/chunk-BJE7AG6V.js.map +0 -1
  130. package/dist/chunk-CSN7YD5Q.js.map +0 -1
  131. package/dist/chunk-D7QQP6MS.js +0 -2
  132. package/dist/chunk-DBFOPEV6.js +0 -23
  133. package/dist/chunk-DBFOPEV6.js.map +0 -1
  134. package/dist/chunk-MQR6SHXZ.js.map +0 -1
  135. package/dist/chunk-O5JXKTWP.js.map +0 -1
  136. package/dist/chunk-OUWB3FHZ.js.map +0 -1
  137. package/dist/chunk-PE2LLUTJ.js +0 -213
  138. package/dist/chunk-PE2LLUTJ.js.map +0 -1
  139. package/dist/chunk-QVFMD6S2.js +0 -21
  140. package/dist/chunk-QVFMD6S2.js.map +0 -1
  141. package/dist/chunk-QXLZPSSR.js +0 -3316
  142. package/dist/chunk-QXLZPSSR.js.map +0 -1
  143. package/dist/chunk-UYRQ5MJQ.js.map +0 -1
  144. package/dist/utils/abi/abi/standard/index.d.ts +0 -25
  145. package/dist/utils/abi/abi/standard/index.js +0 -8
  146. package/dist/utils/abi/clients/index.d.ts +0 -27
  147. package/dist/utils/abi/clients/index.js +0 -13
  148. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/styles.css.ts +0 -33
  149. package/src/react/ui/modals/_internal/components/expirationDateSelect/styles.css.ts +0 -25
  150. package/src/utils/abi/abi/standard/index.ts +0 -1
  151. package/src/utils/abi/clients/ERC1155.ts +0 -82
  152. package/src/utils/abi/clients/ERC20.ts +0 -101
  153. package/src/utils/abi/clients/ERC721.ts +0 -97
  154. package/src/utils/abi/clients/index.ts +0 -3
  155. /package/dist/{chunk-BCNFYVAL.js.map → chunk-MCI3KOSQ.js.map} +0 -0
  156. /package/dist/{chunk-D7QQP6MS.js.map → chunk-UISBTKFF.js.map} +0 -0
  157. /package/dist/utils/abi/{abi/standard/index.js.map → index.js.map} +0 -0
  158. /package/dist/utils/abi/{abi/token → marketplace}/index.js.map +0 -0
  159. /package/dist/utils/abi/{abi/token → token}/index.d.ts +0 -0
  160. /package/dist/utils/abi/{clients → token}/index.js.map +0 -0
  161. /package/src/react/hooks/{useGenerateCancleTransaction.tsx → useGenerateCancelTransaction.tsx} +0 -0
  162. /package/src/utils/abi/{abi/standard → marketplace}/EIP2981.ts +0 -0
  163. /package/src/utils/abi/{abi/token → token}/ERC1155.ts +0 -0
  164. /package/src/utils/abi/{abi/token → token}/ERC20.ts +0 -0
  165. /package/src/utils/abi/{abi/token → token}/ERC721.ts +0 -0
  166. /package/src/utils/abi/{abi/token → token}/index.ts +0 -0
@@ -0,0 +1,119 @@
1
+ import type { Hex } from 'viem';
2
+ import { buyModal$ } from './_store';
3
+ import { ContractType, type Order } from '../../../_internal';
4
+ import { observer, useSelector } from '@legendapp/state/react';
5
+ import { useCollectible, useCollection } from '../../../hooks';
6
+ import { ActionModal } from '../_internal/components/actionModal';
7
+ import { useEffect } from 'react';
8
+ import QuantityInput from '..//_internal/components/quantityInput';
9
+ import { useBuyCollectable } from '../../../hooks/useBuyCollectable';
10
+ import type { ModalCallbacks } from '../_internal/types';
11
+
12
+ export type ShowBuyModalArgs = {
13
+ chainId: string;
14
+ collectionAddress: Hex;
15
+ tokenId: string;
16
+ order: Order;
17
+ };
18
+
19
+ export const useBuyModal = (callbacks?: ModalCallbacks) => {
20
+ return {
21
+ show: (args: ShowBuyModalArgs) =>
22
+ buyModal$.open({ ...args, defaultCallbacks: callbacks }),
23
+ close: () => buyModal$.close(),
24
+ };
25
+ };
26
+
27
+ export const BuyModal = () => {
28
+ const isOpen = useSelector(buyModal$.isOpen);
29
+ const { data: collection } = useCollection({
30
+ chainId: buyModal$.state.order.chainId.get(),
31
+ collectionAddress: buyModal$.state.order.collectionContractAddress.get(),
32
+ });
33
+
34
+ if (!isOpen || !collection) return null;
35
+
36
+ return collection.type === ContractType.ERC721 ? (
37
+ <CheckoutModal />
38
+ ) : (
39
+ <ERC1155QuantityModal />
40
+ );
41
+ };
42
+
43
+ const CheckoutModal = observer(() => {
44
+ const order = buyModal$.state.order.get();
45
+ const chainId = String(order.chainId);
46
+ const collectionAddress = order.collectionContractAddress as Hex;
47
+ const collectibleId = order.tokenId;
48
+
49
+ const { buy } = useBuyCollectable({
50
+ chainId,
51
+ collectionAddress,
52
+ });
53
+
54
+ const { data: collectable } = useCollectible({
55
+ chainId,
56
+ collectionAddress,
57
+ collectibleId,
58
+ });
59
+
60
+ // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
61
+ useEffect(() => {
62
+ if (!collectable) return;
63
+ buy({
64
+ orderId: order.orderId,
65
+ collectableDecimals: collectable.decimals || 0,
66
+ quantity: '1',
67
+ marketplace: order.marketplace,
68
+ });
69
+ }, [order, collectable]);
70
+
71
+ return <></>;
72
+ });
73
+
74
+ const ERC1155QuantityModal = observer(() => {
75
+ const order = buyModal$.state.order.get();
76
+ const chainId = String(order.chainId);
77
+ const collectionAddress = order.collectionContractAddress as Hex;
78
+ const collectibleId = order.tokenId;
79
+
80
+ const { buy } = useBuyCollectable({
81
+ chainId,
82
+ collectionAddress,
83
+ });
84
+
85
+ const { data: collectable } = useCollectible({
86
+ chainId,
87
+ collectionAddress,
88
+ collectibleId,
89
+ });
90
+
91
+ if (!order || !collectable) return null;
92
+
93
+ return (
94
+ <ActionModal
95
+ store={buyModal$}
96
+ onClose={() => buyModal$.close()}
97
+ title="Select Quantity"
98
+ ctas={[
99
+ {
100
+ label: 'Select Quantity',
101
+ onClick: () =>
102
+ buy({
103
+ quantity: buyModal$.state.quantity.get(),
104
+ orderId: order.orderId,
105
+ collectableDecimals: collectable.decimals || 0,
106
+ marketplace: order.marketplace,
107
+ }),
108
+ },
109
+ ]}
110
+ >
111
+ <QuantityInput
112
+ chainId={chainId}
113
+ collectionAddress={collectionAddress}
114
+ collectibleId={collectibleId}
115
+ $quantity={buyModal$.state.quantity}
116
+ />
117
+ </ActionModal>
118
+ );
119
+ });
@@ -1,325 +1,48 @@
1
- import { observable, when } from '@legendapp/state';
2
- import { useMount, useSelector } from '@legendapp/state/react';
3
- import type { QueryKey } from '@tanstack/react-query';
1
+ import { observable } from '@legendapp/state';
4
2
  import { addDays } from 'date-fns/addDays';
5
- import type { Hex } from 'viem';
6
- import { useAccount, useSendTransaction } from 'wagmi';
7
- import type { ShowCreateListingModalArgs } from '.';
8
- import type { Price } from '../../../../types';
9
- import type {
10
- CreateListingErrorCallbacks,
11
- CreateListingSuccessCallbacks,
12
- } from '../../../../types/callbacks';
13
- import {
14
- type CollectionType,
15
- type Currency,
16
- OrderbookKind,
17
- type Step,
18
- StepType,
19
- type WalletKind,
20
- collectableKeys,
21
- } from '../../../_internal';
22
- import {
23
- useCollectible,
24
- useCollection,
25
- useGenerateListingTransaction,
26
- } from '../../../hooks';
27
- import { useTransactionStatusModal } from '../_internal/components/transactionStatusModal';
28
- import {
29
- getCreateListingTransactionMessage,
30
- getCreateListingTransactionTitle,
31
- } from './_utils/getCreateListingTransactionTitleMessage';
3
+ import type { Hash, Hex } from 'viem';
4
+ import type { Currency } from '../../../../types';
5
+ import type { ModalCallbacks } from '../_internal/types';
32
6
 
33
- export interface CreateListingModalState {
34
- isOpen: boolean;
35
- open: (args: ShowCreateListingModalArgs) => void;
36
- close: () => void;
37
- state: {
38
- collectionName: string;
39
- collectionType: CollectionType | undefined;
40
- listingPrice: Price;
41
- quantity: string;
7
+ const initialState = {
8
+ isOpen: false,
9
+ collectionAddress: '' as Hex,
10
+ chainId: '',
11
+ collectibleId: '',
12
+ collectionName: '',
13
+ collectionType: undefined,
14
+ listingPrice: {
15
+ amountRaw: '0',
16
+ currency: {} as Currency,
17
+ },
18
+ quantity: '1',
19
+ expiry: new Date(addDays(new Date(), 7).toJSON()),
20
+ callbacks: undefined as ModalCallbacks | undefined,
21
+
22
+ onError: undefined as undefined | ((error: Error) => void),
23
+ onSuccess: undefined as undefined | ((hash: Hash) => void),
24
+
25
+ open: (args: {
42
26
  collectionAddress: Hex;
43
27
  chainId: string;
44
28
  collectibleId: string;
45
- expiry: Date;
46
- errorCallbacks?: CreateListingErrorCallbacks;
47
- successCallbacks?: CreateListingSuccessCallbacks;
48
- };
49
- steps: {
50
- isLoading: () => boolean;
51
- stepsData: Step[] | undefined;
52
- _currentStep: null | 'tokenApproval' | 'createListing';
53
- tokenApproval: {
54
- isNeeded: () => boolean;
55
- pending: boolean;
56
- getStep: () => Step | undefined;
57
- execute: () => void;
58
- };
59
- createListing: {
60
- pending: boolean;
61
- execute: () => void;
62
- };
63
- };
64
- hash: Hex | undefined;
65
- }
66
-
67
- export const initialState: CreateListingModalState = {
68
- isOpen: false,
69
- open: ({
70
- collectionAddress,
71
- chainId,
72
- collectibleId,
73
- }: ShowCreateListingModalArgs) => {
74
- createListingModal$.state.set({
75
- ...createListingModal$.state.get(),
76
- collectionAddress,
77
- chainId,
78
- collectibleId,
79
- });
29
+ callbacks?: ModalCallbacks;
30
+ defaultCallbacks?: ModalCallbacks;
31
+ onSuccess?: (hash?: Hash) => void;
32
+ onError?: (error: Error) => void;
33
+ }) => {
34
+ createListingModal$.collectionAddress.set(args.collectionAddress);
35
+ createListingModal$.chainId.set(args.chainId);
36
+ createListingModal$.collectibleId.set(args.collectibleId);
37
+ createListingModal$.callbacks.set(args.callbacks || args.defaultCallbacks);
38
+ createListingModal$.onSuccess.set(args.onSuccess);
39
+ createListingModal$.onError.set(args.onError);
80
40
  createListingModal$.isOpen.set(true);
81
41
  },
82
42
  close: () => {
83
43
  createListingModal$.isOpen.set(false);
44
+ createListingModal$.callbacks.set(undefined);
84
45
  },
85
- state: {
86
- collectionName: '',
87
- listingPrice: {
88
- amountRaw: '0',
89
- currency: {} as Currency,
90
- },
91
- quantity: '1',
92
- expiry: new Date(addDays(new Date(), 7).toJSON()),
93
- collectionType: undefined,
94
- collectionAddress: '' as Hex,
95
- chainId: '',
96
- collectibleId: '',
97
- },
98
- steps: {
99
- isLoading: () => !!createListingModal$.steps.stepsData.get(),
100
- stepsData: undefined,
101
- _currentStep: null,
102
- tokenApproval: {} as CreateListingModalState['steps']['tokenApproval'],
103
- createListing: {} as CreateListingModalState['steps']['createListing'],
104
- },
105
- hash: undefined,
106
46
  };
107
47
 
108
48
  export const createListingModal$ = observable(initialState);
109
-
110
- const exp = new Date(addDays(new Date(), 7).toJSON());
111
-
112
- export const useHydrate = () => {
113
- const chainId = useSelector(createListingModal$.state.chainId);
114
- const collectionAddress = useSelector(
115
- createListingModal$.state.collectionAddress,
116
- );
117
- const collectionType = useSelector(createListingModal$.state.collectionType);
118
- const { data: collection, isSuccess: isSuccessCollection } = useCollection({
119
- chainId,
120
- collectionAddress,
121
- });
122
-
123
- when(isSuccessCollection, () => {
124
- createListingModal$.state.collectionName.set(collection!.name);
125
- createListingModal$.state.collectionType.set(
126
- collection!.type as CollectionType,
127
- );
128
- });
129
-
130
- useTokenApprovalHandler(chainId);
131
- useCreateListingHandler(chainId);
132
- useShowTransactionStatusModal();
133
-
134
- const onListingSuccess = (data?: Step[]) => {
135
- createListingModal$.steps.stepsData.set(data);
136
- };
137
-
138
- const { generateListingTransactionAsync } = useGenerateListingTransaction({
139
- chainId,
140
- onSuccess: onListingSuccess,
141
- });
142
-
143
- const { connector, address: userAddress } = useAccount();
144
-
145
- useMount(() => {
146
- const setSteps = async () => {
147
- const createListingTransactionSteps =
148
- await generateListingTransactionAsync({
149
- collectionAddress,
150
- orderbook: OrderbookKind.sequence_marketplace_v1,
151
- listing: {
152
- tokenId: '1',
153
- quantity: '1',
154
- expiry: exp,
155
- currencyAddress:
156
- createListingModal$.state.listingPrice.currency.contractAddress.get(),
157
- pricePerToken:
158
- createListingModal$.state.listingPrice.amountRaw.get() || '1',
159
- },
160
- contractType: collectionType!,
161
- walletType: connector?.id as WalletKind,
162
- owner: userAddress!,
163
- });
164
-
165
- createListingModal$.steps.stepsData.set(createListingTransactionSteps);
166
- };
167
-
168
- when(isSuccessCollection && collectionType, setSteps);
169
- });
170
- };
171
-
172
- const useTokenApprovalHandler = (chainId: string) => {
173
- const { sendTransactionAsync, isPending, isSuccess } = useSendTransaction();
174
- const onError =
175
- createListingModal$.state.get().errorCallbacks?.onApproveTokenError;
176
- const onSuccess: (() => void) | undefined =
177
- createListingModal$.state.get().successCallbacks?.onApproveTokenSuccess;
178
-
179
- createListingModal$.steps.tokenApproval.set({
180
- isNeeded: () => !!createListingModal$.steps.tokenApproval.getStep(),
181
- getStep: () =>
182
- createListingModal$.steps.stepsData
183
- ?.get()
184
- ?.find((s) => s.id === StepType.tokenApproval),
185
- pending:
186
- createListingModal$.steps._currentStep.get() === 'tokenApproval' &&
187
- isPending,
188
- execute: async () => {
189
- const step = createListingModal$.steps.tokenApproval.getStep();
190
- if (!step) return;
191
- createListingModal$.steps._currentStep.set('tokenApproval');
192
-
193
- try {
194
- await sendTransactionAsync({
195
- to: step.to as Hex,
196
- chainId: Number(chainId),
197
- data: step.data as Hex,
198
- value: BigInt(step.value || '0'),
199
- });
200
-
201
- onSuccess && onSuccess();
202
- } catch (error) {
203
- onError && onError(error);
204
- }
205
- },
206
- });
207
-
208
- if (
209
- isSuccess &&
210
- createListingModal$.steps._currentStep.get() === 'tokenApproval'
211
- ) {
212
- createListingModal$.steps._currentStep.set(null);
213
- }
214
- };
215
-
216
- const useCreateListingHandler = (chainId: string) => {
217
- const { collectibleId, collectionAddress, errorCallbacks, successCallbacks } =
218
- createListingModal$.state.get();
219
- const { connector, address } = useAccount();
220
- const {
221
- generateListingTransactionAsync,
222
- isPending: generateListingTransactionPending,
223
- } = useGenerateListingTransaction({ chainId });
224
- const { data: collectible } = useCollectible({
225
- chainId,
226
- collectionAddress,
227
- collectibleId,
228
- });
229
-
230
- const { sendTransactionAsync, isPending: sendTransactionPending } =
231
- useSendTransaction();
232
-
233
- const { show: showTransactionStatusModal } = useTransactionStatusModal();
234
-
235
- createListingModal$.steps.createListing.set({
236
- pending:
237
- createListingModal$.steps._currentStep.get() === 'createListing' &&
238
- (generateListingTransactionPending || sendTransactionPending),
239
- execute: () => {
240
- createListingModal$.steps._currentStep.set('createListing');
241
- generateListingTransactionAsync({
242
- collectionAddress: createListingModal$.state.collectionAddress.get(),
243
- contractType: createListingModal$.state.collectionType.get()!,
244
- orderbook: OrderbookKind.sequence_marketplace_v1,
245
- walletType: connector?.id as WalletKind,
246
- listing: {
247
- tokenId: createListingModal$.state.collectibleId.get(),
248
- quantity: createListingModal$.state.quantity.get(),
249
- expiry: createListingModal$.state.expiry.get(),
250
- currencyAddress:
251
- createListingModal$.state.listingPrice.currency.contractAddress.get(),
252
- pricePerToken:
253
- createListingModal$.state.listingPrice.amountRaw.get() || '1',
254
- },
255
- owner: address!,
256
- })
257
- .then(async (steps) => {
258
- const step = steps.find((s) => s.id === StepType.createListing);
259
- if (!step) throw new Error('No steps found');
260
- const hash = await sendTransactionAsync({
261
- to: step.to as Hex,
262
- chainId: Number(chainId),
263
- data: step.data as Hex,
264
- value: BigInt(step.value || '0'),
265
- });
266
-
267
- createListingModal$.hash.set(hash);
268
-
269
- createListingModal$.steps._currentStep.set(null);
270
-
271
- createListingModal$.close();
272
-
273
- showTransactionStatusModal({
274
- hash: hash!,
275
- price: createListingModal$.state.listingPrice.get(),
276
- collectionAddress,
277
- chainId,
278
- tokenId: collectibleId,
279
- getTitle: getCreateListingTransactionTitle,
280
- getMessage: (params) =>
281
- getCreateListingTransactionMessage(
282
- params,
283
- collectible?.name || '',
284
- ),
285
- type: 'transfer',
286
- callbacks: {
287
- onSuccess: successCallbacks?.onCreateListingSuccess,
288
- onUnknownError: errorCallbacks?.onCreateListingError,
289
- },
290
- queriesToInvalidate: collectableKeys.all as unknown as QueryKey[],
291
- });
292
- })
293
- .catch((error) => {
294
- errorCallbacks?.onCreateListingError?.(error);
295
- });
296
- },
297
- });
298
- };
299
-
300
- const useShowTransactionStatusModal = () => {
301
- const { hash } = createListingModal$.get();
302
- const { collectibleId, chainId, collectionAddress } =
303
- createListingModal$.state.get();
304
- const { data: collectible } = useCollectible({
305
- collectionAddress,
306
- chainId,
307
- collectibleId,
308
- });
309
-
310
- const { show: showTransactionStatusModal } = useTransactionStatusModal();
311
-
312
- when(!!hash, () => {
313
- showTransactionStatusModal({
314
- hash: hash!,
315
- collectionAddress,
316
- chainId,
317
- price: createListingModal$.state.listingPrice.get(),
318
- tokenId: collectibleId,
319
- getTitle: getCreateListingTransactionTitle,
320
- getMessage: (params) =>
321
- getCreateListingTransactionMessage(params, collectible?.name || ''),
322
- type: StepType.createListing,
323
- });
324
- });
325
- };