@coin-voyage/crypto 2.2.0 → 2.2.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 +11 -0
- package/dist/evm/create-default-evm-config.js +10 -5
- package/dist/evm/utils.d.ts +4 -1
- package/dist/evm/utils.js +25 -0
- package/dist/hooks/use-universal-connect.js +15 -2
- package/dist/lib/config/chain.js +1 -28
- package/dist/utxo/create-default-utxo-config.d.ts +9 -0
- package/dist/utxo/create-default-utxo-config.js +7 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HttpTransportConfig } from "viem";
|
|
1
2
|
import type { Config, CreateConnectorFn } from "wagmi";
|
|
2
3
|
import { type CoinbaseWalletParameters, type MetaMaskParameters, type WalletConnectParameters } from "wagmi/connectors";
|
|
3
4
|
/**
|
|
@@ -27,6 +28,16 @@ export interface EVMConfiguration {
|
|
|
27
28
|
* Load Wallet SDKs only if the wallet is the most recently connected wallet
|
|
28
29
|
*/
|
|
29
30
|
lazy?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* RPC configuration per chain
|
|
33
|
+
* Key is chain ID, value is a single URL or an array of URLs
|
|
34
|
+
*/
|
|
35
|
+
rpcConfig?: {
|
|
36
|
+
[chainId: number]: {
|
|
37
|
+
url?: string | undefined;
|
|
38
|
+
config?: HttpTransportConfig;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
30
41
|
}
|
|
31
42
|
export interface DefaultWagmiConfigResult {
|
|
32
43
|
config: Config;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getValue } from "@coin-voyage/shared/common";
|
|
2
|
-
import {
|
|
2
|
+
import { fallback, http } from "viem";
|
|
3
3
|
import { createConfig, injected } from "wagmi";
|
|
4
4
|
import { safe, } from "wagmi/connectors";
|
|
5
5
|
import { DEFAULT_CHAINS } from "../lib/config/chain";
|
|
@@ -7,7 +7,7 @@ import { createCoinbaseConnector } from "../lib/connectors/coinbase";
|
|
|
7
7
|
import { createMetaMaskConnector } from "../lib/connectors/metaMask";
|
|
8
8
|
import { createWalletConnectConnector } from "../lib/connectors/walletConnect";
|
|
9
9
|
import { isWalletInstalled } from "../lib/utils/is-wallet-installed";
|
|
10
|
-
import { extendConnector } from "./utils";
|
|
10
|
+
import { extendConnector, fallbackRPCUrls } from "./utils";
|
|
11
11
|
export function createDefaultEVMConfig(props) {
|
|
12
12
|
const connectors = [...(props?.connectors ?? [])];
|
|
13
13
|
const anyWindow = typeof window !== "undefined" ? window : undefined;
|
|
@@ -57,9 +57,14 @@ export function createDefaultEVMConfig(props) {
|
|
|
57
57
|
const config = createConfig({
|
|
58
58
|
...props?.additionalConfigOptions,
|
|
59
59
|
chains: DEFAULT_CHAINS,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
transports: Object.fromEntries(DEFAULT_CHAINS.map((chain) => {
|
|
61
|
+
const chainRpcConfig = props?.rpcConfig?.[chain.id];
|
|
62
|
+
let config = fallbackRPCUrls(chain.id).map((url) => http(url));
|
|
63
|
+
if (chainRpcConfig) {
|
|
64
|
+
config = [http(chainRpcConfig.url, chainRpcConfig.config), http()];
|
|
65
|
+
}
|
|
66
|
+
return [chain.id, fallback(config)];
|
|
67
|
+
})),
|
|
63
68
|
connectors,
|
|
64
69
|
multiInjectedProviderDiscovery,
|
|
65
70
|
});
|
package/dist/evm/utils.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { ChainId } from "@coin-voyage/shared/common";
|
|
1
2
|
import type { Connector, CreateConnectorFn } from "wagmi";
|
|
2
|
-
import type { CreateConnectorFnExtended } from "./types";
|
|
3
3
|
import { BaseConnector } from "../types/base-connector";
|
|
4
|
+
import type { CreateConnectorFnExtended } from "./types";
|
|
5
|
+
export declare const ALCHEMY_KEY = "kikl1LthkvlPnpk8Y2eY3vqGSKVoRGFj";
|
|
4
6
|
export declare const extendConnector: (connector: CreateConnectorFn, id: string, name: string) => CreateConnectorFnExtended;
|
|
5
7
|
export declare const toBaseConnector: (connector: CreateConnectorFnExtended | Connector) => BaseConnector;
|
|
8
|
+
export declare const fallbackRPCUrls: (chainID: ChainId) => string[];
|
package/dist/evm/utils.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { ChainId } from "@coin-voyage/shared/common";
|
|
1
2
|
import { getWalletIcon } from "../assets/icons";
|
|
3
|
+
export const ALCHEMY_KEY = "kikl1LthkvlPnpk8Y2eY3vqGSKVoRGFj";
|
|
2
4
|
export const extendConnector = (connector, id, name) => {
|
|
3
5
|
const extendedConnector = connector;
|
|
4
6
|
extendedConnector.id = id;
|
|
@@ -13,3 +15,26 @@ export const toBaseConnector = (connector) => {
|
|
|
13
15
|
icon: getWalletIcon(connector.id) || connector.icon,
|
|
14
16
|
};
|
|
15
17
|
};
|
|
18
|
+
export const fallbackRPCUrls = (chainID) => {
|
|
19
|
+
switch (chainID) {
|
|
20
|
+
case ChainId.ARB:
|
|
21
|
+
return ["https://arbitrum.drpc.org", `https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
|
|
22
|
+
case ChainId.BASE: {
|
|
23
|
+
return ["https://base.drpc.org", `https://base-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
|
|
24
|
+
}
|
|
25
|
+
case ChainId.BSC: {
|
|
26
|
+
return ["https://bsc.drpc.org", `https://bnb-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
|
|
27
|
+
}
|
|
28
|
+
case ChainId.ETH: {
|
|
29
|
+
return ["https://mainnet.gateway.tenderly.co", `https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
|
|
30
|
+
}
|
|
31
|
+
case ChainId.OP: {
|
|
32
|
+
return ["https://optimism.drpc.org", `https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
|
|
33
|
+
}
|
|
34
|
+
case ChainId.POL: {
|
|
35
|
+
return ["https://polygon.drpc.org", `https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
|
|
36
|
+
}
|
|
37
|
+
default:
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -5,6 +5,7 @@ import { useWallet } from "@solana/wallet-adapter-react";
|
|
|
5
5
|
import { useConfig as useWagmiConfig, useConnect as useWagmiConnect } from "wagmi";
|
|
6
6
|
import { getConnectorId } from "../lib/utils/connector";
|
|
7
7
|
import { useLastConnector } from "./use-last-connector";
|
|
8
|
+
import { useCallback } from "react";
|
|
8
9
|
export const useUniversalConnect = (props) => {
|
|
9
10
|
const utxoConfig = useBigmiConfig();
|
|
10
11
|
const evmConfig = useWagmiConfig();
|
|
@@ -41,7 +42,7 @@ export const useUniversalConnect = (props) => {
|
|
|
41
42
|
onError: props?.onError,
|
|
42
43
|
},
|
|
43
44
|
});
|
|
44
|
-
const connect = async ({ walletConnector }) => {
|
|
45
|
+
const connect = useCallback(async ({ walletConnector }) => {
|
|
45
46
|
const { connector, chainType } = walletConnector;
|
|
46
47
|
props?.onMutate?.({ connector });
|
|
47
48
|
try {
|
|
@@ -104,6 +105,18 @@ export const useUniversalConnect = (props) => {
|
|
|
104
105
|
catch (err) {
|
|
105
106
|
props?.onError?.(err);
|
|
106
107
|
}
|
|
107
|
-
}
|
|
108
|
+
}, [
|
|
109
|
+
connectAsync,
|
|
110
|
+
utxoConnectAsync,
|
|
111
|
+
suiConnectAsync,
|
|
112
|
+
connected,
|
|
113
|
+
disconnect,
|
|
114
|
+
select,
|
|
115
|
+
updateLastConnectorId,
|
|
116
|
+
props?.onError,
|
|
117
|
+
props?.onSuccess,
|
|
118
|
+
props?.onSettled,
|
|
119
|
+
props?.onMutate,
|
|
120
|
+
]);
|
|
108
121
|
return { connect };
|
|
109
122
|
};
|
package/dist/lib/config/chain.js
CHANGED
|
@@ -1,29 +1,2 @@
|
|
|
1
|
-
import { defineChain } from "viem";
|
|
2
1
|
import { arbitrum, base, bsc, mainnet, optimism, polygon } from "viem/chains";
|
|
3
|
-
const
|
|
4
|
-
id: 2201,
|
|
5
|
-
name: "Stable Testnet",
|
|
6
|
-
nativeCurrency: {
|
|
7
|
-
decimals: 18,
|
|
8
|
-
name: "Tether",
|
|
9
|
-
symbol: "USDT",
|
|
10
|
-
},
|
|
11
|
-
rpcUrls: {
|
|
12
|
-
default: {
|
|
13
|
-
http: ["https://stable-jsonrpc.testnet.chain0.dev"],
|
|
14
|
-
webSocket: ["wss://stable-ws.testnet.chain0.dev"],
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
blockExplorers: {
|
|
18
|
-
default: { name: "Explorer", url: "https://stable-explorer.testnet.chain0.dev" },
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
export const DEFAULT_CHAINS = [
|
|
22
|
-
mainnet,
|
|
23
|
-
arbitrum,
|
|
24
|
-
base,
|
|
25
|
-
bsc,
|
|
26
|
-
optimism,
|
|
27
|
-
polygon,
|
|
28
|
-
stableTestnet,
|
|
29
|
-
];
|
|
2
|
+
export const DEFAULT_CHAINS = [mainnet, arbitrum, base, bsc, optimism, polygon];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Config, CreateConnectorFn } from "@bigmi/client";
|
|
2
|
+
import { HttpTransportConfig } from "@bigmi/core";
|
|
2
3
|
/**
|
|
3
4
|
* UTXO Configuration for Wallets and Connectors
|
|
4
5
|
* Includes options for Bigmi-specific configurations
|
|
@@ -17,6 +18,14 @@ export interface UTXOConfiguration {
|
|
|
17
18
|
* Load Wallet SDKs only if the wallet is the most recently connected wallet
|
|
18
19
|
*/
|
|
19
20
|
lazy?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* RPC configuration per chain
|
|
23
|
+
* Key is chain ID, value is a single URL or an array of URLs
|
|
24
|
+
*/
|
|
25
|
+
rpcConfig?: {
|
|
26
|
+
url?: string | undefined;
|
|
27
|
+
config?: HttpTransportConfig;
|
|
28
|
+
};
|
|
20
29
|
}
|
|
21
30
|
export interface DefaultBigmiConfigResult {
|
|
22
31
|
config: Config;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createConfig, leather, magicEden, okx, onekey, phantom, unisat, xverse, } from "@bigmi/client";
|
|
2
2
|
import { bitcoin, createClient, http } from "@bigmi/core";
|
|
3
|
+
import { ALCHEMY_KEY } from "../evm/utils";
|
|
3
4
|
export function createDefaultBigmiConfig(props = {
|
|
4
5
|
additionalConfigOptions: { multiInjectedProviderDiscovery: false },
|
|
5
6
|
}) {
|
|
@@ -17,7 +18,12 @@ export function createDefaultBigmiConfig(props = {
|
|
|
17
18
|
chains: [bitcoin],
|
|
18
19
|
connectors,
|
|
19
20
|
client({ chain }) {
|
|
20
|
-
|
|
21
|
+
const chainRpcConfig = props?.rpcConfig;
|
|
22
|
+
let config = [http(), http(`https://bitcoin-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`)];
|
|
23
|
+
if (chainRpcConfig) {
|
|
24
|
+
config = [http(chainRpcConfig.url, chainRpcConfig.config), http()];
|
|
25
|
+
}
|
|
26
|
+
return createClient({ chain, transport: config[0] });
|
|
21
27
|
},
|
|
22
28
|
...props?.additionalConfigOptions,
|
|
23
29
|
});
|