@0xsequence/marketplace-sdk 0.0.1 → 0.2.0

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 (144) hide show
  1. package/.ctirc +32 -0
  2. package/dist/{chunk-TZGLKJRF.js → chunk-4E34HVSA.js} +2 -2
  3. package/dist/chunk-5EOVZAKT.js +1325 -0
  4. package/dist/chunk-5EOVZAKT.js.map +1 -0
  5. package/dist/{chunk-RNUHUVLC.js → chunk-6JWGELXL.js} +1 -1
  6. package/dist/chunk-6JWGELXL.js.map +1 -0
  7. package/dist/{chunk-4PFMUVE4.js → chunk-CSN7YD5Q.js} +2 -2
  8. package/dist/chunk-CSN7YD5Q.js.map +1 -0
  9. package/dist/{chunk-G3D572BT.js → chunk-FCQCNLFZ.js} +24 -1
  10. package/dist/chunk-FCQCNLFZ.js.map +1 -0
  11. package/dist/{chunk-HGBEC3WX.js → chunk-GZIA25G4.js} +1 -1
  12. package/dist/chunk-GZIA25G4.js.map +1 -0
  13. package/dist/{chunk-QOJXWHRZ.js → chunk-LFQB477Y.js} +3 -1
  14. package/dist/chunk-LFQB477Y.js.map +1 -0
  15. package/dist/{chunk-SM7V6ZWI.js → chunk-MD4JHPMH.js} +493 -418
  16. package/dist/chunk-MD4JHPMH.js.map +1 -0
  17. package/dist/{chunk-EDTC7UES.js → chunk-NII6JJGH.js} +9 -4
  18. package/dist/chunk-NII6JJGH.js.map +1 -0
  19. package/dist/{chunk-BBB3XUB4.js → chunk-PE2LLUTJ.js} +1 -1
  20. package/dist/chunk-PE2LLUTJ.js.map +1 -0
  21. package/dist/chunk-Q2BVDQ3G.js +41 -0
  22. package/dist/chunk-Q2BVDQ3G.js.map +1 -0
  23. package/dist/{chunk-3TYUQEFM.js → chunk-VEX7FDL6.js} +2 -2
  24. package/dist/chunk-VEX7FDL6.js.map +1 -0
  25. package/dist/{create-config-Dz0gCiQ0.d.ts → create-config-CgtmCzvb.d.ts} +2 -2
  26. package/dist/index.css +4 -1
  27. package/dist/index.d.ts +3 -2
  28. package/dist/index.js +4 -4
  29. package/dist/{marketplace-config-DZbtyrma.d.ts → marketplace-config-Bbxl-uKX.d.ts} +2 -1
  30. package/dist/react/_internal/api/index.d.ts +1 -1
  31. package/dist/react/_internal/api/index.js +1 -1
  32. package/dist/react/_internal/index.d.ts +5 -4
  33. package/dist/react/_internal/index.js +16 -8
  34. package/dist/react/_internal/wagmi/index.d.ts +3 -3
  35. package/dist/react/_internal/wagmi/index.js +1 -1
  36. package/dist/react/hooks/index.d.ts +1691 -103
  37. package/dist/react/hooks/index.js +34 -22
  38. package/dist/react/index.css +4 -1
  39. package/dist/react/index.css.map +1 -1
  40. package/dist/react/index.d.ts +7 -6
  41. package/dist/react/index.js +43 -31
  42. package/dist/react/ssr/index.d.ts +26 -25
  43. package/dist/react/ssr/index.js +34 -4
  44. package/dist/react/ssr/index.js.map +1 -1
  45. package/dist/react/ui/icons/index.js +2 -2
  46. package/dist/react/ui/index.css +4 -1
  47. package/dist/react/ui/index.css.map +1 -1
  48. package/dist/react/ui/index.d.ts +47 -42
  49. package/dist/react/ui/index.js +10 -10
  50. package/dist/react/ui/modals/_internal/components/actionModal/index.js +4 -4
  51. package/dist/{services-BIwQ1C1c.d.ts → services-Dei25J6_.d.ts} +1 -1
  52. package/dist/styles/index.css +4 -1
  53. package/dist/styles/index.css.map +1 -1
  54. package/dist/styles/index.d.ts +2 -1
  55. package/dist/styles/index.js +4 -4973
  56. package/dist/styles/index.js.map +1 -1
  57. package/dist/types/index.d.ts +2 -1
  58. package/dist/types/index.js +3 -3
  59. package/dist/types-BzZVURNL.d.ts +19 -0
  60. package/dist/utils/abi/clients/index.js +1 -1
  61. package/dist/utils/index.d.ts +2 -1
  62. package/dist/utils/index.js +2 -2
  63. package/package.json +19 -25
  64. package/src/react/_internal/api/marketplace.gen.ts +4 -1
  65. package/src/react/_internal/api/zod-schema.ts +636 -0
  66. package/src/react/_internal/types.ts +33 -9
  67. package/src/react/_internal/wagmi/create-config.ts +9 -3
  68. package/src/react/_internal/wagmi/embedded.ts +1 -1
  69. package/src/react/_internal/wagmi/universal.ts +1 -1
  70. package/src/react/hooks/index.ts +3 -0
  71. package/src/react/hooks/options/marketplaceConfigOptions.ts +2 -2
  72. package/src/react/hooks/useBalanceOfCollectible.tsx +47 -21
  73. package/src/react/hooks/useCheckoutOptions.tsx +63 -0
  74. package/src/react/hooks/useCollectible.tsx +20 -14
  75. package/src/react/hooks/useCollection.tsx +18 -12
  76. package/src/react/hooks/useCountOfCollectables.tsx +77 -0
  77. package/src/react/hooks/useCurrencies.tsx +67 -56
  78. package/src/react/hooks/useFilters.tsx +18 -12
  79. package/src/react/hooks/useFloorOrder.tsx +24 -9
  80. package/src/react/hooks/useGenerateListingTransaction.tsx +8 -7
  81. package/src/react/hooks/useGenerateOfferTransaction.tsx +5 -5
  82. package/src/react/hooks/useGenerateSellTransaction.tsx +19 -12
  83. package/src/react/hooks/useHighestOffer.tsx +26 -16
  84. package/src/react/hooks/useListBalances.tsx +60 -29
  85. package/src/react/hooks/useListCollectibles.tsx +28 -15
  86. package/src/react/hooks/useListOffersForCollectible.tsx +17 -8
  87. package/src/react/hooks/useLowestListing.tsx +26 -17
  88. package/src/react/hooks/useRoyaltyPercentage.tsx +18 -8
  89. package/src/react/hooks/useTransferTokens.tsx +3 -3
  90. package/src/react/provider.tsx +1 -1
  91. package/src/react/ssr/create-ssr-client.ts +1 -1
  92. package/src/react/ui/modals/CreateListingModal/_store.ts +39 -40
  93. package/src/react/ui/modals/CreateListingModal/index.tsx +152 -130
  94. package/src/react/ui/modals/MakeOfferModal/_store.ts +38 -43
  95. package/src/react/ui/modals/MakeOfferModal/index.tsx +39 -28
  96. package/src/react/ui/modals/SellModal/_store.ts +59 -57
  97. package/src/react/ui/modals/SellModal/index.tsx +34 -12
  98. package/src/react/ui/modals/SuccessfulPurchaseModal/_store.ts +1 -1
  99. package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +14 -14
  100. package/src/react/ui/modals/TransferModal/_store.ts +11 -11
  101. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +92 -89
  102. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +114 -0
  103. package/src/react/ui/modals/TransferModal/_views/followWalletInstructions/index.tsx +0 -96
  104. package/src/react/ui/modals/TransferModal/index.tsx +24 -3
  105. package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +1 -1
  106. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +4 -4
  107. package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +4 -3
  108. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +55 -12
  109. package/src/react/ui/modals/_internal/components/priceInput/styles.css.ts +4 -0
  110. package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +3 -2
  111. package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +4 -4
  112. package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +4 -4
  113. package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +3 -2
  114. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +7 -5
  115. package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +6 -6
  116. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +47 -14
  117. package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +14 -6
  118. package/src/types/api-types.ts +2 -2
  119. package/src/types/callbacks.ts +51 -0
  120. package/src/types/marketplace-config.ts +2 -1
  121. package/src/types/types.ts +1 -1
  122. package/src/utils/get-public-rpc-client.ts +1 -1
  123. package/tsconfig.json +24 -0
  124. package/tsconfig.tsbuildinfo +1 -0
  125. package/tsup.config.ts +35 -0
  126. package/README.md +0 -8
  127. package/dist/chunk-3TYUQEFM.js.map +0 -1
  128. package/dist/chunk-4PFMUVE4.js.map +0 -1
  129. package/dist/chunk-BBB3XUB4.js.map +0 -1
  130. package/dist/chunk-EDTC7UES.js.map +0 -1
  131. package/dist/chunk-G3D572BT.js.map +0 -1
  132. package/dist/chunk-HGBEC3WX.js.map +0 -1
  133. package/dist/chunk-QOJXWHRZ.js.map +0 -1
  134. package/dist/chunk-RNUHUVLC.js.map +0 -1
  135. package/dist/chunk-SM7V6ZWI.js.map +0 -1
  136. package/dist/chunk-STO74F2I.js +0 -14
  137. package/dist/chunk-STO74F2I.js.map +0 -1
  138. package/dist/chunk-VPGWEMWL.js +0 -162
  139. package/dist/chunk-VPGWEMWL.js.map +0 -1
  140. package/dist/chunk-ZE2LNX65.js +0 -394
  141. package/dist/chunk-ZE2LNX65.js.map +0 -1
  142. package/dist/types-BrAQ8-w4.d.ts +0 -12
  143. package/src/react/hooks/useCollectionCounts.tsx +0 -61
  144. /package/dist/{chunk-TZGLKJRF.js.map → chunk-4E34HVSA.js.map} +0 -0
@@ -0,0 +1,114 @@
1
+ import type { QueryKey } from '@tanstack/react-query';
2
+ import type { Hex } from 'viem';
3
+ import { ContractType } from '../../../../../../types';
4
+ import { balanceQueries } from '../../../../../_internal';
5
+ import { useCollectible, useTransferTokens } from '../../../../../hooks';
6
+ import { useTransactionStatusModal } from '../../../_internal/components/transactionStatusModal';
7
+ import { transferModal$ } from '../../_store';
8
+ import {
9
+ getTransferTransactionMessage,
10
+ getTransferTransactionTitle,
11
+ } from '../../_utils/getTransferTransactionTitleMessage';
12
+
13
+ const useHandleTransfer = () => {
14
+ const {
15
+ receiverAddress,
16
+ collectionAddress,
17
+ tokenId,
18
+ quantity,
19
+ chainId,
20
+ collectionType,
21
+ successCallbacks,
22
+ errorCallbacks,
23
+ } = transferModal$.state.get();
24
+ const { transferTokensAsync } = useTransferTokens();
25
+ const { show: showTransactionStatusModal } = useTransactionStatusModal();
26
+ const { data: collectible } = useCollectible({
27
+ collectionAddress,
28
+ collectibleId: tokenId,
29
+ chainId,
30
+ });
31
+
32
+ async function transfer() {
33
+ if (
34
+ collectionType !== ContractType.ERC721 &&
35
+ collectionType !== ContractType.ERC1155
36
+ ) {
37
+ throw new Error('Invalid contract type');
38
+ }
39
+
40
+ if (collectionType === ContractType.ERC721) {
41
+ try {
42
+ const hash = await transferTokensAsync({
43
+ receiverAddress: receiverAddress as Hex,
44
+ collectionAddress,
45
+ tokenId,
46
+ chainId,
47
+ contractType: ContractType.ERC721,
48
+ });
49
+
50
+ transferModal$.close();
51
+
52
+ showTransactionStatusModal({
53
+ hash: hash,
54
+ collectionAddress,
55
+ chainId,
56
+ tokenId,
57
+ price: undefined,
58
+ getTitle: getTransferTransactionTitle,
59
+ getMessage: (params) =>
60
+ getTransferTransactionMessage(params, collectible!.name),
61
+ type: 'transfer',
62
+ callbacks: {
63
+ onSuccess: successCallbacks?.onTransferSuccess,
64
+ onUnknownError: errorCallbacks?.onTransferError,
65
+ },
66
+ queriesToInvalidate: balanceQueries.all as unknown as QueryKey[],
67
+ });
68
+ } catch (error) {
69
+ transferModal$.view.set('enterReceiverAddress');
70
+
71
+ errorCallbacks?.onTransferError?.(error);
72
+ }
73
+ }
74
+
75
+ if (collectionType === ContractType.ERC1155) {
76
+ try {
77
+ const hash = await transferTokensAsync({
78
+ receiverAddress: receiverAddress as Hex,
79
+ collectionAddress,
80
+ tokenId,
81
+ chainId,
82
+ contractType: ContractType.ERC1155,
83
+ quantity: String(quantity),
84
+ });
85
+
86
+ transferModal$.close();
87
+
88
+ showTransactionStatusModal({
89
+ hash: hash,
90
+ collectionAddress,
91
+ chainId,
92
+ tokenId,
93
+ price: undefined,
94
+ getTitle: getTransferTransactionTitle,
95
+ getMessage: (params) =>
96
+ getTransferTransactionMessage(params, collectible!.name),
97
+ type: 'transfer',
98
+ callbacks: {
99
+ onSuccess: successCallbacks?.onTransferSuccess,
100
+ onUnknownError: errorCallbacks?.onTransferError,
101
+ },
102
+ });
103
+ } catch (error) {
104
+ transferModal$.view.set('enterReceiverAddress');
105
+
106
+ errorCallbacks?.onTransferError?.(error);
107
+ }
108
+ }
109
+ }
110
+
111
+ return { transfer };
112
+ };
113
+
114
+ export default useHandleTransfer;
@@ -2,104 +2,8 @@ import { observer } from '@legendapp/state/react';
2
2
  import AlertMessage from '../../../_internal/components/alertMessage';
3
3
  import getMessage from '../../messages';
4
4
  import { Box, Button, Text } from '@0xsequence/design-system';
5
- import { ContractType } from '@internal';
6
- import { transferModal$ } from '../../_store';
7
- import { useCollection } from '@react-hooks/useCollection';
8
- import { useTransferTokens } from '@react-hooks/useTransferTokens';
9
- import type { Hex } from 'viem';
10
- import { useTransactionStatusModal } from '../../../_internal/components/transactionStatusModal';
11
- import {
12
- getTransferTransactionMessage,
13
- getTransferTransactionTitle,
14
- } from '../../_utils/getTransferTransactionTitleMessage';
15
- import { useCollectible } from '@react-hooks/useCollectible';
16
- import { useEffect } from 'react';
17
5
 
18
6
  const FollowWalletInstructionsView = observer(() => {
19
- const {
20
- receiverAddress,
21
- collectionAddress,
22
- tokenId,
23
- quantity,
24
- chainId,
25
- messages,
26
- } = transferModal$.state.get();
27
- const { transferTokensAsync, hash } = useTransferTokens();
28
- const { show: showTransactionStatusModal } = useTransactionStatusModal();
29
- const { data: collection, isSuccess: collectionSuccess } = useCollection({
30
- collectionAddress,
31
- chainId,
32
- });
33
- const { data: collectible, isSuccess: collectibleSuccess } = useCollectible({
34
- collectionAddress,
35
- collectibleId: tokenId,
36
- chainId,
37
- });
38
-
39
- useEffect(() => {
40
- if (!hash && collectionSuccess) {
41
- transfer();
42
- }
43
- }, [collectionSuccess, collectibleSuccess, hash]);
44
-
45
- async function transfer() {
46
- if (collection!.type === ContractType.ERC721) {
47
- try {
48
- const hash = await transferTokensAsync({
49
- receiverAddress: receiverAddress as Hex,
50
- collectionAddress,
51
- tokenId,
52
- chainId,
53
- contractType: ContractType.ERC721,
54
- });
55
-
56
- transferModal$.close();
57
-
58
- showTransactionStatusModal({
59
- hash: hash,
60
- collectionAddress,
61
- chainId,
62
- tokenId,
63
- price: undefined,
64
- getTitle: getTransferTransactionTitle,
65
- getMessage: (params) =>
66
- getTransferTransactionMessage(params, collectible!.name),
67
- type: 'transfer',
68
- });
69
- } catch (error) {
70
- messages?.transferCollectibles?.onUnknownError &&
71
- messages.transferCollectibles.onUnknownError(error);
72
- }
73
- }
74
-
75
- try {
76
- const hash = await transferTokensAsync({
77
- receiverAddress: receiverAddress as Hex,
78
- collectionAddress,
79
- tokenId,
80
- chainId,
81
- contractType: ContractType.ERC1155,
82
- quantity: String(quantity),
83
- });
84
-
85
- transferModal$.close();
86
-
87
- showTransactionStatusModal({
88
- hash: hash,
89
- collectionAddress,
90
- chainId,
91
- tokenId,
92
- price: undefined,
93
- getTitle: getTransferTransactionTitle,
94
- getMessage: (params) =>
95
- getTransferTransactionMessage(params, collectible!.name),
96
- type: 'transfer',
97
- });
98
- } catch (error) {
99
- messages?.transferCollectibles?.onUnknownError &&
100
- messages.transferCollectibles.onUnknownError(error);
101
- }
102
- }
103
7
  return (
104
8
  <Box display="grid" gap="6" flexGrow="1">
105
9
  <Text color="white" fontSize="large" fontWeight="bold">
@@ -5,21 +5,24 @@ import { observer, Show } from '@legendapp/state/react';
5
5
  import { Close, Content, Overlay, Portal, Root } from '@radix-ui/react-dialog';
6
6
  import { useAccount } from 'wagmi';
7
7
  import { useSwitchChainModal } from '../_internal/components/switchChainModal';
8
- import type { Messages } from '../../../../types/messages';
9
8
  import type { Hex } from 'viem';
10
9
  import EnterWalletAddressView from './_views/enterWalletAddress';
11
10
  import FollowWalletInstructionsView from './_views/followWalletInstructions';
11
+ import {
12
+ TransferErrorCallbacks,
13
+ TransferSuccessCallbacks,
14
+ } from '../../../../types/callbacks';
12
15
 
13
16
  export type ShowTransferModalArgs = {
14
17
  collectionAddress: Hex;
15
18
  tokenId: string;
16
19
  chainId: string;
17
- messages?: Messages;
18
20
  };
19
21
 
20
22
  export const useTransferModal = () => {
21
23
  const { chainId: accountChainId } = useAccount();
22
24
  const { show: showSwitchNetworkModal } = useSwitchChainModal();
25
+ const { errorCallbacks, successCallbacks } = transferModal$.state.get();
23
26
 
24
27
  const openModal = (args: ShowTransferModalArgs) => {
25
28
  transferModal$.open(args);
@@ -32,7 +35,13 @@ export const useTransferModal = () => {
32
35
  showSwitchNetworkModal({
33
36
  chainIdToSwitchTo: Number(args.chainId),
34
37
  onSwitchChain: () => openModal(args),
35
- messages: args.messages?.switchChain,
38
+ callbacks: {
39
+ onSuccess: successCallbacks?.onSwitchChainSuccess,
40
+ onUnknownError: errorCallbacks?.onSwitchChainError,
41
+ onSwitchingNotSupported: errorCallbacks?.onSwitchingNotSupportedError,
42
+ onUserRejectedRequest:
43
+ errorCallbacks?.onUserRejectedSwitchingChainRequestError,
44
+ },
36
45
  });
37
46
  return;
38
47
  }
@@ -43,6 +52,18 @@ export const useTransferModal = () => {
43
52
  return {
44
53
  show: handleShowModal,
45
54
  close: () => transferModal$.close(),
55
+ onError: (callbacks: TransferErrorCallbacks) => {
56
+ transferModal$.state.set({
57
+ ...transferModal$.state.get(),
58
+ errorCallbacks: callbacks,
59
+ });
60
+ },
61
+ onSuccess: (callbacks: TransferSuccessCallbacks) => {
62
+ transferModal$.state.set({
63
+ ...transferModal$.state.get(),
64
+ successCallbacks: callbacks,
65
+ });
66
+ },
46
67
  };
47
68
  };
48
69
 
@@ -10,10 +10,10 @@ import {
10
10
  IconButton,
11
11
  Text,
12
12
  } from '@0xsequence/design-system';
13
- import { getProviderEl } from '@internal';
14
13
  import type { Observable } from '@legendapp/state';
15
14
  import { observer } from '@legendapp/state/react';
16
15
  import { Close, Content, Overlay, Portal, Root } from '@radix-ui/react-dialog';
16
+ import { getProviderEl } from '../../../../../_internal';
17
17
  import type { ActionModalState } from './store';
18
18
  import {
19
19
  closeButton,
@@ -1,10 +1,10 @@
1
1
  import { Box, Select, Skeleton } from '@0xsequence/design-system';
2
- import type { ChainId } from '@internal';
3
2
  import type { Observable } from '@legendapp/state';
4
3
  import { observer } from '@legendapp/state/react';
5
- import { useCurrencies } from '@react-hooks/useCurrencies';
6
- import type { Currency } from '@types';
7
4
  import { useEffect, useState } from 'react';
5
+ import type { Hex } from 'viem';
6
+ import type { ChainId, Currency } from '../../../../../_internal';
7
+ import { useCurrencies } from '../../../../../hooks';
8
8
  import { currencySelect } from './styles.css';
9
9
 
10
10
  // TODO: this should be exported from design system
@@ -14,7 +14,7 @@ type SelectOption = {
14
14
  };
15
15
 
16
16
  type CurrencyOptionsSelectProps = {
17
- collectionAddress: string;
17
+ collectionAddress: Hex;
18
18
  chainId: ChainId;
19
19
  $selectedCurrency: Observable<Currency | null | undefined>;
20
20
  };
@@ -1,7 +1,8 @@
1
1
  import { Text } from '@0xsequence/design-system';
2
- import type { Price } from '@types';
2
+ import type { Hex } from 'viem';
3
+ import type { Price } from '../../../../../../types';
3
4
  import { calculatePriceDifferencePercentage } from '../../../../../../utils';
4
- import { useLowestListing } from '@react-hooks/useLowestListing';
5
+ import { useLowestListing } from '../../../../../hooks';
5
6
 
6
7
  export default function FloorPriceText({
7
8
  chainId,
@@ -10,7 +11,7 @@ export default function FloorPriceText({
10
11
  price,
11
12
  }: {
12
13
  chainId: string;
13
- collectionAddress: string;
14
+ collectionAddress: Hex;
14
15
  tokenId: string;
15
16
  price: Price;
16
17
  }) {
@@ -1,40 +1,76 @@
1
1
  import { Box, NumericInput, TokenImage } from '@0xsequence/design-system';
2
2
  import type { Observable } from '@legendapp/state';
3
3
  import { observer } from '@legendapp/state/react';
4
- import type { Price } from '@types';
5
4
  import { useState } from 'react';
5
+ import { type Hex, erc20Abi, formatUnits, parseUnits } from 'viem';
6
+ import { useAccount, useReadContract } from 'wagmi';
7
+ import type { Price } from '../../../../../../types';
6
8
  import CurrencyOptionsSelect from '../currencyOptionsSelect';
7
- import { priceInputWrapper } from './styles.css';
8
- import { parseUnits } from 'viem';
9
+ import { priceInputCurrencyImage, priceInputWrapper } from './styles.css';
9
10
 
10
11
  type PriceInputProps = {
11
- collectionAddress: string;
12
+ collectionAddress: Hex;
12
13
  chainId: string;
13
14
  $listingPrice: Observable<Price | undefined>;
14
- error?: string;
15
+ checkBalance?: {
16
+ enabled: boolean;
17
+ callback: (state: boolean) => void;
18
+ };
15
19
  };
16
20
 
17
21
  const PriceInput = observer(function PriceInput({
18
22
  chainId,
19
23
  collectionAddress,
20
24
  $listingPrice,
21
- error,
25
+ checkBalance,
22
26
  }: PriceInputProps) {
23
- const [inputPrice, setInputPrice] = useState('');
27
+ const [balanceError, setBalanceError] = useState('');
28
+ const { address: accountAddress } = useAccount();
29
+ const { data: balance, isSuccess: isBalanceSuccess } = useReadContract({
30
+ address: $listingPrice.currency.contractAddress.get() as Hex,
31
+ abi: erc20Abi,
32
+ functionName: 'balanceOf',
33
+ args: [accountAddress as Hex],
34
+ query: {
35
+ enabled: checkBalance?.enabled,
36
+ },
37
+ });
38
+ const listingPriceAmountRaw = $listingPrice.amountRaw.get();
39
+ const currencyDecimals = $listingPrice.currency.decimals.get();
40
+
41
+ const checkInsufficientBalance = (priceAmountRaw: string) => {
42
+ const hasInsufficientBalance =
43
+ isBalanceSuccess &&
44
+ priceAmountRaw &&
45
+ currencyDecimals &&
46
+ BigInt(priceAmountRaw) > (balance || 0);
47
+
48
+ if (!checkBalance) return;
49
+
50
+ if (hasInsufficientBalance) {
51
+ setBalanceError('Insufficient balance');
52
+ checkBalance.callback(true);
53
+ } else {
54
+ setBalanceError('');
55
+ checkBalance.callback(false);
56
+ }
57
+ };
58
+
24
59
  const changeListingPrice = (value: string) => {
25
- setInputPrice(value);
26
60
  const parsedAmount = parseUnits(
27
61
  value,
28
62
  Number($listingPrice.currency.decimals.get()),
29
63
  );
64
+
30
65
  $listingPrice.amountRaw.set(parsedAmount.toString());
66
+ checkBalance && checkInsufficientBalance(parsedAmount.toString());
31
67
  };
32
68
 
33
69
  return (
34
70
  <Box className={priceInputWrapper} position="relative">
35
71
  <Box
72
+ className={priceInputCurrencyImage}
36
73
  position="absolute"
37
- bottom="3"
38
74
  left="2"
39
75
  display="flex"
40
76
  alignItems="center"
@@ -56,13 +92,20 @@ const PriceInput = observer(function PriceInput({
56
92
  />
57
93
  }
58
94
  numeric={true}
59
- value={inputPrice}
95
+ value={
96
+ listingPriceAmountRaw
97
+ ? formatUnits(
98
+ BigInt(listingPriceAmountRaw),
99
+ Number(currencyDecimals),
100
+ )
101
+ : ''
102
+ }
60
103
  onChange={(event) => changeListingPrice(event.target.value)}
61
104
  width="full"
62
105
  />
63
- {error && (
106
+ {balanceError && (
64
107
  <Box color="negative" fontSize="small">
65
- {error}
108
+ {balanceError}
66
109
  </Box>
67
110
  )}
68
111
  </Box>
@@ -6,6 +6,10 @@ export const priceInputWrapper = style({
6
6
  width: '100%',
7
7
  });
8
8
 
9
+ export const priceInputCurrencyImage = style({
10
+ top: 29,
11
+ });
12
+
9
13
  globalStyle(`${priceInputWrapper} > label`, {
10
14
  gap: 2,
11
15
  });
@@ -1,6 +1,7 @@
1
1
  import { Box, IconButton, NumericInput } from '@0xsequence/design-system';
2
2
  import type { Observable } from '@legendapp/state';
3
- import { useCollectible } from '@react-hooks/useCollectible';
3
+ import type { Hex } from 'viem';
4
+ import { useCollectible } from '../../../../../hooks';
4
5
  import SvgMinusIcon from '../../../../icons/MinusIcon';
5
6
  import SvgPlusIcon from '../../../../icons/PlusIcon';
6
7
  import { quantityInputWrapper } from './styles.css';
@@ -8,7 +9,7 @@ import { quantityInputWrapper } from './styles.css';
8
9
  type QuantityInputProps = {
9
10
  $quantity: Observable<string>;
10
11
  chainId: string;
11
- collectionAddress: string;
12
+ collectionAddress: Hex;
12
13
  collectibleId: string;
13
14
  };
14
15
 
@@ -21,12 +21,12 @@ import { getPresentableChainName } from '../../../../../../utils/network';
21
21
 
22
22
  import { UserRejectedRequestError } from 'viem';
23
23
  import { SwitchChainNotSupportedError } from 'wagmi';
24
- import type { SwitchChainMessageCallbacks } from '../../../../../../types/messages';
24
+ import type { SwitchChainCallbacks } from '../../../../../../types/callbacks';
25
25
 
26
26
  export type ShowSwitchChainModalArgs = {
27
27
  chainIdToSwitchTo: number;
28
28
  onSwitchChain: () => void;
29
- messages?: SwitchChainMessageCallbacks;
29
+ callbacks?: SwitchChainCallbacks;
30
30
  };
31
31
 
32
32
  export const useSwitchChainModal = () => {
@@ -47,8 +47,8 @@ const SwitchChainModal = observer(() => {
47
47
  onUserRejectedRequest,
48
48
  onUnknownError,
49
49
  onSuccess,
50
- }: Partial<SwitchChainMessageCallbacks> =
51
- switchChainModal$.state.messages.get() || {};
50
+ }: Partial<SwitchChainCallbacks> =
51
+ switchChainModal$.state.callbacks.get() || {};
52
52
 
53
53
  async function handleSwitchChain() {
54
54
  isSwitching$.set(true);
@@ -1,6 +1,6 @@
1
1
  import { observable } from '@legendapp/state';
2
2
  import type { ShowSwitchChainModalArgs } from '.';
3
- import type { SwitchChainMessageCallbacks } from '../../../../../../types/messages';
3
+ import type { SwitchChainCallbacks } from '../../../../../../types/callbacks';
4
4
 
5
5
  export interface SwitchChainModalState {
6
6
  isOpen: boolean;
@@ -10,18 +10,18 @@ export interface SwitchChainModalState {
10
10
  chainIdToSwitchTo?: number;
11
11
  onSwitchChain?: () => void;
12
12
  isSwitching: boolean;
13
- messages?: SwitchChainMessageCallbacks;
13
+ callbacks?: SwitchChainCallbacks;
14
14
  };
15
15
  }
16
16
 
17
17
  export const initialState: SwitchChainModalState = {
18
18
  isOpen: false,
19
- open: ({ chainIdToSwitchTo, onSwitchChain, messages }) => {
19
+ open: ({ chainIdToSwitchTo, onSwitchChain, callbacks }) => {
20
20
  switchChainModal$.state.set({
21
21
  ...switchChainModal$.state.get(),
22
22
  chainIdToSwitchTo,
23
23
  onSwitchChain,
24
- messages,
24
+ callbacks,
25
25
  });
26
26
  switchChainModal$.isOpen.set(true);
27
27
  },
@@ -1,10 +1,11 @@
1
1
  import { Box, Image, Skeleton, Text } from '@0xsequence/design-system';
2
- import { useCollectible } from '@react-hooks/useCollectible';
2
+ import type { Hex } from 'viem';
3
+ import { useCollectible } from '../../../../../hooks';
3
4
  import { tokenPreview } from './styles.css';
4
5
 
5
6
  type TokenPreviewProps = {
6
7
  collectionName?: string;
7
- collectionAddress: string;
8
+ collectionAddress: Hex;
8
9
  collectibleId: string;
9
10
  chainId: string;
10
11
  };
@@ -1,12 +1,14 @@
1
1
  import { Box, NetworkImage, Skeleton, Text } from '@0xsequence/design-system';
2
- import { useMarketplaceConfig } from '@react-hooks/useMarketplaceConfig';
3
- import { useRoyaltyPercentage } from '@react-hooks/useRoyaltyPercentage';
4
- import type { Price } from '@types';
5
- import { formatUnits } from 'viem';
2
+ import { type Hex, formatUnits } from 'viem';
3
+ import type { Price } from '../../../../../../types';
4
+ import {
5
+ useMarketplaceConfig,
6
+ useRoyaltyPercentage,
7
+ } from '../../../../../hooks';
6
8
 
7
9
  type TransactionDetailsProps = {
8
10
  collectibleId: string;
9
- collectionAddress: string;
11
+ collectionAddress: Hex;
10
12
  chainId: string;
11
13
  price?: Price;
12
14
  };
@@ -1,16 +1,16 @@
1
1
  import { Box, Image, NetworkImage, Text } from '@0xsequence/design-system';
2
- import type { TokenMetadata } from '@internal';
3
- import { useCollection } from '@react-hooks/useCollection';
2
+ import { observer } from '@legendapp/state/react';
3
+ import { type Hex, formatUnits } from 'viem';
4
+ import type { Price } from '../../../../../../types';
5
+ import type { TokenMetadata } from '../../../../../_internal';
6
+ import { useCollection } from '../../../../../hooks';
4
7
  import TimeAgo from '../timeAgo';
5
8
  import { transactionStatusModal$ } from '../transactionStatusModal/store';
6
- import { observer } from '@legendapp/state/react';
7
9
  import { useTransactionPreviewTitle } from './useTransactionPreviewTitle';
8
- import type { Price } from '@types';
9
- import { formatUnits } from 'viem';
10
10
 
11
11
  type TransactionPreviewProps = {
12
12
  price?: Price;
13
- collectionAddress: string;
13
+ collectionAddress: Hex;
14
14
  chainId: string;
15
15
  collectible: TokenMetadata;
16
16
  isConfirming: boolean;