@coin-voyage/crypto 2.2.2 → 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.
@@ -1,4 +1,4 @@
1
- import { ChainId } from "@coin-voyage/shared/common";
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/common";
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/common";
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/common";
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 { useConfig as useBigmiConfig, useAccount as useBtcAccount } from "@bigmi/react";
2
- import { ChainId, ChainType } from "@coin-voyage/shared/common";
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
- const btcAccount = useBtcAccount({ config: btcConfig });
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/common";
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?: number;
6
+ chainId?: ChainId;
7
7
  connectorId?: string;
8
8
  type: ChainType;
9
9
  }) => void;
@@ -1,4 +1,4 @@
1
- import { ChainType } from "@coin-voyage/shared/common";
1
+ import { ChainType } from "@coin-voyage/shared/types";
2
2
  import type { ChainTypeWalletConnector } from "../types/wallet";
3
3
  export type Wallet = {
4
4
  id: string;
@@ -1,5 +1,5 @@
1
1
  import { useConfig as useBigmiConfig } from "@bigmi/react";
2
- import { ChainType } from "@coin-voyage/shared/common";
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 walletMap = new Map();
33
+ const allConnectors = [];
35
34
  utxoConnectorList.forEach((utxo) => {
36
- const utxoName = utxo.name;
37
- const normalizedName = normalizeName(utxoName);
38
- const existing = walletMap.get(normalizedName) || {
35
+ allConnectors.push({
39
36
  id: utxo.id,
40
- name: utxoName,
37
+ name: utxo.name,
41
38
  icon: getConnectorIcon(utxo),
42
- connectors: [],
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
- const evmName = evm?.displayName || evm?.name;
49
- const normalizedName = normalizeName(evmName);
50
- const existing = walletMap.get(normalizedName) || {
43
+ allConnectors.push({
51
44
  id: evm.id,
52
- name: evmName,
45
+ name: evm?.displayName || evm?.name,
53
46
  icon: getConnectorIcon(evm),
54
- connectors: [],
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
- const normalizedName = normalizeName(svm.adapter.name);
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
- connectors: [],
66
- };
67
- existing.connectors.push({
68
- connector: extendsWalletAdapter(svm.adapter, svm.adapter.name),
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
- const normalizedName = normalizeName(moveVM.name);
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
- connectors: [],
80
- };
81
- existing.connectors.push({
82
- connector: moveVM,
83
- chainType: ChainType.SUI,
66
+ connector: { connector: moveVM, chainType: ChainType.SUI },
84
67
  });
85
- walletMap.set(normalizedName, existing);
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/common";
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/common";
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,17 +1,18 @@
1
1
  import { useConfig as useBigmiConfig, useConnect as useUTXOConnect } from "@bigmi/react";
2
- import { ChainId, ChainType } from "@coin-voyage/shared/common";
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";
8
- import { useCallback } from "react";
9
9
  export const useUniversalConnect = (props) => {
10
10
  const utxoConfig = useBigmiConfig();
11
11
  const evmConfig = useWagmiConfig();
12
12
  const { updateLastConnectorId } = useLastConnector();
13
13
  const { select, disconnect, connected } = useWallet();
14
14
  const { mutateAsync: suiConnectAsync } = useConnectWallet();
15
+ const { onError, onSuccess, onSettled, onMutate } = props || {};
15
16
  const { connectAsync } = useWagmiConnect({
16
17
  config: evmConfig,
17
18
  mutation: {
@@ -19,12 +20,12 @@ export const useUniversalConnect = (props) => {
19
20
  onSuccess(data, variables) {
20
21
  const connector = variables.connector || variables.connector;
21
22
  updateLastConnectorId(getConnectorId(connector));
22
- props?.onSuccess?.(data, {
23
+ onSuccess?.(data, {
23
24
  chainId: variables?.chainId,
24
25
  connector,
25
26
  });
26
27
  },
27
- onError: props?.onError,
28
+ onError,
28
29
  },
29
30
  });
30
31
  const { connectAsync: utxoConnectAsync } = useUTXOConnect({
@@ -34,17 +35,17 @@ export const useUniversalConnect = (props) => {
34
35
  onSuccess(data, variables) {
35
36
  const connector = variables.connector;
36
37
  updateLastConnectorId(getConnectorId(connector));
37
- props?.onSuccess?.(data, {
38
+ onSuccess?.(data, {
38
39
  chainId: ChainId.BTC,
39
40
  connector,
40
41
  });
41
42
  },
42
- onError: props?.onError,
43
+ onError,
43
44
  },
44
45
  });
45
46
  const connect = useCallback(async ({ walletConnector }) => {
46
47
  const { connector, chainType } = walletConnector;
47
- props?.onMutate?.({ connector });
48
+ onMutate?.({ connector });
48
49
  try {
49
50
  switch (chainType) {
50
51
  case ChainType.EVM:
@@ -83,19 +84,19 @@ export const useUniversalConnect = (props) => {
83
84
  });
84
85
  }
85
86
  updateLastConnectorId(getConnectorId(connector));
86
- props?.onSuccess?.(undefined, { connector: walletAdapter });
87
+ onSuccess?.(undefined, { connector: walletAdapter });
87
88
  break;
88
89
  }
89
90
  case ChainType.SUI:
90
91
  await suiConnectAsync({
91
92
  wallet: connector,
92
93
  }, {
93
- onError: props?.onError,
94
+ onError,
94
95
  onSuccess: async (data) => {
95
96
  updateLastConnectorId(getConnectorId(connector));
96
- props?.onSuccess?.(data, { connector });
97
+ onSuccess?.(data, { connector });
97
98
  },
98
- onSettled: props?.onSettled,
99
+ onSettled: onSettled,
99
100
  });
100
101
  break;
101
102
  default:
@@ -103,7 +104,7 @@ export const useUniversalConnect = (props) => {
103
104
  }
104
105
  }
105
106
  catch (err) {
106
- props?.onError?.(err);
107
+ onError?.(err);
107
108
  }
108
109
  }, [
109
110
  connectAsync,
@@ -113,10 +114,10 @@ export const useUniversalConnect = (props) => {
113
114
  disconnect,
114
115
  select,
115
116
  updateLastConnectorId,
116
- props?.onError,
117
- props?.onSuccess,
118
- props?.onSettled,
119
- props?.onMutate,
117
+ onError,
118
+ onSuccess,
119
+ onSettled,
120
+ onMutate,
120
121
  ]);
121
122
  return { connect };
122
123
  };
@@ -1,4 +1,4 @@
1
- import type { ChainType } from "@coin-voyage/shared/common";
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;
@@ -3,9 +3,9 @@ const walletPriority = {
3
3
  metamask: 1,
4
4
  "io.metamask": 1,
5
5
  "io.metamask.mobile": 1,
6
+ slush: 1,
6
7
  phantom: 1,
7
8
  "app.phantom": 1,
8
- slush: 1,
9
9
  coinbasewalletsdk: 2,
10
10
  "com.coinbase.wallet": 2,
11
11
  walletconnect: 1001,
@@ -1,4 +1,4 @@
1
- import type { ChainId, ChainType } from "@coin-voyage/shared/common";
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";
@@ -1,5 +1,5 @@
1
1
  import { sendUTXOTransaction } from "@bigmi/core";
2
- import { ChainId } from "@coin-voyage/shared/common";
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.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.0"
53
+ "@coin-voyage/shared": "2.2.5-beta.8"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/elliptic": "6.4.18"