@0xsequence/marketplace-sdk 0.4.2 → 0.4.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.
- package/dist/{chunk-ZWIRTV7A.js → chunk-4VS5NKDD.js} +2 -2
- package/dist/{chunk-GSDUAHL3.js → chunk-6WB4GCCJ.js} +1 -1
- package/dist/chunk-6WB4GCCJ.js.map +1 -0
- package/dist/{chunk-MTFS5SED.js → chunk-6XUCLBZC.js} +3093 -2463
- package/dist/chunk-6XUCLBZC.js.map +1 -0
- package/dist/{chunk-T5T6JNB2.js → chunk-ATDCYXXV.js} +49 -49
- package/dist/chunk-ATDCYXXV.js.map +1 -0
- package/dist/{chunk-LSMQVX77.js → chunk-CP2IVRMX.js} +2 -2
- package/dist/{chunk-OPMDGQFB.js → chunk-DNDPYQKV.js} +20 -2
- package/dist/chunk-DNDPYQKV.js.map +1 -0
- package/dist/{chunk-WBJKZOQ7.js → chunk-GLOIEUWC.js} +225 -364
- package/dist/chunk-GLOIEUWC.js.map +1 -0
- package/dist/{chunk-4RKM3VUV.js → chunk-IQXJZBMR.js} +2 -2
- package/dist/{chunk-MQ5WSFDH.js → chunk-J4TRSLTB.js} +29 -4
- package/dist/chunk-J4TRSLTB.js.map +1 -0
- package/dist/chunk-LHN6EBLM.js +420 -0
- package/dist/chunk-LHN6EBLM.js.map +1 -0
- package/dist/{chunk-WQCWBXBM.js → chunk-PAZ4MQXZ.js} +1 -1
- package/dist/chunk-PAZ4MQXZ.js.map +1 -0
- package/dist/{chunk-S5IPE7TH.js → chunk-URX7ZHX4.js} +2 -2
- package/dist/chunk-Y75XGZOB.js +11 -0
- package/dist/chunk-Y75XGZOB.js.map +1 -0
- package/dist/{chunk-Q2BVDQ3G.js → chunk-ZEKRTFBU.js} +1 -1
- package/dist/{chunk-Q2BVDQ3G.js.map → chunk-ZEKRTFBU.js.map} +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/dist/react/_internal/api/index.js +2 -2
- package/dist/react/_internal/index.d.ts +1 -1
- package/dist/react/_internal/index.js +4 -4
- package/dist/react/_internal/wagmi/index.js +2 -2
- package/dist/react/hooks/index.d.ts +54 -42
- package/dist/react/hooks/index.js +8 -6
- package/dist/react/index.css +24 -24
- package/dist/react/index.css.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +11 -9
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/components/index.css +24 -24
- package/dist/react/ui/components/index.css.map +1 -1
- package/dist/react/ui/components/index.d.ts +1 -1
- package/dist/react/ui/components/index.js +11 -9
- package/dist/react/ui/icons/index.js +1 -1
- package/dist/react/ui/index.css +24 -24
- package/dist/react/ui/index.css.map +1 -1
- package/dist/react/ui/index.d.ts +5 -2
- package/dist/react/ui/index.js +11 -9
- package/dist/react/ui/modals/_internal/components/actionModal/index.css +46 -0
- package/dist/react/ui/modals/_internal/components/actionModal/index.css.map +1 -1
- package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +1 -1
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +11 -6
- package/dist/types/index.js +4 -4
- package/dist/{types-BlDoGvJV.d.ts → types-DZb7GsfL.d.ts} +10 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +2 -2
- package/package.json +1 -1
- package/src/consts.ts +3 -0
- package/src/react/_internal/transaction-machine/useTransactionMachine.ts +9 -12
- package/src/react/_internal/transaction-machine/useWallet.ts +58 -0
- package/src/react/_internal/transaction-machine/wallet.ts +60 -3
- package/src/react/_internal/types.ts +11 -0
- package/src/react/hooks/useCancelOrder.tsx +26 -30
- package/src/react/hooks/useCancelTransactionSteps.tsx +222 -0
- package/src/react/hooks/useGetReceiptFromHash.tsx +32 -0
- package/src/react/ui/modals/BuyModal/Modal.tsx +97 -0
- package/src/react/ui/modals/BuyModal/hooks/useBuyCollectable.ts +109 -0
- package/src/react/ui/modals/BuyModal/hooks/useCheckoutOptions.ts +50 -0
- package/src/react/ui/modals/BuyModal/hooks/useFees.ts +38 -0
- package/src/react/ui/modals/BuyModal/hooks/useLoadData.ts +58 -0
- package/src/react/ui/modals/BuyModal/index.tsx +3 -210
- package/src/react/ui/modals/BuyModal/modals/CheckoutModal.tsx +29 -0
- package/src/react/ui/modals/BuyModal/modals/Modal1155.tsx +84 -0
- package/src/react/ui/modals/CreateListingModal/Modal.tsx +150 -207
- package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +62 -0
- package/src/react/ui/modals/CreateListingModal/hooks/useGetTokenApproval.ts +75 -0
- package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +216 -0
- package/src/react/ui/modals/CreateListingModal/index.tsx +1 -1
- package/src/react/ui/modals/CreateListingModal/store.ts +17 -9
- package/src/react/ui/modals/MakeOfferModal/Modal.tsx +173 -215
- package/src/react/ui/modals/MakeOfferModal/hooks/useGetTokenApproval.tsx +76 -0
- package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +62 -0
- package/src/react/ui/modals/MakeOfferModal/hooks/useTransactionSteps.tsx +225 -0
- package/src/react/ui/modals/MakeOfferModal/store.ts +15 -2
- package/src/react/ui/modals/SellModal/Modal.tsx +117 -190
- package/src/react/ui/modals/SellModal/hooks/useGetTokenApproval.tsx +73 -0
- package/src/react/ui/modals/SellModal/hooks/useSell.tsx +65 -0
- package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +224 -0
- package/src/react/ui/modals/SellModal/store.ts +14 -1
- package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +26 -1
- package/src/react/ui/modals/_internal/components/currencyImage/index.tsx +8 -10
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +9 -1
- package/src/react/ui/modals/_internal/components/priceInput/hooks/useBalanceCheck.ts +67 -0
- package/src/react/ui/modals/_internal/components/priceInput/hooks/usePriceInput.ts +54 -0
- package/src/react/ui/modals/_internal/components/priceInput/index.tsx +49 -62
- package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +9 -4
- package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +3 -3
- package/src/react/ui/modals/_internal/types.ts +1 -1
- package/src/react/ui/modals/modal-provider.tsx +1 -1
- package/src/utils/_internal/error/transaction.ts +21 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/chunk-GSDUAHL3.js.map +0 -1
- package/dist/chunk-MQ5WSFDH.js.map +0 -1
- package/dist/chunk-MTFS5SED.js.map +0 -1
- package/dist/chunk-OPMDGQFB.js.map +0 -1
- package/dist/chunk-T5T6JNB2.js.map +0 -1
- package/dist/chunk-WBJKZOQ7.js.map +0 -1
- package/dist/chunk-WQCWBXBM.js.map +0 -1
- package/src/react/hooks/useCreateListing.tsx +0 -125
- package/src/react/hooks/useMakeOffer.tsx +0 -122
- package/src/react/hooks/useSell.tsx +0 -121
- /package/dist/{chunk-ZWIRTV7A.js.map → chunk-4VS5NKDD.js.map} +0 -0
- /package/dist/{chunk-LSMQVX77.js.map → chunk-CP2IVRMX.js.map} +0 -0
- /package/dist/{chunk-4RKM3VUV.js.map → chunk-IQXJZBMR.js.map} +0 -0
- /package/dist/{chunk-S5IPE7TH.js.map → chunk-URX7ZHX4.js.map} +0 -0
- /package/src/react/ui/modals/BuyModal/{_store.ts → store.ts} +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { avalanche, optimism } from 'viem/chains';
|
|
2
|
+
import type { AdditionalFee } from '../../../../_internal';
|
|
3
|
+
import { useMarketplaceConfig } from '../../../../hooks';
|
|
4
|
+
|
|
5
|
+
export const useFees = ({
|
|
6
|
+
chainId,
|
|
7
|
+
collectionAddress,
|
|
8
|
+
}: { chainId: number; collectionAddress: string }) => {
|
|
9
|
+
const defaultFee = 2.5;
|
|
10
|
+
const defaultPlatformFeeRecipient =
|
|
11
|
+
'0x858dB1cbF6D09D447C96A11603189b49B2D1C219';
|
|
12
|
+
const avalancheAndOptimismPlatformFeeRecipient =
|
|
13
|
+
'0x400cdab4676c17aec07e8ec748a5fc3b674bca41';
|
|
14
|
+
const { data: marketplaceConfig } = useMarketplaceConfig();
|
|
15
|
+
|
|
16
|
+
const collection = marketplaceConfig?.collections.find(
|
|
17
|
+
(collection) =>
|
|
18
|
+
collection.collectionAddress.toLowerCase() ===
|
|
19
|
+
collectionAddress.toLowerCase() &&
|
|
20
|
+
chainId === Number(collection.chainId),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const avalancheOrOptimism =
|
|
24
|
+
chainId === avalanche.id || chainId === optimism.id;
|
|
25
|
+
const receiver = avalancheOrOptimism
|
|
26
|
+
? avalancheAndOptimismPlatformFeeRecipient
|
|
27
|
+
: defaultPlatformFeeRecipient;
|
|
28
|
+
|
|
29
|
+
const percentageToBPS = (percentage: string | number) =>
|
|
30
|
+
(Number(percentage) * 10000) / 100;
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
amount: percentageToBPS(
|
|
34
|
+
collection?.marketplaceFeePercentage || defaultFee,
|
|
35
|
+
).toString(),
|
|
36
|
+
receiver,
|
|
37
|
+
} satisfies AdditionalFee;
|
|
38
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { MarketplaceKind } from '../../../../_internal';
|
|
2
|
+
import type { Hex } from 'viem';
|
|
3
|
+
import { useCollectible, useCollection } from '../../../../hooks';
|
|
4
|
+
|
|
5
|
+
import { useCheckoutOptions } from './useCheckoutOptions';
|
|
6
|
+
|
|
7
|
+
export const useLoadData = ({
|
|
8
|
+
chainId,
|
|
9
|
+
collectionAddress,
|
|
10
|
+
collectibleId,
|
|
11
|
+
orderId,
|
|
12
|
+
marketplace,
|
|
13
|
+
}: {
|
|
14
|
+
chainId: number;
|
|
15
|
+
collectionAddress: Hex;
|
|
16
|
+
collectibleId: string;
|
|
17
|
+
orderId: string;
|
|
18
|
+
marketplace: MarketplaceKind;
|
|
19
|
+
}) => {
|
|
20
|
+
const {
|
|
21
|
+
data: collection,
|
|
22
|
+
isLoading: collectionLoading,
|
|
23
|
+
isError: collectionError,
|
|
24
|
+
} = useCollection({
|
|
25
|
+
chainId,
|
|
26
|
+
collectionAddress,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const {
|
|
30
|
+
data: collectable,
|
|
31
|
+
isLoading: collectableLoading,
|
|
32
|
+
isError: collectableError,
|
|
33
|
+
} = useCollectible({
|
|
34
|
+
chainId: String(chainId),
|
|
35
|
+
collectionAddress,
|
|
36
|
+
collectibleId,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const {
|
|
40
|
+
data: checkoutOptions,
|
|
41
|
+
isLoading: checkoutOptionsLoading,
|
|
42
|
+
isError: checkoutOptionsError,
|
|
43
|
+
} = useCheckoutOptions({
|
|
44
|
+
chainId,
|
|
45
|
+
collectionAddress,
|
|
46
|
+
orderId,
|
|
47
|
+
marketplace,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
collection,
|
|
52
|
+
collectable,
|
|
53
|
+
checkoutOptions,
|
|
54
|
+
isLoading:
|
|
55
|
+
collectionLoading || collectableLoading || checkoutOptionsLoading,
|
|
56
|
+
isError: collectionError || collectableError || checkoutOptionsError,
|
|
57
|
+
};
|
|
58
|
+
};
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import { Show, observer, useSelector } from '@legendapp/state/react';
|
|
4
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
5
|
-
import type { Address, Hex } from 'viem';
|
|
6
|
-
import { formatUnits, parseUnits } from 'viem';
|
|
7
|
-
import { ContractType, type Order } from '../../../_internal';
|
|
8
|
-
import type { BuyInput } from '../../../_internal/transaction-machine/execute-transaction';
|
|
9
|
-
import { useCollectible, useCollection } from '../../../hooks';
|
|
10
|
-
import { useCurrencies } from '../../../hooks';
|
|
11
|
-
import { useBuyCollectable } from '../../../hooks/useBuyCollectable';
|
|
12
|
-
import { useCurrencyOptions } from '../../../hooks/useCurrencyOptions';
|
|
13
|
-
import QuantityInput from '..//_internal/components/quantityInput';
|
|
14
|
-
import { ActionModal } from '../_internal/components/actionModal';
|
|
1
|
+
import type { Hex } from 'viem';
|
|
2
|
+
import type { Order } from '../../../_internal';
|
|
15
3
|
import type { ModalCallbacks } from '../_internal/types';
|
|
16
|
-
import { buyModal$ } from './
|
|
17
|
-
import { LoadingModal } from '../_internal/components/actionModal/LoadingModal';
|
|
4
|
+
import { buyModal$ } from './store';
|
|
18
5
|
|
|
19
6
|
export type ShowBuyModalArgs = {
|
|
20
7
|
chainId: string;
|
|
@@ -30,197 +17,3 @@ export const useBuyModal = (callbacks?: ModalCallbacks) => {
|
|
|
30
17
|
close: () => buyModal$.close(),
|
|
31
18
|
};
|
|
32
19
|
};
|
|
33
|
-
|
|
34
|
-
export const BuyModal = () => (
|
|
35
|
-
<Show if={buyModal$.isOpen}>
|
|
36
|
-
<BuyModalContent />
|
|
37
|
-
</Show>
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
export const BuyModalContent = () => {
|
|
41
|
-
const chainId = String(useSelector(buyModal$.state.order.chainId));
|
|
42
|
-
const collectionAddress = useSelector(
|
|
43
|
-
buyModal$.state.order.collectionContractAddress,
|
|
44
|
-
) as Hex;
|
|
45
|
-
const collectibleId = useSelector(buyModal$.state.order.tokenId);
|
|
46
|
-
const modalId = useSelector(buyModal$.state.modalId);
|
|
47
|
-
const callbacks = useSelector(buyModal$.callbacks);
|
|
48
|
-
const [paymentLoadingModalOpen, setPaymentLoadingModalOpen] = useState(false);
|
|
49
|
-
|
|
50
|
-
const { data: collection } = useCollection({
|
|
51
|
-
chainId,
|
|
52
|
-
collectionAddress,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const onPaymentModalLoaded = useCallback(() => {
|
|
56
|
-
buyModal$.close();
|
|
57
|
-
setPaymentLoadingModalOpen(false);
|
|
58
|
-
}, [setPaymentLoadingModalOpen]);
|
|
59
|
-
|
|
60
|
-
const { buy, isLoading } = useBuyCollectable({
|
|
61
|
-
chainId,
|
|
62
|
-
collectionAddress,
|
|
63
|
-
enabled: buyModal$.isOpen.get(),
|
|
64
|
-
setPaymentLoadingModalOpen,
|
|
65
|
-
onPaymentModalLoaded,
|
|
66
|
-
onError: (error) => {
|
|
67
|
-
if (callbacks?.onError) {
|
|
68
|
-
callbacks.onError(error);
|
|
69
|
-
} else {
|
|
70
|
-
console.debug('onError callback not provided', error);
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
onSuccess: (hash) => {
|
|
74
|
-
if (callbacks?.onSuccess) {
|
|
75
|
-
callbacks.onSuccess(hash);
|
|
76
|
-
} else {
|
|
77
|
-
console.debug('onSuccess callback not provided', hash);
|
|
78
|
-
}
|
|
79
|
-
buyModal$.close();
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const { data: collectable } = useCollectible({
|
|
84
|
-
chainId,
|
|
85
|
-
collectionAddress,
|
|
86
|
-
collectibleId,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
if (modalId === 0 || !collection || !collectable || !buy) return null;
|
|
90
|
-
|
|
91
|
-
if (paymentLoadingModalOpen) {
|
|
92
|
-
return (
|
|
93
|
-
<LoadingModal
|
|
94
|
-
isOpen={buyModal$.isOpen.get()}
|
|
95
|
-
chainId={Number(chainId)}
|
|
96
|
-
onClose={buyModal$.close}
|
|
97
|
-
title="Loading Sequence Pay"
|
|
98
|
-
/>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return collection.type === ContractType.ERC721 ? (
|
|
103
|
-
<CheckoutModal
|
|
104
|
-
key={modalId}
|
|
105
|
-
buy={buy}
|
|
106
|
-
collectable={collectable}
|
|
107
|
-
order={buyModal$.state.order.get()}
|
|
108
|
-
isLoading={isLoading}
|
|
109
|
-
/>
|
|
110
|
-
) : (
|
|
111
|
-
<ERC1155QuantityModal
|
|
112
|
-
buy={buy}
|
|
113
|
-
collectable={collectable}
|
|
114
|
-
order={buyModal$.state.order.get()}
|
|
115
|
-
chainId={chainId}
|
|
116
|
-
collectionAddress={collectionAddress}
|
|
117
|
-
collectibleId={collectibleId}
|
|
118
|
-
isLoading={isLoading}
|
|
119
|
-
/>
|
|
120
|
-
);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
interface CheckoutModalProps {
|
|
124
|
-
buy: (props: BuyInput) => void;
|
|
125
|
-
collectable: TokenMetadata;
|
|
126
|
-
order: Order;
|
|
127
|
-
isLoading?: boolean;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function CheckoutModal({
|
|
131
|
-
buy,
|
|
132
|
-
collectable,
|
|
133
|
-
order,
|
|
134
|
-
isLoading,
|
|
135
|
-
}: CheckoutModalProps) {
|
|
136
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
137
|
-
useEffect(() => {
|
|
138
|
-
const executeBuy = () => {
|
|
139
|
-
if (isLoading) return;
|
|
140
|
-
buy({
|
|
141
|
-
orderId: order.orderId,
|
|
142
|
-
collectableDecimals: collectable.decimals || 0,
|
|
143
|
-
quantity: parseUnits('1', collectable.decimals || 0).toString(),
|
|
144
|
-
marketplace: order.marketplace,
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
executeBuy();
|
|
149
|
-
}, [isLoading]);
|
|
150
|
-
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
interface ERC1155QuantityModalProps extends CheckoutModalProps {
|
|
155
|
-
chainId: string;
|
|
156
|
-
collectionAddress: Hex;
|
|
157
|
-
collectibleId: string;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const ERC1155QuantityModal = observer(
|
|
161
|
-
({ buy, collectable, order }: ERC1155QuantityModalProps) => {
|
|
162
|
-
buyModal$.state.quantity.set(
|
|
163
|
-
Math.min(Number(order.quantityRemaining), 1).toString(),
|
|
164
|
-
);
|
|
165
|
-
const currencyOptions = useCurrencyOptions({
|
|
166
|
-
collectionAddress: order.collectionContractAddress as Address,
|
|
167
|
-
});
|
|
168
|
-
const { data: currencies } = useCurrencies({
|
|
169
|
-
chainId: order.chainId,
|
|
170
|
-
currencyOptions,
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const currency = currencies?.find(
|
|
174
|
-
(currency) => currency.contractAddress === order.priceCurrencyAddress,
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
const quantity = Number(buyModal$.state.quantity.get());
|
|
178
|
-
const pricePerToken = order.priceAmount;
|
|
179
|
-
const totalPrice = (BigInt(quantity) * BigInt(pricePerToken)).toString();
|
|
180
|
-
|
|
181
|
-
return (
|
|
182
|
-
<ActionModal
|
|
183
|
-
isOpen={buyModal$.isOpen.get()}
|
|
184
|
-
chainId={order.chainId}
|
|
185
|
-
onClose={() => buyModal$.close()}
|
|
186
|
-
title="Select Quantity"
|
|
187
|
-
ctas={[
|
|
188
|
-
{
|
|
189
|
-
label: 'Buy now',
|
|
190
|
-
onClick: () => {
|
|
191
|
-
buy({
|
|
192
|
-
quantity: parseUnits(
|
|
193
|
-
buyModal$.state.quantity.get(),
|
|
194
|
-
collectable.decimals || 0,
|
|
195
|
-
).toString(),
|
|
196
|
-
orderId: order.orderId,
|
|
197
|
-
collectableDecimals: collectable.decimals || 0,
|
|
198
|
-
marketplace: order.marketplace,
|
|
199
|
-
});
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
]}
|
|
203
|
-
>
|
|
204
|
-
<Box display="flex" flexDirection="column" gap="4">
|
|
205
|
-
<QuantityInput
|
|
206
|
-
$quantity={buyModal$.state.quantity}
|
|
207
|
-
$invalidQuantity={buyModal$.state.invalidQuantity}
|
|
208
|
-
decimals={order.quantityDecimals}
|
|
209
|
-
maxQuantity={order.quantityRemaining}
|
|
210
|
-
/>
|
|
211
|
-
<Box display="flex" justifyContent="space-between">
|
|
212
|
-
<Text color="text50" fontSize="small">
|
|
213
|
-
Total Price
|
|
214
|
-
</Text>
|
|
215
|
-
<Box display="flex" alignItems="center" gap="2">
|
|
216
|
-
<TokenImage src={currency?.imageUrl} size="xs" />
|
|
217
|
-
<Text color="text100" fontSize="small" fontWeight="bold">
|
|
218
|
-
{formatUnits(BigInt(totalPrice), currency?.decimals || 0)}
|
|
219
|
-
</Text>
|
|
220
|
-
</Box>
|
|
221
|
-
</Box>
|
|
222
|
-
</Box>
|
|
223
|
-
</ActionModal>
|
|
224
|
-
);
|
|
225
|
-
},
|
|
226
|
-
);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BuyInput } from '../../../../_internal/transaction-machine/execute-transaction';
|
|
2
|
+
import type { Order } from '../../../../_internal';
|
|
3
|
+
import type { TokenMetadata } from '../../../../_internal/api/marketplace.gen';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { parseUnits } from 'viem';
|
|
6
|
+
|
|
7
|
+
export interface CheckoutModalProps {
|
|
8
|
+
buy: (props: BuyInput) => void;
|
|
9
|
+
collectable: TokenMetadata;
|
|
10
|
+
order: Order;
|
|
11
|
+
isLoading?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export function CheckoutModal({ buy, collectable, order }: CheckoutModalProps) {
|
|
14
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const executeBuy = () => {
|
|
17
|
+
buy({
|
|
18
|
+
orderId: order.orderId,
|
|
19
|
+
collectableDecimals: collectable.decimals || 0,
|
|
20
|
+
quantity: parseUnits('1', collectable.decimals || 0).toString(),
|
|
21
|
+
marketplace: order.marketplace,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
executeBuy();
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Box, Text, TokenImage } from '@0xsequence/design-system';
|
|
2
|
+
import { observer } from '@legendapp/state/react';
|
|
3
|
+
import type { Address, Hex } from 'viem';
|
|
4
|
+
import { formatUnits, parseUnits } from 'viem';
|
|
5
|
+
import { useCurrencies } from '../../../../hooks';
|
|
6
|
+
import { useCurrencyOptions } from '../../../../hooks/useCurrencyOptions';
|
|
7
|
+
import QuantityInput from '../../_internal/components/quantityInput';
|
|
8
|
+
import { ActionModal } from '../../_internal/components/actionModal';
|
|
9
|
+
import { buyModal$ } from '../store';
|
|
10
|
+
import type { CheckoutModalProps } from './CheckoutModal';
|
|
11
|
+
|
|
12
|
+
interface ERC1155QuantityModalProps extends CheckoutModalProps {
|
|
13
|
+
chainId: string;
|
|
14
|
+
collectionAddress: Hex;
|
|
15
|
+
collectibleId: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ERC1155QuantityModal = observer(
|
|
19
|
+
({ buy, collectable, order }: ERC1155QuantityModalProps) => {
|
|
20
|
+
buyModal$.state.quantity.set(
|
|
21
|
+
Math.min(Number(order.quantityRemaining), 1).toString(),
|
|
22
|
+
);
|
|
23
|
+
const currencyOptions = useCurrencyOptions({
|
|
24
|
+
collectionAddress: order.collectionContractAddress as Address,
|
|
25
|
+
});
|
|
26
|
+
const { data: currencies } = useCurrencies({
|
|
27
|
+
chainId: order.chainId,
|
|
28
|
+
currencyOptions,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const currency = currencies?.find(
|
|
32
|
+
(currency) => currency.contractAddress === order.priceCurrencyAddress,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const quantity = Number(buyModal$.state.quantity.get());
|
|
36
|
+
const pricePerToken = order.priceAmount;
|
|
37
|
+
const totalPrice = (BigInt(quantity) * BigInt(pricePerToken)).toString();
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<ActionModal
|
|
41
|
+
isOpen={buyModal$.isOpen.get()}
|
|
42
|
+
chainId={order.chainId}
|
|
43
|
+
onClose={() => buyModal$.close()}
|
|
44
|
+
title="Select Quantity"
|
|
45
|
+
ctas={[
|
|
46
|
+
{
|
|
47
|
+
label: 'Buy now',
|
|
48
|
+
onClick: () => {
|
|
49
|
+
buy({
|
|
50
|
+
quantity: parseUnits(
|
|
51
|
+
buyModal$.state.quantity.get(),
|
|
52
|
+
collectable.decimals || 0,
|
|
53
|
+
).toString(),
|
|
54
|
+
orderId: order.orderId,
|
|
55
|
+
collectableDecimals: collectable.decimals || 0,
|
|
56
|
+
marketplace: order.marketplace,
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
]}
|
|
61
|
+
>
|
|
62
|
+
<Box display="flex" flexDirection="column" gap="4">
|
|
63
|
+
<QuantityInput
|
|
64
|
+
$quantity={buyModal$.state.quantity}
|
|
65
|
+
$invalidQuantity={buyModal$.state.invalidQuantity}
|
|
66
|
+
decimals={order.quantityDecimals}
|
|
67
|
+
maxQuantity={order.quantityRemaining}
|
|
68
|
+
/>
|
|
69
|
+
<Box display="flex" justifyContent="space-between">
|
|
70
|
+
<Text color="text50" fontSize="small">
|
|
71
|
+
Total Price
|
|
72
|
+
</Text>
|
|
73
|
+
<Box display="flex" alignItems="center" gap="2">
|
|
74
|
+
<TokenImage src={currency?.imageUrl} size="xs" />
|
|
75
|
+
<Text color="text100" fontSize="small" fontWeight="bold">
|
|
76
|
+
{formatUnits(BigInt(totalPrice), currency?.decimals || 0)}
|
|
77
|
+
</Text>
|
|
78
|
+
</Box>
|
|
79
|
+
</Box>
|
|
80
|
+
</Box>
|
|
81
|
+
</ActionModal>
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
);
|