@0xsequence/marketplace-sdk 0.4.4 → 0.4.5

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 (69) hide show
  1. package/dist/{chunk-J4TRSLTB.js → chunk-CKOWM2ZR.js} +3 -3
  2. package/dist/{chunk-4VS5NKDD.js → chunk-FT3J32ZV.js} +2 -2
  3. package/dist/{chunk-IQXJZBMR.js → chunk-HTFBQVLV.js} +2 -2
  4. package/dist/{chunk-URX7ZHX4.js → chunk-KILOCWY2.js} +2 -2
  5. package/dist/{chunk-LHN6EBLM.js → chunk-KL5JPUPS.js} +3 -4
  6. package/dist/{chunk-LHN6EBLM.js.map → chunk-KL5JPUPS.js.map} +1 -1
  7. package/dist/{chunk-GLOIEUWC.js → chunk-KZGDOIZY.js} +18 -569
  8. package/dist/chunk-KZGDOIZY.js.map +1 -0
  9. package/dist/{chunk-6XUCLBZC.js → chunk-SEISACMH.js} +172 -103
  10. package/dist/chunk-SEISACMH.js.map +1 -0
  11. package/dist/{chunk-DNDPYQKV.js → chunk-YUETNNZQ.js} +1 -144
  12. package/dist/{chunk-DNDPYQKV.js.map → chunk-YUETNNZQ.js.map} +1 -1
  13. package/dist/{create-config-8sffBvlt.d.ts → create-config-DMBOGsJp.d.ts} +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +5 -5
  16. package/dist/{marketplace-config-Bbxl-uKX.d.ts → marketplace-config-0Rft6_Hv.d.ts} +2 -0
  17. package/dist/react/_internal/api/index.js +2 -2
  18. package/dist/react/_internal/index.d.ts +2 -2
  19. package/dist/react/_internal/index.js +3 -3
  20. package/dist/react/_internal/wagmi/index.d.ts +3 -2
  21. package/dist/react/_internal/wagmi/index.js +2 -2
  22. package/dist/react/hooks/index.d.ts +4 -205
  23. package/dist/react/hooks/index.js +6 -9
  24. package/dist/react/index.d.ts +7 -4
  25. package/dist/react/index.js +11 -11
  26. package/dist/react/ssr/index.d.ts +14 -0
  27. package/dist/react/ssr/index.js +10 -32
  28. package/dist/react/ssr/index.js.map +1 -1
  29. package/dist/react/ui/components/index.js +9 -9
  30. package/dist/react/ui/index.js +9 -9
  31. package/dist/react/ui/modals/_internal/components/actionModal/index.js +6 -6
  32. package/dist/react/ui/styles/index.d.ts +1 -1
  33. package/dist/styles/index.d.ts +1 -1
  34. package/dist/types/index.d.ts +1 -1
  35. package/dist/types/index.js +3 -3
  36. package/dist/utils/index.js +2 -2
  37. package/package.json +1 -1
  38. package/src/react/hooks/index.ts +0 -1
  39. package/src/react/hooks/useCancelTransactionSteps.tsx +6 -3
  40. package/src/react/hooks/useCurrency.tsx +1 -1
  41. package/src/react/provider.tsx +18 -3
  42. package/src/react/ssr/create-ssr-client.ts +9 -5
  43. package/src/react/ui/modals/BuyModal/Modal.tsx +4 -0
  44. package/src/react/ui/modals/BuyModal/hooks/useBuyCollectable.ts +29 -3
  45. package/src/react/ui/modals/BuyModal/modals/Modal1155.tsx +8 -3
  46. package/src/react/ui/modals/BuyModal/store.ts +14 -0
  47. package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +21 -5
  48. package/src/react/ui/modals/CreateListingModal/hooks/useGetTokenApproval.ts +34 -28
  49. package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +21 -15
  50. package/src/react/ui/modals/MakeOfferModal/Modal.tsx +1 -1
  51. package/src/react/ui/modals/MakeOfferModal/hooks/useGetTokenApproval.tsx +34 -28
  52. package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +8 -8
  53. package/src/react/ui/modals/MakeOfferModal/hooks/useTransactionSteps.tsx +29 -15
  54. package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +3 -4
  55. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +38 -54
  56. package/src/react/ui/modals/_internal/components/priceInput/hooks/usePriceInput.ts +3 -3
  57. package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +2 -1
  58. package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +1 -1
  59. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +15 -6
  60. package/src/react/ui/modals/_internal/components/transactionStatusModal/util/getMessage.ts +12 -1
  61. package/src/types/marketplace-config.ts +3 -0
  62. package/tsconfig.tsbuildinfo +1 -1
  63. package/dist/chunk-6XUCLBZC.js.map +0 -1
  64. package/dist/chunk-GLOIEUWC.js.map +0 -1
  65. package/src/react/hooks/useBuyCollectable.tsx +0 -61
  66. /package/dist/{chunk-J4TRSLTB.js.map → chunk-CKOWM2ZR.js.map} +0 -0
  67. /package/dist/{chunk-4VS5NKDD.js.map → chunk-FT3J32ZV.js.map} +0 -0
  68. /package/dist/{chunk-IQXJZBMR.js.map → chunk-HTFBQVLV.js.map} +0 -0
  69. /package/dist/{chunk-URX7ZHX4.js.map → chunk-KILOCWY2.js.map} +0 -0
@@ -17,9 +17,6 @@ interface ERC1155QuantityModalProps extends CheckoutModalProps {
17
17
 
18
18
  export const ERC1155QuantityModal = observer(
19
19
  ({ buy, collectable, order }: ERC1155QuantityModalProps) => {
20
- buyModal$.state.quantity.set(
21
- Math.min(Number(order.quantityRemaining), 1).toString(),
22
- );
23
20
  const currencyOptions = useCurrencyOptions({
24
21
  collectionAddress: order.collectionContractAddress as Address,
25
22
  });
@@ -36,6 +33,10 @@ export const ERC1155QuantityModal = observer(
36
33
  const pricePerToken = order.priceAmount;
37
34
  const totalPrice = (BigInt(quantity) * BigInt(pricePerToken)).toString();
38
35
 
36
+ if (buyModal$.state.checkoutModalLoaded.get()) {
37
+ return null;
38
+ }
39
+
39
40
  return (
40
41
  <ActionModal
41
42
  isOpen={buyModal$.isOpen.get()}
@@ -46,6 +47,8 @@ export const ERC1155QuantityModal = observer(
46
47
  {
47
48
  label: 'Buy now',
48
49
  onClick: () => {
50
+ buyModal$.state.checkoutModalIsLoading.set(true);
51
+
49
52
  buy({
50
53
  quantity: parseUnits(
51
54
  buyModal$.state.quantity.get(),
@@ -56,6 +59,8 @@ export const ERC1155QuantityModal = observer(
56
59
  marketplace: order.marketplace,
57
60
  });
58
61
  },
62
+ disabled: buyModal$.state.checkoutModalIsLoading.get(),
63
+ pending: buyModal$.state.checkoutModalIsLoading.get(),
59
64
  },
60
65
  ]}
61
66
  >
@@ -17,7 +17,11 @@ export interface BuyModalState {
17
17
  quantity: string;
18
18
  modalId: number;
19
19
  invalidQuantity: boolean;
20
+ checkoutModalIsLoading: boolean;
21
+ checkoutModalLoaded: boolean;
20
22
  };
23
+ setCheckoutModalIsLoading: (isLoading: boolean) => void;
24
+ setCheckoutModalLoaded: (isLoaded: boolean) => void;
21
25
  callbacks?: ModalCallbacks;
22
26
  }
23
27
 
@@ -36,6 +40,8 @@ export const initialState: BuyModalState = {
36
40
  order: args.order,
37
41
  modalId: buyModal$.state.modalId.get() + 1,
38
42
  invalidQuantity: false,
43
+ checkoutModalIsLoading: false,
44
+ checkoutModalLoaded: false,
39
45
  });
40
46
  buyModal$.callbacks.set(callbacks || defaultCallbacks);
41
47
  buyModal$.isOpen.set(true);
@@ -48,6 +54,14 @@ export const initialState: BuyModalState = {
48
54
  quantity: '1',
49
55
  modalId: 0,
50
56
  invalidQuantity: false,
57
+ checkoutModalIsLoading: false,
58
+ checkoutModalLoaded: false,
59
+ },
60
+ setCheckoutModalIsLoading: (isLoading: boolean) => {
61
+ buyModal$.state.checkoutModalIsLoading.set(isLoading);
62
+ },
63
+ setCheckoutModalLoaded: (isLoaded: boolean) => {
64
+ buyModal$.state.checkoutModalLoaded.set(isLoaded);
51
65
  },
52
66
  callbacks: undefined,
53
67
  };
@@ -1,9 +1,10 @@
1
+ import type { Observable } from '@legendapp/state';
1
2
  import { useEffect } from 'react';
2
- import { Observable } from '@legendapp/state';
3
+ import { OrderbookKind, type TransactionSteps } from '../../../../_internal';
4
+ import type { ListingInput } from '../../../../_internal/transaction-machine/execute-transaction';
5
+ import { useMarketplaceConfig } from '../../../../hooks';
6
+ import type { ModalCallbacks } from '../../_internal/types';
3
7
  import { useGetTokenApprovalData } from './useGetTokenApproval';
4
- import { ListingInput } from '../../../../_internal/transaction-machine/execute-transaction';
5
- import { OrderbookKind, TransactionSteps } from '../../../../_internal';
6
- import { ModalCallbacks } from '../../_internal/types';
7
8
  import { useTransactionSteps } from './useTransactionSteps';
8
9
 
9
10
  interface UseCreateListingArgs {
@@ -20,11 +21,23 @@ export const useCreateListing = ({
20
21
  listingInput,
21
22
  chainId,
22
23
  collectionAddress,
23
- orderbookKind = OrderbookKind.sequence_marketplace_v2,
24
+ orderbookKind,
24
25
  steps$,
25
26
  callbacks,
26
27
  closeMainModal,
27
28
  }: UseCreateListingArgs) => {
29
+ const { data: marketplaceConfig, isLoading: marketplaceIsLoading } =
30
+ useMarketplaceConfig();
31
+
32
+ const collectionConfig = marketplaceConfig?.collections.find(
33
+ (c) => c.collectionAddress === collectionAddress,
34
+ );
35
+
36
+ orderbookKind =
37
+ orderbookKind ??
38
+ collectionConfig?.destinationMarketplace ??
39
+ OrderbookKind.sequence_marketplace_v2;
40
+
28
41
  const { data: tokenApproval, isLoading: tokenApprovalIsLoading } =
29
42
  useGetTokenApprovalData({
30
43
  chainId,
@@ -33,6 +46,9 @@ export const useCreateListing = ({
33
46
  currencyAddress: listingInput.listing.currencyAddress,
34
47
  contractType: listingInput.contractType,
35
48
  orderbook: orderbookKind,
49
+ query: {
50
+ enabled: !marketplaceIsLoading,
51
+ },
36
52
  });
37
53
 
38
54
  useEffect(() => {
@@ -1,15 +1,16 @@
1
+ import { skipToken, useQuery } from '@tanstack/react-query';
2
+ import { useConfig } from '../../../..';
3
+ import { dateToUnixTime } from '../../../../../utils/date';
1
4
  import {
2
5
  type ContractType,
3
6
  type CreateReq,
4
7
  type GenerateListingTransactionArgs,
5
- getMarketplaceClient,
6
8
  type OrderbookKind,
9
+ type QueryArg,
7
10
  StepType,
11
+ getMarketplaceClient,
8
12
  } from '../../../../_internal';
9
- import { useConfig } from '../../../..';
10
- import { dateToUnixTime } from '../../../../../utils/date';
11
13
  import { useWallet } from '../../../../_internal/transaction-machine/useWallet';
12
- import { useQuery } from '@tanstack/react-query';
13
14
 
14
15
  export interface UseGetTokenApprovalDataArgs {
15
16
  chainId: string;
@@ -18,6 +19,7 @@ export interface UseGetTokenApprovalDataArgs {
18
19
  currencyAddress: string;
19
20
  contractType: ContractType;
20
21
  orderbook: OrderbookKind;
22
+ query?: QueryArg;
21
23
  }
22
24
 
23
25
  const ONE_DAY_IN_SECONDS = 60 * 60 * 24;
@@ -37,34 +39,38 @@ export const useGetTokenApprovalData = (
37
39
  expiry: String(Number(dateToUnixTime(new Date())) + ONE_DAY_IN_SECONDS),
38
40
  } satisfies CreateReq;
39
41
 
42
+ const isEnabled = wallet && params.query?.enabled !== false;
43
+
40
44
  const { data, isLoading, isSuccess } = useQuery({
41
45
  queryKey: ['token-approval-data', params.currencyAddress],
42
- queryFn: async () => {
43
- const args = {
44
- collectionAddress: params.collectionAddress,
45
- owner: await wallet!.address(),
46
- walletType: wallet!.walletKind,
47
- contractType: params.contractType,
48
- orderbook: params.orderbook,
49
- listing,
50
- } satisfies GenerateListingTransactionArgs;
51
- const steps = await marketplaceClient
52
- .generateListingTransaction(args)
53
- .then((resp) => resp.steps);
46
+ queryFn: isEnabled
47
+ ? async () => {
48
+ const args = {
49
+ collectionAddress: params.collectionAddress,
50
+ owner: await wallet.address(),
51
+ walletType: wallet.walletKind,
52
+ contractType: params.contractType,
53
+ orderbook: params.orderbook,
54
+ listing,
55
+ } satisfies GenerateListingTransactionArgs;
56
+ const steps = await marketplaceClient
57
+ .generateListingTransaction(args)
58
+ .then((resp) => resp.steps);
54
59
 
55
- const tokenApprovalStep = steps.find(
56
- (step) => step.id === StepType.tokenApproval,
57
- );
58
- if (!tokenApprovalStep) {
59
- return {
60
- step: null,
61
- };
62
- }
60
+ const tokenApprovalStep = steps.find(
61
+ (step) => step.id === StepType.tokenApproval,
62
+ );
63
+ if (!tokenApprovalStep) {
64
+ return {
65
+ step: null,
66
+ };
67
+ }
63
68
 
64
- return {
65
- step: tokenApprovalStep,
66
- };
67
- },
69
+ return {
70
+ step: tokenApprovalStep,
71
+ };
72
+ }
73
+ : skipToken,
68
74
  });
69
75
 
70
76
  return {
@@ -1,29 +1,31 @@
1
+ import type { Observable } from '@legendapp/state';
2
+ import type { Address } from 'viem';
3
+ import type { OrderbookKind } from '../../../../../types';
1
4
  import {
2
5
  ExecuteType,
3
- getMarketplaceClient,
4
- Step,
6
+ type Step,
5
7
  StepType,
6
- TransactionSteps,
8
+ type TransactionSteps,
9
+ balanceQueries,
10
+ collectableKeys,
11
+ getMarketplaceClient,
7
12
  } from '../../../../_internal';
8
- import { OrderbookKind } from '../../../../../types';
9
- import { ModalCallbacks } from '../../_internal/types';
10
13
  import {
11
- ListingInput,
14
+ type ListingInput,
12
15
  TransactionType,
13
16
  } from '../../../../_internal/transaction-machine/execute-transaction';
14
- import { useTransactionStatusModal } from '../../_internal/components/transactionStatusModal';
15
- import { Address } from 'viem';
16
- import { Observable } from '@legendapp/state';
17
17
  import { useWallet } from '../../../../_internal/transaction-machine/useWallet';
18
- import { SignatureStep } from '../../../../_internal/transaction-machine/utils';
18
+ import type { SignatureStep } from '../../../../_internal/transaction-machine/utils';
19
19
  import { useConfig, useGenerateListingTransaction } from '../../../../hooks';
20
20
  import { useGetReceiptFromHash } from '../../../../hooks/useGetReceiptFromHash';
21
+ import { useTransactionStatusModal } from '../../_internal/components/transactionStatusModal';
22
+ import type { ModalCallbacks } from '../../_internal/types';
21
23
 
22
24
  interface UseTransactionStepsArgs {
23
25
  listingInput: ListingInput;
24
26
  chainId: string;
25
27
  collectionAddress: string;
26
- orderbookKind?: OrderbookKind;
28
+ orderbookKind: OrderbookKind;
27
29
  callbacks?: ModalCallbacks;
28
30
  closeMainModal: () => void;
29
31
  steps$: Observable<TransactionSteps>;
@@ -33,7 +35,7 @@ export const useTransactionSteps = ({
33
35
  listingInput,
34
36
  chainId,
35
37
  collectionAddress,
36
- orderbookKind = OrderbookKind.sequence_marketplace_v2,
38
+ orderbookKind,
37
39
  callbacks,
38
40
  closeMainModal,
39
41
  steps$,
@@ -77,7 +79,6 @@ export const useTransactionSteps = ({
77
79
  } else {
78
80
  console.debug('onError callback not provided:', error);
79
81
  }
80
- throw error;
81
82
  }
82
83
  };
83
84
 
@@ -103,7 +104,6 @@ export const useTransactionSteps = ({
103
104
  }
104
105
  } catch (error) {
105
106
  steps$.approval.isExecuting.set(false);
106
- throw error;
107
107
  }
108
108
  };
109
109
 
@@ -147,6 +147,13 @@ export const useTransactionSteps = ({
147
147
  hash,
148
148
  orderId,
149
149
  callbacks,
150
+ queriesToInvalidate: [
151
+ balanceQueries.all,
152
+ collectableKeys.lowestListings,
153
+ collectableKeys.listings,
154
+ collectableKeys.listingsCount,
155
+ collectableKeys.userBalances,
156
+ ],
150
157
  });
151
158
 
152
159
  if (hash) {
@@ -173,7 +180,6 @@ export const useTransactionSteps = ({
173
180
  if (callbacks?.onError && typeof callbacks.onError === 'function') {
174
181
  callbacks.onError(error as Error);
175
182
  }
176
- throw error;
177
183
  }
178
184
  };
179
185
 
@@ -142,7 +142,7 @@ const Modal = observer(() => {
142
142
  insufficientBalance ||
143
143
  isLoading ||
144
144
  invalidQuantity ||
145
- invalidCurrency
145
+ invalidCurrency,
146
146
  },
147
147
  ];
148
148
 
@@ -1,15 +1,16 @@
1
+ import { skipToken, useQuery } from '@tanstack/react-query';
2
+ import { dateToUnixTime } from '../../../../../utils/date';
1
3
  import {
2
4
  type ContractType,
3
5
  type CreateReq,
4
- GenerateOfferTransactionArgs,
5
- getMarketplaceClient,
6
+ type GenerateOfferTransactionArgs,
6
7
  type OrderbookKind,
8
+ type QueryArg,
7
9
  StepType,
10
+ getMarketplaceClient,
8
11
  } from '../../../../_internal';
9
- import { useQuery } from '@tanstack/react-query';
10
12
  import { useWallet } from '../../../../_internal/transaction-machine/useWallet';
11
13
  import { useConfig } from '../../../../hooks/useConfig';
12
- import { dateToUnixTime } from '../../../../../utils/date';
13
14
 
14
15
  export interface UseGetTokenApprovalDataArgs {
15
16
  chainId: string;
@@ -18,6 +19,7 @@ export interface UseGetTokenApprovalDataArgs {
18
19
  currencyAddress: string;
19
20
  contractType: ContractType;
20
21
  orderbook: OrderbookKind;
22
+ query?: QueryArg;
21
23
  }
22
24
 
23
25
  const ONE_DAY_IN_SECONDS = 60 * 60 * 24;
@@ -37,34 +39,38 @@ export const useGetTokenApprovalData = (
37
39
  expiry: String(Number(dateToUnixTime(new Date())) + ONE_DAY_IN_SECONDS),
38
40
  } satisfies CreateReq;
39
41
 
42
+ const isEnabled = wallet && params.query?.enabled !== false;
43
+
40
44
  const { data, isLoading, isSuccess } = useQuery({
41
45
  queryKey: ['token-approval-data', params.currencyAddress],
42
- queryFn: async () => {
43
- const args = {
44
- collectionAddress: params.collectionAddress,
45
- maker: await wallet!.address(),
46
- walletType: wallet!.walletKind,
47
- contractType: params.contractType,
48
- orderbook: params.orderbook,
49
- offer,
50
- } satisfies GenerateOfferTransactionArgs;
51
- const steps = await marketplaceClient
52
- .generateOfferTransaction(args)
53
- .then((resp) => resp.steps);
46
+ queryFn: isEnabled
47
+ ? async () => {
48
+ const args = {
49
+ collectionAddress: params.collectionAddress,
50
+ maker: await wallet.address(),
51
+ walletType: wallet.walletKind,
52
+ contractType: params.contractType,
53
+ orderbook: params.orderbook,
54
+ offer,
55
+ } satisfies GenerateOfferTransactionArgs;
56
+ const steps = await marketplaceClient
57
+ .generateOfferTransaction(args)
58
+ .then((resp) => resp.steps);
54
59
 
55
- const tokenApprovalStep = steps.find(
56
- (step) => step.id === StepType.tokenApproval,
57
- );
58
- if (!tokenApprovalStep) {
59
- return {
60
- step: null,
61
- };
62
- }
60
+ const tokenApprovalStep = steps.find(
61
+ (step) => step.id === StepType.tokenApproval,
62
+ );
63
+ if (!tokenApprovalStep) {
64
+ return {
65
+ step: null,
66
+ };
67
+ }
63
68
 
64
- return {
65
- step: tokenApprovalStep,
66
- };
67
- },
69
+ return {
70
+ step: tokenApprovalStep,
71
+ };
72
+ }
73
+ : skipToken,
68
74
  enabled: !!wallet && !!params.collectionAddress && !!params.currencyAddress,
69
75
  });
70
76
 
@@ -1,17 +1,17 @@
1
- import { Observable } from '@legendapp/state';
2
- import { OrderbookKind } from '../../../../../types';
3
- import { OfferInput } from '../../../../_internal/transaction-machine/execute-transaction';
4
- import { ModalCallbacks } from '../../_internal/types';
1
+ import type { Observable } from '@legendapp/state';
2
+ import { useEffect } from 'react';
3
+ import type { OrderbookKind } from '../../../../../types';
4
+ import type { TransactionSteps } from '../../../../_internal';
5
+ import type { OfferInput } from '../../../../_internal/transaction-machine/execute-transaction';
6
+ import type { ModalCallbacks } from '../../_internal/types';
5
7
  import { useGetTokenApprovalData } from './useGetTokenApproval';
6
8
  import { useTransactionSteps } from './useTransactionSteps';
7
- import { useEffect } from 'react';
8
- import { TransactionSteps } from '../../../../_internal';
9
9
 
10
10
  interface UseMakeOfferArgs {
11
11
  offerInput: OfferInput;
12
12
  chainId: string;
13
13
  collectionAddress: string;
14
- orderbookKind?: OrderbookKind;
14
+ orderbookKind: OrderbookKind;
15
15
  callbacks?: ModalCallbacks;
16
16
  closeMainModal: () => void;
17
17
  steps$: Observable<TransactionSteps>;
@@ -21,7 +21,7 @@ export const useMakeOffer = ({
21
21
  offerInput,
22
22
  chainId,
23
23
  collectionAddress,
24
- orderbookKind = OrderbookKind.sequence_marketplace_v2,
24
+ orderbookKind,
25
25
  callbacks,
26
26
  closeMainModal,
27
27
  steps$,
@@ -1,24 +1,26 @@
1
+ import type { Observable } from '@legendapp/state';
2
+ import type { Address } from 'viem';
3
+ import { OrderbookKind, Price } from '../../../../../types';
1
4
  import {
2
5
  ExecuteType,
3
- getMarketplaceClient,
4
- Step,
6
+ type Step,
5
7
  StepType,
6
- TransactionSteps,
8
+ type TransactionSteps,
9
+ balanceQueries,
10
+ collectableKeys,
11
+ getMarketplaceClient,
7
12
  } from '../../../../_internal';
8
- import { useGenerateOfferTransaction } from '../../../../hooks/useGenerateOfferTransaction';
9
- import { OrderbookKind } from '../../../../../types';
10
- import { ModalCallbacks } from '../../_internal/types';
11
13
  import {
12
- OfferInput,
14
+ type OfferInput,
13
15
  TransactionType,
14
16
  } from '../../../../_internal/transaction-machine/execute-transaction';
15
- import { useTransactionStatusModal } from '../../_internal/components/transactionStatusModal';
16
- import { Address } from 'viem';
17
- import { Observable } from '@legendapp/state';
18
17
  import { useWallet } from '../../../../_internal/transaction-machine/useWallet';
19
- import { SignatureStep } from '../../../../_internal/transaction-machine/utils';
20
- import { useConfig } from '../../../../hooks';
18
+ import type { SignatureStep } from '../../../../_internal/transaction-machine/utils';
19
+ import { useConfig, useCurrency } from '../../../../hooks';
20
+ import { useGenerateOfferTransaction } from '../../../../hooks/useGenerateOfferTransaction';
21
21
  import { useGetReceiptFromHash } from '../../../../hooks/useGetReceiptFromHash';
22
+ import { useTransactionStatusModal } from '../../_internal/components/transactionStatusModal';
23
+ import type { ModalCallbacks } from '../../_internal/types';
22
24
 
23
25
  export type ExecutionState = 'approval' | 'offer' | null;
24
26
 
@@ -54,6 +56,10 @@ export const useTransactionSteps = ({
54
56
  if (!steps) return;
55
57
  },
56
58
  });
59
+ const { data: currency } = useCurrency({
60
+ chainId,
61
+ currencyAddress: offerInput.offer.currencyAddress,
62
+ });
57
63
 
58
64
  const getOfferSteps = async () => {
59
65
  if (!wallet) return;
@@ -80,7 +86,6 @@ export const useTransactionSteps = ({
80
86
  } else {
81
87
  console.debug('onError callback not provided:', error);
82
88
  }
83
- throw error;
84
89
  }
85
90
  };
86
91
 
@@ -106,7 +111,6 @@ export const useTransactionSteps = ({
106
111
  }
107
112
  } catch (error) {
108
113
  steps$.approval.isExecuting.set(false);
109
- throw error;
110
114
  }
111
115
  };
112
116
 
@@ -150,6 +154,17 @@ export const useTransactionSteps = ({
150
154
  hash,
151
155
  orderId,
152
156
  callbacks,
157
+ queriesToInvalidate: [
158
+ balanceQueries.all,
159
+ collectableKeys.highestOffers,
160
+ collectableKeys.offers,
161
+ collectableKeys.offersCount,
162
+ collectableKeys.userBalances,
163
+ ],
164
+ price: {
165
+ amountRaw: offerInput.offer.pricePerToken,
166
+ currency,
167
+ } as Price,
153
168
  });
154
169
 
155
170
  if (hash) {
@@ -178,7 +193,6 @@ export const useTransactionSteps = ({
178
193
  if (callbacks?.onError && typeof callbacks.onError === 'function') {
179
194
  callbacks.onError(error as Error);
180
195
  }
181
- throw error;
182
196
  }
183
197
  };
184
198
 
@@ -1,4 +1,6 @@
1
1
  import {
2
+ balanceQueries,
3
+ collectableKeys,
2
4
  ExecuteType,
3
5
  getMarketplaceClient,
4
6
  MarketplaceKind,
@@ -85,7 +87,6 @@ export const useTransactionSteps = ({
85
87
  } else {
86
88
  console.debug('onError callback not provided:', error);
87
89
  }
88
- throw error;
89
90
  }
90
91
  };
91
92
 
@@ -111,7 +112,6 @@ export const useTransactionSteps = ({
111
112
  }
112
113
  } catch (error) {
113
114
  steps$.approval.isExecuting.set(false);
114
- throw error;
115
115
  }
116
116
  };
117
117
 
@@ -153,6 +153,7 @@ export const useTransactionSteps = ({
153
153
  hash,
154
154
  orderId,
155
155
  callbacks,
156
+ queriesToInvalidate: [balanceQueries.all, collectableKeys.userBalances],
156
157
  });
157
158
 
158
159
  if (hash) {
@@ -180,8 +181,6 @@ export const useTransactionSteps = ({
180
181
  if (callbacks?.onError && typeof callbacks.onError === 'function') {
181
182
  callbacks.onError(error as Error);
182
183
  }
183
-
184
- throw error;
185
184
  }
186
185
  };
187
186
 
@@ -1,8 +1,7 @@
1
- import type { QueryKey } from '@tanstack/react-query';
2
1
  import type { Hex } from 'viem';
3
2
  import { ContractType } from '../../../../../../types';
4
3
  import { InvalidContractTypeError } from '../../../../../../utils/_internal/error/transaction';
5
- import { balanceQueries } from '../../../../../_internal';
4
+ import { balanceQueries, collectableKeys } from '../../../../../_internal';
6
5
  import { TransactionType } from '../../../../../_internal/transaction-machine/execute-transaction';
7
6
  import { useTransferTokens } from '../../../../../hooks';
8
7
  import { useTransactionStatusModal } from '../../../_internal/components/transactionStatusModal';
@@ -21,6 +20,28 @@ const useHandleTransfer = () => {
21
20
  const { transferTokensAsync } = useTransferTokens();
22
21
  const { show: showTransactionStatusModal } = useTransactionStatusModal();
23
22
 
23
+ const getHash = async () => {
24
+ if (collectionType === ContractType.ERC721) {
25
+ return await transferTokensAsync({
26
+ receiverAddress: receiverAddress as Hex,
27
+ collectionAddress,
28
+ tokenId: collectibleId,
29
+ chainId,
30
+ contractType: ContractType.ERC721,
31
+ });
32
+ }
33
+
34
+ // For ERC1155
35
+ return await transferTokensAsync({
36
+ receiverAddress: receiverAddress as Hex,
37
+ collectionAddress,
38
+ tokenId: collectibleId,
39
+ chainId,
40
+ contractType: ContractType.ERC1155,
41
+ quantity: String(quantity),
42
+ });
43
+ };
44
+
24
45
  async function transfer() {
25
46
  if (
26
47
  collectionType !== ContractType.ERC721 &&
@@ -29,61 +50,24 @@ const useHandleTransfer = () => {
29
50
  throw new InvalidContractTypeError(collectionType);
30
51
  }
31
52
 
32
- if (collectionType === ContractType.ERC721) {
33
- try {
34
- const hash = await transferTokensAsync({
35
- receiverAddress: receiverAddress as Hex,
36
- collectionAddress,
37
- tokenId: collectibleId,
38
- chainId,
39
- contractType: ContractType.ERC721,
40
- });
41
-
42
- transferModal$.close();
43
-
44
- showTransactionStatusModal({
45
- hash: hash,
46
- collectionAddress,
47
- chainId,
48
- collectibleId,
49
- price: undefined,
50
- type: TransactionType.TRANSFER,
51
- queriesToInvalidate: balanceQueries.all as unknown as QueryKey[],
52
- });
53
- } catch (error) {
54
- transferModal$.view.set('enterReceiverAddress');
55
-
56
- callbacks?.onError?.(error as Error);
57
- }
58
- }
59
-
60
- if (collectionType === ContractType.ERC1155) {
61
- try {
62
- const hash = await transferTokensAsync({
63
- receiverAddress: receiverAddress as Hex,
64
- collectionAddress,
65
- tokenId: collectibleId,
66
- chainId,
67
- contractType: ContractType.ERC1155,
68
- quantity: String(quantity),
69
- });
53
+ try {
54
+ const hash = await getHash();
70
55
 
71
- transferModal$.close();
56
+ transferModal$.close();
72
57
 
73
- showTransactionStatusModal({
74
- hash: hash,
75
- collectionAddress,
76
- chainId,
77
- collectibleId,
78
- price: undefined,
79
- type: TransactionType.TRANSFER,
80
- queriesToInvalidate: balanceQueries.all as unknown as QueryKey[],
81
- });
82
- } catch (error) {
83
- transferModal$.view.set('enterReceiverAddress');
58
+ showTransactionStatusModal({
59
+ hash: hash,
60
+ collectionAddress,
61
+ chainId,
62
+ collectibleId,
63
+ price: undefined,
64
+ type: TransactionType.TRANSFER,
65
+ queriesToInvalidate: [balanceQueries.all, collectableKeys.userBalances],
66
+ });
67
+ } catch (error) {
68
+ transferModal$.view.set('enterReceiverAddress');
84
69
 
85
- callbacks?.onError?.(error as Error);
86
- }
70
+ callbacks?.onError?.(error as Error);
87
71
  }
88
72
  }
89
73