@coin-voyage/crypto 2.2.1 → 2.2.3-beta.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/dist/evm/utils.d.ts +1 -1
- package/dist/evm/utils.js +1 -1
- package/dist/hooks/use-account-disconnect.js +4 -3
- package/dist/hooks/use-account.d.ts +1 -1
- package/dist/hooks/use-account.js +17 -3
- package/dist/hooks/use-connect-callback.d.ts +2 -2
- package/dist/hooks/use-installed-wallets.d.ts +1 -1
- package/dist/hooks/use-installed-wallets.js +27 -35
- package/dist/hooks/use-prepare-transaction.d.ts +1 -1
- package/dist/hooks/use-prepare-transaction.js +1 -1
- package/dist/hooks/use-universal-connect.js +27 -13
- package/dist/lib/config/chain.js +1 -8
- package/dist/lib/utils/connector.d.ts +1 -1
- package/dist/lib/utils/get-wallet-priority.js +1 -1
- package/dist/types/wallet.d.ts +1 -1
- package/dist/utxo/send-btc.js +1 -1
- package/package.json +2 -2
package/dist/evm/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainId } from "@coin-voyage/shared/
|
|
1
|
+
import { ChainId } from "@coin-voyage/shared/types";
|
|
2
2
|
import type { Connector, CreateConnectorFn } from "wagmi";
|
|
3
3
|
import { BaseConnector } from "../types/base-connector";
|
|
4
4
|
import type { CreateConnectorFnExtended } from "./types";
|
package/dist/evm/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainId } from "@coin-voyage/shared/
|
|
1
|
+
import { ChainId } from "@coin-voyage/shared/types";
|
|
2
2
|
import { getWalletIcon } from "../assets/icons";
|
|
3
3
|
export const ALCHEMY_KEY = "kikl1LthkvlPnpk8Y2eY3vqGSKVoRGFj";
|
|
4
4
|
export const extendConnector = (connector, id, name) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { disconnect as utxoDisconnect } from "@bigmi/client";
|
|
2
2
|
import { useConfig as useBigmiConfig } from "@bigmi/react";
|
|
3
|
-
import { ChainType } from "@coin-voyage/shared/
|
|
3
|
+
import { ChainType } from "@coin-voyage/shared/types";
|
|
4
4
|
import { useDisconnectWallet } from "@mysten/dapp-kit";
|
|
5
5
|
import { useWallet } from "@solana/wallet-adapter-react";
|
|
6
6
|
import { useDisconnect } from "wagmi";
|
|
@@ -26,13 +26,14 @@ export const useAccountDisconnect = () => {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
return async (account) => {
|
|
29
|
-
if (account) {
|
|
29
|
+
if (account?.isConnected) {
|
|
30
30
|
return disconnect(account.chainType);
|
|
31
31
|
}
|
|
32
32
|
// Disconnect all accounts if no specific account is provided
|
|
33
33
|
for (const acc of accounts) {
|
|
34
|
+
if (!acc.isConnected)
|
|
35
|
+
continue;
|
|
34
36
|
await disconnect(acc.chainType);
|
|
35
|
-
console.log(`Disconnected account on ${acc.chainType}`);
|
|
36
37
|
}
|
|
37
38
|
};
|
|
38
39
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connector as UTXOConnector } from "@bigmi/client";
|
|
2
2
|
import { Account as BTCAccount } from "@bigmi/core";
|
|
3
|
-
import { ChainType } from "@coin-voyage/shared/
|
|
3
|
+
import { ChainType } from "@coin-voyage/shared/types";
|
|
4
4
|
import type { Connector } from "wagmi";
|
|
5
5
|
import type { WalletAdapterExtended } from "../solana/types";
|
|
6
6
|
import type { WalletProps } from "../types/wallet";
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getAccount as getBtcAccount, watchAccount as watchBtcAccount, } from "@bigmi/client";
|
|
2
|
+
import { useConfig as useBigmiConfig } from "@bigmi/react";
|
|
3
|
+
import { ChainId, ChainType } from "@coin-voyage/shared/types";
|
|
3
4
|
import { useCurrentAccount, useCurrentWallet } from "@mysten/dapp-kit";
|
|
4
5
|
import { useWallet } from "@solana/wallet-adapter-react";
|
|
6
|
+
import { useCallback, useRef, useSyncExternalStore } from "react";
|
|
5
7
|
import { useAccount as useAccountInternal } from "wagmi";
|
|
6
8
|
import { getConnector } from "../lib/utils/connector";
|
|
7
9
|
import { extendsWalletAdapter } from "../solana/utils";
|
|
@@ -109,7 +111,19 @@ const buildUtxoAccount = (btcAccount) => {
|
|
|
109
111
|
*/
|
|
110
112
|
export const useAccount = (args) => {
|
|
111
113
|
const btcConfig = useBigmiConfig();
|
|
112
|
-
|
|
114
|
+
// Use @bigmi/client primitives directly instead of @bigmi/react's useAccount
|
|
115
|
+
// to fix "getServerSnapshot should be cached" error. The upstream hook passes
|
|
116
|
+
// an uncached getServerSnapshot to useSyncExternalStore, causing infinite loops
|
|
117
|
+
// during SSR/hydration in Next.js.
|
|
118
|
+
const btcSnapshotCache = useRef(getBtcAccount(btcConfig));
|
|
119
|
+
const btcSubscribe = useCallback((onChange) => watchBtcAccount(btcConfig, {
|
|
120
|
+
onChange: () => {
|
|
121
|
+
btcSnapshotCache.current = getBtcAccount(btcConfig);
|
|
122
|
+
onChange();
|
|
123
|
+
},
|
|
124
|
+
}), [btcConfig]);
|
|
125
|
+
const btcGetSnapshot = useCallback(() => btcSnapshotCache.current, []);
|
|
126
|
+
const btcAccount = useSyncExternalStore(btcSubscribe, btcGetSnapshot, btcGetSnapshot);
|
|
113
127
|
const wagmiAccount = useAccountInternal();
|
|
114
128
|
const { wallet } = useWallet();
|
|
115
129
|
const suiWallet = useCurrentWallet();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ChainId, ChainType } from "@coin-voyage/shared/
|
|
1
|
+
import { ChainId, ChainType } from "@coin-voyage/shared/types";
|
|
2
2
|
import React from "react";
|
|
3
3
|
export type useConnectCallbackProps = {
|
|
4
4
|
onConnect?: ({ address, chainId, connectorId, type, }: {
|
|
5
5
|
address: string;
|
|
6
|
-
chainId?:
|
|
6
|
+
chainId?: ChainId;
|
|
7
7
|
connectorId?: string;
|
|
8
8
|
type: ChainType;
|
|
9
9
|
}) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useConfig as useBigmiConfig } from "@bigmi/react";
|
|
2
|
-
import { ChainType } from "@coin-voyage/shared/
|
|
2
|
+
import { ChainType } from "@coin-voyage/shared/types";
|
|
3
3
|
import { useWallets } from "@mysten/dapp-kit";
|
|
4
4
|
import { WalletReadyState } from "@solana/wallet-adapter-base";
|
|
5
5
|
import { useWallet } from "@solana/wallet-adapter-react";
|
|
@@ -9,7 +9,6 @@ import { getConnectorIcon } from "../lib/utils/get-connector-icon";
|
|
|
9
9
|
import { getWalletPriority } from "../lib/utils/get-wallet-priority";
|
|
10
10
|
import { isWalletInstalled } from "../lib/utils/is-wallet-installed";
|
|
11
11
|
import { extendsWalletAdapter } from "../solana/utils";
|
|
12
|
-
const normalizeName = (name) => name.split(" ")[0].toLowerCase().trim();
|
|
13
12
|
export const useInstalledWallets = (filterChainType) => {
|
|
14
13
|
const bigmiConfig = useBigmiConfig?.() ?? null;
|
|
15
14
|
const wagmiConfig = useContext(WagmiContext) ?? null;
|
|
@@ -31,58 +30,51 @@ export const useInstalledWallets = (filterChainType) => {
|
|
|
31
30
|
}, [bigmiConfig?.connectors, wagmiConfig?.connectors, solanaWallets, suiWallets, filterChainType]);
|
|
32
31
|
};
|
|
33
32
|
const combineWalletLists = (utxoConnectorList, evmConnectorList, solanaWalletList, suiWalletList) => {
|
|
34
|
-
const
|
|
33
|
+
const allConnectors = [];
|
|
35
34
|
utxoConnectorList.forEach((utxo) => {
|
|
36
|
-
|
|
37
|
-
const normalizedName = normalizeName(utxoName);
|
|
38
|
-
const existing = walletMap.get(normalizedName) || {
|
|
35
|
+
allConnectors.push({
|
|
39
36
|
id: utxo.id,
|
|
40
|
-
name:
|
|
37
|
+
name: utxo.name,
|
|
41
38
|
icon: getConnectorIcon(utxo),
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
existing.connectors.push({ connector: utxo, chainType: ChainType.UTXO });
|
|
45
|
-
walletMap.set(normalizedName, existing);
|
|
39
|
+
connector: { connector: utxo, chainType: ChainType.UTXO },
|
|
40
|
+
});
|
|
46
41
|
});
|
|
47
42
|
evmConnectorList.forEach((evm) => {
|
|
48
|
-
|
|
49
|
-
const normalizedName = normalizeName(evmName);
|
|
50
|
-
const existing = walletMap.get(normalizedName) || {
|
|
43
|
+
allConnectors.push({
|
|
51
44
|
id: evm.id,
|
|
52
|
-
name:
|
|
45
|
+
name: evm?.displayName || evm?.name,
|
|
53
46
|
icon: getConnectorIcon(evm),
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
existing.connectors.push({ connector: evm, chainType: ChainType.EVM });
|
|
57
|
-
walletMap.set(normalizedName, existing);
|
|
47
|
+
connector: { connector: evm, chainType: ChainType.EVM },
|
|
48
|
+
});
|
|
58
49
|
});
|
|
59
50
|
solanaWalletList.forEach((svm) => {
|
|
60
|
-
|
|
61
|
-
const existing = walletMap.get(normalizedName) || {
|
|
51
|
+
allConnectors.push({
|
|
62
52
|
id: svm.adapter.name,
|
|
63
53
|
name: svm.adapter.name,
|
|
64
54
|
icon: svm.adapter.icon,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
chainType: ChainType.SOL,
|
|
55
|
+
connector: {
|
|
56
|
+
connector: extendsWalletAdapter(svm.adapter, svm.adapter.name),
|
|
57
|
+
chainType: ChainType.SOL,
|
|
58
|
+
},
|
|
70
59
|
});
|
|
71
|
-
walletMap.set(normalizedName, existing);
|
|
72
60
|
});
|
|
73
61
|
suiWalletList.forEach((moveVM) => {
|
|
74
|
-
|
|
75
|
-
const existing = walletMap.get(normalizedName) || {
|
|
62
|
+
allConnectors.push({
|
|
76
63
|
id: moveVM.name,
|
|
77
64
|
name: moveVM.name,
|
|
78
65
|
icon: moveVM.icon,
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
existing.connectors.push({
|
|
82
|
-
connector: moveVM,
|
|
83
|
-
chainType: ChainType.SUI,
|
|
66
|
+
connector: { connector: moveVM, chainType: ChainType.SUI },
|
|
84
67
|
});
|
|
85
|
-
|
|
68
|
+
});
|
|
69
|
+
const walletMap = new Map();
|
|
70
|
+
allConnectors.forEach(({ id, name, icon, connector }) => {
|
|
71
|
+
const existing = walletMap.get(id);
|
|
72
|
+
if (existing) {
|
|
73
|
+
existing.connectors.push(connector);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
walletMap.set(id, { id, name, icon, connectors: [connector] });
|
|
77
|
+
}
|
|
86
78
|
});
|
|
87
79
|
const combinedWallets = Array.from(walletMap.values());
|
|
88
80
|
combinedWallets.sort(walletComparator);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainType } from "@coin-voyage/shared/
|
|
1
|
+
import { ChainType } from "@coin-voyage/shared/types";
|
|
2
2
|
import { ExecuteTransaction } from "../types/transaction";
|
|
3
3
|
export declare function usePrepareTransaction(chainType?: ChainType): {
|
|
4
4
|
execute: (params: ExecuteTransaction) => Promise<string | undefined>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainType } from "@coin-voyage/shared/
|
|
1
|
+
import { ChainType } from "@coin-voyage/shared/types";
|
|
2
2
|
import { useEVMTransaction } from "../evm/use-evm-transaction";
|
|
3
3
|
import { useSolanaTransaction } from "../solana/use-solana-transaction";
|
|
4
4
|
import { useSUITransaction } from "../sui/use-sui-transaction";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useConfig as useBigmiConfig, useConnect as useUTXOConnect } from "@bigmi/react";
|
|
2
|
-
import { ChainId, ChainType } from "@coin-voyage/shared/
|
|
2
|
+
import { ChainId, ChainType } from "@coin-voyage/shared/types";
|
|
3
3
|
import { useConnectWallet } from "@mysten/dapp-kit";
|
|
4
4
|
import { useWallet } from "@solana/wallet-adapter-react";
|
|
5
|
+
import { useCallback } from "react";
|
|
5
6
|
import { useConfig as useWagmiConfig, useConnect as useWagmiConnect } from "wagmi";
|
|
6
7
|
import { getConnectorId } from "../lib/utils/connector";
|
|
7
8
|
import { useLastConnector } from "./use-last-connector";
|
|
@@ -11,6 +12,7 @@ export const useUniversalConnect = (props) => {
|
|
|
11
12
|
const { updateLastConnectorId } = useLastConnector();
|
|
12
13
|
const { select, disconnect, connected } = useWallet();
|
|
13
14
|
const { mutateAsync: suiConnectAsync } = useConnectWallet();
|
|
15
|
+
const { onError, onSuccess, onSettled, onMutate } = props || {};
|
|
14
16
|
const { connectAsync } = useWagmiConnect({
|
|
15
17
|
config: evmConfig,
|
|
16
18
|
mutation: {
|
|
@@ -18,12 +20,12 @@ export const useUniversalConnect = (props) => {
|
|
|
18
20
|
onSuccess(data, variables) {
|
|
19
21
|
const connector = variables.connector || variables.connector;
|
|
20
22
|
updateLastConnectorId(getConnectorId(connector));
|
|
21
|
-
|
|
23
|
+
onSuccess?.(data, {
|
|
22
24
|
chainId: variables?.chainId,
|
|
23
25
|
connector,
|
|
24
26
|
});
|
|
25
27
|
},
|
|
26
|
-
onError
|
|
28
|
+
onError,
|
|
27
29
|
},
|
|
28
30
|
});
|
|
29
31
|
const { connectAsync: utxoConnectAsync } = useUTXOConnect({
|
|
@@ -33,17 +35,17 @@ export const useUniversalConnect = (props) => {
|
|
|
33
35
|
onSuccess(data, variables) {
|
|
34
36
|
const connector = variables.connector;
|
|
35
37
|
updateLastConnectorId(getConnectorId(connector));
|
|
36
|
-
|
|
38
|
+
onSuccess?.(data, {
|
|
37
39
|
chainId: ChainId.BTC,
|
|
38
40
|
connector,
|
|
39
41
|
});
|
|
40
42
|
},
|
|
41
|
-
onError
|
|
43
|
+
onError,
|
|
42
44
|
},
|
|
43
45
|
});
|
|
44
|
-
const connect = async ({ walletConnector }) => {
|
|
46
|
+
const connect = useCallback(async ({ walletConnector }) => {
|
|
45
47
|
const { connector, chainType } = walletConnector;
|
|
46
|
-
|
|
48
|
+
onMutate?.({ connector });
|
|
47
49
|
try {
|
|
48
50
|
switch (chainType) {
|
|
49
51
|
case ChainType.EVM:
|
|
@@ -82,19 +84,19 @@ export const useUniversalConnect = (props) => {
|
|
|
82
84
|
});
|
|
83
85
|
}
|
|
84
86
|
updateLastConnectorId(getConnectorId(connector));
|
|
85
|
-
|
|
87
|
+
onSuccess?.(undefined, { connector: walletAdapter });
|
|
86
88
|
break;
|
|
87
89
|
}
|
|
88
90
|
case ChainType.SUI:
|
|
89
91
|
await suiConnectAsync({
|
|
90
92
|
wallet: connector,
|
|
91
93
|
}, {
|
|
92
|
-
onError
|
|
94
|
+
onError,
|
|
93
95
|
onSuccess: async (data) => {
|
|
94
96
|
updateLastConnectorId(getConnectorId(connector));
|
|
95
|
-
|
|
97
|
+
onSuccess?.(data, { connector });
|
|
96
98
|
},
|
|
97
|
-
onSettled:
|
|
99
|
+
onSettled: onSettled,
|
|
98
100
|
});
|
|
99
101
|
break;
|
|
100
102
|
default:
|
|
@@ -102,8 +104,20 @@ export const useUniversalConnect = (props) => {
|
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
catch (err) {
|
|
105
|
-
|
|
107
|
+
onError?.(err);
|
|
106
108
|
}
|
|
107
|
-
}
|
|
109
|
+
}, [
|
|
110
|
+
connectAsync,
|
|
111
|
+
utxoConnectAsync,
|
|
112
|
+
suiConnectAsync,
|
|
113
|
+
connected,
|
|
114
|
+
disconnect,
|
|
115
|
+
select,
|
|
116
|
+
updateLastConnectorId,
|
|
117
|
+
onError,
|
|
118
|
+
onSuccess,
|
|
119
|
+
onSettled,
|
|
120
|
+
onMutate,
|
|
121
|
+
]);
|
|
108
122
|
return { connect };
|
|
109
123
|
};
|
package/dist/lib/config/chain.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChainType } from "@coin-voyage/shared/
|
|
1
|
+
import type { ChainType } from "@coin-voyage/shared/types";
|
|
2
2
|
import type { ChainTypeWalletConnector } from "../../types/wallet";
|
|
3
3
|
import type { WalletConnector } from "../../types/wallet-connector";
|
|
4
4
|
export declare const getConnectorId: (connector: WalletConnector) => string;
|
package/dist/types/wallet.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChainId, ChainType } from "@coin-voyage/shared/
|
|
1
|
+
import type { ChainId, ChainType } from "@coin-voyage/shared/types";
|
|
2
2
|
import type { WalletProviderProps as SuiWalletProviderProps } from "@mysten/dapp-kit";
|
|
3
3
|
import type { WalletProviderProps } from "@solana/wallet-adapter-react";
|
|
4
4
|
import type { EVMConfiguration } from "../evm/create-default-evm-config";
|
package/dist/utxo/send-btc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sendUTXOTransaction } from "@bigmi/core";
|
|
2
|
-
import { ChainId } from "@coin-voyage/shared/
|
|
2
|
+
import { ChainId } from "@coin-voyage/shared/types";
|
|
3
3
|
import { Psbt } from "bitcoinjs-lib";
|
|
4
4
|
import { createUnsecuredToken } from "jsontokens";
|
|
5
5
|
import { withTimeout } from "viem";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coin-voyage/crypto",
|
|
3
3
|
"description": "Crypto utilities for Coin Voyage",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.3-beta.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"author": "Lars <lars@coinvoyage.io>",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@solana/wallet-adapter-walletconnect": "0.1.21",
|
|
51
51
|
"@solana/wallet-adapter-base": "0.9.27",
|
|
52
52
|
"@solana/wallet-adapter-coinbase": "0.1.23",
|
|
53
|
-
"@coin-voyage/shared": "2.2.
|
|
53
|
+
"@coin-voyage/shared": "2.2.5-beta.8"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/elliptic": "6.4.18"
|