@coin-voyage/crypto 2.5.2-beta.0 → 2.5.2-beta.2
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/evm/create-default-evm-config.d.ts +1 -0
- package/dist/evm/provider/base-provider.d.ts +1 -2
- package/dist/evm/provider/base-provider.js +2 -2
- package/dist/evm/use-evm-transaction.js +3 -3
- package/dist/evm/use-sign-in-with-evm.js +4 -4
- package/dist/hooks/use-account-disconnect.js +1 -1
- package/dist/hooks/use-account.d.ts +1 -1
- package/dist/hooks/use-account.js +3 -3
- package/dist/hooks/use-universal-connect.d.ts +0 -7
- package/dist/hooks/use-universal-connect.js +2 -2
- package/package.json +1 -1
- package/dist/hooks/use-universal-connect.test.d.ts +0 -1
- package/dist/hooks/use-universal-connect.test.js +0 -51
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type PropsWithChildren } from "react";
|
|
2
2
|
import { EVMConfiguration } from "../create-default-evm-config";
|
|
3
|
-
export declare function EVMBaseProvider({ children, config,
|
|
3
|
+
export declare function EVMBaseProvider({ children, config, }: PropsWithChildren<{
|
|
4
4
|
config?: EVMConfiguration;
|
|
5
|
-
reconnectOnMount?: boolean;
|
|
6
5
|
}>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { WagmiProvider } from "wagmi";
|
|
4
4
|
import { createDefaultEVMConfig } from "../create-default-evm-config";
|
|
5
|
-
export function EVMBaseProvider({ children, config,
|
|
5
|
+
export function EVMBaseProvider({ children, config, }) {
|
|
6
6
|
const evmConfig = useMemo(() => createDefaultEVMConfig(config), [config]);
|
|
7
|
-
return (_jsx(WagmiProvider, { config: evmConfig.config, reconnectOnMount: reconnectOnMount, children: children }));
|
|
7
|
+
return (_jsx(WagmiProvider, { config: evmConfig.config, reconnectOnMount: Boolean(config?.reconnectOnMount), children: children }));
|
|
8
8
|
}
|
|
@@ -2,11 +2,11 @@ import { estimateFeesPerGas } from "viem/actions";
|
|
|
2
2
|
import { useChainId, useConfig, useSendTransaction, useSwitchChain, useWriteContract } from "wagmi";
|
|
3
3
|
import { GAS_ESTIMATION_ERROR, isUserRejectedError, SWITCH_CHAIN_ERROR, toTransactionError, USER_REJECTED_ERROR, walletError, } from "./errors";
|
|
4
4
|
export function useEVMTransaction() {
|
|
5
|
-
const { writeContractAsync } = useWriteContract();
|
|
6
|
-
const { sendTransactionAsync } = useSendTransaction();
|
|
5
|
+
const { mutateAsync: writeContractAsync } = useWriteContract();
|
|
6
|
+
const { mutateAsync: sendTransactionAsync } = useSendTransaction();
|
|
7
7
|
const config = useConfig();
|
|
8
8
|
const walletChainId = useChainId();
|
|
9
|
-
const { switchChainAsync } = useSwitchChain();
|
|
9
|
+
const { mutateAsync: switchChainAsync } = useSwitchChain();
|
|
10
10
|
const trySwitchChain = async (sourceChainId) => {
|
|
11
11
|
if (walletChainId === sourceChainId)
|
|
12
12
|
return;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useCallback, useMemo } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { useConnection, useConnect, useConnectors, useSignMessage } from "wagmi";
|
|
3
3
|
import { isWalletInstalled } from "../utils/is-wallet-installed";
|
|
4
4
|
import { toMessage } from "../utils/message";
|
|
5
5
|
import { generateNonce as generateDefaultNonce } from "../utils/nonce";
|
|
6
6
|
import { toBaseConnector } from "./utils";
|
|
7
7
|
export function useSignInWithEvm({ signIn, onError, generateNonce }) {
|
|
8
|
-
const { address, connector, isConnected } =
|
|
9
|
-
const { connectAsync } = useConnect();
|
|
10
|
-
const { signMessageAsync } = useSignMessage();
|
|
8
|
+
const { address, connector, isConnected } = useConnection();
|
|
9
|
+
const { mutateAsync: connectAsync } = useConnect();
|
|
10
|
+
const { mutateAsync: signMessageAsync } = useSignMessage();
|
|
11
11
|
const connectors = useConnectors();
|
|
12
12
|
const wallets = useMemo(() => Array.from(connectors)
|
|
13
13
|
.filter((c) => isWalletInstalled(c.id))
|
|
@@ -8,7 +8,7 @@ import { useAccount } from "./use-account";
|
|
|
8
8
|
export const useAccountDisconnect = () => {
|
|
9
9
|
const { accounts } = useAccount();
|
|
10
10
|
const bigmiConfig = useBigmiConfig();
|
|
11
|
-
const { disconnectAsync } = useDisconnect();
|
|
11
|
+
const { mutateAsync: disconnectAsync } = useDisconnect();
|
|
12
12
|
const { disconnect: solanaDisconnect } = useWallet();
|
|
13
13
|
const { disconnectWallet } = useDAppKit();
|
|
14
14
|
const disconnect = async (chainType) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Connector as UTXOConnector } from "@bigmi/client";
|
|
2
2
|
import { Account as BTCAccount } from "@bigmi/core";
|
|
3
3
|
import { ChainType } from "@coin-voyage/shared/types";
|
|
4
|
-
import type
|
|
4
|
+
import { type Connector } from "wagmi";
|
|
5
5
|
import type { WalletAdapterExtended } from "../solana/types";
|
|
6
6
|
import type { WalletProps } from "../types/wallet";
|
|
7
7
|
import type { SuiConnector } from "../types/wallet-connector";
|
|
@@ -2,7 +2,7 @@ import { useAccount as useBTCAccount } from "@bigmi/react";
|
|
|
2
2
|
import { ChainId, ChainType } from "@coin-voyage/shared/types";
|
|
3
3
|
import { useWalletConnection } from "@mysten/dapp-kit-react";
|
|
4
4
|
import { useWallet } from "@solana/wallet-adapter-react";
|
|
5
|
-
import {
|
|
5
|
+
import { useConnection } from "wagmi";
|
|
6
6
|
import { extendsWalletAdapter } from "../solana/utils";
|
|
7
7
|
import { getConnector } from "../utils";
|
|
8
8
|
import { useLastConnector } from "./use-last-connector";
|
|
@@ -110,7 +110,7 @@ const buildUtxoAccount = (btcAccount) => {
|
|
|
110
110
|
*/
|
|
111
111
|
export const useAccount = (args) => {
|
|
112
112
|
const { lastConnector } = useLastConnector();
|
|
113
|
-
const
|
|
113
|
+
const evmConnection = useConnection();
|
|
114
114
|
const { wallet } = useWallet();
|
|
115
115
|
const suiConnection = useWalletConnection();
|
|
116
116
|
const btcAccount = useBTCAccount();
|
|
@@ -118,7 +118,7 @@ export const useAccount = (args) => {
|
|
|
118
118
|
? getConnector(args?.selectedWallet.connectors, args.chainType ?? lastConnector?.chainType)
|
|
119
119
|
: undefined;
|
|
120
120
|
const accounts = [
|
|
121
|
-
buildEvmAccount(
|
|
121
|
+
buildEvmAccount(evmConnection),
|
|
122
122
|
buildSolanaAccount(wallet),
|
|
123
123
|
buildSuiAccount(suiConnection),
|
|
124
124
|
buildUtxoAccount(btcAccount),
|
|
@@ -11,13 +11,6 @@ interface UseUniversalConnectProps {
|
|
|
11
11
|
connector: any;
|
|
12
12
|
}) => void;
|
|
13
13
|
}
|
|
14
|
-
type SolanaConnectAdapter = {
|
|
15
|
-
connected: boolean;
|
|
16
|
-
connect: () => Promise<void>;
|
|
17
|
-
off: (event: "connect" | "error", listener: (value?: unknown) => void) => unknown;
|
|
18
|
-
once: (event: "connect" | "error", listener: (value?: unknown) => void) => unknown;
|
|
19
|
-
};
|
|
20
|
-
export declare function waitForSolanaWalletConnect(walletAdapter: SolanaConnectAdapter, timeoutMs?: number): Promise<void>;
|
|
21
14
|
export declare const useUniversalConnect: (props?: UseUniversalConnectProps) => {
|
|
22
15
|
connect: ({ walletConnector }: {
|
|
23
16
|
walletConnector: ChainTypeWalletConnector;
|
|
@@ -6,7 +6,7 @@ import { useCallback } from "react";
|
|
|
6
6
|
import { useConfig as useWagmiConfig, useConnect as useWagmiConnect } from "wagmi";
|
|
7
7
|
import { useLastConnector } from "./use-last-connector";
|
|
8
8
|
const SOLANA_CONNECT_TIMEOUT_MS = 30000;
|
|
9
|
-
|
|
9
|
+
function waitForSolanaWalletConnect(walletAdapter, timeoutMs = SOLANA_CONNECT_TIMEOUT_MS) {
|
|
10
10
|
if (walletAdapter.connected)
|
|
11
11
|
return Promise.resolve();
|
|
12
12
|
return new Promise((resolve, reject) => {
|
|
@@ -42,7 +42,7 @@ export const useUniversalConnect = (props) => {
|
|
|
42
42
|
const { select, disconnect, connected } = useWallet();
|
|
43
43
|
const { connectWallet } = useDAppKit();
|
|
44
44
|
const { onError, onSuccess, onSettled, onMutate } = props || {};
|
|
45
|
-
const { connectAsync } = useWagmiConnect({
|
|
45
|
+
const { mutateAsync: connectAsync } = useWagmiConnect({
|
|
46
46
|
config: evmConfig,
|
|
47
47
|
mutation: {
|
|
48
48
|
...props,
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { waitForSolanaWalletConnect } from "./use-universal-connect";
|
|
3
|
-
class FakeSolanaWalletAdapter {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.connected = false;
|
|
6
|
-
this.listeners = new Map();
|
|
7
|
-
this.connect = vi.fn(() => new Promise(() => { }));
|
|
8
|
-
}
|
|
9
|
-
once(event, listener) {
|
|
10
|
-
this.listeners.set(event, new Set([...(this.listeners.get(event) ?? []), listener]));
|
|
11
|
-
return this;
|
|
12
|
-
}
|
|
13
|
-
off(event, listener) {
|
|
14
|
-
this.listeners.get(event)?.delete(listener);
|
|
15
|
-
return this;
|
|
16
|
-
}
|
|
17
|
-
emit(event, value) {
|
|
18
|
-
for (const listener of this.listeners.get(event) ?? []) {
|
|
19
|
-
listener(value);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
listenerCount(event) {
|
|
23
|
-
return this.listeners.get(event)?.size ?? 0;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
describe("waitForSolanaWalletConnect", () => {
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
vi.useRealTimers();
|
|
29
|
-
});
|
|
30
|
-
it("removes listeners when a wallet connect attempt times out", async () => {
|
|
31
|
-
vi.useFakeTimers();
|
|
32
|
-
const adapter = new FakeSolanaWalletAdapter();
|
|
33
|
-
const result = waitForSolanaWalletConnect(adapter, 100);
|
|
34
|
-
expect(adapter.listenerCount("connect")).toBe(1);
|
|
35
|
-
expect(adapter.listenerCount("error")).toBe(1);
|
|
36
|
-
const rejection = expect(result).rejects.toThrow("Solana wallet connection timed out");
|
|
37
|
-
await vi.advanceTimersByTimeAsync(100);
|
|
38
|
-
await rejection;
|
|
39
|
-
expect(adapter.listenerCount("connect")).toBe(0);
|
|
40
|
-
expect(adapter.listenerCount("error")).toBe(0);
|
|
41
|
-
});
|
|
42
|
-
it("removes listeners after a successful wallet connect event", async () => {
|
|
43
|
-
vi.useFakeTimers();
|
|
44
|
-
const adapter = new FakeSolanaWalletAdapter();
|
|
45
|
-
const result = waitForSolanaWalletConnect(adapter, 100);
|
|
46
|
-
adapter.emit("connect");
|
|
47
|
-
await expect(result).resolves.toBeUndefined();
|
|
48
|
-
expect(adapter.listenerCount("connect")).toBe(0);
|
|
49
|
-
expect(adapter.listenerCount("error")).toBe(0);
|
|
50
|
-
});
|
|
51
|
-
});
|