@0xsequence/marketplace-sdk 0.1.0 → 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-SNOEEUPZ.js → chunk-CSN7YD5Q.js} +2 -2
- package/dist/chunk-CSN7YD5Q.js.map +1 -0
- package/dist/{chunk-G3YU4NQ2.js → chunk-FCQCNLFZ.js} +1 -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-GNB736ZE.js → chunk-MD4JHPMH.js} +318 -261
- 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-7CL54NCX.js → chunk-Q2BVDQ3G.js} +1 -1
- 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/index.js +4 -4
- 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 +2 -2
- package/dist/react/_internal/index.js +8 -8
- package/dist/react/_internal/wagmi/index.d.ts +2 -2
- package/dist/react/_internal/wagmi/index.js +1 -1
- package/dist/react/hooks/index.d.ts +336 -10
- package/dist/react/hooks/index.js +26 -20
- package/dist/react/index.d.ts +5 -5
- package/dist/react/index.js +34 -28
- package/dist/react/ssr/index.d.ts +24 -24
- package/dist/react/ssr/index.js +11 -4
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/icons/index.js +2 -2
- package/dist/react/ui/index.d.ts +43 -38
- package/dist/react/ui/index.js +9 -9
- 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.js +1 -1
- package/dist/types/index.js +3 -3
- package/dist/utils/abi/clients/index.js +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/package.json +18 -25
- package/src/react/_internal/api/marketplace.gen.ts +4 -1
- package/src/react/_internal/types.ts +1 -1
- 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 +2 -0
- package/src/react/hooks/options/marketplaceConfigOptions.ts +2 -2
- package/src/react/hooks/useBalanceOfCollectible.tsx +10 -9
- package/src/react/hooks/useCheckoutOptions.tsx +63 -0
- package/src/react/hooks/useCollectible.tsx +4 -4
- package/src/react/hooks/useCollection.tsx +30 -30
- package/src/react/hooks/useCountOfCollectables.tsx +52 -52
- package/src/react/hooks/useCurrencies.tsx +60 -60
- package/src/react/hooks/useFilters.tsx +4 -4
- package/src/react/hooks/useFloorOrder.tsx +4 -4
- package/src/react/hooks/useGenerateListingTransaction.tsx +8 -7
- package/src/react/hooks/useGenerateOfferTransaction.tsx +5 -5
- package/src/react/hooks/useGenerateSellTransaction.tsx +4 -4
- package/src/react/hooks/useHighestOffer.tsx +4 -4
- package/src/react/hooks/useListBalances.tsx +4 -4
- package/src/react/hooks/useListCollectibles.tsx +4 -4
- package/src/react/hooks/useListOffersForCollectible.tsx +5 -4
- package/src/react/hooks/useLowestListing.tsx +4 -4
- package/src/react/hooks/useRoyaltyPercentage.tsx +6 -6
- package/src/react/hooks/useTransferTokens.tsx +1 -1
- 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 +37 -38
- package/src/react/ui/modals/CreateListingModal/index.tsx +152 -131
- package/src/react/ui/modals/MakeOfferModal/_store.ts +35 -37
- package/src/react/ui/modals/MakeOfferModal/index.tsx +25 -4
- package/src/react/ui/modals/SellModal/_store.ts +48 -51
- package/src/react/ui/modals/SellModal/index.tsx +27 -6
- 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 -90
- 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 +2 -3
- package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +2 -2
- package/src/react/ui/modals/_internal/components/priceInput/index.tsx +4 -4
- package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +1 -1
- 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 +1 -1
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +5 -3
- package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +3 -3
- package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +35 -2
- package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +10 -2
- package/src/types/api-types.ts +2 -2
- package/src/types/callbacks.ts +51 -0
- 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-7CL54NCX.js.map +0 -1
- package/dist/chunk-BBB3XUB4.js.map +0 -1
- package/dist/chunk-EDTC7UES.js.map +0 -1
- package/dist/chunk-G3YU4NQ2.js.map +0 -1
- package/dist/chunk-GNB736ZE.js.map +0 -1
- package/dist/chunk-HGBEC3WX.js.map +0 -1
- package/dist/chunk-ITJEOCDV.js +0 -1006
- package/dist/chunk-ITJEOCDV.js.map +0 -1
- package/dist/chunk-M4MXVMAM.js +0 -271
- package/dist/chunk-M4MXVMAM.js.map +0 -1
- package/dist/chunk-RNUHUVLC.js.map +0 -1
- package/dist/chunk-SNOEEUPZ.js.map +0 -1
- package/dist/{chunk-TZGLKJRF.js.map → chunk-4E34HVSA.js.map} +0 -0
- package/dist/{create-config-Cto2ehcz.d.ts → create-config-CgtmCzvb.d.ts} +1 -1
|
@@ -1,147 +1,168 @@
|
|
|
1
|
-
import { Box } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { useAccount } from 'wagmi';
|
|
6
|
-
import type { Messages } from '../../../../types/messages';
|
|
1
|
+
import { Box } from "@0xsequence/design-system";
|
|
2
|
+
import { Show, observer } from "@legendapp/state/react";
|
|
3
|
+
import type { Hex } from "viem";
|
|
4
|
+
import { useAccount } from "wagmi";
|
|
7
5
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from
|
|
11
|
-
import ExpirationDateSelect from
|
|
12
|
-
import FloorPriceText from
|
|
13
|
-
import PriceInput from
|
|
14
|
-
import QuantityInput from
|
|
15
|
-
import { useSwitchChainModal } from
|
|
16
|
-
import TokenPreview from
|
|
17
|
-
import TransactionDetails from
|
|
18
|
-
import { createListingModal$, useHydrate } from
|
|
6
|
+
ActionModal,
|
|
7
|
+
type ActionModalProps,
|
|
8
|
+
} from "../_internal/components/actionModal/ActionModal";
|
|
9
|
+
import ExpirationDateSelect from "../_internal/components/expirationDateSelect";
|
|
10
|
+
import FloorPriceText from "../_internal/components/floorPriceText";
|
|
11
|
+
import PriceInput from "../_internal/components/priceInput";
|
|
12
|
+
import QuantityInput from "../_internal/components/quantityInput";
|
|
13
|
+
import { useSwitchChainModal } from "../_internal/components/switchChainModal";
|
|
14
|
+
import TokenPreview from "../_internal/components/tokenPreview";
|
|
15
|
+
import TransactionDetails from "../_internal/components/transactionDetails";
|
|
16
|
+
import { createListingModal$, useHydrate } from "./_store";
|
|
17
|
+
import {
|
|
18
|
+
CreateListingErrorCallbacks,
|
|
19
|
+
CreateListingSuccessCallbacks,
|
|
20
|
+
} from "../../../../types/callbacks";
|
|
21
|
+
import { ContractType } from "../../../_internal";
|
|
19
22
|
|
|
20
23
|
export type ShowCreateListingModalArgs = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
messages?: Messages;
|
|
24
|
+
collectionAddress: Hex;
|
|
25
|
+
chainId: string;
|
|
26
|
+
collectibleId: string;
|
|
25
27
|
};
|
|
26
28
|
|
|
27
29
|
export const useCreateListingModal = () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
30
|
+
const { chainId: accountChainId } = useAccount();
|
|
31
|
+
const { show: showSwitchNetworkModal } = useSwitchChainModal();
|
|
32
|
+
const { errorCallbacks, successCallbacks } = createListingModal$.state.get();
|
|
33
|
+
|
|
34
|
+
const openModal = (args: ShowCreateListingModalArgs) => {
|
|
35
|
+
createListingModal$.open(args);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const handleShowModal = (args: ShowCreateListingModalArgs) => {
|
|
39
|
+
const isSameChain = accountChainId === Number(args.chainId);
|
|
40
|
+
|
|
41
|
+
if (!isSameChain) {
|
|
42
|
+
showSwitchNetworkModal({
|
|
43
|
+
chainIdToSwitchTo: Number(args.chainId),
|
|
44
|
+
onSwitchChain: () => openModal(args),
|
|
45
|
+
callbacks: {
|
|
46
|
+
onSuccess: successCallbacks?.onSwitchChainSuccess,
|
|
47
|
+
onUnknownError: errorCallbacks?.onSwitchChainError,
|
|
48
|
+
onSwitchingNotSupported: errorCallbacks?.onSwitchingNotSupportedError,
|
|
49
|
+
onUserRejectedRequest:
|
|
50
|
+
errorCallbacks?.onUserRejectedSwitchingChainRequestError,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
openModal(args);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
show: handleShowModal,
|
|
61
|
+
close: () => createListingModal$.close(),
|
|
62
|
+
onError: (callbacks: CreateListingErrorCallbacks) => {
|
|
63
|
+
createListingModal$.state.set({
|
|
64
|
+
...createListingModal$.state.get(),
|
|
65
|
+
errorCallbacks: callbacks,
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
onSuccess: (callbacks: CreateListingSuccessCallbacks) => {
|
|
69
|
+
createListingModal$.state.set({
|
|
70
|
+
...createListingModal$.state.get(),
|
|
71
|
+
successCallbacks: callbacks,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
};
|
|
54
75
|
};
|
|
55
76
|
|
|
56
77
|
export const CreateListingModal = () => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
78
|
+
return (
|
|
79
|
+
<Show if={createListingModal$.isOpen}>
|
|
80
|
+
<Modal />
|
|
81
|
+
</Show>
|
|
82
|
+
);
|
|
62
83
|
};
|
|
63
84
|
|
|
64
85
|
const Modal = () => {
|
|
65
|
-
|
|
66
|
-
|
|
86
|
+
useHydrate();
|
|
87
|
+
return <ModalContent />;
|
|
67
88
|
};
|
|
68
89
|
|
|
69
90
|
const ModalContent = observer(() => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
91
|
+
const {
|
|
92
|
+
chainId,
|
|
93
|
+
collectionAddress,
|
|
94
|
+
collectibleId,
|
|
95
|
+
collectionName,
|
|
96
|
+
collectionType,
|
|
97
|
+
listingPrice,
|
|
98
|
+
} = createListingModal$.state.get();
|
|
99
|
+
|
|
100
|
+
const { steps } = createListingModal$.get();
|
|
101
|
+
|
|
102
|
+
const ctas = [
|
|
103
|
+
{
|
|
104
|
+
label: "Approve TOKEN",
|
|
105
|
+
onClick: steps.tokenApproval.execute,
|
|
106
|
+
hidden: !steps.tokenApproval.isNeeded(),
|
|
107
|
+
pending: steps.tokenApproval.pending,
|
|
108
|
+
variant: "glass" as const,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
label: "List item for sale",
|
|
112
|
+
onClick: steps.createListing.execute,
|
|
113
|
+
pending: steps.createListing.pending,
|
|
114
|
+
disabled:
|
|
115
|
+
steps.tokenApproval.isNeeded() || listingPrice.amountRaw === "0",
|
|
116
|
+
},
|
|
117
|
+
] satisfies ActionModalProps["ctas"];
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<ActionModal
|
|
121
|
+
store={createListingModal$}
|
|
122
|
+
onClose={() => createListingModal$.close()}
|
|
123
|
+
title="List item for sale"
|
|
124
|
+
ctas={ctas}
|
|
125
|
+
>
|
|
126
|
+
<TokenPreview
|
|
127
|
+
collectionName={collectionName}
|
|
128
|
+
collectionAddress={collectionAddress}
|
|
129
|
+
collectibleId={collectibleId}
|
|
130
|
+
chainId={chainId}
|
|
131
|
+
/>
|
|
132
|
+
|
|
133
|
+
<Box display="flex" flexDirection="column" width="full" gap="1">
|
|
134
|
+
<PriceInput
|
|
135
|
+
chainId={chainId}
|
|
136
|
+
collectionAddress={collectionAddress}
|
|
137
|
+
$listingPrice={createListingModal$.state.listingPrice}
|
|
138
|
+
/>
|
|
139
|
+
{!!listingPrice && (
|
|
140
|
+
<FloorPriceText
|
|
141
|
+
tokenId={collectibleId}
|
|
142
|
+
chainId={chainId}
|
|
143
|
+
collectionAddress={collectionAddress}
|
|
144
|
+
price={listingPrice}
|
|
145
|
+
/>
|
|
146
|
+
)}
|
|
147
|
+
</Box>
|
|
148
|
+
|
|
149
|
+
{collectionType === ContractType.ERC1155 && (
|
|
150
|
+
<QuantityInput
|
|
151
|
+
chainId={chainId}
|
|
152
|
+
collectionAddress={collectionAddress}
|
|
153
|
+
collectibleId={collectibleId}
|
|
154
|
+
$quantity={createListingModal$.state.quantity}
|
|
155
|
+
/>
|
|
156
|
+
)}
|
|
157
|
+
|
|
158
|
+
<ExpirationDateSelect $date={createListingModal$.state.expiry} />
|
|
159
|
+
|
|
160
|
+
<TransactionDetails
|
|
161
|
+
collectibleId={collectibleId}
|
|
162
|
+
collectionAddress={collectionAddress}
|
|
163
|
+
chainId={chainId}
|
|
164
|
+
price={createListingModal$.state.listingPrice.get()}
|
|
165
|
+
/>
|
|
166
|
+
</ActionModal>
|
|
167
|
+
);
|
|
147
168
|
});
|
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
import type { CollectionType } from '@internal';
|
|
2
1
|
import { observable, when } from '@legendapp/state';
|
|
3
2
|
import { useMount, useSelector } from '@legendapp/state/react';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import type { QueryKey } from '@tanstack/react-query';
|
|
4
|
+
import { addDays } from 'date-fns/addDays';
|
|
5
|
+
import type { Hex } from 'viem';
|
|
6
|
+
import { useAccount, useSendTransaction } from 'wagmi';
|
|
7
|
+
import type { ShowMakeOfferModalArgs } from '.';
|
|
8
|
+
import type { Price } from '../../../../types';
|
|
9
|
+
import type {
|
|
10
|
+
MakeOfferErrorCallbacks,
|
|
11
|
+
MakeOfferSuccessCallbacks,
|
|
12
|
+
} from '../../../../types/callbacks';
|
|
7
13
|
import {
|
|
14
|
+
type CollectionType,
|
|
8
15
|
type Currency,
|
|
9
16
|
OrderbookKind,
|
|
10
|
-
type Price,
|
|
11
17
|
type Step,
|
|
12
18
|
StepType,
|
|
13
19
|
type WalletKind,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
collectableKeys,
|
|
21
|
+
} from '../../../_internal';
|
|
22
|
+
import {
|
|
23
|
+
useCollectible,
|
|
24
|
+
useCollection,
|
|
25
|
+
useGenerateOfferTransaction,
|
|
26
|
+
} from '../../../hooks';
|
|
20
27
|
import { useTransactionStatusModal } from '../_internal/components/transactionStatusModal';
|
|
21
28
|
import {
|
|
22
29
|
getMakeOfferTransactionMessage,
|
|
@@ -36,7 +43,8 @@ export interface MakeOfferModalState {
|
|
|
36
43
|
chainId: string;
|
|
37
44
|
collectibleId: string;
|
|
38
45
|
expiry: Date;
|
|
39
|
-
|
|
46
|
+
errorCallbacks?: MakeOfferErrorCallbacks;
|
|
47
|
+
successCallbacks?: MakeOfferSuccessCallbacks;
|
|
40
48
|
};
|
|
41
49
|
steps: {
|
|
42
50
|
isLoading: () => boolean;
|
|
@@ -62,14 +70,12 @@ export const initialState: MakeOfferModalState = {
|
|
|
62
70
|
collectionAddress,
|
|
63
71
|
chainId,
|
|
64
72
|
collectibleId,
|
|
65
|
-
messages,
|
|
66
73
|
}: ShowMakeOfferModalArgs) => {
|
|
67
74
|
makeOfferModal$.state.set({
|
|
68
75
|
...makeOfferModal$.state.get(),
|
|
69
76
|
collectionAddress,
|
|
70
77
|
chainId,
|
|
71
78
|
collectibleId,
|
|
72
|
-
messages,
|
|
73
79
|
});
|
|
74
80
|
makeOfferModal$.isOpen.set(true);
|
|
75
81
|
},
|
|
@@ -164,11 +170,10 @@ export const useHydrate = () => {
|
|
|
164
170
|
|
|
165
171
|
const useTokenApprovalHandler = (chainId: string) => {
|
|
166
172
|
const { sendTransactionAsync, isPending, isSuccess } = useSendTransaction();
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
makeOfferModal$.state.get().messages?.approveToken || {};
|
|
173
|
+
const onError =
|
|
174
|
+
makeOfferModal$.state.get().errorCallbacks?.onApproveTokenError;
|
|
175
|
+
const onSuccess: (() => void) | undefined =
|
|
176
|
+
makeOfferModal$.state.get().successCallbacks?.onApproveTokenSuccess;
|
|
172
177
|
|
|
173
178
|
makeOfferModal$.steps.tokenApproval.set({
|
|
174
179
|
isNeeded: () => !!makeOfferModal$.steps.tokenApproval.getStep(),
|
|
@@ -192,7 +197,7 @@ const useTokenApprovalHandler = (chainId: string) => {
|
|
|
192
197
|
|
|
193
198
|
onSuccess && onSuccess();
|
|
194
199
|
} catch (error) {
|
|
195
|
-
|
|
200
|
+
onError && onError(error);
|
|
196
201
|
}
|
|
197
202
|
},
|
|
198
203
|
});
|
|
@@ -206,12 +211,12 @@ const useTokenApprovalHandler = (chainId: string) => {
|
|
|
206
211
|
};
|
|
207
212
|
|
|
208
213
|
const useCreateOfferHandler = (chainId: string) => {
|
|
209
|
-
const { collectibleId, collectionAddress } =
|
|
214
|
+
const { collectibleId, collectionAddress, errorCallbacks, successCallbacks } =
|
|
215
|
+
makeOfferModal$.state.get();
|
|
210
216
|
const { connector, address } = useAccount();
|
|
211
217
|
const {
|
|
212
218
|
generateOfferTransactionAsync,
|
|
213
219
|
isPending: generateOfferTransactionPending,
|
|
214
|
-
error: generateOfferTransactionError,
|
|
215
220
|
} = useGenerateOfferTransaction({ chainId });
|
|
216
221
|
const { data: collectible } = useCollectible({
|
|
217
222
|
chainId,
|
|
@@ -219,12 +224,6 @@ const useCreateOfferHandler = (chainId: string) => {
|
|
|
219
224
|
collectibleId,
|
|
220
225
|
});
|
|
221
226
|
|
|
222
|
-
const {
|
|
223
|
-
onUnknownError,
|
|
224
|
-
onSuccess,
|
|
225
|
-
}: { onUnknownError?: Function; onSuccess?: Function } =
|
|
226
|
-
makeOfferModal$.state.get().messages?.sellCollectible || {};
|
|
227
|
-
|
|
228
227
|
const { sendTransactionAsync, isPending: sendTransactionPending } =
|
|
229
228
|
useSendTransaction();
|
|
230
229
|
|
|
@@ -265,6 +264,8 @@ const useCreateOfferHandler = (chainId: string) => {
|
|
|
265
264
|
|
|
266
265
|
makeOfferModal$.steps._currentStep.set(null);
|
|
267
266
|
|
|
267
|
+
makeOfferModal$.close();
|
|
268
|
+
|
|
268
269
|
showTransactionStatusModal({
|
|
269
270
|
hash: hash!,
|
|
270
271
|
price: makeOfferModal$.state.offerPrice.get(),
|
|
@@ -275,19 +276,16 @@ const useCreateOfferHandler = (chainId: string) => {
|
|
|
275
276
|
getMessage: (params) =>
|
|
276
277
|
getMakeOfferTransactionMessage(params, collectible?.name || ''),
|
|
277
278
|
type: StepType.createOffer,
|
|
279
|
+
callbacks: {
|
|
280
|
+
onSuccess: successCallbacks?.onMakeOfferSuccess,
|
|
281
|
+
onUnknownError: errorCallbacks?.onMakeOfferError,
|
|
282
|
+
},
|
|
283
|
+
queriesToInvalidate: collectableKeys.all as unknown as QueryKey[],
|
|
278
284
|
});
|
|
279
|
-
|
|
280
|
-
makeOfferModal$.close();
|
|
281
|
-
|
|
282
|
-
onSuccess && onSuccess();
|
|
283
285
|
})
|
|
284
286
|
.catch((error) => {
|
|
285
|
-
|
|
287
|
+
errorCallbacks?.onMakeOfferError?.(error);
|
|
286
288
|
});
|
|
287
289
|
},
|
|
288
290
|
});
|
|
289
|
-
|
|
290
|
-
if (generateOfferTransactionError) {
|
|
291
|
-
onUnknownError && onUnknownError(generateOfferTransactionError);
|
|
292
|
-
}
|
|
293
291
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { ContractType } from '@internal';
|
|
2
1
|
import { Show, observer } from '@legendapp/state/react';
|
|
3
2
|
import { useState } from 'react';
|
|
4
3
|
import type { Hex } from 'viem';
|
|
5
4
|
import { useAccount } from 'wagmi';
|
|
6
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
MakeOfferErrorCallbacks,
|
|
7
|
+
MakeOfferSuccessCallbacks,
|
|
8
|
+
} from '../../../../types/callbacks';
|
|
9
|
+
import { ContractType } from '../../../_internal';
|
|
7
10
|
import {
|
|
8
11
|
ActionModal,
|
|
9
12
|
type ActionModalProps,
|
|
@@ -20,12 +23,12 @@ export type ShowMakeOfferModalArgs = {
|
|
|
20
23
|
collectionAddress: Hex;
|
|
21
24
|
chainId: string;
|
|
22
25
|
collectibleId: string;
|
|
23
|
-
messages?: Messages;
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
export const useMakeOfferModal = () => {
|
|
27
29
|
const { chainId: accountChainId } = useAccount();
|
|
28
30
|
const { show: showSwitchNetworkModal } = useSwitchChainModal();
|
|
31
|
+
const { errorCallbacks, successCallbacks } = makeOfferModal$.state.get();
|
|
29
32
|
|
|
30
33
|
const openModal = (args: ShowMakeOfferModalArgs) => {
|
|
31
34
|
makeOfferModal$.open(args);
|
|
@@ -38,7 +41,13 @@ export const useMakeOfferModal = () => {
|
|
|
38
41
|
showSwitchNetworkModal({
|
|
39
42
|
chainIdToSwitchTo: Number(args.chainId),
|
|
40
43
|
onSwitchChain: () => openModal(args),
|
|
41
|
-
|
|
44
|
+
callbacks: {
|
|
45
|
+
onSuccess: successCallbacks?.onSwitchChainSuccess,
|
|
46
|
+
onUnknownError: errorCallbacks?.onSwitchChainError,
|
|
47
|
+
onSwitchingNotSupported: errorCallbacks?.onSwitchingNotSupportedError,
|
|
48
|
+
onUserRejectedRequest:
|
|
49
|
+
errorCallbacks?.onUserRejectedSwitchingChainRequestError,
|
|
50
|
+
},
|
|
42
51
|
});
|
|
43
52
|
return;
|
|
44
53
|
}
|
|
@@ -49,6 +58,18 @@ export const useMakeOfferModal = () => {
|
|
|
49
58
|
return {
|
|
50
59
|
show: handleShowModal,
|
|
51
60
|
close: () => makeOfferModal$.close(),
|
|
61
|
+
onError: (callbacks: MakeOfferErrorCallbacks) => {
|
|
62
|
+
makeOfferModal$.state.set({
|
|
63
|
+
...makeOfferModal$.state.get(),
|
|
64
|
+
errorCallbacks: callbacks,
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
onSuccess: (callbacks: MakeOfferSuccessCallbacks) => {
|
|
68
|
+
makeOfferModal$.state.set({
|
|
69
|
+
...makeOfferModal$.state.get(),
|
|
70
|
+
successCallbacks: callbacks,
|
|
71
|
+
});
|
|
72
|
+
},
|
|
52
73
|
};
|
|
53
74
|
};
|
|
54
75
|
|