@tcswap/wallet-extensions 4.1.16
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/chunk-7y3ffnf3.js +4 -0
- package/dist/chunk-7y3ffnf3.js.map +10 -0
- package/dist/chunk-fazw0jvt.js +4 -0
- package/dist/chunk-fazw0jvt.js.map +9 -0
- package/dist/chunk-kx2thqhk.js +5 -0
- package/dist/chunk-kx2thqhk.js.map +9 -0
- package/dist/chunk-swh9jwp7.js +4 -0
- package/dist/chunk-swh9jwp7.js.map +10 -0
- package/dist/src/bitget/index.cjs +4 -0
- package/dist/src/bitget/index.cjs.map +11 -0
- package/dist/src/bitget/index.js +4 -0
- package/dist/src/bitget/index.js.map +11 -0
- package/dist/src/cosmostation/index.cjs +4 -0
- package/dist/src/cosmostation/index.cjs.map +10 -0
- package/dist/src/cosmostation/index.js +4 -0
- package/dist/src/cosmostation/index.js.map +10 -0
- package/dist/src/ctrl/index.cjs +4 -0
- package/dist/src/ctrl/index.cjs.map +11 -0
- package/dist/src/ctrl/index.js +4 -0
- package/dist/src/ctrl/index.js.map +11 -0
- package/dist/src/evm-extensions/index.cjs +4 -0
- package/dist/src/evm-extensions/index.cjs.map +10 -0
- package/dist/src/evm-extensions/index.js +4 -0
- package/dist/src/evm-extensions/index.js.map +10 -0
- package/dist/src/index.cjs +4 -0
- package/dist/src/index.cjs.map +9 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +9 -0
- package/dist/src/keepkey-bex/index.cjs +4 -0
- package/dist/src/keepkey-bex/index.cjs.map +11 -0
- package/dist/src/keepkey-bex/index.js +4 -0
- package/dist/src/keepkey-bex/index.js.map +11 -0
- package/dist/src/keplr/index.cjs +4 -0
- package/dist/src/keplr/index.cjs.map +11 -0
- package/dist/src/keplr/index.js +4 -0
- package/dist/src/keplr/index.js.map +11 -0
- package/dist/src/okx/index.cjs +4 -0
- package/dist/src/okx/index.cjs.map +11 -0
- package/dist/src/okx/index.js +4 -0
- package/dist/src/okx/index.js.map +11 -0
- package/dist/src/onekey/index.cjs +4 -0
- package/dist/src/onekey/index.cjs.map +10 -0
- package/dist/src/onekey/index.js +4 -0
- package/dist/src/onekey/index.js.map +10 -0
- package/dist/src/phantom/index.cjs +4 -0
- package/dist/src/phantom/index.cjs.map +10 -0
- package/dist/src/phantom/index.js +4 -0
- package/dist/src/phantom/index.js.map +10 -0
- package/dist/src/polkadotjs/index.cjs +4 -0
- package/dist/src/polkadotjs/index.cjs.map +10 -0
- package/dist/src/polkadotjs/index.js +4 -0
- package/dist/src/polkadotjs/index.js.map +10 -0
- package/dist/src/talisman/index.cjs +4 -0
- package/dist/src/talisman/index.cjs.map +10 -0
- package/dist/src/talisman/index.js +4 -0
- package/dist/src/talisman/index.js.map +10 -0
- package/dist/src/tronlink/index.cjs +4 -0
- package/dist/src/tronlink/index.cjs.map +12 -0
- package/dist/src/tronlink/index.js +4 -0
- package/dist/src/tronlink/index.js.map +12 -0
- package/dist/src/vultisig/index.cjs +4 -0
- package/dist/src/vultisig/index.cjs.map +11 -0
- package/dist/src/vultisig/index.js +4 -0
- package/dist/src/vultisig/index.js.map +11 -0
- package/dist/types/bitget/helpers.d.ts +1607 -0
- package/dist/types/bitget/helpers.d.ts.map +1 -0
- package/dist/types/bitget/index.d.ts +11 -0
- package/dist/types/bitget/index.d.ts.map +1 -0
- package/dist/types/cosmostation/index.d.ts +24 -0
- package/dist/types/cosmostation/index.d.ts.map +1 -0
- package/dist/types/ctrl/index.d.ts +14 -0
- package/dist/types/ctrl/index.d.ts.map +1 -0
- package/dist/types/ctrl/walletHelpers.d.ts +23 -0
- package/dist/types/ctrl/walletHelpers.d.ts.map +1 -0
- package/dist/types/evm-extensions/index.d.ts +747 -0
- package/dist/types/evm-extensions/index.d.ts.map +1 -0
- package/dist/types/evm-extensions/types.d.ts +18 -0
- package/dist/types/evm-extensions/types.d.ts.map +1 -0
- package/dist/types/helpers/near.d.ts +60 -0
- package/dist/types/helpers/near.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/keepkey-bex/index.d.ts +14 -0
- package/dist/types/keepkey-bex/index.d.ts.map +1 -0
- package/dist/types/keepkey-bex/walletHelpers.d.ts +48 -0
- package/dist/types/keepkey-bex/walletHelpers.d.ts.map +1 -0
- package/dist/types/keplr/chainRegistry.d.ts +4 -0
- package/dist/types/keplr/chainRegistry.d.ts.map +1 -0
- package/dist/types/keplr/index.d.ts +14 -0
- package/dist/types/keplr/index.d.ts.map +1 -0
- package/dist/types/okx/helpers.d.ts +855 -0
- package/dist/types/okx/helpers.d.ts.map +1 -0
- package/dist/types/okx/index.d.ts +11 -0
- package/dist/types/okx/index.d.ts.map +1 -0
- package/dist/types/okx/types.d.ts +104 -0
- package/dist/types/okx/types.d.ts.map +1 -0
- package/dist/types/onekey/evmSigner.d.ts +32 -0
- package/dist/types/onekey/evmSigner.d.ts.map +1 -0
- package/dist/types/onekey/index.d.ts +14 -0
- package/dist/types/onekey/index.d.ts.map +1 -0
- package/dist/types/phantom/index.d.ts +15 -0
- package/dist/types/phantom/index.d.ts.map +1 -0
- package/dist/types/polkadotjs/index.d.ts +14 -0
- package/dist/types/polkadotjs/index.d.ts.map +1 -0
- package/dist/types/talisman/index.d.ts +14 -0
- package/dist/types/talisman/index.d.ts.map +1 -0
- package/dist/types/tronlink/helpers.d.ts +29 -0
- package/dist/types/tronlink/helpers.d.ts.map +1 -0
- package/dist/types/tronlink/index.d.ts +13 -0
- package/dist/types/tronlink/index.d.ts.map +1 -0
- package/dist/types/tronlink/types.d.ts +55 -0
- package/dist/types/tronlink/types.d.ts.map +1 -0
- package/dist/types/types.d.ts +166 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/vultisig/index.d.ts +14 -0
- package/dist/types/vultisig/index.d.ts.map +1 -0
- package/dist/types/vultisig/walletHelpers.d.ts +37 -0
- package/dist/types/vultisig/walletHelpers.d.ts.map +1 -0
- package/package.json +133 -0
- package/src/bitget/helpers.ts +181 -0
- package/src/bitget/index.ts +26 -0
- package/src/cosmostation/index.ts +122 -0
- package/src/ctrl/index.ts +194 -0
- package/src/ctrl/walletHelpers.ts +186 -0
- package/src/evm-extensions/index.ts +122 -0
- package/src/evm-extensions/types.ts +15 -0
- package/src/helpers/near-browser-provider.d.ts +270 -0
- package/src/helpers/near.ts +174 -0
- package/src/index.ts +1 -0
- package/src/keepkey-bex/index.ts +151 -0
- package/src/keepkey-bex/walletHelpers.ts +241 -0
- package/src/keplr/chainRegistry.ts +240 -0
- package/src/keplr/index.ts +54 -0
- package/src/okx/helpers.ts +192 -0
- package/src/okx/index.ts +43 -0
- package/src/okx/types.ts +117 -0
- package/src/onekey/evmSigner.ts +116 -0
- package/src/onekey/index.ts +182 -0
- package/src/phantom/index.ts +136 -0
- package/src/polkadotjs/index.ts +61 -0
- package/src/talisman/index.ts +132 -0
- package/src/tronlink/helpers.ts +153 -0
- package/src/tronlink/index.ts +49 -0
- package/src/tronlink/types.ts +44 -0
- package/src/types.ts +157 -0
- package/src/vultisig/index.ts +179 -0
- package/src/vultisig/walletHelpers.ts +295 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type AssetValue,
|
|
7
|
+
Chain,
|
|
8
|
+
ChainToChainId,
|
|
9
|
+
type CosmosChain,
|
|
10
|
+
type EVMChain,
|
|
11
|
+
EVMChains,
|
|
12
|
+
type FeeOption,
|
|
13
|
+
getChainConfig,
|
|
14
|
+
type NetworkParams,
|
|
15
|
+
providerRequest,
|
|
16
|
+
USwapError,
|
|
17
|
+
type UTXOChain,
|
|
18
|
+
WalletOption,
|
|
19
|
+
} from "@tcswap/helpers";
|
|
20
|
+
import { erc20ABI } from "@tcswap/helpers/contracts";
|
|
21
|
+
import type { getCosmosToolbox } from "@tcswap/toolboxes/cosmos";
|
|
22
|
+
import type { ApproveParams, CallParams, EVMTxParams } from "@tcswap/toolboxes/evm";
|
|
23
|
+
import type { SolanaProvider } from "@tcswap/toolboxes/solana";
|
|
24
|
+
import type { BrowserProvider, Eip1193Provider } from "ethers";
|
|
25
|
+
import type { VultisigCosmosProvider } from "../types";
|
|
26
|
+
|
|
27
|
+
type TransactionMethod = "send_transaction" | "deposit_transaction";
|
|
28
|
+
|
|
29
|
+
type TransactionParams = {
|
|
30
|
+
asset: string | { chain: string; symbol: string; ticker: string };
|
|
31
|
+
amount: number | string | { amount: number; decimals?: number };
|
|
32
|
+
decimal?: number;
|
|
33
|
+
to: string;
|
|
34
|
+
data?: string;
|
|
35
|
+
from?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type WalletTxParams = {
|
|
39
|
+
feeOptionKey?: FeeOption;
|
|
40
|
+
from?: string;
|
|
41
|
+
memo?: string;
|
|
42
|
+
recipient: string;
|
|
43
|
+
assetValue: AssetValue;
|
|
44
|
+
gasLimit?: string | bigint;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type VultisigProviderType<T> = T extends typeof Chain.Solana
|
|
48
|
+
? SolanaProvider
|
|
49
|
+
: T extends Exclude<CosmosChain, typeof Chain.Noble>
|
|
50
|
+
? VultisigCosmosProvider
|
|
51
|
+
: T extends EVMChain
|
|
52
|
+
? Eip1193Provider
|
|
53
|
+
: T extends typeof Chain.Maya | typeof Chain.THORChain | typeof Chain.Ripple | typeof Chain.Polkadot | UTXOChain
|
|
54
|
+
? Eip1193Provider
|
|
55
|
+
: undefined;
|
|
56
|
+
|
|
57
|
+
export async function getVultisigProvider<T extends Chain>(chain: T): Promise<VultisigProviderType<T>> {
|
|
58
|
+
if (!window.vultisig) throw new USwapError("wallet_vultisig_not_found");
|
|
59
|
+
const { match } = await import("ts-pattern");
|
|
60
|
+
|
|
61
|
+
return match(chain as Chain)
|
|
62
|
+
.with(...EVMChains, () => window.vultisig?.ethereum as Eip1193Provider)
|
|
63
|
+
.with(Chain.Cosmos, Chain.Kujira, () => window.vultisig?.cosmos as VultisigCosmosProvider)
|
|
64
|
+
.with(Chain.Bitcoin, () => window.vultisig?.bitcoin as Eip1193Provider)
|
|
65
|
+
.with(Chain.BitcoinCash, () => window.vultisig?.bitcoincash as Eip1193Provider)
|
|
66
|
+
.with(Chain.Dash, () => window.vultisig?.dash as Eip1193Provider)
|
|
67
|
+
.with(Chain.Dogecoin, () => window.vultisig?.dogecoin as Eip1193Provider)
|
|
68
|
+
.with(Chain.Litecoin, () => window.vultisig?.litecoin as Eip1193Provider)
|
|
69
|
+
.with(Chain.Solana, () => window.vultisig?.solana as SolanaProvider)
|
|
70
|
+
.with(Chain.THORChain, () => window.vultisig?.thorchain as Eip1193Provider)
|
|
71
|
+
.with(Chain.Maya, () => window.vultisig?.mayachain as Eip1193Provider)
|
|
72
|
+
.with(Chain.Polkadot, () => window.vultisig?.polkadot as Eip1193Provider)
|
|
73
|
+
.with(Chain.Ripple, () => window.vultisig?.ripple as Eip1193Provider)
|
|
74
|
+
.with(Chain.Zcash, () => window.vultisig?.zcash as Eip1193Provider)
|
|
75
|
+
.otherwise(() => undefined) as VultisigProviderType<T>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function transaction({
|
|
79
|
+
method,
|
|
80
|
+
params,
|
|
81
|
+
chain,
|
|
82
|
+
}: {
|
|
83
|
+
method: TransactionMethod;
|
|
84
|
+
params: TransactionParams[];
|
|
85
|
+
chain: Chain;
|
|
86
|
+
}): Promise<string> {
|
|
87
|
+
const client = await getVultisigProvider(chain);
|
|
88
|
+
let finalParams: TransactionParams[] | { from: string; to?: string; value: string; data?: string }[] = params;
|
|
89
|
+
|
|
90
|
+
if (chain === Chain.Cosmos || chain === Chain.Kujira || chain === Chain.Ripple) {
|
|
91
|
+
finalParams = params.map((p) => ({
|
|
92
|
+
data: p.data as string,
|
|
93
|
+
from: p.from as string,
|
|
94
|
+
to: p.to as string,
|
|
95
|
+
value: (p.amount as { amount: number; decimals?: number }).amount.toString(),
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return new Promise<string>((resolve, reject) => {
|
|
100
|
+
if (client && "request" in client) {
|
|
101
|
+
// @ts-expect-error
|
|
102
|
+
client.request({ method, params: finalParams }, (err: string, tx: string) => {
|
|
103
|
+
err ? reject(err) : resolve(tx);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function getVultisigAddress(chain: Chain) {
|
|
110
|
+
try {
|
|
111
|
+
const windowProvider = (await getVultisigProvider(chain)) as Eip1193Provider;
|
|
112
|
+
if (!windowProvider) {
|
|
113
|
+
throw new USwapError({ errorKey: "wallet_provider_not_found", info: { chain, wallet: WalletOption.VULTISIG } });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if ([Chain.Cosmos, Chain.Kujira].includes(chain as typeof Chain.Cosmos)) {
|
|
117
|
+
const chainId = ChainToChainId[chain];
|
|
118
|
+
|
|
119
|
+
await windowProvider.request({ method: "wallet_switch_chain", params: [{ chainId }] });
|
|
120
|
+
|
|
121
|
+
let account = await windowProvider.request({ method: "get_accounts" });
|
|
122
|
+
if (!account) {
|
|
123
|
+
const connectedAcount = await windowProvider.request({ method: "request_accounts" });
|
|
124
|
+
account = connectedAcount[0].address;
|
|
125
|
+
}
|
|
126
|
+
return account;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (EVMChains.includes(chain as EVMChain)) {
|
|
130
|
+
const { BrowserProvider } = await import("ethers");
|
|
131
|
+
const provider = new BrowserProvider(windowProvider, "any");
|
|
132
|
+
const [response] = await providerRequest({ method: "eth_requestAccounts", params: [], provider });
|
|
133
|
+
return response;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (chain === Chain.Solana) {
|
|
137
|
+
const solanaProvider = await getVultisigProvider(Chain.Solana);
|
|
138
|
+
|
|
139
|
+
const accounts = await solanaProvider.connect();
|
|
140
|
+
return accounts.publicKey.toString();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const accounts = await windowProvider.request({ method: "request_accounts", params: [] });
|
|
144
|
+
return accounts[0];
|
|
145
|
+
} catch {
|
|
146
|
+
throw new USwapError({ errorKey: "wallet_provider_not_found", info: { chain, wallet: WalletOption.VULTISIG } });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function walletTransfer(
|
|
151
|
+
{ assetValue, recipient, memo, gasLimit }: WalletTxParams,
|
|
152
|
+
method: TransactionMethod = "send_transaction",
|
|
153
|
+
) {
|
|
154
|
+
if (!assetValue) {
|
|
155
|
+
throw new USwapError("wallet_vultisig_asset_not_defined");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* EVM requires amount to be hex string
|
|
160
|
+
* UTXO/Cosmos requires amount to be number
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
const from = await getVultisigAddress(assetValue.chain);
|
|
164
|
+
const params = [
|
|
165
|
+
{
|
|
166
|
+
amount: { amount: assetValue.getBaseValue("number"), decimals: assetValue.decimal },
|
|
167
|
+
asset: {
|
|
168
|
+
chain: assetValue.chain,
|
|
169
|
+
symbol: assetValue.symbol.toUpperCase(),
|
|
170
|
+
ticker: assetValue.symbol.toUpperCase(),
|
|
171
|
+
},
|
|
172
|
+
data: memo || "",
|
|
173
|
+
from,
|
|
174
|
+
gasLimit,
|
|
175
|
+
to: recipient,
|
|
176
|
+
},
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
return transaction({ chain: assetValue.chain, method, params });
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function getVultisigMethods(provider: BrowserProvider, chain: EVMChain) {
|
|
183
|
+
return {
|
|
184
|
+
approve: async ({ assetAddress, spenderAddress, amount, from }: ApproveParams) => {
|
|
185
|
+
const { MAX_APPROVAL, getCreateContractTxObject } = await import("@tcswap/toolboxes/evm");
|
|
186
|
+
const funcParams = [spenderAddress, BigInt(amount || MAX_APPROVAL)];
|
|
187
|
+
const txOverrides = { from };
|
|
188
|
+
|
|
189
|
+
const functionCallParams = {
|
|
190
|
+
abi: erc20ABI,
|
|
191
|
+
contractAddress: assetAddress,
|
|
192
|
+
funcName: "approve",
|
|
193
|
+
funcParams,
|
|
194
|
+
txOverrides,
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const createTx = getCreateContractTxObject({ chain, provider });
|
|
198
|
+
const { value, to, data } = await createTx(functionCallParams);
|
|
199
|
+
|
|
200
|
+
const signer = await provider.getSigner();
|
|
201
|
+
const tx = await signer.sendTransaction({ data: data || "0x", from, to, value: BigInt(value || 0) });
|
|
202
|
+
return tx.hash;
|
|
203
|
+
},
|
|
204
|
+
call: async <T>({ contractAddress, abi, funcName, funcParams = [], txOverrides }: CallParams): Promise<T> => {
|
|
205
|
+
if (!contractAddress) {
|
|
206
|
+
throw new USwapError("wallet_vultisig_contract_address_not_provided");
|
|
207
|
+
}
|
|
208
|
+
const { createContract, getCreateContractTxObject, isStateChangingCall } = await import("@tcswap/toolboxes/evm");
|
|
209
|
+
|
|
210
|
+
const isStateChanging = isStateChangingCall({ abi, funcName });
|
|
211
|
+
|
|
212
|
+
if (isStateChanging) {
|
|
213
|
+
const createTx = getCreateContractTxObject({ chain, provider });
|
|
214
|
+
const { value, from, to, data } = await createTx({ abi, contractAddress, funcName, funcParams, txOverrides });
|
|
215
|
+
|
|
216
|
+
const signer = await provider.getSigner();
|
|
217
|
+
const tx = await signer.sendTransaction({ data: data || "0x", from, to, value: BigInt(value || 0) });
|
|
218
|
+
return tx.hash as T;
|
|
219
|
+
}
|
|
220
|
+
const contract = createContract(contractAddress, abi, provider);
|
|
221
|
+
|
|
222
|
+
const result = await contract[funcName]?.(...funcParams);
|
|
223
|
+
|
|
224
|
+
return typeof result?.hash === "string" ? result?.hash : result;
|
|
225
|
+
},
|
|
226
|
+
sendTransaction: async (txParams: EVMTxParams) => {
|
|
227
|
+
const { from, to, data, value } = txParams;
|
|
228
|
+
if (!to) {
|
|
229
|
+
throw new USwapError("wallet_vultisig_send_transaction_no_address");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const signer = await provider.getSigner();
|
|
233
|
+
const tx = await signer.sendTransaction({ data: data || "0x", from, to, value: BigInt(value || 0) });
|
|
234
|
+
return tx.hash;
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export async function switchCosmosWalletNetwork(
|
|
240
|
+
provider: VultisigCosmosProvider,
|
|
241
|
+
chain: Exclude<CosmosChain, typeof Chain.Noble>,
|
|
242
|
+
networkParams?: NetworkParams,
|
|
243
|
+
) {
|
|
244
|
+
try {
|
|
245
|
+
await provider.request({ method: "wallet_switch_chain", params: [{ chainId: getChainConfig(chain).chainId }] });
|
|
246
|
+
} catch (error) {
|
|
247
|
+
if (!networkParams) {
|
|
248
|
+
throw new USwapError("helpers_failed_to_switch_network", { error: error, reason: "networkParams not provided" });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function wrapMethodWithNetworkSwitch<T extends (...args: any[]) => any>(
|
|
254
|
+
func: T,
|
|
255
|
+
provider: VultisigCosmosProvider,
|
|
256
|
+
chain: Exclude<CosmosChain, typeof Chain.Noble>,
|
|
257
|
+
) {
|
|
258
|
+
return (async (...args: any[]) => {
|
|
259
|
+
try {
|
|
260
|
+
await switchCosmosWalletNetwork(provider, chain);
|
|
261
|
+
} catch (error) {
|
|
262
|
+
throw new USwapError({ errorKey: "helpers_failed_to_switch_network", info: { error } });
|
|
263
|
+
}
|
|
264
|
+
return func(...args);
|
|
265
|
+
}) as unknown as T;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function prepareNetworkSwitchCosmos<T extends Awaited<ReturnType<typeof getCosmosToolbox>>, M extends keyof T>({
|
|
269
|
+
toolbox,
|
|
270
|
+
chain,
|
|
271
|
+
provider = window.ethereum,
|
|
272
|
+
methodNames = [],
|
|
273
|
+
}: {
|
|
274
|
+
toolbox: T;
|
|
275
|
+
chain: Chain;
|
|
276
|
+
provider?: VultisigCosmosProvider;
|
|
277
|
+
methodNames?: M[];
|
|
278
|
+
}) {
|
|
279
|
+
const methodsToWrap = [...methodNames, "transfer", "getAddress", "getBalance"] as M[];
|
|
280
|
+
const wrappedMethods = methodsToWrap.reduce((object, methodName) => {
|
|
281
|
+
if (!toolbox[methodName]) return object;
|
|
282
|
+
|
|
283
|
+
const method = toolbox[methodName];
|
|
284
|
+
|
|
285
|
+
if (typeof method !== "function") return object;
|
|
286
|
+
|
|
287
|
+
// @ts-expect-error
|
|
288
|
+
const wrappedMethod = wrapMethodWithNetworkSwitch(method, provider, chain);
|
|
289
|
+
|
|
290
|
+
// biome-ignore lint/performance/noAccumulatingSpread: valid use case
|
|
291
|
+
return { ...object, [methodName]: wrappedMethod };
|
|
292
|
+
}, {});
|
|
293
|
+
|
|
294
|
+
return { ...toolbox, ...wrappedMethods };
|
|
295
|
+
}
|