@enclave-hq/wallet-sdk 1.2.4 → 1.2.5
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/index.d.mts +9 -227
- package/dist/index.js +320 -729
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +323 -38
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +3 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +321 -36
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +322 -37
- package/dist/react/index.mjs.map +1 -1
- package/dist/tron.d.mts +36 -0
- package/dist/tron.js +852 -0
- package/dist/tron.js.map +1 -0
- package/dist/tron.mjs +846 -0
- package/dist/tron.mjs.map +1 -0
- package/dist/wallet-adapter-DRd0xm3N.d.mts +197 -0
- package/package.json +8 -3
- package/dist/index.d.ts +0 -880
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChainType as ChainType$1 } from '@enclave-hq/chain-utils';
|
|
2
2
|
import EventEmitter from 'eventemitter3';
|
|
3
|
-
import { createWalletClient, custom, createPublicClient, http, isAddress, getAddress, verifyMessage } from 'viem';
|
|
3
|
+
import { encodeFunctionData, createWalletClient, custom, createPublicClient, http, isAddress, getAddress, verifyMessage } from 'viem';
|
|
4
4
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
5
5
|
import EthereumProvider from '@walletconnect/ethereum-provider';
|
|
6
6
|
import { WalletConnectChainID, WalletConnectWallet } from '@tronweb3/walletconnect-tron';
|
|
@@ -909,7 +909,12 @@ var CHAIN_INFO = {
|
|
|
909
909
|
symbol: "ETH",
|
|
910
910
|
decimals: 18
|
|
911
911
|
},
|
|
912
|
-
|
|
912
|
+
// 使用支持浏览器 CORS 的公共 RPC,避免 dapp 域名被跨域拦截(如 eth.llamarpc.com 无 CORS 头)
|
|
913
|
+
rpcUrls: [
|
|
914
|
+
"https://cloudflare-eth.com",
|
|
915
|
+
"https://rpc.ankr.com/eth",
|
|
916
|
+
"https://eth.llamarpc.com"
|
|
917
|
+
],
|
|
913
918
|
blockExplorerUrls: ["https://etherscan.io"]
|
|
914
919
|
},
|
|
915
920
|
// EVM Testnets
|
|
@@ -1317,6 +1322,56 @@ var MetaMaskAdapter = class extends BrowserWalletAdapter {
|
|
|
1317
1322
|
}]
|
|
1318
1323
|
});
|
|
1319
1324
|
}
|
|
1325
|
+
/**
|
|
1326
|
+
* 请求切换账户
|
|
1327
|
+
* 弹出 MetaMask 账户选择界面,让用户选择或切换到目标地址
|
|
1328
|
+
* @param targetAddress 目标地址(可选),如果提供,会在切换后验证是否匹配
|
|
1329
|
+
* @returns 切换后的账户信息
|
|
1330
|
+
*/
|
|
1331
|
+
async requestSwitchAccount(targetAddress) {
|
|
1332
|
+
const provider = this.getBrowserProvider();
|
|
1333
|
+
if (!provider) {
|
|
1334
|
+
throw new Error("MetaMask provider not available");
|
|
1335
|
+
}
|
|
1336
|
+
try {
|
|
1337
|
+
await provider.request({
|
|
1338
|
+
method: "wallet_requestPermissions",
|
|
1339
|
+
params: [{ eth_accounts: {} }]
|
|
1340
|
+
});
|
|
1341
|
+
const accounts = await provider.request({
|
|
1342
|
+
method: "eth_accounts"
|
|
1343
|
+
});
|
|
1344
|
+
if (!accounts || accounts.length === 0) {
|
|
1345
|
+
throw new ConnectionRejectedError(this.type);
|
|
1346
|
+
}
|
|
1347
|
+
const address = formatEVMAddress(accounts[0]);
|
|
1348
|
+
if (targetAddress && address.toLowerCase() !== targetAddress.toLowerCase()) {
|
|
1349
|
+
throw new Error(`\u8BF7\u5728 MetaMask \u4E2D\u9009\u62E9\u5730\u5740 ${targetAddress.slice(0, 6)}...${targetAddress.slice(-4)}\uFF0C\u5F53\u524D\u9009\u62E9\u7684\u662F ${address.slice(0, 6)}...${address.slice(-4)}`);
|
|
1350
|
+
}
|
|
1351
|
+
const chainId = this.currentAccount?.chainId || 1;
|
|
1352
|
+
const account = {
|
|
1353
|
+
universalAddress: createUniversalAddress(chainId, address),
|
|
1354
|
+
nativeAddress: address,
|
|
1355
|
+
chainId,
|
|
1356
|
+
chainType: ChainType.EVM,
|
|
1357
|
+
isActive: true
|
|
1358
|
+
};
|
|
1359
|
+
this.setAccount(account);
|
|
1360
|
+
this.emitAccountChanged(account);
|
|
1361
|
+
const viemChain = this.getViemChain(chainId);
|
|
1362
|
+
this.walletClient = createWalletClient({
|
|
1363
|
+
account: address,
|
|
1364
|
+
chain: viemChain,
|
|
1365
|
+
transport: custom(provider)
|
|
1366
|
+
});
|
|
1367
|
+
return account;
|
|
1368
|
+
} catch (error) {
|
|
1369
|
+
if (error.code === 4001) {
|
|
1370
|
+
throw new ConnectionRejectedError(this.type);
|
|
1371
|
+
}
|
|
1372
|
+
throw error;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1320
1375
|
/**
|
|
1321
1376
|
* 读取合约
|
|
1322
1377
|
*/
|
|
@@ -1542,6 +1597,46 @@ var MetaMaskAdapter = class extends BrowserWalletAdapter {
|
|
|
1542
1597
|
|
|
1543
1598
|
// src/adapters/tron/tronlink.ts
|
|
1544
1599
|
init_types();
|
|
1600
|
+
var TronApiRateLimiter = class {
|
|
1601
|
+
constructor(minIntervalMs = 600) {
|
|
1602
|
+
this.lastCallTime = 0;
|
|
1603
|
+
this.minInterval = minIntervalMs;
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* 等待直到可以进行下一次 API 调用
|
|
1607
|
+
*/
|
|
1608
|
+
async waitForNextCall() {
|
|
1609
|
+
const now = Date.now();
|
|
1610
|
+
const timeSinceLastCall = now - this.lastCallTime;
|
|
1611
|
+
if (timeSinceLastCall < this.minInterval) {
|
|
1612
|
+
const waitTime = this.minInterval - timeSinceLastCall;
|
|
1613
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
1614
|
+
}
|
|
1615
|
+
this.lastCallTime = Date.now();
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
var tronApiRateLimiter = new TronApiRateLimiter(600);
|
|
1619
|
+
async function retryWithBackoff(fn, maxRetries = 3, initialDelay = 500) {
|
|
1620
|
+
let lastError;
|
|
1621
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
1622
|
+
try {
|
|
1623
|
+
return await fn();
|
|
1624
|
+
} catch (error) {
|
|
1625
|
+
lastError = error;
|
|
1626
|
+
const errorMsg = error?.message || String(error);
|
|
1627
|
+
const errorLower = errorMsg.toLowerCase();
|
|
1628
|
+
const isRateLimitError = error?.response?.status === 429 || error?.status === 429 || errorLower.includes("429") || errorLower.includes("rate limit") || errorLower.includes("too many requests") || error?.code === "ERR_BAD_REQUEST" && error?.response?.status === 429;
|
|
1629
|
+
if (isRateLimitError && attempt < maxRetries - 1) {
|
|
1630
|
+
const delay = initialDelay * Math.pow(2, attempt);
|
|
1631
|
+
console.warn(`[TronLink] \u9047\u5230\u901F\u7387\u9650\u5236 (429)\uFF0C\u7B49\u5F85 ${delay}ms \u540E\u91CD\u8BD5 (${attempt + 1}/${maxRetries})...`);
|
|
1632
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1633
|
+
continue;
|
|
1634
|
+
}
|
|
1635
|
+
throw error;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
throw lastError;
|
|
1639
|
+
}
|
|
1545
1640
|
var _TronLinkAdapter = class _TronLinkAdapter extends BrowserWalletAdapter {
|
|
1546
1641
|
constructor() {
|
|
1547
1642
|
super(...arguments);
|
|
@@ -1719,10 +1814,12 @@ var _TronLinkAdapter = class _TronLinkAdapter extends BrowserWalletAdapter {
|
|
|
1719
1814
|
/**
|
|
1720
1815
|
* 读取合约
|
|
1721
1816
|
* 参考 webserver 的实现,使用 TronWeb 合约实例的标准 call() 方法
|
|
1817
|
+
* 带 TronGrid 限流 + 429 重试
|
|
1722
1818
|
*/
|
|
1723
1819
|
async readContract(params) {
|
|
1724
1820
|
this.ensureConnected();
|
|
1725
|
-
|
|
1821
|
+
await tronApiRateLimiter.waitForNextCall();
|
|
1822
|
+
const doRead = async () => {
|
|
1726
1823
|
const tronWeb = this.getTronWeb();
|
|
1727
1824
|
if (!this.currentAccount) {
|
|
1728
1825
|
throw new Error("No account connected");
|
|
@@ -1737,19 +1834,17 @@ var _TronLinkAdapter = class _TronLinkAdapter extends BrowserWalletAdapter {
|
|
|
1737
1834
|
return result;
|
|
1738
1835
|
} catch (method1Error) {
|
|
1739
1836
|
console.warn("\u26A0\uFE0F [\u65B9\u6CD51] TronWeb\u6807\u51C6\u65B9\u6CD5\u5931\u8D25\uFF0C\u5C1D\u8BD5\u65B9\u6CD52:", method1Error.message);
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
throw new Error(`Function ${params.functionName} not found in contract`);
|
|
1745
|
-
}
|
|
1746
|
-
const result = await method2(...params.args || []).call();
|
|
1747
|
-
return result;
|
|
1748
|
-
} catch (method2Error) {
|
|
1749
|
-
console.error("\u26A0\uFE0F [\u65B9\u6CD52] \u4E5F\u5931\u8D25:", method2Error.message);
|
|
1750
|
-
throw method1Error;
|
|
1837
|
+
const contract2 = await tronWeb.contract().at(params.address);
|
|
1838
|
+
const method2 = contract2[params.functionName];
|
|
1839
|
+
if (!method2 || typeof method2 !== "function") {
|
|
1840
|
+
throw new Error(`Function ${params.functionName} not found in contract`);
|
|
1751
1841
|
}
|
|
1842
|
+
const result = await method2(...params.args || []).call();
|
|
1843
|
+
return result;
|
|
1752
1844
|
}
|
|
1845
|
+
};
|
|
1846
|
+
try {
|
|
1847
|
+
return await retryWithBackoff(doRead, 3, 800);
|
|
1753
1848
|
} catch (error) {
|
|
1754
1849
|
console.error("Read contract error:", error);
|
|
1755
1850
|
throw new Error(`Failed to read contract: ${error.message || "Unknown error"}`);
|
|
@@ -1760,6 +1855,7 @@ var _TronLinkAdapter = class _TronLinkAdapter extends BrowserWalletAdapter {
|
|
|
1760
1855
|
*/
|
|
1761
1856
|
async writeContract(params) {
|
|
1762
1857
|
this.ensureConnected();
|
|
1858
|
+
await tronApiRateLimiter.waitForNextCall();
|
|
1763
1859
|
try {
|
|
1764
1860
|
const tronWeb = this.getTronWeb();
|
|
1765
1861
|
console.log("[TronLink] writeContract params:", {
|
|
@@ -1785,29 +1881,171 @@ var _TronLinkAdapter = class _TronLinkAdapter extends BrowserWalletAdapter {
|
|
|
1785
1881
|
}
|
|
1786
1882
|
console.log("[TronLink] Function ABI:", functionAbi);
|
|
1787
1883
|
console.log("[TronLink] Calling with args:", params.args);
|
|
1884
|
+
const TRON_FEE_LIMIT = 1e8;
|
|
1788
1885
|
const options = {
|
|
1789
|
-
feeLimit:
|
|
1790
|
-
//
|
|
1886
|
+
feeLimit: TRON_FEE_LIMIT,
|
|
1887
|
+
// 固定为 100 TRX 的能量限制
|
|
1791
1888
|
callValue: params.value || 0
|
|
1792
1889
|
// 发送的 TRX 数量(单位:SUN)
|
|
1793
1890
|
};
|
|
1794
|
-
const
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1891
|
+
const hasTupleArray = functionAbi.inputs.some((input) => input.type === "tuple[]");
|
|
1892
|
+
console.log("[TronLink] \u68C0\u67E5 tuple[] \u7C7B\u578B:", {
|
|
1893
|
+
hasTupleArray,
|
|
1894
|
+
inputs: functionAbi.inputs.map((i) => ({ name: i.name, type: i.type }))
|
|
1895
|
+
});
|
|
1896
|
+
let tx;
|
|
1897
|
+
if (hasTupleArray) {
|
|
1898
|
+
console.log("[TronLink] \u68C0\u6D4B\u5230 tuple[] \u53C2\u6570\uFF0C\u4F7F\u7528\u624B\u52A8\u7F16\u7801\u65B9\u5F0F");
|
|
1899
|
+
const processedArgs = params.args.map((argValue, index) => {
|
|
1900
|
+
const input = functionAbi.inputs[index];
|
|
1901
|
+
if (input.type === "address" && typeof argValue === "string") {
|
|
1902
|
+
if (argValue.startsWith("T") && argValue.length === 34) {
|
|
1903
|
+
const hexAddress = tronWeb.address.toHex(argValue);
|
|
1904
|
+
return hexAddress.startsWith("0x") ? hexAddress : `0x${hexAddress}`;
|
|
1905
|
+
}
|
|
1906
|
+
return argValue.startsWith("0x") ? argValue : `0x${argValue}`;
|
|
1907
|
+
}
|
|
1908
|
+
if (input.type === "tuple[]" && Array.isArray(argValue)) {
|
|
1909
|
+
return argValue.map((tupleItem) => {
|
|
1910
|
+
if (input.components && Array.isArray(input.components)) {
|
|
1911
|
+
const processedTuple = {};
|
|
1912
|
+
input.components.forEach((component) => {
|
|
1913
|
+
let value = tupleItem[component.name];
|
|
1914
|
+
if (component.type === "address" && typeof value === "string") {
|
|
1915
|
+
if (value.startsWith("T") && value.length === 34) {
|
|
1916
|
+
const hexAddress = tronWeb.address.toHex(value);
|
|
1917
|
+
value = hexAddress.startsWith("0x") ? hexAddress : `0x${hexAddress}`;
|
|
1918
|
+
} else if (!value.startsWith("0x")) {
|
|
1919
|
+
value = `0x${value}`;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
processedTuple[component.name] = value;
|
|
1923
|
+
});
|
|
1924
|
+
return processedTuple;
|
|
1925
|
+
}
|
|
1926
|
+
return tupleItem;
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
if (input.type === "tuple" && typeof argValue === "object" && !Array.isArray(argValue)) {
|
|
1930
|
+
if (input.components && Array.isArray(input.components)) {
|
|
1931
|
+
const processedTuple = {};
|
|
1932
|
+
input.components.forEach((component) => {
|
|
1933
|
+
let value = argValue[component.name];
|
|
1934
|
+
if (component.type === "address" && typeof value === "string") {
|
|
1935
|
+
if (value.startsWith("T") && value.length === 34) {
|
|
1936
|
+
const hexAddress = tronWeb.address.toHex(value);
|
|
1937
|
+
value = hexAddress.startsWith("0x") ? hexAddress : `0x${hexAddress}`;
|
|
1938
|
+
} else if (!value.startsWith("0x")) {
|
|
1939
|
+
value = `0x${value}`;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
processedTuple[component.name] = value;
|
|
1943
|
+
});
|
|
1944
|
+
return processedTuple;
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
return argValue;
|
|
1948
|
+
});
|
|
1949
|
+
console.log("[TronLink] \u5904\u7406\u540E\u7684\u53C2\u6570\uFF08\u7528\u4E8E viem \u7F16\u7801\uFF09:", processedArgs);
|
|
1950
|
+
const encodedData = encodeFunctionData({
|
|
1951
|
+
abi: [functionAbi],
|
|
1952
|
+
functionName: params.functionName,
|
|
1953
|
+
args: processedArgs
|
|
1954
|
+
});
|
|
1955
|
+
console.log("[TronLink] \u7F16\u7801\u540E\u7684\u6570\u636E:", encodedData);
|
|
1956
|
+
const functionSelector = encodedData.slice(0, 10);
|
|
1957
|
+
const parameterData = encodedData.slice(10);
|
|
1958
|
+
console.log("[TronLink] \u51FD\u6570\u9009\u62E9\u5668:", functionSelector);
|
|
1959
|
+
console.log("[TronLink] \u53C2\u6570\u6570\u636E:", parameterData);
|
|
1960
|
+
const functionSignature = params.functionName + "(" + functionAbi.inputs.map((i) => i.type).join(",") + ")";
|
|
1961
|
+
const parameterHexClean = parameterData.startsWith("0x") ? parameterData.slice(2) : parameterData;
|
|
1962
|
+
console.log("[TronLink] \u4F7F\u7528 TronWeb triggerSmartContract (rawParameter)...", {
|
|
1963
|
+
contractAddress: params.address,
|
|
1964
|
+
functionSelector: functionSignature,
|
|
1965
|
+
encodedDataLength: parameterHexClean.length
|
|
1966
|
+
});
|
|
1967
|
+
tx = await retryWithBackoff(
|
|
1968
|
+
() => tronWeb.transactionBuilder.triggerSmartContract(
|
|
1969
|
+
params.address,
|
|
1970
|
+
// Base58 格式的合约地址
|
|
1971
|
+
functionSignature,
|
|
1972
|
+
// 函数签名(用于识别函数)
|
|
1973
|
+
{
|
|
1974
|
+
feeLimit: options.feeLimit,
|
|
1975
|
+
callValue: options.callValue,
|
|
1976
|
+
rawParameter: parameterHexClean
|
|
1977
|
+
// 使用 rawParameter 直接提供编码后的数据
|
|
1978
|
+
},
|
|
1979
|
+
[],
|
|
1980
|
+
// parameter 留空(因为使用 rawParameter)
|
|
1981
|
+
this.currentAccount.nativeAddress
|
|
1982
|
+
// Base58 格式的发送地址
|
|
1983
|
+
),
|
|
1984
|
+
3,
|
|
1985
|
+
// 最多重试 3 次
|
|
1986
|
+
500
|
|
1987
|
+
// 初始延迟 500ms
|
|
1988
|
+
);
|
|
1989
|
+
console.log("[TronLink] \u4F7F\u7528 TronWeb API \u6784\u5EFA\u7684\u4EA4\u6613:", tx);
|
|
1990
|
+
} else {
|
|
1991
|
+
const parameter = functionAbi.inputs.map((input, index) => {
|
|
1992
|
+
const argValue = params.args[index];
|
|
1993
|
+
if (input.type === "tuple" && typeof argValue === "object" && !Array.isArray(argValue)) {
|
|
1994
|
+
if (input.components && Array.isArray(input.components)) {
|
|
1995
|
+
return {
|
|
1996
|
+
type: input.type,
|
|
1997
|
+
value: input.components.map((component) => ({
|
|
1998
|
+
type: component.type,
|
|
1999
|
+
value: argValue[component.name]
|
|
2000
|
+
}))
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
if (input.type === "address" && typeof argValue === "string") {
|
|
2005
|
+
if (argValue.startsWith("T") && argValue.length === 34) {
|
|
2006
|
+
return {
|
|
2007
|
+
type: input.type,
|
|
2008
|
+
value: argValue
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
try {
|
|
2012
|
+
const base58Address = tronWeb.address.fromHex(argValue.startsWith("0x") ? argValue : `0x${argValue}`);
|
|
2013
|
+
return {
|
|
2014
|
+
type: input.type,
|
|
2015
|
+
value: base58Address
|
|
2016
|
+
};
|
|
2017
|
+
} catch (e) {
|
|
2018
|
+
return {
|
|
2019
|
+
type: input.type,
|
|
2020
|
+
value: argValue
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
return {
|
|
2025
|
+
type: input.type,
|
|
2026
|
+
value: argValue
|
|
2027
|
+
};
|
|
2028
|
+
});
|
|
2029
|
+
console.log("[TronLink] Transaction options:", options);
|
|
2030
|
+
console.log("[TronLink] Parameters:", parameter);
|
|
2031
|
+
const functionSelector = params.functionName + "(" + functionAbi.inputs.map((i) => i.type).join(",") + ")";
|
|
2032
|
+
console.log("[TronLink] Function selector:", functionSelector);
|
|
2033
|
+
console.log("[TronLink] Transaction options:", options);
|
|
2034
|
+
console.log("[TronLink] Parameters:", parameter);
|
|
2035
|
+
tx = await retryWithBackoff(
|
|
2036
|
+
() => tronWeb.transactionBuilder.triggerSmartContract(
|
|
2037
|
+
params.address,
|
|
2038
|
+
functionSelector,
|
|
2039
|
+
options,
|
|
2040
|
+
parameter,
|
|
2041
|
+
this.currentAccount.nativeAddress
|
|
2042
|
+
),
|
|
2043
|
+
3,
|
|
2044
|
+
// 最多重试 3 次
|
|
2045
|
+
500
|
|
2046
|
+
// 初始延迟 500ms
|
|
2047
|
+
);
|
|
2048
|
+
}
|
|
1811
2049
|
console.log("[TronLink] Transaction built:", tx);
|
|
1812
2050
|
if (!tx || !tx.transaction) {
|
|
1813
2051
|
throw new Error("Failed to build transaction");
|
|
@@ -1847,6 +2085,7 @@ var _TronLinkAdapter = class _TronLinkAdapter extends BrowserWalletAdapter {
|
|
|
1847
2085
|
const maxAttempts = 60;
|
|
1848
2086
|
while (attempts < maxAttempts) {
|
|
1849
2087
|
try {
|
|
2088
|
+
await tronApiRateLimiter.waitForNextCall();
|
|
1850
2089
|
const txInfo = await tronWeb.trx.getTransactionInfo(txHash);
|
|
1851
2090
|
if (txInfo && txInfo.id) {
|
|
1852
2091
|
const receipt = {
|
|
@@ -3264,6 +3503,12 @@ _WalletConnectAdapter.providerChains = null;
|
|
|
3264
3503
|
_WalletConnectAdapter.isInitializing = false;
|
|
3265
3504
|
_WalletConnectAdapter.initPromise = null;
|
|
3266
3505
|
var WalletConnectAdapter = _WalletConnectAdapter;
|
|
3506
|
+
|
|
3507
|
+
// src/adapters/tron/wallet-connect.ts
|
|
3508
|
+
var wallet_connect_exports = {};
|
|
3509
|
+
__export(wallet_connect_exports, {
|
|
3510
|
+
WalletConnectTronAdapter: () => WalletConnectTronAdapter
|
|
3511
|
+
});
|
|
3267
3512
|
init_types();
|
|
3268
3513
|
var _WalletConnectTronAdapter = class _WalletConnectTronAdapter extends WalletAdapter {
|
|
3269
3514
|
constructor(projectId) {
|
|
@@ -3956,6 +4201,11 @@ _WalletConnectTronAdapter.walletInstance = null;
|
|
|
3956
4201
|
_WalletConnectTronAdapter.walletProjectId = null;
|
|
3957
4202
|
var WalletConnectTronAdapter = _WalletConnectTronAdapter;
|
|
3958
4203
|
|
|
4204
|
+
// src/internal/walletconnect-tron-loader.esm.ts
|
|
4205
|
+
function loadWalletConnectTronModule() {
|
|
4206
|
+
return wallet_connect_exports;
|
|
4207
|
+
}
|
|
4208
|
+
|
|
3959
4209
|
// src/adapters/deep-link/adapter.ts
|
|
3960
4210
|
init_types();
|
|
3961
4211
|
var DeepLinkProviderType = /* @__PURE__ */ ((DeepLinkProviderType2) => {
|
|
@@ -4270,10 +4520,10 @@ var AdapterRegistry = class {
|
|
|
4270
4520
|
"walletconnect" /* WALLETCONNECT */,
|
|
4271
4521
|
() => new WalletConnectAdapter(this.config.walletConnectProjectId)
|
|
4272
4522
|
);
|
|
4273
|
-
this.register(
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
);
|
|
4523
|
+
this.register("walletconnect-tron" /* WALLETCONNECT_TRON */, () => {
|
|
4524
|
+
const { WalletConnectTronAdapter: WalletConnectTronAdapter2 } = loadWalletConnectTronModule();
|
|
4525
|
+
return new WalletConnectTronAdapter2(this.config.walletConnectProjectId);
|
|
4526
|
+
});
|
|
4277
4527
|
}
|
|
4278
4528
|
this.register("tronlink" /* TRONLINK */, () => new TronLinkAdapter());
|
|
4279
4529
|
this.register(
|
|
@@ -4797,6 +5047,41 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
4797
5047
|
throw error;
|
|
4798
5048
|
}
|
|
4799
5049
|
}
|
|
5050
|
+
/**
|
|
5051
|
+
* Request account switch (opens wallet account selector)
|
|
5052
|
+
* @param targetAddress Optional target address to verify after switching
|
|
5053
|
+
* @returns The new account after switching
|
|
5054
|
+
*/
|
|
5055
|
+
async requestSwitchAccount(targetAddress) {
|
|
5056
|
+
if (!this.primaryWallet) {
|
|
5057
|
+
throw new WalletNotConnectedError();
|
|
5058
|
+
}
|
|
5059
|
+
if (!this.primaryWallet.requestSwitchAccount) {
|
|
5060
|
+
throw new Error(`Account switching not supported by ${this.primaryWallet.type}`);
|
|
5061
|
+
}
|
|
5062
|
+
const account = await this.primaryWallet.requestSwitchAccount(targetAddress);
|
|
5063
|
+
if (this.config.enableStorage) {
|
|
5064
|
+
this.saveToStorage();
|
|
5065
|
+
}
|
|
5066
|
+
return account;
|
|
5067
|
+
}
|
|
5068
|
+
/**
|
|
5069
|
+
* Ensure the current account matches the target address
|
|
5070
|
+
* If not matching, request account switch
|
|
5071
|
+
* @param targetAddress The address that should be active
|
|
5072
|
+
* @returns The account (either existing or after switch)
|
|
5073
|
+
*/
|
|
5074
|
+
async ensureAccount(targetAddress) {
|
|
5075
|
+
const currentAccount = this.getPrimaryAccount();
|
|
5076
|
+
if (!currentAccount) {
|
|
5077
|
+
throw new WalletNotConnectedError();
|
|
5078
|
+
}
|
|
5079
|
+
if (currentAccount.nativeAddress.toLowerCase() === targetAddress.toLowerCase()) {
|
|
5080
|
+
return currentAccount;
|
|
5081
|
+
}
|
|
5082
|
+
console.log(`[WalletManager] Current account ${currentAccount.nativeAddress} doesn't match target ${targetAddress}, requesting switch...`);
|
|
5083
|
+
return this.requestSwitchAccount(targetAddress);
|
|
5084
|
+
}
|
|
4800
5085
|
// ===== Contract Calls =====
|
|
4801
5086
|
/**
|
|
4802
5087
|
* Read contract
|
|
@@ -5972,6 +6257,6 @@ function removeHexPrefix(value) {
|
|
|
5972
6257
|
// src/index.ts
|
|
5973
6258
|
var index_default = WalletManager;
|
|
5974
6259
|
|
|
5975
|
-
export { AdapterRegistry, AuthMessageGenerator, BrowserWalletAdapter, CHAIN_INFO, ChainNotSupportedError, ChainType, ConfigurationError, ConnectionRejectedError, DeepLinkAdapter, DeepLinkProviderType, DeepLinkWalletType, EVMPrivateKeyAdapter, ImTokenDeepLinkProvider, MetaMaskAdapter, MetaMaskDeepLinkProvider, MethodNotSupportedError, NetworkError, OKXDeepLinkProvider, QRCodeSignStatus, QRCodeSigner, SUPPORTED_WALLETS, SignatureRejectedError, SignatureVerifier, TokenPocketDeepLinkProvider, TransactionFailedError, TronDeepLinkAdapter, TronLinkAdapter, TronLinkDeepLinkProvider, WalletAdapter, WalletConnectAdapter,
|
|
6260
|
+
export { AdapterRegistry, AuthMessageGenerator, BrowserWalletAdapter, CHAIN_INFO, ChainNotSupportedError, ChainType, ConfigurationError, ConnectionRejectedError, DeepLinkAdapter, DeepLinkProviderType, DeepLinkWalletType, EVMPrivateKeyAdapter, ImTokenDeepLinkProvider, MetaMaskAdapter, MetaMaskDeepLinkProvider, MethodNotSupportedError, NetworkError, OKXDeepLinkProvider, QRCodeSignStatus, QRCodeSigner, SUPPORTED_WALLETS, SignatureRejectedError, SignatureVerifier, TokenPocketDeepLinkProvider, TransactionFailedError, TronDeepLinkAdapter, TronLinkAdapter, TronLinkDeepLinkProvider, WalletAdapter, WalletConnectAdapter, WalletDetector, WalletManager, WalletNotAvailableError, WalletNotConnectedError, WalletSDKError, WalletState, WalletType, compareEVMAddresses, compareTronAddresses, compareUniversalAddresses, createUniversalAddress, index_default as default, ensureHexPrefix, formatEVMAddress, fromHex, getAddressFromUniversalAddress, getChainIdFromUniversalAddress, getChainInfo, getChainType, getEVMWallets, getTronWallets, getWalletMetadata, hexToNumber, isEVMChain, isHex, isTronChain, isValidChainId, isValidEVMAddress, isValidSignature, isValidTransactionHash, isValidTronAddress, isValidTronHexAddress, isValidUniversalAddress, numberToHex, parseUniversalAddress, removeHexPrefix, shortenAddress, shortenTronAddress, toHex, validateAddress, validateAddressForChain };
|
|
5976
6261
|
//# sourceMappingURL=index.mjs.map
|
|
5977
6262
|
//# sourceMappingURL=index.mjs.map
|