@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
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
alertMessageBoxVariants,
|
|
8
|
-
closeButton,
|
|
9
|
-
dialogOverlay,
|
|
10
|
-
switchChainCta,
|
|
11
|
-
switchChainModalContent
|
|
12
|
-
} from "./chunk-FI723DGL.js";
|
|
3
|
+
createLogger,
|
|
4
|
+
useSwitchChainModal,
|
|
5
|
+
useWallet
|
|
6
|
+
} from "./chunk-LHN6EBLM.js";
|
|
13
7
|
import {
|
|
14
|
-
getPresentableChainName,
|
|
15
8
|
getPublicRpcClient
|
|
16
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-4VS5NKDD.js";
|
|
17
10
|
import {
|
|
18
11
|
EIP2981_ABI
|
|
19
12
|
} from "./chunk-3OHM45R3.js";
|
|
@@ -26,7 +19,7 @@ import {
|
|
|
26
19
|
CollectableIdSchema,
|
|
27
20
|
PROVIDER_ID,
|
|
28
21
|
QueryArgSchema
|
|
29
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-ZEKRTFBU.js";
|
|
30
23
|
import {
|
|
31
24
|
CollectibleStatus,
|
|
32
25
|
CollectionStatus,
|
|
@@ -57,10 +50,11 @@ import {
|
|
|
57
50
|
getMarketplaceClient,
|
|
58
51
|
getMetadataClient,
|
|
59
52
|
getQueryClient
|
|
60
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-URX7ZHX4.js";
|
|
61
54
|
import {
|
|
62
55
|
BaseError,
|
|
63
56
|
ChainSwitchError,
|
|
57
|
+
ChainSwitchUserRejectedError,
|
|
64
58
|
CheckoutOptionsError,
|
|
65
59
|
InvalidCurrencyOptionsError,
|
|
66
60
|
MarketplaceConfigFetchError,
|
|
@@ -77,15 +71,12 @@ import {
|
|
|
77
71
|
ProjectNotFoundError,
|
|
78
72
|
StepExecutionError,
|
|
79
73
|
StepGenerationError,
|
|
80
|
-
TransactionConfirmationError,
|
|
81
74
|
TransactionError,
|
|
82
|
-
TransactionExecutionError,
|
|
83
75
|
TransactionReceiptError,
|
|
84
|
-
TransactionSignatureError,
|
|
85
76
|
UnexpectedStepsError,
|
|
86
77
|
UnknownTransactionTypeError,
|
|
87
|
-
|
|
88
|
-
} from "./chunk-
|
|
78
|
+
WalletInstanceNotFoundError
|
|
79
|
+
} from "./chunk-DNDPYQKV.js";
|
|
89
80
|
|
|
90
81
|
// src/react/hooks/useBalanceOfCollectible.tsx
|
|
91
82
|
import { queryOptions, skipToken, useQuery } from "@tanstack/react-query";
|
|
@@ -1603,64 +1594,219 @@ var useGenerateBuyTransaction = (args) => {
|
|
|
1603
1594
|
);
|
|
1604
1595
|
};
|
|
1605
1596
|
|
|
1606
|
-
// src/react/
|
|
1607
|
-
import {
|
|
1597
|
+
// src/react/hooks/useCancelOrder.tsx
|
|
1598
|
+
import { useState } from "react";
|
|
1608
1599
|
|
|
1609
|
-
// src/react/
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1600
|
+
// src/react/hooks/useGetReceiptFromHash.tsx
|
|
1601
|
+
import { usePublicClient } from "wagmi";
|
|
1602
|
+
import { useCallback } from "react";
|
|
1603
|
+
var useGetReceiptFromHash = () => {
|
|
1604
|
+
const publicClient = usePublicClient();
|
|
1605
|
+
const waitForReceipt = useCallback(
|
|
1606
|
+
async (transactionHash) => {
|
|
1607
|
+
if (!publicClient) {
|
|
1608
|
+
throw new Error("Public client not found");
|
|
1609
|
+
}
|
|
1610
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
1611
|
+
hash: transactionHash
|
|
1612
|
+
});
|
|
1613
|
+
return receipt;
|
|
1614
|
+
},
|
|
1615
|
+
[publicClient]
|
|
1616
|
+
);
|
|
1617
|
+
return {
|
|
1618
|
+
waitForReceipt
|
|
1619
|
+
};
|
|
1620
|
+
};
|
|
1621
|
+
|
|
1622
|
+
// src/react/hooks/useCancelTransactionSteps.tsx
|
|
1623
|
+
var useCancelTransactionSteps = ({
|
|
1624
|
+
collectionAddress,
|
|
1625
|
+
chainId,
|
|
1626
|
+
callbacks,
|
|
1627
|
+
setSteps,
|
|
1628
|
+
onSuccess,
|
|
1629
|
+
onError
|
|
1630
|
+
}) => {
|
|
1631
|
+
const { show: showSwitchChainModal } = useSwitchChainModal();
|
|
1632
|
+
const { wallet, isLoading, isError } = useWallet();
|
|
1633
|
+
const walletIsInitialized = wallet && !isLoading && !isError;
|
|
1634
|
+
const sdkConfig = useConfig();
|
|
1635
|
+
const marketplaceClient = getMarketplaceClient(chainId, sdkConfig);
|
|
1636
|
+
const { waitForReceipt } = useGetReceiptFromHash();
|
|
1637
|
+
const { generateCancelTransactionAsync } = useGenerateCancelTransaction({
|
|
1638
|
+
chainId
|
|
1639
|
+
});
|
|
1640
|
+
const getWalletChainId = async () => {
|
|
1641
|
+
return await wallet.getChainId();
|
|
1642
|
+
};
|
|
1643
|
+
const switchChain = async () => {
|
|
1644
|
+
await wallet.switchChain(Number(chainId));
|
|
1645
|
+
};
|
|
1646
|
+
const checkAndSwitchChain = async () => {
|
|
1647
|
+
const walletChainId = await getWalletChainId();
|
|
1648
|
+
const isWaaS = wallet?.isWaaS;
|
|
1649
|
+
const chainIdMismatch = walletChainId !== Number(chainId);
|
|
1650
|
+
return new Promise((resolve, reject) => {
|
|
1651
|
+
if (chainIdMismatch) {
|
|
1652
|
+
if (isWaaS) {
|
|
1653
|
+
switchChain().then(resolve).catch(reject);
|
|
1654
|
+
} else {
|
|
1655
|
+
showSwitchChainModal({
|
|
1656
|
+
chainIdToSwitchTo: chainId,
|
|
1657
|
+
onSuccess: () => resolve({ chainId }),
|
|
1658
|
+
onError: (error) => reject(error),
|
|
1659
|
+
onClose: () => reject(new ChainSwitchUserRejectedError())
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
} else {
|
|
1663
|
+
resolve({ chainId });
|
|
1664
|
+
}
|
|
1665
|
+
});
|
|
1666
|
+
};
|
|
1667
|
+
const getCancelSteps = async ({
|
|
1668
|
+
orderId,
|
|
1669
|
+
marketplace
|
|
1670
|
+
}) => {
|
|
1671
|
+
try {
|
|
1672
|
+
const address = await wallet.address();
|
|
1673
|
+
const steps = await generateCancelTransactionAsync({
|
|
1674
|
+
collectionAddress,
|
|
1675
|
+
maker: address,
|
|
1676
|
+
marketplace,
|
|
1677
|
+
orderId
|
|
1678
|
+
});
|
|
1679
|
+
return steps;
|
|
1680
|
+
} catch (error) {
|
|
1681
|
+
if (callbacks?.onError) {
|
|
1682
|
+
callbacks.onError(error);
|
|
1683
|
+
} else {
|
|
1684
|
+
console.debug("onError callback not provided:", error);
|
|
1685
|
+
}
|
|
1686
|
+
throw error;
|
|
1623
1687
|
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1688
|
+
};
|
|
1689
|
+
const cancelOrder = async ({
|
|
1690
|
+
orderId,
|
|
1691
|
+
marketplace
|
|
1692
|
+
}) => {
|
|
1693
|
+
if (!walletIsInitialized) {
|
|
1694
|
+
throw new WalletInstanceNotFoundError();
|
|
1626
1695
|
}
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1696
|
+
try {
|
|
1697
|
+
await checkAndSwitchChain();
|
|
1698
|
+
setSteps((prev) => ({
|
|
1699
|
+
...prev,
|
|
1700
|
+
isExecuting: true
|
|
1701
|
+
}));
|
|
1702
|
+
const cancelSteps = await getCancelSteps({
|
|
1703
|
+
orderId,
|
|
1704
|
+
marketplace
|
|
1705
|
+
});
|
|
1706
|
+
const transactionStep = cancelSteps?.find(
|
|
1707
|
+
(step) => step.id === "cancel" /* cancel */
|
|
1708
|
+
);
|
|
1709
|
+
const signatureStep = cancelSteps?.find(
|
|
1710
|
+
(step) => step.id === "signEIP712" /* signEIP712 */
|
|
1633
1711
|
);
|
|
1712
|
+
console.debug("transactionStep", transactionStep);
|
|
1713
|
+
console.debug("signatureStep", signatureStep);
|
|
1714
|
+
if (!transactionStep && !signatureStep) {
|
|
1715
|
+
throw new Error("No transaction or signature step found");
|
|
1716
|
+
}
|
|
1717
|
+
let hash, reservoirOrderId;
|
|
1718
|
+
if (transactionStep && wallet) {
|
|
1719
|
+
hash = await executeTransaction({ transactionStep });
|
|
1720
|
+
if (hash) {
|
|
1721
|
+
await waitForReceipt(hash);
|
|
1722
|
+
if (onSuccess && typeof onSuccess === "function") {
|
|
1723
|
+
onSuccess({ hash });
|
|
1724
|
+
}
|
|
1725
|
+
setSteps((prev) => ({
|
|
1726
|
+
...prev,
|
|
1727
|
+
isExecuting: false
|
|
1728
|
+
}));
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
if (signatureStep) {
|
|
1732
|
+
reservoirOrderId = await executeSignature({ signatureStep });
|
|
1733
|
+
if (onSuccess && typeof onSuccess === "function") {
|
|
1734
|
+
onSuccess({ orderId: reservoirOrderId });
|
|
1735
|
+
}
|
|
1736
|
+
setSteps((prev) => ({
|
|
1737
|
+
...prev,
|
|
1738
|
+
isExecuting: false
|
|
1739
|
+
}));
|
|
1740
|
+
}
|
|
1741
|
+
} catch (error) {
|
|
1742
|
+
setSteps((prev) => ({
|
|
1743
|
+
...prev,
|
|
1744
|
+
isExecuting: false
|
|
1745
|
+
}));
|
|
1746
|
+
if (onError && typeof onError === "function") {
|
|
1747
|
+
onError(error);
|
|
1748
|
+
}
|
|
1749
|
+
throw error;
|
|
1634
1750
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1751
|
+
};
|
|
1752
|
+
const executeTransaction = async ({
|
|
1753
|
+
transactionStep
|
|
1754
|
+
}) => {
|
|
1755
|
+
const hash = await wallet.handleSendTransactionStep(
|
|
1756
|
+
Number(chainId),
|
|
1757
|
+
transactionStep
|
|
1642
1758
|
);
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1759
|
+
return hash;
|
|
1760
|
+
};
|
|
1761
|
+
const executeSignature = async ({
|
|
1762
|
+
signatureStep
|
|
1763
|
+
}) => {
|
|
1764
|
+
const signature = await wallet.handleSignMessageStep(
|
|
1765
|
+
signatureStep
|
|
1766
|
+
);
|
|
1767
|
+
const result = await marketplaceClient.execute({
|
|
1768
|
+
signature,
|
|
1769
|
+
executeType: "order" /* order */,
|
|
1770
|
+
body: signatureStep.post?.body
|
|
1771
|
+
});
|
|
1772
|
+
return result.orderId;
|
|
1773
|
+
};
|
|
1774
|
+
return {
|
|
1775
|
+
cancelOrder
|
|
1776
|
+
};
|
|
1777
|
+
};
|
|
1778
|
+
|
|
1779
|
+
// src/react/hooks/useCancelOrder.tsx
|
|
1780
|
+
var useCancelOrder = ({
|
|
1781
|
+
collectionAddress,
|
|
1782
|
+
chainId,
|
|
1783
|
+
onSuccess,
|
|
1784
|
+
onError
|
|
1785
|
+
}) => {
|
|
1786
|
+
const [steps, setSteps] = useState({
|
|
1787
|
+
exist: false,
|
|
1788
|
+
isExecuting: false,
|
|
1789
|
+
execute: () => Promise.resolve()
|
|
1790
|
+
});
|
|
1791
|
+
const { cancelOrder } = useCancelTransactionSteps({
|
|
1792
|
+
collectionAddress,
|
|
1793
|
+
chainId,
|
|
1794
|
+
onSuccess,
|
|
1795
|
+
onError,
|
|
1796
|
+
setSteps
|
|
1797
|
+
});
|
|
1798
|
+
return {
|
|
1799
|
+
cancelOrder,
|
|
1800
|
+
isExecuting: steps.isExecuting
|
|
1801
|
+
};
|
|
1656
1802
|
};
|
|
1657
|
-
var createLogger = (context, enabled = true) => new TransactionLogger(context, enabled);
|
|
1658
1803
|
|
|
1659
1804
|
// src/react/_internal/transaction-machine/execute-transaction.ts
|
|
1805
|
+
import { avalanche, optimism } from "viem/chains";
|
|
1660
1806
|
var TransactionMachine = class {
|
|
1661
|
-
constructor(config,
|
|
1807
|
+
constructor(config, wallet, openSelectPaymentModal, switchChainFn, onPaymentModalLoaded) {
|
|
1662
1808
|
this.config = config;
|
|
1663
|
-
this.wallet =
|
|
1809
|
+
this.wallet = wallet;
|
|
1664
1810
|
this.openSelectPaymentModal = openSelectPaymentModal;
|
|
1665
1811
|
this.switchChainFn = switchChainFn;
|
|
1666
1812
|
this.onPaymentModalLoaded = onPaymentModalLoaded;
|
|
@@ -2060,260 +2206,7 @@ var TransactionMachine = class {
|
|
|
2060
2206
|
|
|
2061
2207
|
// src/react/_internal/transaction-machine/useTransactionMachine.ts
|
|
2062
2208
|
import { useSelectPaymentModal } from "@0xsequence/kit-checkout";
|
|
2063
|
-
import { useAccount as useAccount4, useSwitchChain
|
|
2064
|
-
|
|
2065
|
-
// src/react/ui/modals/_internal/components/switchChainModal/index.tsx
|
|
2066
|
-
import {
|
|
2067
|
-
Button,
|
|
2068
|
-
CloseIcon,
|
|
2069
|
-
IconButton,
|
|
2070
|
-
Spinner,
|
|
2071
|
-
Text as Text2
|
|
2072
|
-
} from "@0xsequence/design-system";
|
|
2073
|
-
import { observer } from "@legendapp/state/react";
|
|
2074
|
-
import { Close, Content, Overlay, Portal, Root } from "@radix-ui/react-dialog";
|
|
2075
|
-
import { useSwitchChain } from "wagmi";
|
|
2076
|
-
|
|
2077
|
-
// src/react/ui/modals/_internal/components/alertMessage/index.tsx
|
|
2078
|
-
import { Box, Text, WarningIcon } from "@0xsequence/design-system";
|
|
2079
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
2080
|
-
function AlertMessage({ message, type }) {
|
|
2081
|
-
return /* @__PURE__ */ jsxs(Box, { className: `${alertMessageBox} ${alertMessageBoxVariants[type]}`, children: [
|
|
2082
|
-
/* @__PURE__ */ jsx2(
|
|
2083
|
-
Text,
|
|
2084
|
-
{
|
|
2085
|
-
color: "white",
|
|
2086
|
-
fontSize: "normal",
|
|
2087
|
-
fontWeight: "medium",
|
|
2088
|
-
fontFamily: "body",
|
|
2089
|
-
children: message
|
|
2090
|
-
}
|
|
2091
|
-
),
|
|
2092
|
-
type === "warning" && /* @__PURE__ */ jsx2(WarningIcon, { size: "sm", color: "white" }),
|
|
2093
|
-
type === "info" && /* @__PURE__ */ jsx2(InfoIcon_default, { size: "sm", color: "white" })
|
|
2094
|
-
] });
|
|
2095
|
-
}
|
|
2096
|
-
|
|
2097
|
-
// src/react/ui/modals/_internal/components/switchChainModal/store.ts
|
|
2098
|
-
import { observable } from "@legendapp/state";
|
|
2099
|
-
var initialState = {
|
|
2100
|
-
isOpen: false,
|
|
2101
|
-
open: ({ chainIdToSwitchTo, onError, onSuccess, onClose }) => {
|
|
2102
|
-
switchChainModal$.state.set({
|
|
2103
|
-
...switchChainModal$.state.get(),
|
|
2104
|
-
chainIdToSwitchTo,
|
|
2105
|
-
onError,
|
|
2106
|
-
onSuccess,
|
|
2107
|
-
onClose
|
|
2108
|
-
});
|
|
2109
|
-
switchChainModal$.isOpen.set(true);
|
|
2110
|
-
},
|
|
2111
|
-
close: () => {
|
|
2112
|
-
switchChainModal$.isOpen.set(false);
|
|
2113
|
-
},
|
|
2114
|
-
state: {
|
|
2115
|
-
chainIdToSwitchTo: void 0,
|
|
2116
|
-
onError: void 0,
|
|
2117
|
-
onSuccess: void 0,
|
|
2118
|
-
onClose: void 0,
|
|
2119
|
-
isSwitching: false
|
|
2120
|
-
}
|
|
2121
|
-
};
|
|
2122
|
-
var switchChainModal$ = observable(initialState);
|
|
2123
|
-
|
|
2124
|
-
// src/react/ui/modals/_internal/components/switchChainModal/index.tsx
|
|
2125
|
-
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2126
|
-
var useSwitchChainModal = () => {
|
|
2127
|
-
return {
|
|
2128
|
-
show: (args) => switchChainModal$.open(args),
|
|
2129
|
-
close: () => switchChainModal$.delete(),
|
|
2130
|
-
isSwitching$: switchChainModal$.state.isSwitching
|
|
2131
|
-
};
|
|
2132
|
-
};
|
|
2133
|
-
var SwitchChainModal = observer(() => {
|
|
2134
|
-
const chainIdToSwitchTo = switchChainModal$.state.chainIdToSwitchTo.get();
|
|
2135
|
-
const isSwitching$ = switchChainModal$.state.isSwitching;
|
|
2136
|
-
const chainName = chainIdToSwitchTo ? getPresentableChainName(chainIdToSwitchTo) : "";
|
|
2137
|
-
const { switchChainAsync } = useSwitchChain();
|
|
2138
|
-
async function handleSwitchChain() {
|
|
2139
|
-
isSwitching$.set(true);
|
|
2140
|
-
try {
|
|
2141
|
-
if (!chainIdToSwitchTo) return;
|
|
2142
|
-
await switchChainAsync({ chainId: Number(chainIdToSwitchTo) });
|
|
2143
|
-
switchChainModal$.state.onSuccess?.();
|
|
2144
|
-
switchChainModal$.delete();
|
|
2145
|
-
} catch (error) {
|
|
2146
|
-
switchChainModal$.state.onError?.(error);
|
|
2147
|
-
} finally {
|
|
2148
|
-
isSwitching$.set(false);
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
return /* @__PURE__ */ jsx3(Root, { open: switchChainModal$.isOpen.get(), children: /* @__PURE__ */ jsxs2(Portal, { children: [
|
|
2152
|
-
/* @__PURE__ */ jsx3(Overlay, { className: dialogOverlay }),
|
|
2153
|
-
/* @__PURE__ */ jsxs2(Content, { className: switchChainModalContent, children: [
|
|
2154
|
-
/* @__PURE__ */ jsx3(Text2, { fontSize: "large", fontWeight: "bold", color: "text100", children: "Wrong network" }),
|
|
2155
|
-
/* @__PURE__ */ jsx3(
|
|
2156
|
-
AlertMessage,
|
|
2157
|
-
{
|
|
2158
|
-
type: "warning",
|
|
2159
|
-
message: `You need to switch to ${chainName} network before completing the transaction`
|
|
2160
|
-
}
|
|
2161
|
-
),
|
|
2162
|
-
/* @__PURE__ */ jsx3(
|
|
2163
|
-
Button,
|
|
2164
|
-
{
|
|
2165
|
-
name: "switch-chain",
|
|
2166
|
-
size: "sm",
|
|
2167
|
-
label: isSwitching$.get() ? /* @__PURE__ */ jsx3(Spinner, {}) : "Switch Network",
|
|
2168
|
-
variant: "primary",
|
|
2169
|
-
pending: isSwitching$.get(),
|
|
2170
|
-
shape: "square",
|
|
2171
|
-
className: isSwitching$.get() ? switchChainCta.pending : switchChainCta.default,
|
|
2172
|
-
justifySelf: "flex-end",
|
|
2173
|
-
onClick: handleSwitchChain
|
|
2174
|
-
}
|
|
2175
|
-
),
|
|
2176
|
-
/* @__PURE__ */ jsx3(
|
|
2177
|
-
Close,
|
|
2178
|
-
{
|
|
2179
|
-
onClick: () => {
|
|
2180
|
-
switchChainModal$.state.onClose?.();
|
|
2181
|
-
switchChainModal$.delete();
|
|
2182
|
-
},
|
|
2183
|
-
className: closeButton,
|
|
2184
|
-
asChild: true,
|
|
2185
|
-
children: /* @__PURE__ */ jsx3(IconButton, { size: "xs", "aria-label": "Close modal", icon: CloseIcon })
|
|
2186
|
-
}
|
|
2187
|
-
)
|
|
2188
|
-
] })
|
|
2189
|
-
] }) });
|
|
2190
|
-
});
|
|
2191
|
-
var switchChainModal_default = SwitchChainModal;
|
|
2192
|
-
|
|
2193
|
-
// src/react/_internal/transaction-machine/wallet.ts
|
|
2194
|
-
import {
|
|
2195
|
-
custom,
|
|
2196
|
-
hexToBigInt,
|
|
2197
|
-
isHex
|
|
2198
|
-
} from "viem";
|
|
2199
|
-
var wallet = ({
|
|
2200
|
-
wallet: wallet2,
|
|
2201
|
-
chains,
|
|
2202
|
-
connector
|
|
2203
|
-
}) => {
|
|
2204
|
-
const logger = createLogger("Wallet");
|
|
2205
|
-
return {
|
|
2206
|
-
transport: custom(wallet2.transport),
|
|
2207
|
-
isWaaS: connector.id.endsWith("waas"),
|
|
2208
|
-
walletKind: connector.id === "sequence" ? "sequence" /* sequence */ : "unknown" /* unknown */,
|
|
2209
|
-
getChainId: wallet2.getChainId,
|
|
2210
|
-
address: async () => {
|
|
2211
|
-
let address = wallet2.account?.address;
|
|
2212
|
-
if (!address) {
|
|
2213
|
-
[address] = await wallet2.getAddresses();
|
|
2214
|
-
}
|
|
2215
|
-
return address;
|
|
2216
|
-
},
|
|
2217
|
-
switchChain: async (chainId) => {
|
|
2218
|
-
logger.debug("Switching chain", { targetChainId: chainId });
|
|
2219
|
-
try {
|
|
2220
|
-
await wallet2.switchChain({
|
|
2221
|
-
id: chainId
|
|
2222
|
-
});
|
|
2223
|
-
logger.info("Chain switch successful", { chainId });
|
|
2224
|
-
return;
|
|
2225
|
-
} catch (e) {
|
|
2226
|
-
const error = e;
|
|
2227
|
-
logger.error("Chain switch failed", error);
|
|
2228
|
-
switch (error.name) {
|
|
2229
|
-
case "SwitchChainNotSupportedError":
|
|
2230
|
-
throw new ChainSwitchError(await wallet2.getChainId(), chainId);
|
|
2231
|
-
case "UserRejectedRequestError":
|
|
2232
|
-
throw new UserRejectedRequestError();
|
|
2233
|
-
case "ChainNotConfiguredError":
|
|
2234
|
-
return;
|
|
2235
|
-
default:
|
|
2236
|
-
throw new ChainSwitchError(await wallet2.getChainId(), chainId);
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
},
|
|
2240
|
-
handleSignMessageStep: async (stepItem) => {
|
|
2241
|
-
try {
|
|
2242
|
-
if (stepItem.id === "signEIP191" /* signEIP191 */) {
|
|
2243
|
-
logger.debug("Signing with EIP-191", { data: stepItem.data });
|
|
2244
|
-
const message = isHex(stepItem.data) ? { raw: stepItem.data } : stepItem.data;
|
|
2245
|
-
return await wallet2.signMessage({
|
|
2246
|
-
account: wallet2.account,
|
|
2247
|
-
message
|
|
2248
|
-
});
|
|
2249
|
-
} else if (stepItem.id === "signEIP712" /* signEIP712 */) {
|
|
2250
|
-
logger.debug("Signing with EIP-712", {
|
|
2251
|
-
domain: stepItem.domain,
|
|
2252
|
-
types: stepItem.signature?.types
|
|
2253
|
-
});
|
|
2254
|
-
return await wallet2.signTypedData({
|
|
2255
|
-
account: wallet2.account,
|
|
2256
|
-
domain: stepItem.signature.domain,
|
|
2257
|
-
// biome-ignore lint/style/noNonNullAssertion: <explanation>
|
|
2258
|
-
types: stepItem.signature.types,
|
|
2259
|
-
// biome-ignore lint/style/noNonNullAssertion: <explanation>
|
|
2260
|
-
primaryType: stepItem.signature.primaryType,
|
|
2261
|
-
// biome-ignore lint/style/noNonNullAssertion: <explanation>
|
|
2262
|
-
message: stepItem.signature.value
|
|
2263
|
-
});
|
|
2264
|
-
}
|
|
2265
|
-
} catch (error) {
|
|
2266
|
-
logger.error("Signature failed", error);
|
|
2267
|
-
throw new TransactionSignatureError(stepItem.id, error);
|
|
2268
|
-
}
|
|
2269
|
-
},
|
|
2270
|
-
handleSendTransactionStep: async (chainId, stepItem) => {
|
|
2271
|
-
logger.debug("Sending transaction", {
|
|
2272
|
-
chainId,
|
|
2273
|
-
to: stepItem.to,
|
|
2274
|
-
value: stepItem.value
|
|
2275
|
-
});
|
|
2276
|
-
const chain = chains.find((chain2) => chain2.id === chainId);
|
|
2277
|
-
try {
|
|
2278
|
-
return await wallet2.sendTransaction({
|
|
2279
|
-
chain,
|
|
2280
|
-
data: stepItem.data,
|
|
2281
|
-
account: wallet2.account,
|
|
2282
|
-
to: stepItem.to,
|
|
2283
|
-
value: hexToBigInt(stepItem.value || "0x0"),
|
|
2284
|
-
...stepItem.maxFeePerGas && {
|
|
2285
|
-
maxFeePerGas: hexToBigInt(stepItem.maxFeePerGas)
|
|
2286
|
-
},
|
|
2287
|
-
...stepItem.maxPriorityFeePerGas && {
|
|
2288
|
-
maxPriorityFeePerGas: hexToBigInt(stepItem.maxPriorityFeePerGas)
|
|
2289
|
-
},
|
|
2290
|
-
...stepItem.gas && {
|
|
2291
|
-
gas: hexToBigInt(stepItem.gas)
|
|
2292
|
-
}
|
|
2293
|
-
});
|
|
2294
|
-
} catch (error) {
|
|
2295
|
-
logger.error("Transaction failed", error);
|
|
2296
|
-
throw new TransactionExecutionError(stepItem.id, error);
|
|
2297
|
-
}
|
|
2298
|
-
},
|
|
2299
|
-
handleConfirmTransactionStep: async (txHash, chainId) => {
|
|
2300
|
-
logger.debug("Confirming transaction", { txHash, chainId });
|
|
2301
|
-
try {
|
|
2302
|
-
const publicClient = getPublicRpcClient(chainId);
|
|
2303
|
-
const receipt = await publicClient.waitForTransactionReceipt({
|
|
2304
|
-
hash: txHash
|
|
2305
|
-
});
|
|
2306
|
-
logger.info("Transaction confirmed", { txHash, receipt });
|
|
2307
|
-
return receipt;
|
|
2308
|
-
} catch (error) {
|
|
2309
|
-
logger.error("Transaction confirmation failed", error);
|
|
2310
|
-
throw new TransactionConfirmationError(txHash, error);
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
};
|
|
2314
|
-
};
|
|
2315
|
-
|
|
2316
|
-
// src/react/_internal/transaction-machine/useTransactionMachine.ts
|
|
2209
|
+
import { useAccount as useAccount4, useSwitchChain } from "wagmi";
|
|
2317
2210
|
var useTransactionMachine = ({
|
|
2318
2211
|
config,
|
|
2319
2212
|
enabled,
|
|
@@ -2323,7 +2216,6 @@ var useTransactionMachine = ({
|
|
|
2323
2216
|
onApprovalSuccess,
|
|
2324
2217
|
onPaymentModalLoaded
|
|
2325
2218
|
}) => {
|
|
2326
|
-
const { data: walletClient, isLoading: walletClientIsLoading } = useWalletClient();
|
|
2327
2219
|
const { show: showSwitchChainModal } = useSwitchChainModal();
|
|
2328
2220
|
const sdkConfig = useConfig();
|
|
2329
2221
|
const {
|
|
@@ -2332,8 +2224,13 @@ var useTransactionMachine = ({
|
|
|
2332
2224
|
isLoading: marketplaceConfigIsLoading
|
|
2333
2225
|
} = useMarketplaceConfig();
|
|
2334
2226
|
const { openSelectPaymentModal } = useSelectPaymentModal();
|
|
2335
|
-
const { chains } =
|
|
2336
|
-
const {
|
|
2227
|
+
const { chains } = useSwitchChain();
|
|
2228
|
+
const { isConnected } = useAccount4();
|
|
2229
|
+
const {
|
|
2230
|
+
wallet: walletInstance,
|
|
2231
|
+
isLoading: walletClientIsLoading,
|
|
2232
|
+
isError: walletClientIsError
|
|
2233
|
+
} = useWallet();
|
|
2337
2234
|
if (!enabled) return { machine: null, error: null, isLoading: false };
|
|
2338
2235
|
if (!isConnected) {
|
|
2339
2236
|
return { machine: null, error: null, isLoading: false };
|
|
@@ -2348,7 +2245,7 @@ var useTransactionMachine = ({
|
|
|
2348
2245
|
onError?.(error);
|
|
2349
2246
|
return { machine: null, error };
|
|
2350
2247
|
}
|
|
2351
|
-
if (
|
|
2248
|
+
if (walletClientIsError) {
|
|
2352
2249
|
const error = new NoWalletConnectedError();
|
|
2353
2250
|
onError?.(error);
|
|
2354
2251
|
return { machine: null, error };
|
|
@@ -2358,11 +2255,6 @@ var useTransactionMachine = ({
|
|
|
2358
2255
|
onError?.(error);
|
|
2359
2256
|
return { machine: null, error };
|
|
2360
2257
|
}
|
|
2361
|
-
const walletInstance = wallet({
|
|
2362
|
-
wallet: walletClient,
|
|
2363
|
-
chains,
|
|
2364
|
-
connector
|
|
2365
|
-
});
|
|
2366
2258
|
const machine = new TransactionMachine(
|
|
2367
2259
|
{
|
|
2368
2260
|
config: {
|
|
@@ -2411,36 +2303,8 @@ var useTransactionMachine = ({
|
|
|
2411
2303
|
};
|
|
2412
2304
|
};
|
|
2413
2305
|
|
|
2414
|
-
// src/react/hooks/useCancelOrder.tsx
|
|
2415
|
-
var useCancelOrder = ({
|
|
2416
|
-
onSuccess,
|
|
2417
|
-
onError,
|
|
2418
|
-
onTransactionSent,
|
|
2419
|
-
enabled,
|
|
2420
|
-
...config
|
|
2421
|
-
}) => {
|
|
2422
|
-
const machineConfig = {
|
|
2423
|
-
...config,
|
|
2424
|
-
type: "CANCEL" /* CANCEL */
|
|
2425
|
-
};
|
|
2426
|
-
const { machine, isLoading } = useTransactionMachine({
|
|
2427
|
-
config: machineConfig,
|
|
2428
|
-
enabled,
|
|
2429
|
-
onSuccess,
|
|
2430
|
-
onError,
|
|
2431
|
-
onTransactionSent
|
|
2432
|
-
});
|
|
2433
|
-
return {
|
|
2434
|
-
cancel: (props) => machine?.start(props),
|
|
2435
|
-
onError,
|
|
2436
|
-
onSuccess,
|
|
2437
|
-
onTransactionSent,
|
|
2438
|
-
isLoading
|
|
2439
|
-
};
|
|
2440
|
-
};
|
|
2441
|
-
|
|
2442
2306
|
// src/react/hooks/useBuyCollectable.tsx
|
|
2443
|
-
import { useCallback } from "react";
|
|
2307
|
+
import { useCallback as useCallback2 } from "react";
|
|
2444
2308
|
var useBuyCollectable = ({
|
|
2445
2309
|
onSuccess,
|
|
2446
2310
|
onError,
|
|
@@ -2462,7 +2326,7 @@ var useBuyCollectable = ({
|
|
|
2462
2326
|
onTransactionSent,
|
|
2463
2327
|
onPaymentModalLoaded
|
|
2464
2328
|
});
|
|
2465
|
-
const buy =
|
|
2329
|
+
const buy = useCallback2(
|
|
2466
2330
|
(props) => {
|
|
2467
2331
|
if (!machine || isLoading) return;
|
|
2468
2332
|
setPaymentLoadingModalOpen(true);
|
|
@@ -2538,11 +2402,8 @@ export {
|
|
|
2538
2402
|
fetchGenerateBuyTransaction,
|
|
2539
2403
|
generateBuyTransactionOptions,
|
|
2540
2404
|
useGenerateBuyTransaction,
|
|
2541
|
-
|
|
2542
|
-
useSwitchChainModal,
|
|
2543
|
-
switchChainModal_default,
|
|
2544
|
-
useTransactionMachine,
|
|
2405
|
+
useGetReceiptFromHash,
|
|
2545
2406
|
useCancelOrder,
|
|
2546
2407
|
useBuyCollectable
|
|
2547
2408
|
};
|
|
2548
|
-
//# sourceMappingURL=chunk-
|
|
2409
|
+
//# sourceMappingURL=chunk-GLOIEUWC.js.map
|