@0xsequence/marketplace-sdk 0.2.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 (204) hide show
  1. package/dist/chess-tile-6BS5MQT5.png +0 -0
  2. package/dist/chunk-22NLQ3AS.js +3078 -0
  3. package/dist/chunk-22NLQ3AS.js.map +1 -0
  4. package/dist/chunk-3OHM45R3.js +1294 -0
  5. package/dist/chunk-3OHM45R3.js.map +1 -0
  6. package/dist/{chunk-4E34HVSA.js → chunk-4YU2UPYH.js} +29 -74
  7. package/dist/chunk-4YU2UPYH.js.map +1 -0
  8. package/dist/chunk-7NJETFMF.js +21 -0
  9. package/dist/chunk-7NJETFMF.js.map +1 -0
  10. package/dist/{chunk-UYRQ5MJQ.js → chunk-FUM4OGOQ.js} +4 -4
  11. package/dist/chunk-FUM4OGOQ.js.map +1 -0
  12. package/dist/{chunk-FCQCNLFZ.js → chunk-G33554LK.js} +4 -1
  13. package/dist/chunk-G33554LK.js.map +1 -0
  14. package/dist/{chunk-7OO74L2K.js → chunk-GJAKQ5Q3.js} +40 -1
  15. package/dist/chunk-GJAKQ5Q3.js.map +1 -0
  16. package/dist/{chunk-GZIA25G4.js → chunk-GZG2QO64.js} +22 -6
  17. package/dist/chunk-GZG2QO64.js.map +1 -0
  18. package/dist/chunk-MCI3KOSQ.js +2 -0
  19. package/dist/{chunk-5EOVZAKT.js → chunk-O7UQGT43.js} +891 -100
  20. package/dist/chunk-O7UQGT43.js.map +1 -0
  21. package/dist/{chunk-CSN7YD5Q.js → chunk-Q57TEA3Z.js} +20 -2
  22. package/dist/chunk-Q57TEA3Z.js.map +1 -0
  23. package/dist/{chunk-VEX7FDL6.js → chunk-SBVLWSRZ.js} +2 -2
  24. package/dist/{chunk-VEX7FDL6.js.map → chunk-SBVLWSRZ.js.map} +1 -1
  25. package/dist/{chunk-6S4FYXP6.js → chunk-SPW24Y7I.js} +40 -1
  26. package/dist/chunk-SPW24Y7I.js.map +1 -0
  27. package/dist/chunk-UISBTKFF.js +1 -0
  28. package/dist/{chunk-LFQB477Y.js → chunk-WA433WAJ.js} +9 -33
  29. package/dist/chunk-WA433WAJ.js.map +1 -0
  30. package/dist/{chunk-O5JXKTWP.js → chunk-WFE6OCYF.js} +4 -4
  31. package/dist/chunk-WFE6OCYF.js.map +1 -0
  32. package/dist/chunk-XX4EVWBF.js +1292 -0
  33. package/dist/chunk-XX4EVWBF.js.map +1 -0
  34. package/dist/chunk-Y7YO5TLE.js +53 -0
  35. package/dist/chunk-Y7YO5TLE.js.map +1 -0
  36. package/dist/index.css +1 -50
  37. package/dist/index.d.ts +5 -7
  38. package/dist/index.js +158 -73
  39. package/dist/index.js.map +1 -1
  40. package/dist/{marketplace.gen-Ceofb9Cs.d.ts → marketplace.gen-BLP7822q.d.ts} +17 -5
  41. package/dist/react/_internal/api/index.d.ts +4 -2
  42. package/dist/react/_internal/api/index.js +1 -1
  43. package/dist/react/_internal/index.d.ts +3 -3
  44. package/dist/react/_internal/index.js +7 -7
  45. package/dist/react/hooks/index.css +82 -0
  46. package/dist/react/hooks/index.css.map +1 -0
  47. package/dist/react/hooks/index.d.ts +577 -427
  48. package/dist/react/hooks/index.js +39 -7
  49. package/dist/react/index.css +86 -81
  50. package/dist/react/index.css.map +1 -1
  51. package/dist/react/index.d.ts +6 -5
  52. package/dist/react/index.js +49 -16
  53. package/dist/react/ssr/index.js +4 -3
  54. package/dist/react/ssr/index.js.map +1 -1
  55. package/dist/react/ui/components/index.css +241 -0
  56. package/dist/react/ui/components/index.css.map +1 -0
  57. package/dist/react/ui/components/index.d.ts +23 -0
  58. package/dist/react/ui/components/index.js +25 -0
  59. package/dist/react/ui/icons/index.js +3 -2
  60. package/dist/react/ui/icons/index.js.map +1 -1
  61. package/dist/react/ui/index.css +86 -81
  62. package/dist/react/ui/index.css.map +1 -1
  63. package/dist/react/ui/index.d.ts +34 -33
  64. package/dist/react/ui/index.js +17 -12
  65. package/dist/react/ui/modals/_internal/components/actionModal/index.js +6 -17
  66. package/dist/react/ui/modals/_internal/components/actionModal/index.js.map +1 -1
  67. package/dist/react/ui/styles/index.d.ts +1 -1
  68. package/dist/{services-Dei25J6_.d.ts → services-C9-lvWcC.d.ts} +1 -1
  69. package/dist/styles/index.css +1 -50
  70. package/dist/styles/index.css.map +1 -1
  71. package/dist/styles/index.d.ts +1 -5
  72. package/dist/styles/index.js +10 -12
  73. package/dist/types/index.d.ts +2 -2
  74. package/dist/types/index.js +2 -2
  75. package/dist/{types-BzZVURNL.d.ts → types-QqXjNuUP.d.ts} +1 -1
  76. package/dist/utils/abi/index.d.ts +2 -0
  77. package/dist/utils/abi/index.js +21 -0
  78. package/dist/utils/abi/marketplace/index.d.ts +805 -0
  79. package/dist/utils/abi/marketplace/index.js +12 -0
  80. package/dist/utils/abi/{abi/token → token}/index.js +1 -2
  81. package/dist/utils/abi/token/index.js.map +1 -0
  82. package/dist/utils/index.d.ts +7 -7
  83. package/dist/utils/index.js +12 -14
  84. package/package.json +17 -15
  85. package/src/react/_internal/api/get-query-client.ts +3 -3
  86. package/src/react/_internal/api/marketplace.gen.ts +34 -10
  87. package/src/react/_internal/api/query-keys.ts +8 -0
  88. package/src/react/_internal/transaction-machine/execute-transaction.ts +592 -0
  89. package/src/react/_internal/transaction-machine/useTransactionMachine.ts +66 -0
  90. package/src/react/hooks/index.ts +7 -0
  91. package/src/react/hooks/useBuyCollectable.tsx +38 -0
  92. package/src/react/hooks/useCancelOrder.tsx +38 -0
  93. package/src/react/hooks/useCheckoutOptions.tsx +46 -43
  94. package/src/react/hooks/useCountOfCollectables.tsx +52 -52
  95. package/src/react/hooks/useCreateListing.tsx +65 -0
  96. package/src/react/hooks/useCurrencies.tsx +60 -60
  97. package/src/react/hooks/useCurrency.tsx +64 -0
  98. package/src/react/hooks/useGenerateBuyTransaction.tsx +71 -0
  99. package/src/react/hooks/useGenerateCancelTransaction.tsx +50 -0
  100. package/src/react/hooks/useListBalances.tsx +2 -3
  101. package/src/react/hooks/useListCollectibles.tsx +5 -6
  102. package/src/react/hooks/useListCollections.tsx +88 -0
  103. package/src/react/hooks/useListListingsForCollectible.tsx +61 -0
  104. package/src/react/hooks/useListOffersForCollectible.tsx +14 -16
  105. package/src/react/hooks/useMakeOffer.tsx +62 -0
  106. package/src/react/hooks/useRoyaltyPercentage.tsx +1 -1
  107. package/src/react/hooks/useSell.tsx +62 -0
  108. package/src/react/ui/components/_internals/action-button/ActionButton.tsx +156 -0
  109. package/src/react/ui/components/_internals/custom-network-image/CustomNetworkImage.tsx +27 -0
  110. package/src/react/ui/components/_internals/custom-network-image/styles.css.ts +51 -0
  111. package/src/react/ui/components/_internals/custom-select/CustomSelect.tsx +63 -0
  112. package/src/react/ui/components/_internals/custom-select/styles.css.ts +64 -0
  113. package/src/react/ui/components/_internals/pill/Pill.tsx +20 -0
  114. package/src/react/ui/components/collectible-card/CollectibleCard.tsx +191 -0
  115. package/src/react/ui/components/collectible-card/Footer.tsx +128 -0
  116. package/src/react/ui/components/collectible-card/styles.css.ts +62 -0
  117. package/src/react/ui/components/index.ts +1 -0
  118. package/src/react/ui/icons/Bell.tsx +31 -0
  119. package/src/react/ui/icons/DiamondEye.tsx +31 -0
  120. package/src/react/ui/images/chess-tile.png +0 -0
  121. package/src/react/ui/index.ts +4 -0
  122. package/src/react/ui/modals/BuyModal/_store.ts +53 -0
  123. package/src/react/ui/modals/BuyModal/index.tsx +119 -0
  124. package/src/react/ui/modals/CreateListingModal/_store.ts +35 -312
  125. package/src/react/ui/modals/CreateListingModal/index.tsx +216 -157
  126. package/src/react/ui/modals/MakeOfferModal/_store.ts +34 -276
  127. package/src/react/ui/modals/MakeOfferModal/index.tsx +195 -136
  128. package/src/react/ui/modals/SellModal/_store.ts +29 -262
  129. package/src/react/ui/modals/SellModal/index.tsx +156 -122
  130. package/src/react/ui/modals/SuccessfulPurchaseModal/_store.ts +17 -3
  131. package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +3 -2
  132. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +92 -92
  133. package/src/react/ui/modals/TransferModal/index.tsx +10 -17
  134. package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +1 -0
  135. package/src/react/ui/modals/_internal/components/actionModal/ErrorModal.tsx +18 -0
  136. package/src/react/ui/modals/_internal/components/actionModal/LoadingModal.tsx +18 -0
  137. package/src/react/ui/modals/_internal/components/calendarPopover/index.tsx +1 -0
  138. package/src/react/ui/modals/_internal/components/calendarPopover/overrides.css +8 -0
  139. package/src/react/ui/modals/_internal/components/calendarPopover/styles.css.ts +10 -4
  140. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +10 -13
  141. package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +23 -9
  142. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +7 -18
  143. package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +17 -44
  144. package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +10 -8
  145. package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +14 -3
  146. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +4 -2
  147. package/src/react/ui/modals/_internal/components/transactionHeader/index.tsx +4 -4
  148. package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +4 -2
  149. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +13 -10
  150. package/src/react/ui/modals/_internal/types.ts +13 -0
  151. package/src/react/ui/modals/modal-provider.tsx +2 -1
  152. package/src/styles/index.ts +0 -2
  153. package/src/types/custom.d.ts +1 -0
  154. package/src/utils/abi/index.ts +2 -0
  155. package/src/utils/abi/marketplace/index.ts +3 -0
  156. package/src/utils/abi/marketplace/sequence-marketplace-v1.ts +463 -0
  157. package/src/utils/abi/marketplace/sequence-marketplace-v2.ts +802 -0
  158. package/src/utils/index.ts +2 -3
  159. package/src/utils/network.ts +4 -2
  160. package/tsconfig.tsbuildinfo +1 -1
  161. package/dist/chunk-4E34HVSA.js.map +0 -1
  162. package/dist/chunk-5EOVZAKT.js.map +0 -1
  163. package/dist/chunk-6JWGELXL.js +0 -214
  164. package/dist/chunk-6JWGELXL.js.map +0 -1
  165. package/dist/chunk-6S4FYXP6.js.map +0 -1
  166. package/dist/chunk-7OO74L2K.js.map +0 -1
  167. package/dist/chunk-BCNFYVAL.js +0 -1
  168. package/dist/chunk-CSN7YD5Q.js.map +0 -1
  169. package/dist/chunk-D7QQP6MS.js +0 -2
  170. package/dist/chunk-DBFOPEV6.js +0 -23
  171. package/dist/chunk-DBFOPEV6.js.map +0 -1
  172. package/dist/chunk-FCQCNLFZ.js.map +0 -1
  173. package/dist/chunk-GZIA25G4.js.map +0 -1
  174. package/dist/chunk-LFQB477Y.js.map +0 -1
  175. package/dist/chunk-MD4JHPMH.js +0 -2815
  176. package/dist/chunk-MD4JHPMH.js.map +0 -1
  177. package/dist/chunk-O5JXKTWP.js.map +0 -1
  178. package/dist/chunk-PE2LLUTJ.js +0 -213
  179. package/dist/chunk-PE2LLUTJ.js.map +0 -1
  180. package/dist/chunk-QVFMD6S2.js +0 -21
  181. package/dist/chunk-QVFMD6S2.js.map +0 -1
  182. package/dist/chunk-UYRQ5MJQ.js.map +0 -1
  183. package/dist/utils/abi/abi/standard/index.d.ts +0 -25
  184. package/dist/utils/abi/abi/standard/index.js +0 -8
  185. package/dist/utils/abi/clients/index.d.ts +0 -27
  186. package/dist/utils/abi/clients/index.js +0 -13
  187. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/styles.css.ts +0 -33
  188. package/src/react/ui/modals/_internal/components/expirationDateSelect/styles.css.ts +0 -25
  189. package/src/utils/abi/abi/standard/index.ts +0 -1
  190. package/src/utils/abi/clients/ERC1155.ts +0 -82
  191. package/src/utils/abi/clients/ERC20.ts +0 -101
  192. package/src/utils/abi/clients/ERC721.ts +0 -97
  193. package/src/utils/abi/clients/index.ts +0 -3
  194. /package/dist/{chunk-BCNFYVAL.js.map → chunk-MCI3KOSQ.js.map} +0 -0
  195. /package/dist/{chunk-D7QQP6MS.js.map → chunk-UISBTKFF.js.map} +0 -0
  196. /package/dist/{utils/abi/abi/standard → react/ui/components}/index.js.map +0 -0
  197. /package/dist/utils/abi/{abi/token/index.js.map → index.js.map} +0 -0
  198. /package/dist/utils/abi/{clients → marketplace}/index.js.map +0 -0
  199. /package/dist/utils/abi/{abi/token → token}/index.d.ts +0 -0
  200. /package/src/utils/abi/{abi/standard → marketplace}/EIP2981.ts +0 -0
  201. /package/src/utils/abi/{abi/token → token}/ERC1155.ts +0 -0
  202. /package/src/utils/abi/{abi/token → token}/ERC20.ts +0 -0
  203. /package/src/utils/abi/{abi/token → token}/ERC721.ts +0 -0
  204. /package/src/utils/abi/{abi/token → token}/index.ts +0 -0
@@ -1,276 +1,43 @@
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 type { Hex } from 'viem';
5
- import { useAccount, useSendTransaction } from 'wagmi';
6
- import type { ShowSellModalArgs } from '.';
7
- import type {
8
- SellErrorCallbacks,
9
- SellSuccessCallbacks,
10
- } from '../../../../types/callbacks';
11
- import {
12
- MarketplaceKind,
13
- type Order,
14
- type Step,
15
- StepType,
16
- type WalletKind,
17
- balanceQueries,
18
- collectableKeys,
19
- } from '../../../_internal';
20
- import {
21
- useCollectible,
22
- useCurrencies,
23
- useGenerateSellTransaction,
24
- } from '../../../hooks';
25
- import { useTransactionStatusModal } from '../_internal/components/transactionStatusModal';
26
- import {
27
- getSellTransactionMessage,
28
- getSellTransactionTitle,
29
- } from './_utils/getSellTransactionTitleMessage';
3
+ import type { Order } from '../../../_internal';
4
+ import type { BaseModalState, ModalCallbacks } from '../_internal/types';
30
5
 
31
- export interface SellModalState {
32
- isOpen: boolean;
33
- open: (args: ShowSellModalArgs) => void;
34
- close: () => void;
35
- state: {
6
+ type SellModalState = BaseModalState & {
7
+ tokenId: string;
8
+ order?: Order;
9
+ };
10
+
11
+ const initialState: SellModalState & {
12
+ open: (args: {
36
13
  collectionAddress: Hex;
37
14
  chainId: string;
38
15
  tokenId: string;
39
- order: Order | undefined;
40
- errorCallbacks?: SellErrorCallbacks;
41
- successCallbacks?: SellSuccessCallbacks;
42
- };
43
- steps: {
44
- isLoading: () => boolean;
45
- stepsData: Step[] | undefined;
46
- _currentStep: null | 'tokenApproval' | 'sell';
47
- tokenApproval: {
48
- isNeeded: () => boolean;
49
- pending: boolean;
50
- getStep: () => Step | undefined;
51
- execute: () => void;
52
- };
53
- sell: {
54
- pending: boolean;
55
- execute: () => void;
56
- };
57
- };
58
- hash: Hex | undefined;
59
- }
60
-
61
- export const initialState: SellModalState = {
16
+ order: Order;
17
+ callbacks?: ModalCallbacks;
18
+ }) => void;
19
+ close: () => void;
20
+ } = {
62
21
  isOpen: false,
63
- open: ({ collectionAddress, chainId, tokenId, order }: ShowSellModalArgs) => {
64
- sellModal$.state.set({
65
- ...sellModal$.state.get(),
66
- collectionAddress,
67
- chainId,
68
- tokenId,
69
- order,
70
- });
22
+ collectionAddress: '' as Hex,
23
+ chainId: '',
24
+ tokenId: '',
25
+ order: undefined,
26
+ callbacks: undefined,
27
+
28
+ open: (args) => {
29
+ sellModal$.collectionAddress.set(args.collectionAddress);
30
+ sellModal$.chainId.set(args.chainId);
31
+ sellModal$.tokenId.set(args.tokenId);
32
+ sellModal$.order.set(args.order);
33
+ sellModal$.callbacks.set(args.callbacks);
71
34
  sellModal$.isOpen.set(true);
72
35
  },
36
+
73
37
  close: () => {
74
38
  sellModal$.isOpen.set(false);
75
- sellModal$.state.set({
76
- ...initialState.state,
77
- });
78
- },
79
- state: {
80
- collectionAddress: '' as Hex,
81
- chainId: '',
82
- tokenId: '',
83
- order: undefined,
39
+ sellModal$.callbacks.set(undefined);
84
40
  },
85
- steps: {
86
- isLoading: () => !!sellModal$.steps.stepsData.get(),
87
- stepsData: undefined,
88
- _currentStep: null,
89
- tokenApproval: {} as SellModalState['steps']['tokenApproval'],
90
- sell: {} as SellModalState['steps']['sell'],
91
- },
92
- hash: undefined,
93
41
  };
94
42
 
95
43
  export const sellModal$ = observable(initialState);
96
-
97
- export const useHydrate = () => {
98
- const chainId = useSelector(sellModal$.state.chainId);
99
-
100
- const collectionAddress = useSelector(sellModal$.state.collectionAddress);
101
-
102
- const order = useSelector(sellModal$.state.order);
103
-
104
- useTokenApprovalHandler(chainId);
105
- useSellHandler(chainId);
106
-
107
- const { generateSellTransactionAsync } = useGenerateSellTransaction({
108
- chainId,
109
- });
110
-
111
- const { connector, address } = useAccount();
112
-
113
- useMount(() => {
114
- const setSteps = async () => {
115
- const sellTransactionData = await generateSellTransactionAsync({
116
- walletType: connector?.walletType as WalletKind,
117
- collectionAddress: collectionAddress,
118
- seller: address as string,
119
- marketplace: MarketplaceKind.sequence_marketplace_v1,
120
- ordersData: [
121
- {
122
- ...order!,
123
- orderId: order!.orderId,
124
- quantity: '1',
125
- },
126
- ],
127
- additionalFees: [],
128
- });
129
- sellModal$.steps.stepsData.set(sellTransactionData);
130
- };
131
-
132
- when(() => !!order && !!connector, setSteps);
133
- });
134
- };
135
-
136
- const useTokenApprovalHandler = (chainId: string) => {
137
- const { sendTransactionAsync, isPending } = useSendTransaction();
138
- const onError = sellModal$.state.get().errorCallbacks?.onApproveTokenError;
139
- const onSuccess: (() => void) | undefined =
140
- sellModal$.state.get().successCallbacks?.onApproveTokenSuccess;
141
-
142
- sellModal$.steps.tokenApproval.set({
143
- isNeeded: () => !!sellModal$.steps.tokenApproval.getStep(),
144
- getStep: () =>
145
- sellModal$.steps.stepsData
146
- ?.get()
147
- ?.find((s) => s.id === StepType.tokenApproval),
148
- pending:
149
- sellModal$.steps._currentStep.get() === 'tokenApproval' && isPending,
150
- execute: async () => {
151
- const step = sellModal$.steps.tokenApproval.getStep();
152
- if (!step) return;
153
- sellModal$.steps._currentStep.set('tokenApproval');
154
-
155
- try {
156
- await sendTransactionAsync({
157
- to: step.to as Hex,
158
- chainId: Number(chainId),
159
- data: step.data as Hex,
160
- value: BigInt(step.value || '0'),
161
- });
162
-
163
- sellModal$.steps._currentStep.set(null);
164
-
165
- onSuccess && onSuccess();
166
- } catch (error) {
167
- onError && onError(error);
168
- }
169
- },
170
- });
171
- };
172
-
173
- const useSellHandler = (chainId: string) => {
174
- const { tokenId, collectionAddress, errorCallbacks, successCallbacks } =
175
- sellModal$.state.get();
176
- const { address } = useAccount();
177
- const {
178
- generateSellTransactionAsync,
179
- isPending: generateSellTransactionPending,
180
- } = useGenerateSellTransaction({
181
- chainId,
182
- });
183
- const { data: collectible } = useCollectible({
184
- chainId,
185
- collectibleId: tokenId,
186
- collectionAddress,
187
- });
188
- const { data: currencies } = useCurrencies({ chainId });
189
-
190
- const { sendTransactionAsync, isPending: sendTransactionPending } =
191
- useSendTransaction();
192
- const { show: showTransactionStatusModal } = useTransactionStatusModal();
193
-
194
- function setSellStep() {
195
- sellModal$.steps.sell.set({
196
- pending:
197
- sellModal$.steps._currentStep.get() === 'sell' &&
198
- (generateSellTransactionPending || sendTransactionPending),
199
- execute: () => {
200
- sellModal$.steps._currentStep.set('sell');
201
- const { collectionAddress, order } = sellModal$.state.get();
202
-
203
- generateSellTransactionAsync({
204
- collectionAddress: collectionAddress,
205
- seller: address as string,
206
- marketplace: order!.marketplace,
207
- ordersData: [
208
- {
209
- ...order!,
210
- quantity: '1',
211
- },
212
- ],
213
- additionalFees: order?.feeBreakdown
214
- ? [
215
- {
216
- amount: String(order!.feeBps),
217
- receiver: order!.feeBreakdown?.[0]?.recipientAddress,
218
- },
219
- ]
220
- : [],
221
- })
222
- .then(async (response) => {
223
- const step = response.find((s) => s.id === StepType.sell);
224
- if (!step) throw new Error('No steps found');
225
- try {
226
- const hash = await sendTransactionAsync({
227
- to: step.to as Hex,
228
- chainId: Number(chainId),
229
- data: step.data as Hex,
230
- value: BigInt(step.value || '0'),
231
- });
232
-
233
- sellModal$.hash.set(hash);
234
-
235
- sellModal$.steps._currentStep.set(null);
236
-
237
- sellModal$.close();
238
-
239
- showTransactionStatusModal({
240
- hash: hash!,
241
- price: {
242
- amountRaw: order!.priceAmount,
243
- currency: currencies!.find(
244
- (currency) =>
245
- currency.contractAddress === order!.priceCurrencyAddress,
246
- )!,
247
- },
248
- collectionAddress,
249
- chainId,
250
- tokenId,
251
- getTitle: getSellTransactionTitle,
252
- getMessage: (params) =>
253
- getSellTransactionMessage(params, collectible?.name || ''),
254
- type: StepType.sell,
255
- callbacks: {
256
- onSuccess: successCallbacks?.onSellSuccess,
257
- onUnknownError: errorCallbacks?.onSellError,
258
- },
259
- queriesToInvalidate: [
260
- ...collectableKeys.all,
261
- balanceQueries.all,
262
- ] as unknown as QueryKey[],
263
- });
264
- } catch (error) {
265
- errorCallbacks?.onSellError?.(error);
266
- }
267
- })
268
- .catch((error) => {
269
- errorCallbacks?.onSellError?.(error);
270
- });
271
- },
272
- });
273
- }
274
-
275
- when(currencies && collectible, setSellStep);
276
- };
@@ -1,148 +1,182 @@
1
1
  import { Show, observer } from '@legendapp/state/react';
2
2
  import type { Hex } from 'viem';
3
- import { useAccount } from 'wagmi';
4
- import type { Price } from '../../../../types';
5
- import type {
6
- SellErrorCallbacks,
7
- SellSuccessCallbacks,
8
- } from '../../../../types/callbacks';
9
- import type { Order } from '../../../_internal';
10
- import { useCollection, useCurrencies } from '../../../hooks';
11
- import {
12
- ActionModal,
13
- type ActionModalProps,
14
- } from '../_internal/components/actionModal/ActionModal';
15
- import { useSwitchChainModal } from '../_internal/components/switchChainModal';
3
+ import { ActionModal } from '../_internal/components/actionModal/ActionModal';
16
4
  import TokenPreview from '../_internal/components/tokenPreview';
17
5
  import TransactionDetails from '../_internal/components/transactionDetails';
18
6
  import TransactionHeader from '../_internal/components/transactionHeader';
19
- import { sellModal$, useHydrate } from './_store';
7
+ import { sellModal$ } from './_store';
8
+ import { useCollection, useCurrencies } from '../../../hooks';
9
+ import {
10
+ balanceQueries,
11
+ collectableKeys,
12
+ StepType,
13
+ type Order,
14
+ } from '../../../_internal';
15
+ import { useSell } from '../../../hooks/useSell';
16
+ import { LoadingModal } from '../_internal/components/actionModal/LoadingModal';
17
+ import { ErrorModal } from '..//_internal/components/actionModal/ErrorModal';
18
+ import type { ModalCallbacks } from '..//_internal/types';
19
+ import {
20
+ getSellTransactionMessage,
21
+ getSellTransactionTitle,
22
+ } from './_utils/getSellTransactionTitleMessage';
23
+ import { useTransactionStatusModal } from '../_internal/components/transactionStatusModal';
24
+ import type { QueryKey } from '@tanstack/react-query';
20
25
 
21
26
  export type ShowSellModalArgs = {
22
27
  chainId: string;
23
28
  collectionAddress: Hex;
24
29
  tokenId: string;
25
30
  order: Order;
26
- collectibleName: string | undefined;
27
31
  };
28
32
 
29
- export const useSellModal = () => {
30
- const { chainId: accountChainId } = useAccount();
31
- const { show: showSwitchNetworkModal } = useSwitchChainModal();
32
- const { errorCallbacks, successCallbacks } = sellModal$.state.get();
33
-
34
- const openModal = (args: ShowSellModalArgs) => {
35
- sellModal$.open(args);
36
- };
37
-
38
- const handleShowModal = (args: ShowSellModalArgs) => {
39
- const isSameChain = accountChainId === Number(args.chainId);
40
-
41
- if (!isSameChain) {
42
- showSwitchNetworkModal({
43
- chainIdToSwitchTo: Number(args.chainId),
44
- onSwitchChain: () => openModal(args),
45
- callbacks: {
46
- onSuccess: successCallbacks?.onSwitchChainSuccess,
47
- onUnknownError: errorCallbacks?.onSwitchChainError,
48
- onSwitchingNotSupported: errorCallbacks?.onSwitchingNotSupportedError,
49
- onUserRejectedRequest:
50
- errorCallbacks?.onUserRejectedSwitchingChainRequestError,
51
- },
52
- });
53
- return;
54
- }
55
-
56
- openModal(args);
57
- };
58
-
59
- return {
60
- show: handleShowModal,
61
- close: () => sellModal$.close(),
62
- onError: (callbacks: SellErrorCallbacks) => {
63
- sellModal$.state.set({
64
- ...sellModal$.state.get(),
65
- errorCallbacks: callbacks,
66
- });
67
- },
68
- onSuccess: (callbacks: SellSuccessCallbacks) => {
69
- sellModal$.state.set({
70
- ...sellModal$.state.get(),
71
- successCallbacks: callbacks,
72
- });
73
- },
74
- };
75
- };
33
+ export const useSellModal = (defaultCallbacks?: ModalCallbacks) => ({
34
+ show: (args: ShowSellModalArgs) =>
35
+ sellModal$.open({ ...args, callbacks: defaultCallbacks }),
36
+ close: sellModal$.close,
37
+ });
76
38
 
77
39
  export const SellModal = () => {
40
+ const { show: showTransactionStatusModal } = useTransactionStatusModal();
78
41
  return (
79
42
  <Show if={sellModal$.isOpen}>
80
- <Modal />
43
+ <ModalContent showTransactionStatusModal={showTransactionStatusModal} />
81
44
  </Show>
82
45
  );
83
46
  };
84
47
 
85
- const Modal = () => {
86
- useHydrate();
87
- return <ModalContent />;
88
- };
48
+ type TransactionStatusModalReturn = ReturnType<
49
+ typeof useTransactionStatusModal
50
+ >;
89
51
 
90
- const ModalContent = observer(() => {
91
- const modalState = sellModal$.state.get();
92
- const { collectionAddress, chainId, tokenId, order } = modalState;
52
+ const ModalContent = observer(
53
+ ({
54
+ showTransactionStatusModal,
55
+ }: {
56
+ showTransactionStatusModal: TransactionStatusModalReturn['show'];
57
+ }) => {
58
+ const { tokenId, collectionAddress, chainId, order } = sellModal$.get();
59
+ const { data: collectible } = useCollection({
60
+ chainId,
61
+ collectionAddress,
62
+ });
93
63
 
94
- const { steps } = sellModal$.get();
64
+ const { sell } = useSell({
65
+ collectionAddress,
66
+ chainId,
67
+ onTransactionSent: (hash) => {
68
+ if (!hash) return;
69
+ showTransactionStatusModal({
70
+ hash: hash,
71
+ price: {
72
+ amountRaw: order!.priceAmount,
73
+ currency: currencies!.find(
74
+ (currency) =>
75
+ currency.contractAddress === order!.priceCurrencyAddress,
76
+ )!,
77
+ },
78
+ collectionAddress,
79
+ chainId,
80
+ tokenId,
81
+ getTitle: getSellTransactionTitle,
82
+ getMessage: (params) =>
83
+ getSellTransactionMessage(params, collectible?.name || ''),
84
+ type: StepType.sell,
85
+ queriesToInvalidate: [
86
+ ...collectableKeys.all,
87
+ balanceQueries.all,
88
+ ] as unknown as QueryKey[],
89
+ });
90
+ sellModal$.close();
91
+ },
92
+ onSuccess: (hash) => {
93
+ sellModal$.callbacks?.onSuccess?.(hash);
94
+ },
95
+ onError: (error) => {
96
+ sellModal$.callbacks?.onError?.(error);
97
+ },
98
+ });
95
99
 
96
- const { data: collection } = useCollection({ chainId, collectionAddress });
97
- const { data: currencies } = useCurrencies({ chainId, collectionAddress });
98
- const currency = currencies?.find(
99
- (currency) => currency.contractAddress === order?.priceCurrencyAddress,
100
- );
100
+ const {
101
+ data: collection,
102
+ isLoading: collectionLoading,
103
+ isError: collectionError,
104
+ } = useCollection({
105
+ chainId,
106
+ collectionAddress,
107
+ });
101
108
 
102
- const ctas = [
103
- {
104
- label: 'Approve TOKEN',
105
- onClick: steps.tokenApproval.execute,
106
- hidden: !steps.tokenApproval.isNeeded(),
107
- pending: steps.tokenApproval.pending,
108
- variant: 'glass' as const,
109
- },
110
- {
111
- label: 'Accept',
112
- onClick: steps.sell.execute,
113
- pending: steps.sell.pending,
114
- disabled: steps.tokenApproval.isNeeded(),
115
- },
116
- ] satisfies ActionModalProps['ctas'];
109
+ const { data: currencies, isLoading: currenciesLoading } = useCurrencies({
110
+ chainId,
111
+ collectionAddress,
112
+ });
117
113
 
118
- return (
119
- <ActionModal
120
- store={sellModal$}
121
- onClose={() => sellModal$.close()}
122
- title="You have an offer"
123
- ctas={ctas}
124
- >
125
- <TransactionHeader
126
- title="Offer received"
127
- chainId={Number(chainId)}
128
- date={order && new Date(order.createdAt)}
129
- />
130
- <TokenPreview
131
- collectionName={collection?.name}
132
- collectionAddress={collectionAddress}
133
- collectibleId={tokenId}
134
- chainId={chainId}
135
- />
136
- <TransactionDetails
137
- collectibleId={tokenId}
138
- collectionAddress={collectionAddress}
139
- chainId={chainId}
140
- price={
141
- currency
142
- ? ({ amountRaw: order?.priceAmount, currency } as Price)
143
- : undefined
144
- }
145
- />
146
- </ActionModal>
147
- );
148
- });
114
+ if (collectionLoading || currenciesLoading) {
115
+ return (
116
+ <LoadingModal
117
+ store={sellModal$}
118
+ onClose={sellModal$.close}
119
+ title="You have an offer"
120
+ />
121
+ );
122
+ }
123
+
124
+ if (collectionError || order === undefined) {
125
+ return (
126
+ <ErrorModal
127
+ store={sellModal$}
128
+ onClose={sellModal$.close}
129
+ title="You have an offer"
130
+ />
131
+ );
132
+ }
133
+
134
+ const currency = currencies?.find(
135
+ (c) => c.contractAddress === order?.priceCurrencyAddress,
136
+ );
137
+
138
+ return (
139
+ <ActionModal
140
+ store={sellModal$}
141
+ onClose={sellModal$.close}
142
+ title="You have an offer"
143
+ ctas={[
144
+ {
145
+ label: 'Accept',
146
+ onClick: () =>
147
+ sell({
148
+ orderId: order?.orderId,
149
+ marketplace: order?.marketplace,
150
+ }),
151
+ },
152
+ ]}
153
+ >
154
+ <TransactionHeader
155
+ title="Offer received"
156
+ currencyImageUrl={currency?.imageUrl}
157
+ date={order && new Date(order.createdAt)}
158
+ />
159
+ <TokenPreview
160
+ collectionName={collection?.name}
161
+ collectionAddress={collectionAddress}
162
+ collectibleId={tokenId}
163
+ chainId={chainId}
164
+ />
165
+ <TransactionDetails
166
+ collectibleId={tokenId}
167
+ collectionAddress={collectionAddress}
168
+ chainId={chainId}
169
+ price={
170
+ currency
171
+ ? {
172
+ amountRaw: order?.priceAmount,
173
+ currency,
174
+ }
175
+ : undefined
176
+ }
177
+ currencyImageUrl={currency?.imageUrl}
178
+ />
179
+ </ActionModal>
180
+ );
181
+ },
182
+ );
@@ -1,12 +1,17 @@
1
1
  import type { ComponentType } from 'react';
2
-
3
2
  import type { IconProps } from '@0xsequence/design-system';
4
3
  import { observable } from '@legendapp/state';
5
4
  import type { TokenMetadata } from '../../../_internal';
5
+ import type { ModalCallbacks } from '../_internal/types';
6
6
 
7
7
  export interface SuccessfulPurchaseModalState {
8
8
  isOpen: boolean;
9
- open: (args: SuccessfulPurchaseModalState['state']) => void;
9
+ open: (
10
+ args: SuccessfulPurchaseModalState['state'] & {
11
+ callbacks?: ModalCallbacks;
12
+ defaultCallbacks?: ModalCallbacks;
13
+ },
14
+ ) => void;
10
15
  close: () => void;
11
16
  state: {
12
17
  collectibles: TokenMetadata[];
@@ -19,6 +24,7 @@ export interface SuccessfulPurchaseModalState {
19
24
  ctaIcon?: ComponentType<IconProps>;
20
25
  };
21
26
  };
27
+ callbacks?: ModalCallbacks;
22
28
  }
23
29
 
24
30
  const initialState: SuccessfulPurchaseModalState = {
@@ -29,7 +35,12 @@ const initialState: SuccessfulPurchaseModalState = {
29
35
  explorerName,
30
36
  explorerUrl,
31
37
  ctaOptions,
32
- }: SuccessfulPurchaseModalState['state']) => {
38
+ callbacks,
39
+ defaultCallbacks,
40
+ }: SuccessfulPurchaseModalState['state'] & {
41
+ callbacks?: ModalCallbacks;
42
+ defaultCallbacks?: ModalCallbacks;
43
+ }) => {
33
44
  successfulPurchaseModal$.state.set({
34
45
  ...successfulPurchaseModal$.state.get(),
35
46
  collectibles,
@@ -38,10 +49,12 @@ const initialState: SuccessfulPurchaseModalState = {
38
49
  explorerUrl: explorerUrl,
39
50
  ctaOptions,
40
51
  });
52
+ successfulPurchaseModal$.callbacks.set(callbacks || defaultCallbacks);
41
53
  successfulPurchaseModal$.isOpen.set(true);
42
54
  },
43
55
  close: () => {
44
56
  successfulPurchaseModal$.isOpen.set(false);
57
+ successfulPurchaseModal$.callbacks.set(undefined);
45
58
  successfulPurchaseModal$.state.set({
46
59
  ...initialState.state,
47
60
  });
@@ -53,6 +66,7 @@ const initialState: SuccessfulPurchaseModalState = {
53
66
  explorerUrl: '',
54
67
  ctaOptions: undefined,
55
68
  },
69
+ callbacks: undefined,
56
70
  };
57
71
 
58
72
  export const successfulPurchaseModal$ = observable(initialState);
@@ -25,11 +25,12 @@ import {
25
25
  dialogContent,
26
26
  dialogOverlay,
27
27
  } from './styles.css';
28
+ import type { ModalCallbacks } from '../_internal/types';
28
29
 
29
- export const useSuccessfulPurchaseModal = () => {
30
+ export const useSuccessfulPurchaseModal = (callbacks?: ModalCallbacks) => {
30
31
  return {
31
32
  show: (args: SuccessfulPurchaseModalState['state']) =>
32
- successfulPurchaseModal$.open(args),
33
+ successfulPurchaseModal$.open({ ...args, defaultCallbacks: callbacks }),
33
34
  close: () => successfulPurchaseModal$.close(),
34
35
  };
35
36
  };