@0xsequence/marketplace-sdk 0.3.2 → 0.3.4

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 (139) hide show
  1. package/dist/{chunk-NII6JJGH.js → chunk-3CXEYH2I.js} +5 -3
  2. package/dist/chunk-3CXEYH2I.js.map +1 -0
  3. package/dist/{chunk-GJAKQ5Q3.js → chunk-53Q7BNZH.js} +8 -2
  4. package/dist/chunk-53Q7BNZH.js.map +1 -0
  5. package/dist/{chunk-O7UQGT43.js → chunk-6LQST3KZ.js} +553 -283
  6. package/dist/chunk-6LQST3KZ.js.map +1 -0
  7. package/dist/{chunk-GZG2QO64.js → chunk-D3HRXVYJ.js} +72 -21
  8. package/dist/chunk-D3HRXVYJ.js.map +1 -0
  9. package/dist/{chunk-4YU2UPYH.js → chunk-FFCNYF3S.js} +61 -61
  10. package/dist/chunk-FFCNYF3S.js.map +1 -0
  11. package/dist/chunk-G2FYRJMK.js +38 -0
  12. package/dist/chunk-G2FYRJMK.js.map +1 -0
  13. package/dist/{chunk-WA433WAJ.js → chunk-L6GSYPCR.js} +20 -6
  14. package/dist/chunk-L6GSYPCR.js.map +1 -0
  15. package/dist/{chunk-SPW24Y7I.js → chunk-OUZ42I6B.js} +7 -2
  16. package/dist/chunk-OUZ42I6B.js.map +1 -0
  17. package/dist/{chunk-22NLQ3AS.js → chunk-PMDJARYX.js} +1081 -980
  18. package/dist/chunk-PMDJARYX.js.map +1 -0
  19. package/dist/chunk-T2AMWIKD.js +277 -0
  20. package/dist/chunk-T2AMWIKD.js.map +1 -0
  21. package/dist/{chunk-G33554LK.js → chunk-WQCWBXBM.js} +8 -16
  22. package/dist/chunk-WQCWBXBM.js.map +1 -0
  23. package/dist/index.css +40 -0
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.js +172 -71
  26. package/dist/index.js.map +1 -1
  27. package/dist/{marketplace.gen-BLP7822q.d.ts → marketplace.gen-jdKqutnd.d.ts} +57 -18
  28. package/dist/react/_internal/api/index.d.ts +4 -2
  29. package/dist/react/_internal/api/index.js +8 -3
  30. package/dist/react/_internal/index.d.ts +3 -3
  31. package/dist/react/_internal/index.js +9 -4
  32. package/dist/react/_internal/wagmi/index.js +2 -1
  33. package/dist/react/hooks/index.d.ts +285 -12
  34. package/dist/react/hooks/index.js +14 -5
  35. package/dist/react/index.css +29 -29
  36. package/dist/react/index.css.map +1 -1
  37. package/dist/react/index.d.ts +4 -4
  38. package/dist/react/index.js +17 -8
  39. package/dist/react/ssr/index.js +55 -4
  40. package/dist/react/ssr/index.js.map +1 -1
  41. package/dist/react/ui/components/index.css +13 -13
  42. package/dist/react/ui/components/index.css.map +1 -1
  43. package/dist/react/ui/components/index.d.ts +3 -3
  44. package/dist/react/ui/components/index.js +9 -8
  45. package/dist/react/ui/icons/index.js +1 -1
  46. package/dist/react/ui/icons/index.js.map +1 -1
  47. package/dist/react/ui/index.css +29 -29
  48. package/dist/react/ui/index.css.map +1 -1
  49. package/dist/react/ui/index.d.ts +3 -3
  50. package/dist/react/ui/index.js +9 -8
  51. package/dist/react/ui/modals/_internal/components/actionModal/index.js +3 -2
  52. package/dist/react/ui/styles/index.d.ts +1 -1
  53. package/dist/{services-C9-lvWcC.d.ts → services-C2O-7p_M.d.ts} +2 -2
  54. package/dist/styles/index.css +40 -0
  55. package/dist/styles/index.css.map +1 -1
  56. package/dist/styles/index.d.ts +9 -2
  57. package/dist/styles/index.js +14 -2
  58. package/dist/types/index.d.ts +2 -2
  59. package/dist/types/index.js +3 -2
  60. package/dist/{types-QqXjNuUP.d.ts → types-BlDoGvJV.d.ts} +1 -1
  61. package/dist/utils/index.d.ts +2 -2
  62. package/dist/utils/index.js +2 -1
  63. package/package.json +18 -15
  64. package/src/react/_internal/api/marketplace.gen.ts +85 -20
  65. package/src/react/_internal/api/query-keys.ts +2 -0
  66. package/src/react/_internal/api/services.ts +4 -3
  67. package/src/react/_internal/api/zod-schema.ts +20 -0
  68. package/src/react/_internal/transaction-machine/execute-transaction.ts +311 -224
  69. package/src/react/_internal/transaction-machine/logger.ts +66 -0
  70. package/src/react/_internal/transaction-machine/useTransactionMachine.ts +69 -19
  71. package/src/react/_internal/wagmi/embedded.ts +2 -2
  72. package/src/react/hooks/index.ts +2 -0
  73. package/src/react/hooks/options/marketplaceConfigOptions.ts +6 -2
  74. package/src/react/hooks/useBuyCollectable.tsx +14 -8
  75. package/src/react/hooks/useCancelOrder.tsx +4 -3
  76. package/src/react/hooks/useCheckoutOptions.tsx +2 -2
  77. package/src/react/hooks/useConfig.tsx +2 -3
  78. package/src/react/hooks/useCountListingsForCollectible.tsx +64 -0
  79. package/src/react/hooks/useCountOffersForCollectible.tsx +64 -0
  80. package/src/react/hooks/useCreateListing.tsx +13 -14
  81. package/src/react/hooks/useCurrencies.tsx +9 -8
  82. package/src/react/hooks/useCurrency.tsx +6 -6
  83. package/src/react/hooks/useGenerateBuyTransaction.tsx +3 -3
  84. package/src/react/hooks/useMakeOffer.tsx +14 -13
  85. package/src/react/hooks/useRoyaltyPercentage.tsx +1 -1
  86. package/src/react/hooks/useSell.tsx +12 -12
  87. package/src/react/hooks/useTransferTokens.tsx +2 -1
  88. package/src/react/ui/components/_internals/action-button/ActionButton.tsx +3 -2
  89. package/src/react/ui/components/_internals/custom-select/CustomSelect.tsx +4 -4
  90. package/src/react/ui/components/collectible-card/CollectibleCard.tsx +2 -2
  91. package/src/react/ui/components/collectible-card/Footer.tsx +33 -29
  92. package/src/react/ui/icons/ArrowUp.tsx +1 -1
  93. package/src/react/ui/modals/BuyModal/_store.ts +8 -6
  94. package/src/react/ui/modals/BuyModal/index.tsx +120 -81
  95. package/src/react/ui/modals/CreateListingModal/_store.ts +1 -0
  96. package/src/react/ui/modals/CreateListingModal/index.tsx +34 -14
  97. package/src/react/ui/modals/MakeOfferModal/_store.ts +2 -0
  98. package/src/react/ui/modals/MakeOfferModal/index.tsx +21 -11
  99. package/src/react/ui/modals/SellModal/index.tsx +21 -13
  100. package/src/react/ui/modals/SuccessfulPurchaseModal/_store.ts +1 -1
  101. package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +1 -1
  102. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +12 -7
  103. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +2 -1
  104. package/src/react/ui/modals/TransferModal/_views/followWalletInstructions/index.tsx +2 -2
  105. package/src/react/ui/modals/TransferModal/styles.css.ts +1 -1
  106. package/src/react/ui/modals/_internal/components/actionModal/ErrorModal.tsx +1 -1
  107. package/src/react/ui/modals/_internal/components/actionModal/LoadingModal.tsx +1 -1
  108. package/src/react/ui/modals/_internal/components/alertMessage/index.tsx +7 -2
  109. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +2 -7
  110. package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +2 -1
  111. package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +1 -0
  112. package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +42 -102
  113. package/src/react/ui/modals/_internal/components/switchChainModal/styles.css.ts +1 -1
  114. package/src/react/ui/modals/_internal/components/timeAgo/index.tsx +1 -1
  115. package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +1 -1
  116. package/src/react/ui/modals/_internal/components/transaction-footer/index.tsx +32 -11
  117. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +2 -2
  118. package/src/react/ui/modals/_internal/components/transactionHeader/index.tsx +14 -2
  119. package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +17 -5
  120. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +12 -4
  121. package/src/react/ui/modals/_internal/components/transactionStatusModal/styles.css.ts +1 -1
  122. package/src/react/ui/modals/modal-provider.tsx +3 -3
  123. package/src/styles/index.ts +3 -0
  124. package/src/utils/_internal/error/base.ts +32 -0
  125. package/src/utils/_internal/error/context.ts +13 -0
  126. package/src/utils/_internal/error/transaction.ts +369 -0
  127. package/src/utils/get-public-rpc-client.ts +4 -1
  128. package/tsconfig.tsbuildinfo +1 -1
  129. package/tsup.config.ts +3 -0
  130. package/dist/chess-tile-6BS5MQT5.png +0 -0
  131. package/dist/chunk-22NLQ3AS.js.map +0 -1
  132. package/dist/chunk-4YU2UPYH.js.map +0 -1
  133. package/dist/chunk-G33554LK.js.map +0 -1
  134. package/dist/chunk-GJAKQ5Q3.js.map +0 -1
  135. package/dist/chunk-GZG2QO64.js.map +0 -1
  136. package/dist/chunk-NII6JJGH.js.map +0 -1
  137. package/dist/chunk-O7UQGT43.js.map +0 -1
  138. package/dist/chunk-SPW24Y7I.js.map +0 -1
  139. package/dist/chunk-WA433WAJ.js.map +0 -1
@@ -13,7 +13,7 @@ import {
13
13
  import {
14
14
  getPresentableChainName,
15
15
  getPublicRpcClient
16
- } from "./chunk-SPW24Y7I.js";
16
+ } from "./chunk-OUZ42I6B.js";
17
17
  import {
18
18
  EIP2981_ABI
19
19
  } from "./chunk-3OHM45R3.js";
@@ -46,6 +46,7 @@ import {
46
46
  TransactionOnRampProvider,
47
47
  TransactionSwapProvider,
48
48
  WalletKind,
49
+ WebrpcError,
49
50
  balanceQueries,
50
51
  builderMarketplaceApi,
51
52
  collectableKeys,
@@ -56,7 +57,34 @@ import {
56
57
  getMarketplaceClient,
57
58
  getMetadataClient,
58
59
  getQueryClient
59
- } from "./chunk-GZG2QO64.js";
60
+ } from "./chunk-D3HRXVYJ.js";
61
+ import {
62
+ BaseError,
63
+ ChainIdUnavailableError,
64
+ ChainSwitchError,
65
+ CheckoutOptionsError,
66
+ CollectionNotFoundError,
67
+ InvalidSignatureStepError,
68
+ MarketplaceConfigFetchError,
69
+ MissingPostStepError,
70
+ MissingSignatureDataError,
71
+ MissingStepDataError,
72
+ NoExecutionStepError,
73
+ NoMarketplaceConfigError,
74
+ NoStepsFoundError,
75
+ NoWalletConnectedError,
76
+ OrderNotFoundError,
77
+ OrdersFetchError,
78
+ PaymentModalError,
79
+ PaymentModalTransactionError,
80
+ ProjectNotFoundError,
81
+ StepExecutionError,
82
+ StepGenerationError,
83
+ TransactionError,
84
+ TransactionReceiptError,
85
+ UnexpectedStepsError,
86
+ UnknownTransactionTypeError
87
+ } from "./chunk-T2AMWIKD.js";
60
88
 
61
89
  // src/react/hooks/useBalanceOfCollectible.tsx
62
90
  import { queryOptions, skipToken, useQuery } from "@tanstack/react-query";
@@ -65,6 +93,14 @@ import { z } from "zod";
65
93
  // src/react/hooks/useConfig.tsx
66
94
  import { useContext } from "react";
67
95
 
96
+ // src/utils/_internal/error/context.ts
97
+ var MarketplaceSdkProviderNotFoundError = class extends BaseError {
98
+ name = "MarketplaceSDKProviderNotFoundError";
99
+ constructor() {
100
+ super("`useConfig` must be used within `MarketplaceSdkProvider`.");
101
+ }
102
+ };
103
+
68
104
  // src/react/provider.tsx
69
105
  import { createContext } from "react";
70
106
  import "@0xsequence/design-system/styles.css";
@@ -81,9 +117,7 @@ function MarketplaceProvider({
81
117
  function useConfig() {
82
118
  const context = useContext(MarketplaceSdkContext);
83
119
  if (!context) {
84
- throw new Error(
85
- "Marketplace SDK must be used within a MarketplaceSdkProvider"
86
- );
120
+ throw new MarketplaceSdkProviderNotFoundError();
87
121
  }
88
122
  return context;
89
123
  }
@@ -411,6 +445,22 @@ var checkoutOptionsSalesContractArgsSchema = z2.object({
411
445
  var checkoutOptionsSalesContractReturnSchema = z2.object({
412
446
  options: checkoutOptionsSchema
413
447
  });
448
+ var countListingsForCollectibleArgsSchema = z2.object({
449
+ contractAddress: z2.string(),
450
+ tokenId: z2.string(),
451
+ filter: orderFilterSchema.optional()
452
+ });
453
+ var countListingsForCollectibleReturnSchema = z2.object({
454
+ count: z2.number()
455
+ });
456
+ var countOffersForCollectibleArgsSchema = z2.object({
457
+ contractAddress: z2.string(),
458
+ tokenId: z2.string(),
459
+ filter: orderFilterSchema.optional()
460
+ });
461
+ var countOffersForCollectibleReturnSchema = z2.object({
462
+ count: z2.number()
463
+ });
414
464
  var tokenMetadataSchema = z2.object({
415
465
  tokenId: z2.string(),
416
466
  name: z2.string(),
@@ -769,7 +819,7 @@ var selectCurrencies = (data, args) => {
769
819
  (collection2) => collection2.collectionAddress === argsParsed.collectionAddress
770
820
  );
771
821
  if (!collection) {
772
- throw new Error("Collection doesn't exist");
822
+ throw new CollectionNotFoundError(argsParsed.collectionAddress);
773
823
  }
774
824
  return data.filter(
775
825
  (currency) => collection.currencyOptions?.includes(currency.contractAddress) || // biome-ignore lint/suspicious/noDoubleEquals: <explanation>
@@ -1028,13 +1078,46 @@ var useListOffersForCollectible = (args) => {
1028
1078
  return useQuery10(listOffersForCollectibleOptions(args, config));
1029
1079
  };
1030
1080
 
1031
- // src/react/hooks/useListListingsForCollectible.tsx
1081
+ // src/react/hooks/useCountOffersForCollectible.tsx
1032
1082
  import { queryOptions as queryOptions11, useQuery as useQuery11 } from "@tanstack/react-query";
1033
1083
  import { z as z14 } from "zod";
1034
- var UseListListingsForCollectibleArgsSchema = listListingsForCollectibleArgsSchema.extend({
1084
+ var UseCountOffersForCollectibleArgsSchema = countOffersForCollectibleArgsSchema.omit({
1085
+ contractAddress: true,
1086
+ tokenId: true
1087
+ }).extend({
1088
+ collectionAddress: AddressSchema,
1089
+ collectibleId: z14.string(),
1035
1090
  chainId: ChainIdSchema.pipe(z14.coerce.string()),
1036
- collectionAddress: z14.string(),
1037
- collectibleId: z14.string()
1091
+ query: QueryArgSchema
1092
+ });
1093
+ var fetchCountOffersForCollectible = async (args, config) => {
1094
+ const parsedArgs = UseCountOffersForCollectibleArgsSchema.parse(args);
1095
+ const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
1096
+ return marketplaceClient.getCountOfOffersForCollectible({
1097
+ ...parsedArgs,
1098
+ contractAddress: parsedArgs.collectionAddress,
1099
+ tokenId: parsedArgs.collectibleId
1100
+ });
1101
+ };
1102
+ var countOffersForCollectibleOptions = (args, config) => {
1103
+ return queryOptions11({
1104
+ ...args.query,
1105
+ queryKey: [...collectableKeys.offersCount, args, config],
1106
+ queryFn: () => fetchCountOffersForCollectible(args, config)
1107
+ });
1108
+ };
1109
+ var useCountOffersForCollectible = (args) => {
1110
+ const config = useConfig();
1111
+ return useQuery11(countOffersForCollectibleOptions(args, config));
1112
+ };
1113
+
1114
+ // src/react/hooks/useListListingsForCollectible.tsx
1115
+ import { queryOptions as queryOptions12, useQuery as useQuery12 } from "@tanstack/react-query";
1116
+ import { z as z15 } from "zod";
1117
+ var UseListListingsForCollectibleArgsSchema = listListingsForCollectibleArgsSchema.extend({
1118
+ chainId: ChainIdSchema.pipe(z15.coerce.string()),
1119
+ collectionAddress: z15.string(),
1120
+ collectibleId: z15.string()
1038
1121
  }).omit({ contractAddress: true, tokenId: true });
1039
1122
  var fetchListListingsForCollectible = async (config, args) => {
1040
1123
  const arg = {
@@ -1047,24 +1130,57 @@ var fetchListListingsForCollectible = async (config, args) => {
1047
1130
  return marketplaceClient.listCollectibleListings(arg);
1048
1131
  };
1049
1132
  var listListingsForCollectibleOptions = (args, config) => {
1050
- return queryOptions11({
1133
+ return queryOptions12({
1051
1134
  queryKey: [...collectableKeys.listings, args, config],
1052
1135
  queryFn: () => fetchListListingsForCollectible(config, args)
1053
1136
  });
1054
1137
  };
1055
1138
  var useListListingsForCollectible = (args) => {
1056
1139
  const config = useConfig();
1057
- return useQuery11(listListingsForCollectibleOptions(args, config));
1140
+ return useQuery12(listListingsForCollectibleOptions(args, config));
1141
+ };
1142
+
1143
+ // src/react/hooks/useCountListingsForCollectible.tsx
1144
+ import { queryOptions as queryOptions13, useQuery as useQuery13 } from "@tanstack/react-query";
1145
+ import { z as z16 } from "zod";
1146
+ var UseCountListingsForCollectibleArgsSchema = countListingsForCollectibleArgsSchema.omit({
1147
+ contractAddress: true,
1148
+ tokenId: true
1149
+ }).extend({
1150
+ collectionAddress: AddressSchema,
1151
+ collectibleId: z16.string(),
1152
+ chainId: ChainIdSchema.pipe(z16.coerce.string()),
1153
+ query: QueryArgSchema
1154
+ });
1155
+ var fetchCountListingsForCollectible = async (args, config) => {
1156
+ const parsedArgs = UseCountListingsForCollectibleArgsSchema.parse(args);
1157
+ const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
1158
+ return marketplaceClient.getCountOfListingsForCollectible({
1159
+ ...parsedArgs,
1160
+ contractAddress: parsedArgs.collectionAddress,
1161
+ tokenId: parsedArgs.collectibleId
1162
+ });
1163
+ };
1164
+ var countListingsForCollectibleOptions = (args, config) => {
1165
+ return queryOptions13({
1166
+ ...args.query,
1167
+ queryKey: [...collectableKeys.listingsCount, args, config],
1168
+ queryFn: () => fetchCountListingsForCollectible(args, config)
1169
+ });
1170
+ };
1171
+ var useCountListingsForCollectible = (args) => {
1172
+ const config = useConfig();
1173
+ return useQuery13(countListingsForCollectibleOptions(args, config));
1058
1174
  };
1059
1175
 
1060
1176
  // src/react/hooks/useLowestListing.tsx
1061
- import { queryOptions as queryOptions12, useQuery as useQuery12 } from "@tanstack/react-query";
1062
- import { z as z15 } from "zod";
1177
+ import { queryOptions as queryOptions14, useQuery as useQuery14 } from "@tanstack/react-query";
1178
+ import { z as z17 } from "zod";
1063
1179
  var UseLowestListingSchema = getCollectibleLowestListingArgsSchema.omit({
1064
1180
  contractAddress: true
1065
1181
  }).extend({
1066
1182
  collectionAddress: AddressSchema,
1067
- chainId: ChainIdSchema.pipe(z15.coerce.string()),
1183
+ chainId: ChainIdSchema.pipe(z17.coerce.string()),
1068
1184
  query: QueryArgSchema
1069
1185
  });
1070
1186
  var fetchLowestListing = async (args, config) => {
@@ -1076,7 +1192,7 @@ var fetchLowestListing = async (args, config) => {
1076
1192
  });
1077
1193
  };
1078
1194
  var lowestListingOptions = (args, config) => {
1079
- return queryOptions12({
1195
+ return queryOptions14({
1080
1196
  ...args.query,
1081
1197
  queryKey: [...collectableKeys.lowestListings, args, config],
1082
1198
  queryFn: () => fetchLowestListing(args, config)
@@ -1084,14 +1200,14 @@ var lowestListingOptions = (args, config) => {
1084
1200
  };
1085
1201
  var useLowestListing = (args) => {
1086
1202
  const config = useConfig();
1087
- return useQuery12(lowestListingOptions(args, config));
1203
+ return useQuery14(lowestListingOptions(args, config));
1088
1204
  };
1089
1205
 
1090
1206
  // src/react/hooks/useMarketplaceConfig.tsx
1091
- import { useQuery as useQuery13 } from "@tanstack/react-query";
1207
+ import { useQuery as useQuery15 } from "@tanstack/react-query";
1092
1208
 
1093
1209
  // src/react/hooks/options/marketplaceConfigOptions.ts
1094
- import { queryOptions as queryOptions13 } from "@tanstack/react-query";
1210
+ import { queryOptions as queryOptions15 } from "@tanstack/react-query";
1095
1211
  var fetchBuilderConfig = async (projectId, env) => {
1096
1212
  const url = `${builderMarketplaceApi(projectId, env)}`;
1097
1213
  const response = await fetch(`${url}/config.json`);
@@ -1100,9 +1216,9 @@ var fetchBuilderConfig = async (projectId, env) => {
1100
1216
  console.error("Failed to fetch marketplace config:", response.status, json);
1101
1217
  switch (json.code) {
1102
1218
  case 3e3:
1103
- throw new Error(`Project id: ${projectId} not found, ${url}`);
1219
+ throw new ProjectNotFoundError(projectId, url);
1104
1220
  default:
1105
- throw new Error(`Failed to fetch marketplace config: ${json.msg}`);
1221
+ throw new MarketplaceConfigFetchError(json.msg);
1106
1222
  }
1107
1223
  }
1108
1224
  return json;
@@ -1131,7 +1247,7 @@ var marketplaceConfigOptions = (config) => {
1131
1247
  env = config._internal.builderEnv ?? env;
1132
1248
  }
1133
1249
  const projectId = config.projectId;
1134
- return queryOptions13({
1250
+ return queryOptions15({
1135
1251
  queryKey: [...configKeys.marketplace, env, projectId],
1136
1252
  queryFn: () => fetchMarketplaceConfig(env, projectId)
1137
1253
  });
@@ -1140,17 +1256,17 @@ var marketplaceConfigOptions = (config) => {
1140
1256
  // src/react/hooks/useMarketplaceConfig.tsx
1141
1257
  var useMarketplaceConfig = () => {
1142
1258
  const config = useConfig();
1143
- return useQuery13(marketplaceConfigOptions(config));
1259
+ return useQuery15(marketplaceConfigOptions(config));
1144
1260
  };
1145
1261
 
1146
1262
  // src/react/hooks/useRoyaltyPercentage.tsx
1147
- import { queryOptions as queryOptions14, useQuery as useQuery14 } from "@tanstack/react-query";
1263
+ import { queryOptions as queryOptions16, useQuery as useQuery16 } from "@tanstack/react-query";
1148
1264
  import { getContract } from "viem";
1149
- import { z as z16 } from "zod";
1150
- var UseRoyaletyPercentageSchema = z16.object({
1151
- chainId: ChainIdSchema.pipe(z16.coerce.string()),
1265
+ import { z as z18 } from "zod";
1266
+ var UseRoyaletyPercentageSchema = z18.object({
1267
+ chainId: ChainIdSchema.pipe(z18.coerce.string()),
1152
1268
  collectionAddress: AddressSchema,
1153
- collectibleId: z16.string(),
1269
+ collectibleId: z18.string(),
1154
1270
  query: QueryArgSchema
1155
1271
  });
1156
1272
  var fetchRoyaletyPercentage = async (args) => {
@@ -1171,13 +1287,13 @@ var fetchRoyaletyPercentage = async (args) => {
1171
1287
  return 0n;
1172
1288
  }
1173
1289
  };
1174
- var royaletyPercentageOptions = (args) => queryOptions14({
1290
+ var royaletyPercentageOptions = (args) => queryOptions16({
1175
1291
  ...args.query,
1176
1292
  queryKey: [...collectableKeys.royaltyPercentage, args],
1177
1293
  queryFn: () => fetchRoyaletyPercentage(args)
1178
1294
  });
1179
1295
  var useRoyaltyPercentage = (args) => {
1180
- return useQuery14(royaletyPercentageOptions(args));
1296
+ return useQuery16(royaletyPercentageOptions(args));
1181
1297
  };
1182
1298
 
1183
1299
  // src/react/hooks/useGenerateListingTransaction.tsx
@@ -1233,13 +1349,13 @@ var useGenerateOfferTransaction = (params) => {
1233
1349
 
1234
1350
  // src/react/hooks/useGenerateSellTransaction.tsx
1235
1351
  import { useMutation as useMutation3 } from "@tanstack/react-query";
1236
- import { z as z17 } from "zod";
1237
- var UserGeneratSellTransactionArgsSchema = z17.object({
1238
- chainId: ChainIdSchema.pipe(z17.coerce.string()),
1239
- onSuccess: z17.function().args(stepSchema.array().optional()).optional()
1352
+ import { z as z19 } from "zod";
1353
+ var UserGeneratSellTransactionArgsSchema = z19.object({
1354
+ chainId: ChainIdSchema.pipe(z19.coerce.string()),
1355
+ onSuccess: z19.function().args(stepSchema.array().optional()).optional()
1240
1356
  });
1241
1357
  var generateSellTransaction = async (args, config, chainId) => {
1242
- const parsedChainId = ChainIdSchema.pipe(z17.coerce.string()).parse(chainId);
1358
+ const parsedChainId = ChainIdSchema.pipe(z19.coerce.string()).parse(chainId);
1243
1359
  const marketplaceClient = getMarketplaceClient(parsedChainId, config);
1244
1360
  return marketplaceClient.generateSellTransaction(args).then((data) => data.steps);
1245
1361
  };
@@ -1258,13 +1374,13 @@ var useGenerateSellTransaction = (params) => {
1258
1374
 
1259
1375
  // src/react/hooks/useGenerateCancelTransaction.tsx
1260
1376
  import { useMutation as useMutation4 } from "@tanstack/react-query";
1261
- import { z as z18 } from "zod";
1262
- var UserGenerateCancelTransactionArgsSchema = z18.object({
1263
- chainId: ChainIdSchema.pipe(z18.coerce.string()),
1264
- onSuccess: z18.function().args(stepSchema.array().optional()).optional()
1377
+ import { z as z20 } from "zod";
1378
+ var UserGenerateCancelTransactionArgsSchema = z20.object({
1379
+ chainId: ChainIdSchema.pipe(z20.coerce.string()),
1380
+ onSuccess: z20.function().args(stepSchema.array().optional()).optional()
1265
1381
  });
1266
1382
  var generateCancelTransaction = async (args, config, chainId) => {
1267
- const parsedChainId = ChainIdSchema.pipe(z18.coerce.string()).parse(chainId);
1383
+ const parsedChainId = ChainIdSchema.pipe(z20.coerce.string()).parse(chainId);
1268
1384
  const marketplaceClient = getMarketplaceClient(parsedChainId, config);
1269
1385
  return marketplaceClient.generateCancelTransaction(args).then((data) => data.steps);
1270
1386
  };
@@ -1322,7 +1438,7 @@ var useTransferTokens = () => {
1322
1438
  } = useWriteContract();
1323
1439
  const transferTokensAsync = async (params) => {
1324
1440
  if (!accountAddress) {
1325
- throw new Error("No wallet connected");
1441
+ throw new NoWalletConnectedError();
1326
1442
  }
1327
1443
  const config = prepareTransferConfig(params, accountAddress);
1328
1444
  return await writeContractAsync(config);
@@ -1337,16 +1453,16 @@ var useTransferTokens = () => {
1337
1453
  };
1338
1454
 
1339
1455
  // src/react/hooks/useCheckoutOptions.tsx
1340
- import { queryOptions as queryOptions15, useQuery as useQuery15 } from "@tanstack/react-query";
1341
- import { z as z19 } from "zod";
1456
+ import { queryOptions as queryOptions17, useQuery as useQuery17 } from "@tanstack/react-query";
1342
1457
  import { useAccount as useAccount2 } from "wagmi";
1343
- var UseCheckoutOptionsSchema = z19.object({
1344
- chainId: ChainIdSchema.pipe(z19.coerce.string()),
1345
- orders: z19.array(
1346
- z19.object({
1458
+ import { z as z21 } from "zod";
1459
+ var UseCheckoutOptionsSchema = z21.object({
1460
+ chainId: ChainIdSchema.pipe(z21.coerce.string()),
1461
+ orders: z21.array(
1462
+ z21.object({
1347
1463
  collectionAddress: AddressSchema,
1348
- orderId: z19.string(),
1349
- marketplace: z19.nativeEnum(MarketplaceKind)
1464
+ orderId: z21.string(),
1465
+ marketplace: z21.nativeEnum(MarketplaceKind)
1350
1466
  })
1351
1467
  ),
1352
1468
  query: QueryArgSchema
@@ -1365,7 +1481,7 @@ var fetchCheckoutOptions = async (args, config) => {
1365
1481
  });
1366
1482
  };
1367
1483
  var checkoutOptionsOptions = (args, config) => {
1368
- return queryOptions15({
1484
+ return queryOptions17({
1369
1485
  queryKey: ["checkoutOptions", args],
1370
1486
  queryFn: () => fetchCheckoutOptions(args, config)
1371
1487
  });
@@ -1373,16 +1489,16 @@ var checkoutOptionsOptions = (args, config) => {
1373
1489
  var useCheckoutOptions = (args) => {
1374
1490
  const { address } = useAccount2();
1375
1491
  const config = useConfig();
1376
- return useQuery15(
1492
+ return useQuery17(
1377
1493
  // biome-ignore lint/style/noNonNullAssertion: <explanation>
1378
1494
  checkoutOptionsOptions({ walletAddress: address, ...args }, config)
1379
1495
  );
1380
1496
  };
1381
1497
 
1382
1498
  // src/react/hooks/useListCollections.tsx
1383
- import { queryOptions as queryOptions16, useQuery as useQuery16 } from "@tanstack/react-query";
1384
- import { z as z20 } from "zod";
1385
- var UseListCollectionsSchema = z20.object({
1499
+ import { queryOptions as queryOptions18, useQuery as useQuery18 } from "@tanstack/react-query";
1500
+ import { z as z22 } from "zod";
1501
+ var UseListCollectionsSchema = z22.object({
1386
1502
  query: QueryArgSchema.optional().default({})
1387
1503
  });
1388
1504
  var fetchListCollections = async ({ marketplaceConfig }, config) => {
@@ -1408,7 +1524,7 @@ var fetchListCollections = async ({ marketplaceConfig }, config) => {
1408
1524
  return results.flat();
1409
1525
  };
1410
1526
  var listCollectionsOptions = (args, config) => {
1411
- return queryOptions16({
1527
+ return queryOptions18({
1412
1528
  ...args.query,
1413
1529
  queryKey: [...collectionKeys.list],
1414
1530
  queryFn: () => fetchListCollections(args, config)
@@ -1417,7 +1533,7 @@ var listCollectionsOptions = (args, config) => {
1417
1533
  var useListCollections = (args = {}) => {
1418
1534
  const config = useConfig();
1419
1535
  const { data: marketplaceConfig, isLoading: isLoadingConfig } = useMarketplaceConfig();
1420
- return useQuery16({
1536
+ return useQuery18({
1421
1537
  ...listCollectionsOptions(
1422
1538
  // biome-ignore lint/style/noNonNullAssertion: <explanation>
1423
1539
  { marketplaceConfig, query: args.query },
@@ -1428,21 +1544,21 @@ var useListCollections = (args = {}) => {
1428
1544
  };
1429
1545
 
1430
1546
  // src/react/hooks/useGenerateBuyTransaction.tsx
1431
- import { queryOptions as queryOptions17, useQuery as useQuery17 } from "@tanstack/react-query";
1432
- import { z as z21 } from "zod";
1547
+ import { queryOptions as queryOptions19, useQuery as useQuery19 } from "@tanstack/react-query";
1433
1548
  import { useAccount as useAccount3 } from "wagmi";
1434
- var UseGenerateBuyTransactionArgsSchema = z21.object({
1435
- chainId: ChainIdSchema.pipe(z21.coerce.string()),
1549
+ import { z as z23 } from "zod";
1550
+ var UseGenerateBuyTransactionArgsSchema = z23.object({
1551
+ chainId: ChainIdSchema.pipe(z23.coerce.string()),
1436
1552
  collectionAddress: AddressSchema,
1437
- marketplace: z21.nativeEnum(MarketplaceKind),
1438
- ordersData: z21.array(
1439
- z21.object({
1440
- orderId: z21.string(),
1441
- quantity: z21.string(),
1442
- marketplace: z21.string()
1553
+ marketplace: z23.nativeEnum(MarketplaceKind),
1554
+ ordersData: z23.array(
1555
+ z23.object({
1556
+ orderId: z23.string(),
1557
+ quantity: z23.string(),
1558
+ marketplace: z23.string()
1443
1559
  })
1444
1560
  ),
1445
- walletType: z21.nativeEnum(WalletKind).optional(),
1561
+ walletType: z23.nativeEnum(WalletKind).optional(),
1446
1562
  query: QueryArgSchema
1447
1563
  });
1448
1564
  var fetchGenerateBuyTransaction = async (args, config) => {
@@ -1456,7 +1572,7 @@ var fetchGenerateBuyTransaction = async (args, config) => {
1456
1572
  }).then((data) => data.steps);
1457
1573
  };
1458
1574
  var generateBuyTransactionOptions = (args, config) => {
1459
- return queryOptions17({
1575
+ return queryOptions19({
1460
1576
  queryKey: ["generateBuyTransaction", args],
1461
1577
  queryFn: () => fetchGenerateBuyTransaction(args, config),
1462
1578
  ...args.query
@@ -1465,17 +1581,66 @@ var generateBuyTransactionOptions = (args, config) => {
1465
1581
  var useGenerateBuyTransaction = (args) => {
1466
1582
  const { address } = useAccount3();
1467
1583
  const config = useConfig();
1468
- return useQuery17(
1584
+ return useQuery19(
1469
1585
  // biome-ignore lint/style/noNonNullAssertion: <explanation>
1470
1586
  generateBuyTransactionOptions({ buyer: address, ...args }, config)
1471
1587
  );
1472
1588
  };
1473
1589
 
1474
1590
  // src/react/_internal/transaction-machine/execute-transaction.ts
1475
- import { avalanche } from "viem/chains";
1476
- var debug = (message, data) => {
1477
- console.debug(`[TransactionMachine] ${message}`, data || "");
1591
+ import { avalanche, optimism } from "viem/chains";
1592
+
1593
+ // src/react/_internal/transaction-machine/logger.ts
1594
+ var TransactionLogger = class {
1595
+ constructor(context, enabled = true) {
1596
+ this.context = context;
1597
+ this.enabled = enabled;
1598
+ }
1599
+ formatData(data) {
1600
+ if (data instanceof Error) {
1601
+ return {
1602
+ name: data.name,
1603
+ message: data.message,
1604
+ cause: data.cause instanceof Error ? this.formatData(data.cause) : data.cause,
1605
+ stack: data.stack?.split("\n").slice(0, 3)
1606
+ };
1607
+ }
1608
+ if (Array.isArray(data)) {
1609
+ return data.map((item) => this.formatData(item));
1610
+ }
1611
+ if (typeof data === "object" && data !== null) {
1612
+ return Object.fromEntries(
1613
+ Object.entries(data).map(([key, value]) => [
1614
+ key,
1615
+ this.formatData(value)
1616
+ ])
1617
+ );
1618
+ }
1619
+ return data;
1620
+ }
1621
+ log(level, message, data) {
1622
+ if (!this.enabled) return;
1623
+ console[level](
1624
+ `[${this.context}] ${message}`,
1625
+ data ? this.formatData(data) : ""
1626
+ );
1627
+ }
1628
+ debug(message, data) {
1629
+ this.log("debug", message, data);
1630
+ }
1631
+ error(message, error) {
1632
+ this.log("error", message, error);
1633
+ }
1634
+ info(message, data) {
1635
+ this.log("info", message, data);
1636
+ }
1637
+ state(from, to) {
1638
+ this.info(`State transition: ${from} -> ${to}`);
1639
+ }
1478
1640
  };
1641
+ var createLogger = (context, enabled = true) => new TransactionLogger(context, enabled);
1642
+
1643
+ // src/react/_internal/transaction-machine/execute-transaction.ts
1479
1644
  var TransactionMachine = class {
1480
1645
  constructor(config, walletClient, publicClient, openSelectPaymentModal, switchChainFn) {
1481
1646
  this.config = config;
@@ -1484,19 +1649,21 @@ var TransactionMachine = class {
1484
1649
  this.openSelectPaymentModal = openSelectPaymentModal;
1485
1650
  this.switchChainFn = switchChainFn;
1486
1651
  this.currentState = "IDLE" /* IDLE */;
1652
+ this.logger = createLogger("TransactionMachine");
1487
1653
  this.marketplaceClient = getMarketplaceClient(
1488
1654
  config.config.chainId,
1489
1655
  config.config.sdkConfig
1490
1656
  );
1491
1657
  }
1492
1658
  currentState;
1659
+ logger;
1493
1660
  marketplaceClient;
1494
1661
  memoizedSteps = null;
1495
1662
  lastProps = null;
1496
1663
  getAccount() {
1497
1664
  const account = this.walletClient.account;
1498
1665
  if (!account) {
1499
- throw new Error("Account not connected");
1666
+ throw new NoWalletConnectedError();
1500
1667
  }
1501
1668
  return account;
1502
1669
  }
@@ -1507,7 +1674,8 @@ var TransactionMachine = class {
1507
1674
  const collection = this.config.config.marketplaceConfig.collections.find(
1508
1675
  (collection2) => collection2.collectionAddress.toLowerCase() === collectionAddress.toLowerCase() && this.getChainId() === Number(collection2.chainId)
1509
1676
  );
1510
- const receiver = this.getChainId() === avalanche.id ? avalancheAndOptimismPlatformFeeRecipient : defaultPlatformFeeRecipient;
1677
+ const avalancheOrOptimism = this.getChainId() === avalanche.id || this.getChainId() === optimism.id;
1678
+ const receiver = avalancheOrOptimism ? avalancheAndOptimismPlatformFeeRecipient : defaultPlatformFeeRecipient;
1511
1679
  const percentageToBPS = (percentage) => Number(percentage) * 1e4 / 100;
1512
1680
  return {
1513
1681
  amount: percentageToBPS(
@@ -1523,79 +1691,90 @@ var TransactionMachine = class {
1523
1691
  type,
1524
1692
  props
1525
1693
  }) {
1526
- debug("Generating steps", { type, props });
1694
+ this.logger.debug("Generating steps", { type, props });
1527
1695
  const { collectionAddress } = this.config.config;
1528
1696
  const address = this.getAccountAddress();
1529
- switch (type) {
1530
- case "BUY" /* BUY */:
1531
- return this.marketplaceClient.generateBuyTransaction({
1532
- collectionAddress,
1533
- buyer: address,
1534
- walletType: this.config.config.walletKind,
1535
- marketplace: props.marketplace,
1536
- ordersData: [
1537
- {
1538
- orderId: props.orderId,
1539
- quantity: props.quantity || "1"
1540
- }
1541
- ],
1542
- additionalFees: [this.getMarketplaceFee(collectionAddress)]
1543
- }).then((resp) => resp.steps);
1544
- case "SELL" /* SELL */:
1545
- return this.marketplaceClient.generateSellTransaction({
1546
- collectionAddress,
1547
- seller: address,
1548
- walletType: this.config.config.walletKind,
1549
- marketplace: props.marketplace,
1550
- ordersData: [
1551
- {
1552
- orderId: props.orderId,
1553
- quantity: props.quantity || "1"
1554
- }
1555
- ],
1556
- additionalFees: []
1557
- }).then((resp) => resp.steps);
1558
- case "LISTING" /* LISTING */:
1559
- return this.marketplaceClient.generateListingTransaction({
1560
- collectionAddress,
1561
- owner: address,
1562
- walletType: this.config.config.walletKind,
1563
- contractType: props.contractType,
1564
- orderbook: "sequence_marketplace_v2" /* sequence_marketplace_v2 */,
1565
- listing: props.listing
1566
- }).then((resp) => resp.steps);
1567
- case "OFFER" /* OFFER */:
1568
- return this.marketplaceClient.generateOfferTransaction({
1569
- collectionAddress,
1570
- maker: address,
1571
- walletType: this.config.config.walletKind,
1572
- contractType: props.contractType,
1573
- orderbook: "sequence_marketplace_v2" /* sequence_marketplace_v2 */,
1574
- offer: props.offer
1575
- }).then((resp) => resp.steps);
1576
- case "CANCEL" /* CANCEL */:
1577
- return this.marketplaceClient.generateCancelTransaction({
1578
- collectionAddress,
1579
- maker: address,
1580
- marketplace: props.marketplace,
1581
- orderId: props.orderId
1582
- }).then((resp) => resp.steps);
1583
- default:
1584
- throw new Error(`Unknown transaction type: ${type}`);
1697
+ try {
1698
+ switch (type) {
1699
+ case "BUY" /* BUY */:
1700
+ return await this.marketplaceClient.generateBuyTransaction({
1701
+ collectionAddress,
1702
+ buyer: address,
1703
+ walletType: this.config.config.walletKind,
1704
+ marketplace: props.marketplace,
1705
+ ordersData: [
1706
+ {
1707
+ orderId: props.orderId,
1708
+ quantity: props.quantity || "1"
1709
+ }
1710
+ ],
1711
+ additionalFees: [this.getMarketplaceFee(collectionAddress)]
1712
+ }).then((resp) => resp.steps);
1713
+ case "SELL" /* SELL */:
1714
+ return await this.marketplaceClient.generateSellTransaction({
1715
+ collectionAddress,
1716
+ seller: address,
1717
+ walletType: this.config.config.walletKind,
1718
+ marketplace: props.marketplace,
1719
+ ordersData: [
1720
+ {
1721
+ orderId: props.orderId,
1722
+ quantity: props.quantity || "1"
1723
+ }
1724
+ ],
1725
+ additionalFees: []
1726
+ }).then((resp) => resp.steps);
1727
+ case "LISTING" /* LISTING */:
1728
+ return await this.marketplaceClient.generateListingTransaction({
1729
+ collectionAddress,
1730
+ owner: address,
1731
+ walletType: this.config.config.walletKind,
1732
+ contractType: props.contractType,
1733
+ orderbook: "sequence_marketplace_v2" /* sequence_marketplace_v2 */,
1734
+ listing: props.listing
1735
+ }).then((resp) => resp.steps);
1736
+ case "OFFER" /* OFFER */:
1737
+ return await this.marketplaceClient.generateOfferTransaction({
1738
+ collectionAddress,
1739
+ maker: address,
1740
+ walletType: this.config.config.walletKind,
1741
+ contractType: props.contractType,
1742
+ orderbook: "sequence_marketplace_v2" /* sequence_marketplace_v2 */,
1743
+ offer: props.offer
1744
+ }).then((resp) => resp.steps);
1745
+ case "CANCEL" /* CANCEL */:
1746
+ return await this.marketplaceClient.generateCancelTransaction({
1747
+ collectionAddress,
1748
+ maker: address,
1749
+ marketplace: props.marketplace,
1750
+ orderId: props.orderId
1751
+ }).then((resp) => resp.steps);
1752
+ default:
1753
+ throw new UnknownTransactionTypeError(type);
1754
+ }
1755
+ } catch (error) {
1756
+ if (error instanceof WebrpcError) {
1757
+ throw new StepGenerationError(type, error);
1758
+ }
1759
+ throw error;
1585
1760
  }
1586
1761
  }
1587
1762
  clearMemoizedSteps() {
1588
- debug("Clearing memoized steps");
1763
+ this.logger.debug("Clearing memoized steps");
1589
1764
  this.memoizedSteps = null;
1590
1765
  this.lastProps = null;
1591
1766
  }
1592
1767
  async transition(newState) {
1593
- debug(`State transition: ${this.currentState} -> ${newState}`);
1768
+ this.logger.state(this.currentState, newState);
1594
1769
  this.currentState = newState;
1595
1770
  this.clearMemoizedSteps();
1596
1771
  }
1597
1772
  getChainId() {
1598
- return this.walletClient.chain?.id;
1773
+ const chainId = this.walletClient.chain?.id;
1774
+ if (!chainId) {
1775
+ throw new ChainIdUnavailableError();
1776
+ }
1777
+ return chainId;
1599
1778
  }
1600
1779
  getChainForTransaction() {
1601
1780
  const chainId = this.config.config.chainId;
@@ -1607,38 +1786,37 @@ var TransactionMachine = class {
1607
1786
  return this.getChainId() === Number(this.config.config.chainId);
1608
1787
  }
1609
1788
  async switchChain() {
1789
+ this.logger.debug("Checking chain", {
1790
+ currentChain: this.getChainId(),
1791
+ targetChain: Number(this.config.config.chainId)
1792
+ });
1610
1793
  if (!this.isOnCorrectChain()) {
1794
+ const currentChain = this.getChainId();
1795
+ const targetChain = Number(this.config.config.chainId);
1611
1796
  await this.transition("SWITCH_CHAIN" /* SWITCH_CHAIN */);
1612
- await this.switchChainFn(this.config.config.chainId);
1613
- await this.walletClient.switchChain({
1614
- id: Number(this.config.config.chainId)
1615
- });
1616
- debug("Switched chain");
1797
+ try {
1798
+ await this.switchChainFn(this.config.config.chainId);
1799
+ await this.walletClient.switchChain({
1800
+ id: Number(this.config.config.chainId)
1801
+ });
1802
+ this.logger.debug("Switched chain");
1803
+ } catch (error) {
1804
+ throw new ChainSwitchError(currentChain, targetChain);
1805
+ }
1617
1806
  }
1618
1807
  }
1619
- async start({ props }) {
1620
- debug("Starting transaction", props);
1621
- try {
1622
- await this.transition("CHECKING_STEPS" /* CHECKING_STEPS */);
1623
- const { type } = this.config.config;
1624
- const steps = await this.generateSteps({
1625
- type,
1626
- props
1627
- });
1628
- for (const step of steps) {
1629
- try {
1630
- await this.executeStep({ step, props });
1631
- } catch (error) {
1632
- await this.transition("ERROR" /* ERROR */);
1633
- throw error;
1634
- }
1635
- }
1636
- await this.transition("SUCCESS" /* SUCCESS */);
1637
- } catch (error) {
1638
- debug("Transaction failed", error);
1639
- await this.transition("ERROR" /* ERROR */);
1640
- throw error;
1808
+ async start(props) {
1809
+ this.logger.debug("Starting transaction", props);
1810
+ await this.transition("CHECKING_STEPS" /* CHECKING_STEPS */);
1811
+ const { type } = this.config.config;
1812
+ const steps = await this.generateSteps({
1813
+ type,
1814
+ props
1815
+ });
1816
+ for (const step of steps) {
1817
+ await this.executeStep({ step, props });
1641
1818
  }
1819
+ await this.transition("SUCCESS" /* SUCCESS */);
1642
1820
  }
1643
1821
  async handleTransactionSuccess(hash) {
1644
1822
  if (!hash) {
@@ -1647,36 +1825,46 @@ var TransactionMachine = class {
1647
1825
  }
1648
1826
  await this.transition("CONFIRMING" /* CONFIRMING */);
1649
1827
  this.config.onTransactionSent?.(hash);
1650
- const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
1651
- debug("Transaction confirmed", receipt);
1652
- await this.transition("SUCCESS" /* SUCCESS */);
1653
- this.config.onSuccess?.(hash);
1828
+ try {
1829
+ const receipt = await this.publicClient.waitForTransactionReceipt({
1830
+ hash
1831
+ });
1832
+ this.logger.debug("Transaction confirmed", receipt);
1833
+ await this.transition("SUCCESS" /* SUCCESS */);
1834
+ this.config.onSuccess?.(hash);
1835
+ } catch (error) {
1836
+ throw new TransactionReceiptError(hash, error);
1837
+ }
1654
1838
  }
1655
1839
  async executeTransaction(step) {
1656
- const transactionData = {
1657
- account: this.getAccount(),
1658
- chain: this.getChainForTransaction(),
1659
- to: step.to,
1660
- data: step.data,
1661
- value: BigInt(step.value || "0")
1662
- };
1663
- debug("Executing transaction", transactionData);
1664
- const hash = await this.walletClient.sendTransaction(transactionData);
1665
- debug("Transaction submitted", { hash });
1666
- await this.handleTransactionSuccess(hash);
1667
- return hash;
1840
+ try {
1841
+ const transactionData = {
1842
+ account: this.getAccount(),
1843
+ chain: this.getChainForTransaction(),
1844
+ to: step.to,
1845
+ data: step.data,
1846
+ value: BigInt(step.value || "0")
1847
+ };
1848
+ this.logger.debug("Executing transaction", transactionData);
1849
+ const hash = await this.walletClient.sendTransaction(transactionData);
1850
+ this.logger.debug("Transaction submitted", { hash });
1851
+ await this.handleTransactionSuccess(hash);
1852
+ return hash;
1853
+ } catch (error) {
1854
+ throw new StepExecutionError(step.id, error);
1855
+ }
1668
1856
  }
1669
1857
  async executeSignature(step) {
1670
- debug("Executing signature", { stepId: step.id });
1671
- let signature;
1858
+ this.logger.debug("Executing signature", { stepId: step.id });
1672
1859
  if (!step.post) {
1673
- throw new Error("Missing post step");
1860
+ throw new MissingPostStepError();
1861
+ }
1862
+ let signature;
1863
+ if (!step.signature) {
1864
+ throw new MissingSignatureDataError();
1674
1865
  }
1675
1866
  switch (step.id) {
1676
1867
  case "signEIP712" /* signEIP712 */:
1677
- if (!step.signature) {
1678
- throw new Error("Missing signature data");
1679
- }
1680
1868
  signature = await this.walletClient.signTypedData({
1681
1869
  domain: step.signature.domain,
1682
1870
  types: step.signature.types,
@@ -1692,7 +1880,7 @@ var TransactionMachine = class {
1692
1880
  });
1693
1881
  break;
1694
1882
  default:
1695
- throw new Error(`Invalid signature step: ${step.id}`);
1883
+ throw new InvalidSignatureStepError(step.id);
1696
1884
  }
1697
1885
  await this.marketplaceClient.execute({
1698
1886
  signature,
@@ -1706,12 +1894,15 @@ var TransactionMachine = class {
1706
1894
  this.openSelectPaymentModal({
1707
1895
  ...settings,
1708
1896
  onSuccess: async (hash) => {
1709
- await this.handleTransactionSuccess(hash);
1710
- resolve();
1897
+ try {
1898
+ await this.handleTransactionSuccess(hash);
1899
+ resolve();
1900
+ } catch (error) {
1901
+ reject(error);
1902
+ }
1711
1903
  },
1712
1904
  onError: (error) => {
1713
- this.config.onError?.(error);
1714
- reject(error);
1905
+ reject(new PaymentModalError(error));
1715
1906
  }
1716
1907
  });
1717
1908
  });
@@ -1720,86 +1911,111 @@ var TransactionMachine = class {
1720
1911
  step,
1721
1912
  props
1722
1913
  }) {
1723
- this.transition("EXECUTING_TRANSACTION" /* EXECUTING_TRANSACTION */);
1724
- const [checkoutOptions, orders] = await Promise.all([
1725
- this.marketplaceClient.checkoutOptionsMarketplace({
1726
- wallet: this.getAccountAddress(),
1727
- orders: [
1728
- {
1729
- contractAddress: this.config.config.collectionAddress,
1730
- orderId: props.orderId,
1731
- marketplace: props.marketplace
1732
- }
1733
- ],
1734
- additionalFee: Number(
1735
- this.getMarketplaceFee(this.config.config.collectionAddress).amount
1736
- )
1737
- }),
1738
- this.marketplaceClient.getOrders({
1739
- input: [
1740
- {
1741
- orderId: props.orderId,
1742
- marketplace: props.marketplace,
1743
- contractAddress: this.config.config.collectionAddress
1744
- }
1745
- ]
1746
- })
1747
- ]);
1748
- const order = orders.orders[0];
1749
- await this.openPaymentModalWithPromise({
1750
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
1751
- chain: this.getChainId(),
1752
- collectibles: [
1753
- {
1754
- tokenId: order.tokenId,
1755
- quantity: props.quantity,
1756
- decimals: props.collectableDecimals
1914
+ try {
1915
+ await this.transition("EXECUTING_TRANSACTION" /* EXECUTING_TRANSACTION */);
1916
+ try {
1917
+ const [checkoutOptions, orders] = await Promise.all([
1918
+ this.marketplaceClient.checkoutOptionsMarketplace({
1919
+ wallet: this.getAccountAddress(),
1920
+ orders: [
1921
+ {
1922
+ contractAddress: this.config.config.collectionAddress,
1923
+ orderId: props.orderId,
1924
+ marketplace: props.marketplace
1925
+ }
1926
+ ],
1927
+ additionalFee: Number(
1928
+ this.getMarketplaceFee(this.config.config.collectionAddress).amount
1929
+ )
1930
+ }).catch((error) => {
1931
+ throw new CheckoutOptionsError(error);
1932
+ }),
1933
+ this.marketplaceClient.getOrders({
1934
+ input: [
1935
+ {
1936
+ orderId: props.orderId,
1937
+ marketplace: props.marketplace,
1938
+ contractAddress: this.config.config.collectionAddress
1939
+ }
1940
+ ]
1941
+ }).catch((error) => {
1942
+ throw new OrdersFetchError(props.orderId, error);
1943
+ })
1944
+ ]);
1945
+ const order = orders.orders[0];
1946
+ if (!order) {
1947
+ throw new OrderNotFoundError(props.orderId);
1757
1948
  }
1758
- ],
1759
- currencyAddress: order.priceCurrencyAddress,
1760
- price: order.priceAmount,
1761
- targetContractAddress: step.to,
1762
- txData: step.data,
1763
- collectionAddress: this.config.config.collectionAddress,
1764
- recipientAddress: this.getAccountAddress(),
1765
- enableMainCurrencyPayment: true,
1766
- enableSwapPayments: !!checkoutOptions.options?.swap?.includes(
1767
- "zerox" /* zerox */
1768
- ),
1769
- creditCardProviders: checkoutOptions?.options.nftCheckout || []
1770
- });
1949
+ const paymentModalProps = {
1950
+ chain: this.getChainId(),
1951
+ collectibles: [
1952
+ {
1953
+ tokenId: order.tokenId,
1954
+ quantity: props.quantity,
1955
+ decimals: props.collectableDecimals
1956
+ }
1957
+ ],
1958
+ currencyAddress: order.priceCurrencyAddress,
1959
+ price: order.priceAmount,
1960
+ targetContractAddress: step.to,
1961
+ txData: step.data,
1962
+ collectionAddress: this.config.config.collectionAddress,
1963
+ recipientAddress: this.getAccountAddress(),
1964
+ enableMainCurrencyPayment: true,
1965
+ enableSwapPayments: !!checkoutOptions.options?.swap?.includes(
1966
+ "zerox" /* zerox */
1967
+ ),
1968
+ creditCardProviders: checkoutOptions?.options.nftCheckout || []
1969
+ };
1970
+ this.logger.debug("Opening payment modal", paymentModalProps);
1971
+ await this.openPaymentModalWithPromise(paymentModalProps);
1972
+ } catch (error) {
1973
+ if (error instanceof TransactionError) {
1974
+ throw error;
1975
+ }
1976
+ throw new PaymentModalTransactionError(step.id, error);
1977
+ }
1978
+ } catch (error) {
1979
+ if (error instanceof TransactionError) {
1980
+ throw error;
1981
+ }
1982
+ throw new StepExecutionError(step.id, error);
1983
+ }
1771
1984
  }
1772
1985
  async executeStep({
1773
1986
  step,
1774
1987
  props
1775
1988
  }) {
1776
- debug("Executing step", { stepId: step.id });
1777
- if (!step.to && !step.signature) {
1778
- throw new Error("Invalid step data");
1779
- }
1780
1989
  try {
1990
+ this.logger.debug("Executing step", { stepId: step.id });
1991
+ if (!step.to && !step.signature) {
1992
+ throw new MissingStepDataError();
1993
+ }
1781
1994
  await this.switchChain();
1782
1995
  if (step.id === "buy" /* buy */) {
1783
1996
  await this.executeBuyStep({ step, props });
1784
- } else if (step.signature) {
1997
+ return;
1998
+ }
1999
+ if (step.signature) {
1785
2000
  await this.executeSignature(step);
1786
- } else if (step.id === "tokenApproval" /* tokenApproval */) {
1787
- const hash = await this.executeTransaction(step);
1788
- return { hash };
1789
- } else {
1790
- const hash = await this.executeTransaction(step);
2001
+ return;
2002
+ }
2003
+ const hash = await this.executeTransaction(step);
2004
+ if (step.id !== "tokenApproval" /* tokenApproval */) {
1791
2005
  this.config.onSuccess?.(hash);
1792
- return { hash };
1793
2006
  }
2007
+ return { hash };
1794
2008
  } catch (error) {
1795
- this.config.onError?.(error);
1796
- throw error;
2009
+ if (error instanceof TransactionError) {
2010
+ throw error;
2011
+ }
2012
+ throw new StepExecutionError(step.id, error);
1797
2013
  }
1798
2014
  }
1799
2015
  async getTransactionSteps(props) {
1800
- debug("Getting transaction steps", props);
2016
+ this.logger.debug("Getting transaction steps", props);
1801
2017
  if (this.memoizedSteps && this.lastProps && JSON.stringify(props) === JSON.stringify(this.lastProps)) {
1802
- debug("Returning memoized steps");
2018
+ this.logger.debug("Returning memoized steps");
1803
2019
  return this.memoizedSteps;
1804
2020
  }
1805
2021
  const type = this.config.config.type;
@@ -1809,14 +2025,14 @@ var TransactionMachine = class {
1809
2025
  });
1810
2026
  const executionStep = steps.pop();
1811
2027
  if (!executionStep) {
1812
- throw new Error("No steps found");
2028
+ throw new NoStepsFoundError();
1813
2029
  }
1814
2030
  if (executionStep.id === "tokenApproval" /* tokenApproval */) {
1815
- throw new Error("No execution step found, only approval step");
2031
+ throw new NoExecutionStepError();
1816
2032
  }
1817
2033
  const approvalStep = steps.pop();
1818
2034
  if (steps.length > 0) {
1819
- throw new Error("Unexpected steps found");
2035
+ throw new UnexpectedStepsError();
1820
2036
  }
1821
2037
  this.lastProps = props;
1822
2038
  this.memoizedSteps = {
@@ -1836,7 +2052,7 @@ var TransactionMachine = class {
1836
2052
  execute: () => this.executeStep({ step: executionStep, props })
1837
2053
  }
1838
2054
  };
1839
- debug("Generated new transaction steps", this.memoizedSteps);
2055
+ this.logger.debug("Generated new transaction steps", this.memoizedSteps);
1840
2056
  return this.memoizedSteps;
1841
2057
  }
1842
2058
  };
@@ -1862,7 +2078,16 @@ import { Box, Text, WarningIcon } from "@0xsequence/design-system";
1862
2078
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
1863
2079
  function AlertMessage({ message, type }) {
1864
2080
  return /* @__PURE__ */ jsxs(Box, { className: `${alertMessageBox} ${alertMessageBoxVariants[type]}`, children: [
1865
- /* @__PURE__ */ jsx2(Text, { color: "white", fontSize: "normal", fontWeight: "medium", children: message }),
2081
+ /* @__PURE__ */ jsx2(
2082
+ Text,
2083
+ {
2084
+ color: "white",
2085
+ fontSize: "normal",
2086
+ fontWeight: "medium",
2087
+ fontFamily: "body",
2088
+ children: message
2089
+ }
2090
+ ),
1866
2091
  type === "warning" && /* @__PURE__ */ jsx2(WarningIcon, { size: "sm", color: "white" }),
1867
2092
  type === "info" && /* @__PURE__ */ jsx2(InfoIcon_default, { size: "sm", color: "white" })
1868
2093
  ] });
@@ -1965,42 +2190,80 @@ var switchChainModal_default = SwitchChainModal;
1965
2190
 
1966
2191
  // src/react/_internal/transaction-machine/useTransactionMachine.ts
1967
2192
  var useTransactionMachine = (config, onSuccess, onError, onTransactionSent) => {
1968
- const { data: walletClient } = useWalletClient();
2193
+ const { data: walletClient, isLoading: walletClientIsLoading } = useWalletClient();
1969
2194
  const { show: showSwitchChainModal } = useSwitchChainModal();
1970
2195
  const sdkConfig = useConfig();
1971
- const { data: marketplaceConfig, error: marketplaceError } = useMarketplaceConfig();
2196
+ const {
2197
+ data: marketplaceConfig,
2198
+ error: marketplaceError,
2199
+ isLoading: marketplaceConfigIsLoading
2200
+ } = useMarketplaceConfig();
1972
2201
  const { openSelectPaymentModal } = useSelectPaymentModal();
1973
2202
  const { chains } = useSwitchChain2();
1974
- const { connector } = useAccount4();
2203
+ const { connector, isConnected } = useAccount4();
1975
2204
  const walletKind = connector?.id === "sequence" ? "sequence" /* sequence */ : "unknown" /* unknown */;
2205
+ if (!isConnected) {
2206
+ return { machine: null, error: null, isLoading: false };
2207
+ }
2208
+ if (walletClientIsLoading || marketplaceConfigIsLoading) {
2209
+ return { machine: null, error: null, isLoading: true };
2210
+ }
1976
2211
  if (marketplaceError) {
1977
- throw marketplaceError;
2212
+ const error = new TransactionError("Marketplace config error", {
2213
+ cause: marketplaceError
2214
+ });
2215
+ onError?.(error);
2216
+ return { machine: null, error };
1978
2217
  }
1979
- if (!walletClient || !marketplaceConfig) return null;
1980
- return new TransactionMachine(
2218
+ if (!walletClient) {
2219
+ const error = new NoWalletConnectedError();
2220
+ onError?.(error);
2221
+ return { machine: null, error };
2222
+ }
2223
+ if (!marketplaceConfig) {
2224
+ const error = new NoMarketplaceConfigError();
2225
+ onError?.(error);
2226
+ return { machine: null, error };
2227
+ }
2228
+ const machine = new TransactionMachine(
1981
2229
  {
1982
2230
  config: { sdkConfig, marketplaceConfig, walletKind, chains, ...config },
1983
2231
  onSuccess,
1984
- onError,
1985
2232
  onTransactionSent
1986
2233
  },
1987
2234
  walletClient,
1988
2235
  getPublicRpcClient(config.chainId),
1989
2236
  openSelectPaymentModal,
1990
- async (chainId) => {
1991
- return new Promise((resolve, reject) => {
1992
- showSwitchChainModal({
1993
- chainIdToSwitchTo: Number(chainId),
1994
- onSuccess: () => {
1995
- resolve();
1996
- },
1997
- onError: (error) => {
1998
- reject(error);
1999
- }
2000
- });
2237
+ async (chainId) => new Promise((resolve, reject) => {
2238
+ showSwitchChainModal({
2239
+ chainIdToSwitchTo: Number(chainId),
2240
+ onSuccess: resolve,
2241
+ onError: reject
2001
2242
  });
2002
- }
2243
+ })
2003
2244
  );
2245
+ return {
2246
+ machine: {
2247
+ getTransactionSteps: async (props) => {
2248
+ try {
2249
+ return await machine.getTransactionSteps(props);
2250
+ } catch (e) {
2251
+ const error = e;
2252
+ onError?.(error);
2253
+ }
2254
+ },
2255
+ start: async (props) => {
2256
+ try {
2257
+ await machine.start(props);
2258
+ } catch (e) {
2259
+ const error = e;
2260
+ onError?.(error);
2261
+ }
2262
+ }
2263
+ },
2264
+ error: null,
2265
+ isLoading: false
2266
+ };
2004
2267
  };
2005
2268
 
2006
2269
  // src/react/hooks/useCancelOrder.tsx
@@ -2010,7 +2273,7 @@ var useCancelOrder = ({
2010
2273
  onTransactionSent,
2011
2274
  ...config
2012
2275
  }) => {
2013
- const machine = useTransactionMachine(
2276
+ const { machine, isLoading } = useTransactionMachine(
2014
2277
  {
2015
2278
  ...config,
2016
2279
  type: "CANCEL" /* CANCEL */
@@ -2020,10 +2283,11 @@ var useCancelOrder = ({
2020
2283
  onTransactionSent
2021
2284
  );
2022
2285
  return {
2023
- cancel: (props) => machine?.start({ props }),
2286
+ cancel: (props) => machine?.start(props),
2024
2287
  onError,
2025
2288
  onSuccess,
2026
- onTransactionSent
2289
+ onTransactionSent,
2290
+ isLoading
2027
2291
  };
2028
2292
  };
2029
2293
 
@@ -2034,7 +2298,7 @@ var useBuyCollectable = ({
2034
2298
  onTransactionSent,
2035
2299
  ...config
2036
2300
  }) => {
2037
- const machine = useTransactionMachine(
2301
+ const { machine, error, isLoading } = useTransactionMachine(
2038
2302
  {
2039
2303
  ...config,
2040
2304
  type: "BUY" /* BUY */
@@ -2044,10 +2308,12 @@ var useBuyCollectable = ({
2044
2308
  onTransactionSent
2045
2309
  );
2046
2310
  return {
2047
- buy: (props) => machine?.start({ props }),
2048
- onError,
2049
- onSuccess,
2050
- onTransactionSent
2311
+ buy: (props) => {
2312
+ if (!machine || isLoading) return;
2313
+ machine.start(props);
2314
+ },
2315
+ isLoading,
2316
+ error
2051
2317
  };
2052
2318
  };
2053
2319
 
@@ -2081,8 +2347,12 @@ export {
2081
2347
  useListCollectibles,
2082
2348
  listOffersForCollectibleOptions,
2083
2349
  useListOffersForCollectible,
2350
+ countOffersForCollectibleOptions,
2351
+ useCountOffersForCollectible,
2084
2352
  listListingsForCollectibleOptions,
2085
2353
  useListListingsForCollectible,
2354
+ countListingsForCollectibleOptions,
2355
+ useCountListingsForCollectible,
2086
2356
  lowestListingOptions,
2087
2357
  useLowestListing,
2088
2358
  marketplaceConfigOptions,
@@ -2113,4 +2383,4 @@ export {
2113
2383
  useCancelOrder,
2114
2384
  useBuyCollectable
2115
2385
  };
2116
- //# sourceMappingURL=chunk-O7UQGT43.js.map
2386
+ //# sourceMappingURL=chunk-6LQST3KZ.js.map