@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.
- package/.ctirc +32 -0
- package/dist/{chunk-TZGLKJRF.js → chunk-4E34HVSA.js} +2 -2
- package/dist/chunk-5EOVZAKT.js +1325 -0
- package/dist/chunk-5EOVZAKT.js.map +1 -0
- package/dist/{chunk-RNUHUVLC.js → chunk-6JWGELXL.js} +1 -1
- package/dist/chunk-6JWGELXL.js.map +1 -0
- package/dist/{chunk-4PFMUVE4.js → chunk-CSN7YD5Q.js} +2 -2
- package/dist/chunk-CSN7YD5Q.js.map +1 -0
- package/dist/{chunk-G3D572BT.js → chunk-FCQCNLFZ.js} +24 -1
- package/dist/chunk-FCQCNLFZ.js.map +1 -0
- package/dist/{chunk-HGBEC3WX.js → chunk-GZIA25G4.js} +1 -1
- package/dist/chunk-GZIA25G4.js.map +1 -0
- package/dist/{chunk-QOJXWHRZ.js → chunk-LFQB477Y.js} +3 -1
- package/dist/chunk-LFQB477Y.js.map +1 -0
- package/dist/{chunk-SM7V6ZWI.js → chunk-MD4JHPMH.js} +493 -418
- package/dist/chunk-MD4JHPMH.js.map +1 -0
- package/dist/{chunk-EDTC7UES.js → chunk-NII6JJGH.js} +9 -4
- package/dist/chunk-NII6JJGH.js.map +1 -0
- package/dist/{chunk-BBB3XUB4.js → chunk-PE2LLUTJ.js} +1 -1
- package/dist/chunk-PE2LLUTJ.js.map +1 -0
- package/dist/chunk-Q2BVDQ3G.js +41 -0
- package/dist/chunk-Q2BVDQ3G.js.map +1 -0
- package/dist/{chunk-3TYUQEFM.js → chunk-VEX7FDL6.js} +2 -2
- package/dist/chunk-VEX7FDL6.js.map +1 -0
- package/dist/{create-config-Dz0gCiQ0.d.ts → create-config-CgtmCzvb.d.ts} +2 -2
- package/dist/index.css +4 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -4
- package/dist/{marketplace-config-DZbtyrma.d.ts → marketplace-config-Bbxl-uKX.d.ts} +2 -1
- package/dist/react/_internal/api/index.d.ts +1 -1
- package/dist/react/_internal/api/index.js +1 -1
- package/dist/react/_internal/index.d.ts +5 -4
- package/dist/react/_internal/index.js +16 -8
- package/dist/react/_internal/wagmi/index.d.ts +3 -3
- package/dist/react/_internal/wagmi/index.js +1 -1
- package/dist/react/hooks/index.d.ts +1691 -103
- package/dist/react/hooks/index.js +34 -22
- package/dist/react/index.css +4 -1
- package/dist/react/index.css.map +1 -1
- package/dist/react/index.d.ts +7 -6
- package/dist/react/index.js +43 -31
- package/dist/react/ssr/index.d.ts +26 -25
- package/dist/react/ssr/index.js +34 -4
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/icons/index.js +2 -2
- package/dist/react/ui/index.css +4 -1
- package/dist/react/ui/index.css.map +1 -1
- package/dist/react/ui/index.d.ts +47 -42
- package/dist/react/ui/index.js +10 -10
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +4 -4
- package/dist/{services-BIwQ1C1c.d.ts → services-Dei25J6_.d.ts} +1 -1
- package/dist/styles/index.css +4 -1
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/index.d.ts +2 -1
- package/dist/styles/index.js +4 -4973
- package/dist/styles/index.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +3 -3
- package/dist/types-BzZVURNL.d.ts +19 -0
- package/dist/utils/abi/clients/index.js +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +2 -2
- package/package.json +19 -25
- package/src/react/_internal/api/marketplace.gen.ts +4 -1
- package/src/react/_internal/api/zod-schema.ts +636 -0
- package/src/react/_internal/types.ts +33 -9
- package/src/react/_internal/wagmi/create-config.ts +9 -3
- package/src/react/_internal/wagmi/embedded.ts +1 -1
- package/src/react/_internal/wagmi/universal.ts +1 -1
- package/src/react/hooks/index.ts +3 -0
- package/src/react/hooks/options/marketplaceConfigOptions.ts +2 -2
- package/src/react/hooks/useBalanceOfCollectible.tsx +47 -21
- package/src/react/hooks/useCheckoutOptions.tsx +63 -0
- package/src/react/hooks/useCollectible.tsx +20 -14
- package/src/react/hooks/useCollection.tsx +18 -12
- package/src/react/hooks/useCountOfCollectables.tsx +77 -0
- package/src/react/hooks/useCurrencies.tsx +67 -56
- package/src/react/hooks/useFilters.tsx +18 -12
- package/src/react/hooks/useFloorOrder.tsx +24 -9
- package/src/react/hooks/useGenerateListingTransaction.tsx +8 -7
- package/src/react/hooks/useGenerateOfferTransaction.tsx +5 -5
- package/src/react/hooks/useGenerateSellTransaction.tsx +19 -12
- package/src/react/hooks/useHighestOffer.tsx +26 -16
- package/src/react/hooks/useListBalances.tsx +60 -29
- package/src/react/hooks/useListCollectibles.tsx +28 -15
- package/src/react/hooks/useListOffersForCollectible.tsx +17 -8
- package/src/react/hooks/useLowestListing.tsx +26 -17
- package/src/react/hooks/useRoyaltyPercentage.tsx +18 -8
- package/src/react/hooks/useTransferTokens.tsx +3 -3
- package/src/react/provider.tsx +1 -1
- package/src/react/ssr/create-ssr-client.ts +1 -1
- package/src/react/ui/modals/CreateListingModal/_store.ts +39 -40
- package/src/react/ui/modals/CreateListingModal/index.tsx +152 -130
- package/src/react/ui/modals/MakeOfferModal/_store.ts +38 -43
- package/src/react/ui/modals/MakeOfferModal/index.tsx +39 -28
- package/src/react/ui/modals/SellModal/_store.ts +59 -57
- package/src/react/ui/modals/SellModal/index.tsx +34 -12
- package/src/react/ui/modals/SuccessfulPurchaseModal/_store.ts +1 -1
- package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +14 -14
- package/src/react/ui/modals/TransferModal/_store.ts +11 -11
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +92 -89
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +114 -0
- package/src/react/ui/modals/TransferModal/_views/followWalletInstructions/index.tsx +0 -96
- package/src/react/ui/modals/TransferModal/index.tsx +24 -3
- package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +1 -1
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +4 -4
- package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +4 -3
- package/src/react/ui/modals/_internal/components/priceInput/index.tsx +55 -12
- package/src/react/ui/modals/_internal/components/priceInput/styles.css.ts +4 -0
- package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +3 -2
- package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +4 -4
- package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +4 -4
- package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +3 -2
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +7 -5
- package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +6 -6
- package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +47 -14
- package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +14 -6
- package/src/types/api-types.ts +2 -2
- package/src/types/callbacks.ts +51 -0
- package/src/types/marketplace-config.ts +2 -1
- package/src/types/types.ts +1 -1
- package/src/utils/get-public-rpc-client.ts +1 -1
- package/tsconfig.json +24 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsup.config.ts +35 -0
- package/README.md +0 -8
- package/dist/chunk-3TYUQEFM.js.map +0 -1
- package/dist/chunk-4PFMUVE4.js.map +0 -1
- package/dist/chunk-BBB3XUB4.js.map +0 -1
- package/dist/chunk-EDTC7UES.js.map +0 -1
- package/dist/chunk-G3D572BT.js.map +0 -1
- package/dist/chunk-HGBEC3WX.js.map +0 -1
- package/dist/chunk-QOJXWHRZ.js.map +0 -1
- package/dist/chunk-RNUHUVLC.js.map +0 -1
- package/dist/chunk-SM7V6ZWI.js.map +0 -1
- package/dist/chunk-STO74F2I.js +0 -14
- package/dist/chunk-STO74F2I.js.map +0 -1
- package/dist/chunk-VPGWEMWL.js +0 -162
- package/dist/chunk-VPGWEMWL.js.map +0 -1
- package/dist/chunk-ZE2LNX65.js +0 -394
- package/dist/chunk-ZE2LNX65.js.map +0 -1
- package/dist/types-BrAQ8-w4.d.ts +0 -12
- package/src/react/hooks/useCollectionCounts.tsx +0 -61
- /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
|
-
|
|
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:
|
|
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 {
|
|
2
|
+
import type { Hex } from 'viem';
|
|
3
|
+
import type { Price } from '../../../../../../types';
|
|
3
4
|
import { calculatePriceDifferencePercentage } from '../../../../../../utils';
|
|
4
|
-
import { useLowestListing } from '
|
|
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:
|
|
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:
|
|
12
|
+
collectionAddress: Hex;
|
|
12
13
|
chainId: string;
|
|
13
14
|
$listingPrice: Observable<Price | undefined>;
|
|
14
|
-
|
|
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
|
-
|
|
25
|
+
checkBalance,
|
|
22
26
|
}: PriceInputProps) {
|
|
23
|
-
const [
|
|
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={
|
|
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
|
-
{
|
|
106
|
+
{balanceError && (
|
|
64
107
|
<Box color="negative" fontSize="small">
|
|
65
|
-
{
|
|
108
|
+
{balanceError}
|
|
66
109
|
</Box>
|
|
67
110
|
)}
|
|
68
111
|
</Box>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Box, IconButton, NumericInput } from '@0xsequence/design-system';
|
|
2
2
|
import type { Observable } from '@legendapp/state';
|
|
3
|
-
import {
|
|
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:
|
|
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 {
|
|
24
|
+
import type { SwitchChainCallbacks } from '../../../../../../types/callbacks';
|
|
25
25
|
|
|
26
26
|
export type ShowSwitchChainModalArgs = {
|
|
27
27
|
chainIdToSwitchTo: number;
|
|
28
28
|
onSwitchChain: () => void;
|
|
29
|
-
|
|
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<
|
|
51
|
-
switchChainModal$.state.
|
|
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 {
|
|
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
|
-
|
|
13
|
+
callbacks?: SwitchChainCallbacks;
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export const initialState: SwitchChainModalState = {
|
|
18
18
|
isOpen: false,
|
|
19
|
-
open: ({ chainIdToSwitchTo, onSwitchChain,
|
|
19
|
+
open: ({ chainIdToSwitchTo, onSwitchChain, callbacks }) => {
|
|
20
20
|
switchChainModal$.state.set({
|
|
21
21
|
...switchChainModal$.state.get(),
|
|
22
22
|
chainIdToSwitchTo,
|
|
23
23
|
onSwitchChain,
|
|
24
|
-
|
|
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 {
|
|
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:
|
|
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 {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
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:
|
|
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
|
|
3
|
-
import {
|
|
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:
|
|
13
|
+
collectionAddress: Hex;
|
|
14
14
|
chainId: string;
|
|
15
15
|
collectible: TokenMetadata;
|
|
16
16
|
isConfirming: boolean;
|