@multiversx/sdk-dapp-liquidity 2.0.0 → 2.1.0-alpha.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/helpers/assertRateConfirmationMatchesIntent.d.ts +8 -0
- package/helpers/assertRateConfirmationMatchesIntent.js +24 -0
- package/helpers/assertRateConfirmationMatchesIntent.mjs +23 -0
- package/helpers/index.d.ts +2 -0
- package/helpers/index.js +4 -0
- package/helpers/index.mjs +4 -0
- package/helpers/safeImageUrl.d.ts +1 -0
- package/helpers/safeImageUrl.js +24 -0
- package/helpers/safeImageUrl.mjs +23 -0
- package/helpers/serializeTransaction.js +1 -1
- package/helpers/serializeTransaction.mjs +1 -1
- package/helpers/tests/assertRateConfirmationMatchesIntent.spec.d.ts +1 -0
- package/helpers/tests/assertRateConfirmationMatchesIntent.spec.js +64 -0
- package/helpers/tests/assertRateConfirmationMatchesIntent.spec.mjs +62 -0
- package/helpers/tests/safeImageUrl.spec.d.ts +1 -0
- package/helpers/tests/safeImageUrl.spec.js +49 -0
- package/helpers/tests/safeImageUrl.spec.mjs +47 -0
- package/helpers/tests/serializeTransaction.spec.d.ts +1 -0
- package/helpers/tests/serializeTransaction.spec.js +37 -0
- package/helpers/tests/serializeTransaction.spec.mjs +35 -0
- package/index.js +7 -3
- package/index.mjs +10 -6
- package/package.json +13 -8
- package/react.esm-7GsOwMPq.js +11815 -0
- package/react.esm-CU-Iqz8D.mjs +11796 -0
- package/reactjs/adapters/SuiAdapter.d.ts +14 -0
- package/reactjs/adapters/SuiAdapter.js +31 -2
- package/reactjs/adapters/SuiAdapter.mjs +31 -2
- package/reactjs/components/BridgeForm/Deposit.js +9 -7
- package/reactjs/components/BridgeForm/Deposit.mjs +8 -6
- package/reactjs/components/BridgeForm/Transfer.js +8 -6
- package/reactjs/components/BridgeForm/Transfer.mjs +7 -5
- package/reactjs/components/BridgeHistory/BridgeHistory.js +20 -6
- package/reactjs/components/BridgeHistory/BridgeHistory.mjs +20 -6
- package/reactjs/components/Connect/BridgeConnectButton.js +2 -1
- package/reactjs/components/Connect/BridgeConnectButton.mjs +2 -1
- package/reactjs/components/CopyButton/CopyButton.mjs +2 -2
- package/reactjs/components/TokenSelector/components/ChainSelect/components/ChainOptionLabel.js +5 -1
- package/reactjs/components/TokenSelector/components/ChainSelect/components/ChainOptionLabel.mjs +6 -2
- package/reactjs/components/TokenSelector/components/ChainSelect/components/SelectedChainOption.js +5 -1
- package/reactjs/components/TokenSelector/components/ChainSelect/components/SelectedChainOption.mjs +6 -2
- package/reactjs/components/TokenSelector/components/TokenIcon.js +2 -1
- package/reactjs/components/TokenSelector/components/TokenIcon.mjs +2 -1
- package/reactjs/context/Web3AppProvider.js +4 -2
- package/reactjs/context/Web3AppProvider.mjs +6 -4
- package/reactjs/hooks/tests/useGenericSignMessage.spec.d.ts +1 -0
- package/reactjs/hooks/tests/useGenericSignMessage.spec.js +69 -0
- package/reactjs/hooks/tests/useGenericSignMessage.spec.mjs +67 -0
- package/reactjs/hooks/tests/useSignTransaction.spec.d.ts +1 -0
- package/reactjs/hooks/tests/useSignTransaction.spec.js +196 -0
- package/reactjs/hooks/tests/useSignTransaction.spec.mjs +194 -0
- package/reactjs/hooks/useBridgeFormik.js +5 -0
- package/reactjs/hooks/useBridgeFormik.mjs +5 -0
- package/reactjs/hooks/useFetchTokens.js +4 -2
- package/reactjs/hooks/useFetchTokens.mjs +4 -2
- package/reactjs/hooks/useGenericSignMessage.js +23 -3
- package/reactjs/hooks/useGenericSignMessage.mjs +23 -3
- package/reactjs/hooks/useSignTransaction.js +27 -1
- package/reactjs/hooks/useSignTransaction.mjs +28 -2
- package/reactjs/index.js +3 -3
- package/reactjs/index.mjs +6 -6
- package/reactjs/init/init.d.ts +1 -0
- package/reactjs/init/init.js +11 -3
- package/reactjs/init/init.mjs +11 -3
- package/reactjs/queries/index.js +3 -3
- package/reactjs/queries/index.mjs +7 -7
- package/reactjs/queries/useCheckAccount.query.js +1 -1
- package/reactjs/queries/useCheckAccount.query.mjs +1 -1
- package/reactjs/queries/useGetAllTokens.query.js +1 -1
- package/reactjs/queries/useGetAllTokens.query.mjs +1 -1
- package/reactjs/queries/useGetChains.query.js +1 -1
- package/reactjs/queries/useGetChains.query.mjs +1 -1
- package/reactjs/queries/useGetHistory.query.d.ts +1 -1
- package/reactjs/queries/useGetHistory.query.js +10 -9
- package/reactjs/queries/useGetHistory.query.mjs +12 -11
- package/reactjs/queries/useGetMvxTokensBalances.query.d.ts +1 -1
- package/reactjs/queries/useGetMvxTokensBalances.query.js +9 -14
- package/reactjs/queries/useGetMvxTokensBalances.query.mjs +12 -17
- package/reactjs/queries/useGetNonMvxTokensBalances.query.d.ts +1 -1
- package/reactjs/queries/useGetNonMvxTokensBalances.query.js +8 -8
- package/reactjs/queries/useGetNonMvxTokensBalances.query.mjs +11 -11
- package/types/errors.d.ts +3 -0
- package/types/errors.js +10 -0
- package/types/errors.mjs +9 -0
- package/reactjs/hooks/useSignTransaction.d.ts +0 -511
|
@@ -2,7 +2,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { faCheck } from "@fortawesome/free-solid-svg-icons/faCheck";
|
|
3
3
|
import { faCopy } from "@fortawesome/free-solid-svg-icons/faCopy";
|
|
4
4
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
5
|
-
import
|
|
5
|
+
import React__default from "react";
|
|
6
6
|
import { copyTextToClipboard } from "./utils/copyToClipboard.mjs";
|
|
7
7
|
import { MxButton } from "../base/MxButton/MxButton.mjs";
|
|
8
8
|
const CopyButton = ({
|
|
@@ -10,7 +10,7 @@ const CopyButton = ({
|
|
|
10
10
|
className = "",
|
|
11
11
|
"data-testid": dataTestId
|
|
12
12
|
}) => {
|
|
13
|
-
const [copyResult, setCopyResut] =
|
|
13
|
+
const [copyResult, setCopyResut] = React__default.useState({
|
|
14
14
|
default: true,
|
|
15
15
|
success: false
|
|
16
16
|
});
|
package/reactjs/components/TokenSelector/components/ChainSelect/components/ChainOptionLabel.js
CHANGED
|
@@ -8,6 +8,7 @@ require("bignumber.js");
|
|
|
8
8
|
require("../../../../../constants/index.js");
|
|
9
9
|
require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount");
|
|
10
10
|
const reactjs_utils_mxClsx = require("../../../../../utils/mxClsx.js");
|
|
11
|
+
const helpers_safeImageUrl = require("../../../../../../helpers/safeImageUrl.js");
|
|
11
12
|
const allNetworks = require("../../../../../../all-networks-NYACMyeN.js");
|
|
12
13
|
const reactjs_constants_chains = require("../../../../../constants/chains.js");
|
|
13
14
|
const ChainOptionLabel = ({
|
|
@@ -23,7 +24,10 @@ const ChainOptionLabel = ({
|
|
|
23
24
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `chain-image liq-mr-2 ${inDropdownClass}`, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "liq-h-6 liq-w-6 liq-flex-shrink-0 liq-overflow-hidden", children: chain.pngUrl ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
24
25
|
"img",
|
|
25
26
|
{
|
|
26
|
-
src:
|
|
27
|
+
src: helpers_safeImageUrl.safeImageUrl(
|
|
28
|
+
chain.pngUrl,
|
|
29
|
+
reactjs_constants_chains.chainIdentifier[chain.name]
|
|
30
|
+
),
|
|
27
31
|
alt: "",
|
|
28
32
|
loading: "lazy",
|
|
29
33
|
className: reactjs_utils_mxClsx.mxClsx("liq-h-full liq-w-full", {
|
package/reactjs/components/TokenSelector/components/ChainSelect/components/ChainOptionLabel.mjs
CHANGED
|
@@ -5,8 +5,9 @@ import "bignumber.js";
|
|
|
5
5
|
import "../../../../../constants/index.mjs";
|
|
6
6
|
import "@multiversx/sdk-dapp-utils/out/helpers/parseAmount";
|
|
7
7
|
import { mxClsx } from "../../../../../utils/mxClsx.mjs";
|
|
8
|
+
import { safeImageUrl } from "../../../../../../helpers/safeImageUrl.mjs";
|
|
8
9
|
import { A as AllNetworks } from "../../../../../../all-networks-EJIVYZ_i.mjs";
|
|
9
|
-
import {
|
|
10
|
+
import { ALL_NETWORK_ID, chainIdentifier } from "../../../../../constants/chains.mjs";
|
|
10
11
|
const ChainOptionLabel = ({
|
|
11
12
|
chain,
|
|
12
13
|
inDropdown = false
|
|
@@ -20,7 +21,10 @@ const ChainOptionLabel = ({
|
|
|
20
21
|
/* @__PURE__ */ jsx("div", { className: `chain-image liq-mr-2 ${inDropdownClass}`, children: /* @__PURE__ */ jsx("div", { className: "liq-h-6 liq-w-6 liq-flex-shrink-0 liq-overflow-hidden", children: chain.pngUrl ? /* @__PURE__ */ jsx(
|
|
21
22
|
"img",
|
|
22
23
|
{
|
|
23
|
-
src:
|
|
24
|
+
src: safeImageUrl(
|
|
25
|
+
chain.pngUrl,
|
|
26
|
+
chainIdentifier[chain.name]
|
|
27
|
+
),
|
|
24
28
|
alt: "",
|
|
25
29
|
loading: "lazy",
|
|
26
30
|
className: mxClsx("liq-h-full liq-w-full", {
|
package/reactjs/components/TokenSelector/components/ChainSelect/components/SelectedChainOption.js
CHANGED
|
@@ -9,6 +9,7 @@ require("bignumber.js");
|
|
|
9
9
|
require("../../../../../constants/index.js");
|
|
10
10
|
require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount");
|
|
11
11
|
const reactjs_utils_mxClsx = require("../../../../../utils/mxClsx.js");
|
|
12
|
+
const helpers_safeImageUrl = require("../../../../../../helpers/safeImageUrl.js");
|
|
12
13
|
const allNetworks = require("../../../../../../all-networks-NYACMyeN.js");
|
|
13
14
|
const reactjs_constants_chains = require("../../../../../constants/chains.js");
|
|
14
15
|
const SelectedChainOption = ({
|
|
@@ -26,7 +27,10 @@ const SelectedChainOption = ({
|
|
|
26
27
|
children: (chain == null ? void 0 : chain.pngUrl) ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
27
28
|
"img",
|
|
28
29
|
{
|
|
29
|
-
src:
|
|
30
|
+
src: helpers_safeImageUrl.safeImageUrl(
|
|
31
|
+
chain.pngUrl,
|
|
32
|
+
reactjs_constants_chains.chainIdentifier[chain.name]
|
|
33
|
+
),
|
|
30
34
|
alt: "",
|
|
31
35
|
loading: "lazy",
|
|
32
36
|
className: reactjs_utils_mxClsx.mxClsx("liq-h-full liq-w-full", {
|
package/reactjs/components/TokenSelector/components/ChainSelect/components/SelectedChainOption.mjs
CHANGED
|
@@ -6,8 +6,9 @@ import "bignumber.js";
|
|
|
6
6
|
import "../../../../../constants/index.mjs";
|
|
7
7
|
import "@multiversx/sdk-dapp-utils/out/helpers/parseAmount";
|
|
8
8
|
import { mxClsx } from "../../../../../utils/mxClsx.mjs";
|
|
9
|
+
import { safeImageUrl } from "../../../../../../helpers/safeImageUrl.mjs";
|
|
9
10
|
import { A as AllNetworks } from "../../../../../../all-networks-EJIVYZ_i.mjs";
|
|
10
|
-
import {
|
|
11
|
+
import { ALL_NETWORK_ID, chainIdentifier } from "../../../../../constants/chains.mjs";
|
|
11
12
|
const SelectedChainOption = ({
|
|
12
13
|
...props
|
|
13
14
|
}) => {
|
|
@@ -23,7 +24,10 @@ const SelectedChainOption = ({
|
|
|
23
24
|
children: (chain == null ? void 0 : chain.pngUrl) ? /* @__PURE__ */ jsx(
|
|
24
25
|
"img",
|
|
25
26
|
{
|
|
26
|
-
src:
|
|
27
|
+
src: safeImageUrl(
|
|
28
|
+
chain.pngUrl,
|
|
29
|
+
chainIdentifier[chain.name]
|
|
30
|
+
),
|
|
27
31
|
alt: "",
|
|
28
32
|
loading: "lazy",
|
|
29
33
|
className: mxClsx("liq-h-full liq-w-full", {
|
|
@@ -5,6 +5,7 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
5
5
|
const faDiamond = require("@fortawesome/free-solid-svg-icons/faDiamond");
|
|
6
6
|
const reactFontawesome = require("@fortawesome/react-fontawesome");
|
|
7
7
|
const React = require("react");
|
|
8
|
+
const helpers_safeImageUrl = require("../../../../helpers/safeImageUrl.js");
|
|
8
9
|
const _default = require("../../../../default-H3AbmzFV.js");
|
|
9
10
|
const reactjs_utils_mxClsx = require("../../../utils/mxClsx.js");
|
|
10
11
|
const TokenIcon = ({
|
|
@@ -20,7 +21,7 @@ const TokenIcon = ({
|
|
|
20
21
|
return token.pngUrl && token.pngUrl !== "" ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
21
22
|
"img",
|
|
22
23
|
{
|
|
23
|
-
src: token.pngUrl,
|
|
24
|
+
src: helpers_safeImageUrl.safeImageUrl(token.pngUrl, _default.DefaultIcon),
|
|
24
25
|
alt: "",
|
|
25
26
|
className: "liq-asset-icon liq-sm liq-p-0"
|
|
26
27
|
}
|
|
@@ -2,6 +2,7 @@ import { jsx, Fragment } from "react/jsx-runtime";
|
|
|
2
2
|
import { faDiamond } from "@fortawesome/free-solid-svg-icons/faDiamond";
|
|
3
3
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
4
4
|
import { useCallback, useMemo } from "react";
|
|
5
|
+
import { safeImageUrl } from "../../../../helpers/safeImageUrl.mjs";
|
|
5
6
|
import { D as DefaultIcon } from "../../../../default-BYtXv70Z.mjs";
|
|
6
7
|
import { mxClsx } from "../../../utils/mxClsx.mjs";
|
|
7
8
|
const TokenIcon = ({
|
|
@@ -17,7 +18,7 @@ const TokenIcon = ({
|
|
|
17
18
|
return token.pngUrl && token.pngUrl !== "" ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
18
19
|
"img",
|
|
19
20
|
{
|
|
20
|
-
src: token.pngUrl,
|
|
21
|
+
src: safeImageUrl(token.pngUrl, DefaultIcon),
|
|
21
22
|
alt: "",
|
|
22
23
|
className: "liq-asset-icon liq-sm liq-p-0"
|
|
23
24
|
}
|
|
@@ -5,8 +5,6 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
5
5
|
const reactQuery = require("@tanstack/react-query");
|
|
6
6
|
const React = require("react");
|
|
7
7
|
const wagmi = require("wagmi");
|
|
8
|
-
const reactjs_context_queryClient = require("./queryClient.js");
|
|
9
|
-
const queryClient = reactjs_context_queryClient.getQueryClient();
|
|
10
8
|
const Web3AppContext = React.createContext(
|
|
11
9
|
void 0
|
|
12
10
|
);
|
|
@@ -22,6 +20,10 @@ function Web3AppProvider({
|
|
|
22
20
|
latestMvxTransactionHash,
|
|
23
21
|
resetMvxTransactionHash
|
|
24
22
|
}) {
|
|
23
|
+
const [queryClient] = React.useState(() => new reactQuery.QueryClient());
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
queryClient.invalidateQueries();
|
|
26
|
+
}, [nativeAuthToken]);
|
|
25
27
|
const value = React.useMemo(() => {
|
|
26
28
|
return {
|
|
27
29
|
config,
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
-
import { createContext, useMemo } from "react";
|
|
2
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
+
import { createContext, useState, useEffect, useMemo } from "react";
|
|
4
4
|
import { WagmiProvider } from "wagmi";
|
|
5
|
-
import { getQueryClient } from "./queryClient.mjs";
|
|
6
|
-
const queryClient = getQueryClient();
|
|
7
5
|
const Web3AppContext = createContext(
|
|
8
6
|
void 0
|
|
9
7
|
);
|
|
@@ -19,6 +17,10 @@ function Web3AppProvider({
|
|
|
19
17
|
latestMvxTransactionHash,
|
|
20
18
|
resetMvxTransactionHash
|
|
21
19
|
}) {
|
|
20
|
+
const [queryClient] = useState(() => new QueryClient());
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
queryClient.invalidateQueries();
|
|
23
|
+
}, [nativeAuthToken]);
|
|
22
24
|
const value = useMemo(() => {
|
|
23
25
|
return {
|
|
24
26
|
config,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
const react = require("@reown/appkit/react");
|
|
4
|
+
const react_esm = require("../../../react.esm-7GsOwMPq.js");
|
|
5
|
+
const wagmi = require("wagmi");
|
|
6
|
+
const reactjs_hooks_useGenericSignMessage = require("../useGenericSignMessage.js");
|
|
7
|
+
jest.mock("../useAccount", () => ({
|
|
8
|
+
useAccount: jest.fn(() => ({
|
|
9
|
+
address: void 0,
|
|
10
|
+
isConnected: true
|
|
11
|
+
}))
|
|
12
|
+
}));
|
|
13
|
+
const mockUseAppKitNetworkCore = jest.mocked(react.useAppKitNetworkCore);
|
|
14
|
+
const mockUseAppKitProvider = jest.mocked(react.useAppKitProvider);
|
|
15
|
+
const mockUseSignMessage = jest.mocked(wagmi.useSignMessage);
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
mockUseSignMessage.mockReturnValue({
|
|
18
|
+
signMessageAsync: jest.fn(),
|
|
19
|
+
data: void 0,
|
|
20
|
+
error: null,
|
|
21
|
+
isError: false,
|
|
22
|
+
isIdle: true,
|
|
23
|
+
isPending: false,
|
|
24
|
+
isSuccess: false,
|
|
25
|
+
reset: jest.fn(),
|
|
26
|
+
status: "idle",
|
|
27
|
+
variables: void 0,
|
|
28
|
+
context: void 0,
|
|
29
|
+
failureCount: 0,
|
|
30
|
+
failureReason: null,
|
|
31
|
+
isPaused: false,
|
|
32
|
+
submittedAt: 0,
|
|
33
|
+
mutate: jest.fn(),
|
|
34
|
+
mutateAsync: jest.fn(),
|
|
35
|
+
signMessage: jest.fn()
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe("useGenericSignMessage — Sui signMessage", () => {
|
|
39
|
+
const suiRequest = jest.fn();
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
suiRequest.mockReset();
|
|
42
|
+
mockUseAppKitNetworkCore.mockReturnValue({
|
|
43
|
+
caipNetwork: { chainNamespace: "sui" }
|
|
44
|
+
});
|
|
45
|
+
mockUseAppKitProvider.mockImplementation((namespace) => {
|
|
46
|
+
if (namespace === "sui") {
|
|
47
|
+
return { walletProvider: { request: suiRequest } };
|
|
48
|
+
}
|
|
49
|
+
return { walletProvider: void 0 };
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it("signs a valid short message successfully", async () => {
|
|
53
|
+
suiRequest.mockResolvedValue({ signature: "sui-message-sig" });
|
|
54
|
+
const { result } = react_esm.renderHook(() => reactjs_hooks_useGenericSignMessage.useGenericSignMessage());
|
|
55
|
+
const sig = await result.current.signMessage("hello world");
|
|
56
|
+
expect(sig).toBe("sui-message-sig");
|
|
57
|
+
expect(suiRequest).toHaveBeenCalledWith(
|
|
58
|
+
expect.objectContaining({ method: "sui_signPersonalMessage" })
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
it("throws when message payload exceeds 32 KiB", async () => {
|
|
62
|
+
const largeMessage = "a".repeat(32 * 1024 + 1);
|
|
63
|
+
const { result } = react_esm.renderHook(() => reactjs_hooks_useGenericSignMessage.useGenericSignMessage());
|
|
64
|
+
await expect(result.current.signMessage(largeMessage)).rejects.toThrow(
|
|
65
|
+
"maximum size"
|
|
66
|
+
);
|
|
67
|
+
expect(suiRequest).not.toHaveBeenCalled();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useAppKitNetworkCore, useAppKitProvider } from "@reown/appkit/react";
|
|
2
|
+
import { r as renderHook } from "../../../react.esm-CU-Iqz8D.mjs";
|
|
3
|
+
import { useSignMessage } from "wagmi";
|
|
4
|
+
import { useGenericSignMessage } from "../useGenericSignMessage.mjs";
|
|
5
|
+
jest.mock("../useAccount", () => ({
|
|
6
|
+
useAccount: jest.fn(() => ({
|
|
7
|
+
address: void 0,
|
|
8
|
+
isConnected: true
|
|
9
|
+
}))
|
|
10
|
+
}));
|
|
11
|
+
const mockUseAppKitNetworkCore = jest.mocked(useAppKitNetworkCore);
|
|
12
|
+
const mockUseAppKitProvider = jest.mocked(useAppKitProvider);
|
|
13
|
+
const mockUseSignMessage = jest.mocked(useSignMessage);
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
mockUseSignMessage.mockReturnValue({
|
|
16
|
+
signMessageAsync: jest.fn(),
|
|
17
|
+
data: void 0,
|
|
18
|
+
error: null,
|
|
19
|
+
isError: false,
|
|
20
|
+
isIdle: true,
|
|
21
|
+
isPending: false,
|
|
22
|
+
isSuccess: false,
|
|
23
|
+
reset: jest.fn(),
|
|
24
|
+
status: "idle",
|
|
25
|
+
variables: void 0,
|
|
26
|
+
context: void 0,
|
|
27
|
+
failureCount: 0,
|
|
28
|
+
failureReason: null,
|
|
29
|
+
isPaused: false,
|
|
30
|
+
submittedAt: 0,
|
|
31
|
+
mutate: jest.fn(),
|
|
32
|
+
mutateAsync: jest.fn(),
|
|
33
|
+
signMessage: jest.fn()
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe("useGenericSignMessage — Sui signMessage", () => {
|
|
37
|
+
const suiRequest = jest.fn();
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
suiRequest.mockReset();
|
|
40
|
+
mockUseAppKitNetworkCore.mockReturnValue({
|
|
41
|
+
caipNetwork: { chainNamespace: "sui" }
|
|
42
|
+
});
|
|
43
|
+
mockUseAppKitProvider.mockImplementation((namespace) => {
|
|
44
|
+
if (namespace === "sui") {
|
|
45
|
+
return { walletProvider: { request: suiRequest } };
|
|
46
|
+
}
|
|
47
|
+
return { walletProvider: void 0 };
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it("signs a valid short message successfully", async () => {
|
|
51
|
+
suiRequest.mockResolvedValue({ signature: "sui-message-sig" });
|
|
52
|
+
const { result } = renderHook(() => useGenericSignMessage());
|
|
53
|
+
const sig = await result.current.signMessage("hello world");
|
|
54
|
+
expect(sig).toBe("sui-message-sig");
|
|
55
|
+
expect(suiRequest).toHaveBeenCalledWith(
|
|
56
|
+
expect.objectContaining({ method: "sui_signPersonalMessage" })
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
it("throws when message payload exceeds 32 KiB", async () => {
|
|
60
|
+
const largeMessage = "a".repeat(32 * 1024 + 1);
|
|
61
|
+
const { result } = renderHook(() => useGenericSignMessage());
|
|
62
|
+
await expect(result.current.signMessage(largeMessage)).rejects.toThrow(
|
|
63
|
+
"maximum size"
|
|
64
|
+
);
|
|
65
|
+
expect(suiRequest).not.toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
const react = require("@reown/appkit/react");
|
|
4
|
+
const react_esm = require("../../../react.esm-7GsOwMPq.js");
|
|
5
|
+
const wagmi = require("wagmi");
|
|
6
|
+
const reactjs_hooks_useSignTransaction = require("../useSignTransaction.js");
|
|
7
|
+
jest.mock("@reown/appkit-adapter-solana/react", () => ({
|
|
8
|
+
useAppKitConnection: jest.fn(() => ({ connection: null }))
|
|
9
|
+
}));
|
|
10
|
+
jest.mock("@solana/web3.js", () => ({
|
|
11
|
+
PublicKey: jest.fn(),
|
|
12
|
+
Transaction: jest.fn(() => ({ add: jest.fn().mockReturnThis() })),
|
|
13
|
+
TransactionInstruction: jest.fn()
|
|
14
|
+
}));
|
|
15
|
+
const mockUseAppKitProvider = jest.mocked(react.useAppKitProvider);
|
|
16
|
+
const mockUseAppKitAccount = jest.mocked(react.useAppKitAccount);
|
|
17
|
+
const mockUseSendTransaction = jest.mocked(wagmi.useSendTransaction);
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
mockUseSendTransaction.mockReturnValue({
|
|
20
|
+
data: void 0,
|
|
21
|
+
sendTransactionAsync: jest.fn(),
|
|
22
|
+
error: null,
|
|
23
|
+
isError: false,
|
|
24
|
+
isIdle: true,
|
|
25
|
+
isPending: false,
|
|
26
|
+
isSuccess: false,
|
|
27
|
+
reset: jest.fn(),
|
|
28
|
+
sendTransaction: jest.fn(),
|
|
29
|
+
status: "idle",
|
|
30
|
+
variables: void 0,
|
|
31
|
+
context: void 0,
|
|
32
|
+
failureCount: 0,
|
|
33
|
+
failureReason: null,
|
|
34
|
+
isPaused: false,
|
|
35
|
+
submittedAt: 0,
|
|
36
|
+
mutate: jest.fn(),
|
|
37
|
+
mutateAsync: jest.fn()
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
const CONNECTED_SUI_ADDRESS = "0xabc123def456aaa000111222333444555666777888999aaabbbcccdddeeefff00";
|
|
41
|
+
function setupSuiMocks(suiRequest) {
|
|
42
|
+
mockUseAppKitProvider.mockImplementation((namespace) => {
|
|
43
|
+
if (namespace === "sui") {
|
|
44
|
+
return { walletProvider: { request: suiRequest } };
|
|
45
|
+
}
|
|
46
|
+
return { walletProvider: void 0 };
|
|
47
|
+
});
|
|
48
|
+
mockUseAppKitAccount.mockImplementation((opts) => {
|
|
49
|
+
if ((opts == null ? void 0 : opts.namespace) === "sui") {
|
|
50
|
+
return {
|
|
51
|
+
address: CONNECTED_SUI_ADDRESS,
|
|
52
|
+
isConnected: true,
|
|
53
|
+
status: "connected"
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
address: void 0,
|
|
58
|
+
isConnected: false,
|
|
59
|
+
status: "disconnected"
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
describe("useSignTransaction — signSuiTransaction", () => {
|
|
64
|
+
const validBase64 = btoa("valid transaction bytes");
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
mockUseSendTransaction.mockReturnValue({
|
|
67
|
+
data: void 0,
|
|
68
|
+
sendTransactionAsync: jest.fn(),
|
|
69
|
+
error: null,
|
|
70
|
+
isError: false,
|
|
71
|
+
isIdle: true,
|
|
72
|
+
isPending: false,
|
|
73
|
+
isSuccess: false,
|
|
74
|
+
reset: jest.fn(),
|
|
75
|
+
sendTransaction: jest.fn(),
|
|
76
|
+
status: "idle",
|
|
77
|
+
variables: void 0,
|
|
78
|
+
context: void 0,
|
|
79
|
+
failureCount: 0,
|
|
80
|
+
failureReason: null,
|
|
81
|
+
isPaused: false,
|
|
82
|
+
submittedAt: 0,
|
|
83
|
+
mutate: jest.fn(),
|
|
84
|
+
mutateAsync: jest.fn()
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it("succeeds with valid base64 payload", async () => {
|
|
88
|
+
const mockRequest = jest.fn().mockResolvedValue({ signature: "sui-sig-ok" });
|
|
89
|
+
setupSuiMocks(mockRequest);
|
|
90
|
+
const { result } = react_esm.renderHook(() => reactjs_hooks_useSignTransaction.useSignTransaction());
|
|
91
|
+
const sig = await result.current.sui.signTransaction({
|
|
92
|
+
transaction: validBase64,
|
|
93
|
+
address: CONNECTED_SUI_ADDRESS
|
|
94
|
+
});
|
|
95
|
+
expect(sig).toBe("sui-sig-ok");
|
|
96
|
+
expect(mockRequest).toHaveBeenCalledWith(
|
|
97
|
+
expect.objectContaining({ method: "sui_signTransaction" })
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
it("throws when payload is not valid base64", async () => {
|
|
101
|
+
const mockRequest = jest.fn();
|
|
102
|
+
setupSuiMocks(mockRequest);
|
|
103
|
+
const { result } = react_esm.renderHook(() => reactjs_hooks_useSignTransaction.useSignTransaction());
|
|
104
|
+
await expect(
|
|
105
|
+
result.current.sui.signTransaction({
|
|
106
|
+
transaction: "not-valid-base64!!!",
|
|
107
|
+
address: CONNECTED_SUI_ADDRESS
|
|
108
|
+
})
|
|
109
|
+
).rejects.toThrow("not valid base64");
|
|
110
|
+
expect(mockRequest).not.toHaveBeenCalled();
|
|
111
|
+
});
|
|
112
|
+
it("throws when payload exceeds 32 KiB", async () => {
|
|
113
|
+
const mockRequest = jest.fn();
|
|
114
|
+
setupSuiMocks(mockRequest);
|
|
115
|
+
const largeBytes = new Uint8Array(32 * 1024 + 1);
|
|
116
|
+
const largeBase64 = btoa(String.fromCharCode(...largeBytes));
|
|
117
|
+
const { result } = react_esm.renderHook(() => reactjs_hooks_useSignTransaction.useSignTransaction());
|
|
118
|
+
await expect(
|
|
119
|
+
result.current.sui.signTransaction({
|
|
120
|
+
transaction: largeBase64,
|
|
121
|
+
address: CONNECTED_SUI_ADDRESS
|
|
122
|
+
})
|
|
123
|
+
).rejects.toThrow("maximum size");
|
|
124
|
+
expect(mockRequest).not.toHaveBeenCalled();
|
|
125
|
+
});
|
|
126
|
+
it("throws when payload is an empty string", async () => {
|
|
127
|
+
const mockRequest = jest.fn();
|
|
128
|
+
setupSuiMocks(mockRequest);
|
|
129
|
+
const { result } = react_esm.renderHook(() => reactjs_hooks_useSignTransaction.useSignTransaction());
|
|
130
|
+
await expect(
|
|
131
|
+
result.current.sui.signTransaction({
|
|
132
|
+
transaction: "",
|
|
133
|
+
address: CONNECTED_SUI_ADDRESS
|
|
134
|
+
})
|
|
135
|
+
).rejects.toThrow("No Sui transaction bytes provided");
|
|
136
|
+
expect(mockRequest).not.toHaveBeenCalled();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe("useSignTransaction — signPSBT", () => {
|
|
140
|
+
it("forwards signInputs verbatim to btcWalletProvider.signPSBT", async () => {
|
|
141
|
+
const mockSignPSBT = jest.fn().mockResolvedValue({ psbt: "signed-psbt" });
|
|
142
|
+
mockUseAppKitProvider.mockImplementation((namespace) => {
|
|
143
|
+
if (namespace === "bip122") {
|
|
144
|
+
return { walletProvider: { signPSBT: mockSignPSBT } };
|
|
145
|
+
}
|
|
146
|
+
return { walletProvider: void 0 };
|
|
147
|
+
});
|
|
148
|
+
const { result } = react_esm.renderHook(() => reactjs_hooks_useSignTransaction.useSignTransaction());
|
|
149
|
+
const signInputs = [
|
|
150
|
+
{
|
|
151
|
+
address: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
|
|
152
|
+
index: 0,
|
|
153
|
+
sighashTypes: [1]
|
|
154
|
+
}
|
|
155
|
+
];
|
|
156
|
+
const params = {
|
|
157
|
+
psbt: "base64psbt==",
|
|
158
|
+
signInputs: [...signInputs],
|
|
159
|
+
broadcast: false
|
|
160
|
+
};
|
|
161
|
+
const originalSignInputs = params.signInputs;
|
|
162
|
+
const psbt = await result.current.bitcoin.signTransaction(params);
|
|
163
|
+
expect(mockSignPSBT).toHaveBeenCalledWith(
|
|
164
|
+
expect.objectContaining({
|
|
165
|
+
signInputs: [
|
|
166
|
+
{
|
|
167
|
+
address: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
|
|
168
|
+
index: 0,
|
|
169
|
+
sighashTypes: [1]
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
})
|
|
173
|
+
);
|
|
174
|
+
expect(mockSignPSBT).not.toHaveBeenCalledWith(
|
|
175
|
+
expect.objectContaining({ signInputs: [] })
|
|
176
|
+
);
|
|
177
|
+
expect(params.signInputs).toBe(originalSignInputs);
|
|
178
|
+
expect(params.signInputs).toEqual(signInputs);
|
|
179
|
+
expect(psbt).toBe("signed-psbt");
|
|
180
|
+
});
|
|
181
|
+
it("throws when btcWalletProvider is not available", async () => {
|
|
182
|
+
mockUseAppKitProvider.mockImplementation(
|
|
183
|
+
() => ({
|
|
184
|
+
walletProvider: void 0
|
|
185
|
+
})
|
|
186
|
+
);
|
|
187
|
+
const { result } = react_esm.renderHook(() => reactjs_hooks_useSignTransaction.useSignTransaction());
|
|
188
|
+
await expect(
|
|
189
|
+
result.current.bitcoin.signTransaction({
|
|
190
|
+
psbt: "base64psbt==",
|
|
191
|
+
signInputs: [],
|
|
192
|
+
broadcast: false
|
|
193
|
+
})
|
|
194
|
+
).rejects.toThrow("user is disconnected");
|
|
195
|
+
});
|
|
196
|
+
});
|