@enclave-hq/wallet-sdk 1.1.2 → 1.1.4
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 +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +143 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +143 -55
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +164 -53
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +164 -53
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -2
package/dist/index.d.mts
CHANGED
|
@@ -150,6 +150,8 @@ interface WalletHistoryRecord {
|
|
|
150
150
|
}
|
|
151
151
|
interface StorageData {
|
|
152
152
|
current: UniversalAddress | null;
|
|
153
|
+
primaryWalletType?: WalletType;
|
|
154
|
+
primaryChainId?: number;
|
|
153
155
|
history: WalletHistoryRecord[];
|
|
154
156
|
}
|
|
155
157
|
interface WalletAvailability {
|
|
@@ -199,7 +201,7 @@ declare class WalletManager extends TypedEventEmitter<WalletManagerEvents> {
|
|
|
199
201
|
private setupAdapterListeners;
|
|
200
202
|
private removeAdapterListeners;
|
|
201
203
|
private saveToStorage;
|
|
202
|
-
|
|
204
|
+
restoreFromStorage(): Promise<Account | null>;
|
|
203
205
|
private clearStorage;
|
|
204
206
|
private getHistoryRecords;
|
|
205
207
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -150,6 +150,8 @@ interface WalletHistoryRecord {
|
|
|
150
150
|
}
|
|
151
151
|
interface StorageData {
|
|
152
152
|
current: UniversalAddress | null;
|
|
153
|
+
primaryWalletType?: WalletType;
|
|
154
|
+
primaryChainId?: number;
|
|
153
155
|
history: WalletHistoryRecord[];
|
|
154
156
|
}
|
|
155
157
|
interface WalletAvailability {
|
|
@@ -199,7 +201,7 @@ declare class WalletManager extends TypedEventEmitter<WalletManagerEvents> {
|
|
|
199
201
|
private setupAdapterListeners;
|
|
200
202
|
private removeAdapterListeners;
|
|
201
203
|
private saveToStorage;
|
|
202
|
-
|
|
204
|
+
restoreFromStorage(): Promise<Account | null>;
|
|
203
205
|
private clearStorage;
|
|
204
206
|
private getHistoryRecords;
|
|
205
207
|
}
|
package/dist/index.js
CHANGED
|
@@ -368,7 +368,7 @@ var CHAIN_INFO = {
|
|
|
368
368
|
"https://data-seed-prebsc-1-s3.binance.org:8545",
|
|
369
369
|
"https://data-seed-prebsc-2-s3.binance.org:8545",
|
|
370
370
|
"https://data-seed-prebsc-1-s1.binance.org:8545"
|
|
371
|
-
//
|
|
371
|
+
// Original main node as last fallback
|
|
372
372
|
],
|
|
373
373
|
blockExplorerUrls: ["https://testnet.bscscan.com"]
|
|
374
374
|
},
|
|
@@ -543,7 +543,7 @@ var MetaMaskAdapter = class extends BrowserWalletAdapter {
|
|
|
543
543
|
};
|
|
544
544
|
}
|
|
545
545
|
/**
|
|
546
|
-
*
|
|
546
|
+
* Connect wallet
|
|
547
547
|
*/
|
|
548
548
|
async connect(chainId) {
|
|
549
549
|
await this.ensureAvailable();
|
|
@@ -1506,7 +1506,7 @@ var AdapterRegistry = class {
|
|
|
1506
1506
|
this.registerDefaultAdapters();
|
|
1507
1507
|
}
|
|
1508
1508
|
/**
|
|
1509
|
-
*
|
|
1509
|
+
* Register default adapters
|
|
1510
1510
|
*/
|
|
1511
1511
|
registerDefaultAdapters() {
|
|
1512
1512
|
this.register("metamask" /* METAMASK */, () => new MetaMaskAdapter());
|
|
@@ -1514,13 +1514,13 @@ var AdapterRegistry = class {
|
|
|
1514
1514
|
this.register("tronlink" /* TRONLINK */, () => new TronLinkAdapter());
|
|
1515
1515
|
}
|
|
1516
1516
|
/**
|
|
1517
|
-
*
|
|
1517
|
+
* Register adapter
|
|
1518
1518
|
*/
|
|
1519
1519
|
register(type, factory) {
|
|
1520
1520
|
this.adapters.set(type, factory);
|
|
1521
1521
|
}
|
|
1522
1522
|
/**
|
|
1523
|
-
*
|
|
1523
|
+
* Get adapter
|
|
1524
1524
|
*/
|
|
1525
1525
|
getAdapter(type) {
|
|
1526
1526
|
const factory = this.adapters.get(type);
|
|
@@ -1530,13 +1530,13 @@ var AdapterRegistry = class {
|
|
|
1530
1530
|
return factory();
|
|
1531
1531
|
}
|
|
1532
1532
|
/**
|
|
1533
|
-
*
|
|
1533
|
+
* Check if adapter is registered
|
|
1534
1534
|
*/
|
|
1535
1535
|
has(type) {
|
|
1536
1536
|
return this.adapters.has(type);
|
|
1537
1537
|
}
|
|
1538
1538
|
/**
|
|
1539
|
-
*
|
|
1539
|
+
* Get all registered adapter types
|
|
1540
1540
|
*/
|
|
1541
1541
|
getRegisteredTypes() {
|
|
1542
1542
|
return Array.from(this.adapters.keys());
|
|
@@ -1560,9 +1560,9 @@ var AdapterRegistry = class {
|
|
|
1560
1560
|
var WalletManager = class extends TypedEventEmitter {
|
|
1561
1561
|
constructor(config = {}) {
|
|
1562
1562
|
super();
|
|
1563
|
-
//
|
|
1563
|
+
// Primary wallet
|
|
1564
1564
|
this.primaryWallet = null;
|
|
1565
|
-
//
|
|
1565
|
+
// Connected wallet pool
|
|
1566
1566
|
this.connectedWallets = /* @__PURE__ */ new Map();
|
|
1567
1567
|
this.config = {
|
|
1568
1568
|
enableStorage: config.enableStorage ?? true,
|
|
@@ -1572,13 +1572,10 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1572
1572
|
walletConnectProjectId: config.walletConnectProjectId ?? ""
|
|
1573
1573
|
};
|
|
1574
1574
|
this.registry = new AdapterRegistry();
|
|
1575
|
-
if (this.config.enableStorage) {
|
|
1576
|
-
this.restoreFromStorage();
|
|
1577
|
-
}
|
|
1578
1575
|
}
|
|
1579
|
-
// =====
|
|
1576
|
+
// ===== Connection Management =====
|
|
1580
1577
|
/**
|
|
1581
|
-
*
|
|
1578
|
+
* Connect primary wallet
|
|
1582
1579
|
*/
|
|
1583
1580
|
async connect(type, chainId) {
|
|
1584
1581
|
const adapter = this.registry.getAdapter(type);
|
|
@@ -1599,7 +1596,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1599
1596
|
return account;
|
|
1600
1597
|
}
|
|
1601
1598
|
/**
|
|
1602
|
-
*
|
|
1599
|
+
* Connect additional wallet (without changing primary wallet)
|
|
1603
1600
|
*/
|
|
1604
1601
|
async connectAdditional(type, chainId) {
|
|
1605
1602
|
const adapter = this.registry.getAdapter(type);
|
|
@@ -1619,7 +1616,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1619
1616
|
return account;
|
|
1620
1617
|
}
|
|
1621
1618
|
/**
|
|
1622
|
-
*
|
|
1619
|
+
* Connect with private key (for development/testing only)
|
|
1623
1620
|
*/
|
|
1624
1621
|
async connectWithPrivateKey(privateKey, chainId) {
|
|
1625
1622
|
const adapter = new EVMPrivateKeyAdapter();
|
|
@@ -1631,7 +1628,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1631
1628
|
return account;
|
|
1632
1629
|
}
|
|
1633
1630
|
/**
|
|
1634
|
-
*
|
|
1631
|
+
* Disconnect primary wallet
|
|
1635
1632
|
*/
|
|
1636
1633
|
async disconnect() {
|
|
1637
1634
|
if (!this.primaryWallet) {
|
|
@@ -1648,7 +1645,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1648
1645
|
this.emit("disconnected");
|
|
1649
1646
|
}
|
|
1650
1647
|
/**
|
|
1651
|
-
*
|
|
1648
|
+
* Disconnect all wallets
|
|
1652
1649
|
*/
|
|
1653
1650
|
async disconnectAll() {
|
|
1654
1651
|
const wallets = Array.from(this.connectedWallets.values());
|
|
@@ -1663,9 +1660,9 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1663
1660
|
}
|
|
1664
1661
|
this.emit("disconnected");
|
|
1665
1662
|
}
|
|
1666
|
-
// =====
|
|
1663
|
+
// ===== Primary Wallet Management =====
|
|
1667
1664
|
/**
|
|
1668
|
-
*
|
|
1665
|
+
* Switch primary wallet
|
|
1669
1666
|
*/
|
|
1670
1667
|
async switchPrimaryWallet(chainType) {
|
|
1671
1668
|
const adapter = this.connectedWallets.get(chainType);
|
|
@@ -1685,13 +1682,13 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1685
1682
|
return adapter.currentAccount;
|
|
1686
1683
|
}
|
|
1687
1684
|
/**
|
|
1688
|
-
*
|
|
1685
|
+
* Get primary wallet account
|
|
1689
1686
|
*/
|
|
1690
1687
|
getPrimaryAccount() {
|
|
1691
1688
|
return this.primaryWallet?.currentAccount || null;
|
|
1692
1689
|
}
|
|
1693
1690
|
/**
|
|
1694
|
-
*
|
|
1691
|
+
* Get all connected wallets
|
|
1695
1692
|
*/
|
|
1696
1693
|
getConnectedWallets() {
|
|
1697
1694
|
return Array.from(this.connectedWallets.values()).map((adapter) => ({
|
|
@@ -1704,14 +1701,14 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1704
1701
|
}));
|
|
1705
1702
|
}
|
|
1706
1703
|
/**
|
|
1707
|
-
*
|
|
1704
|
+
* Get wallet by chain type
|
|
1708
1705
|
*/
|
|
1709
1706
|
getWalletByChainType(chainType) {
|
|
1710
1707
|
return this.connectedWallets.get(chainType) || null;
|
|
1711
1708
|
}
|
|
1712
|
-
// =====
|
|
1709
|
+
// ===== Signing =====
|
|
1713
1710
|
/**
|
|
1714
|
-
*
|
|
1711
|
+
* Sign message with primary wallet
|
|
1715
1712
|
*/
|
|
1716
1713
|
async signMessage(message) {
|
|
1717
1714
|
if (!this.primaryWallet) {
|
|
@@ -1720,7 +1717,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1720
1717
|
return this.primaryWallet.signMessage(message);
|
|
1721
1718
|
}
|
|
1722
1719
|
/**
|
|
1723
|
-
*
|
|
1720
|
+
* Sign message with wallet of specified chain type
|
|
1724
1721
|
*/
|
|
1725
1722
|
async signMessageWithChainType(message, chainType) {
|
|
1726
1723
|
if (!chainType) {
|
|
@@ -1733,7 +1730,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1733
1730
|
return adapter.signMessage(message);
|
|
1734
1731
|
}
|
|
1735
1732
|
/**
|
|
1736
|
-
*
|
|
1733
|
+
* Sign TypedData (EVM only)
|
|
1737
1734
|
*/
|
|
1738
1735
|
async signTypedData(typedData, chainType) {
|
|
1739
1736
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1746,7 +1743,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1746
1743
|
return adapter.signTypedData(typedData);
|
|
1747
1744
|
}
|
|
1748
1745
|
/**
|
|
1749
|
-
*
|
|
1746
|
+
* Sign transaction (with primary wallet)
|
|
1750
1747
|
*/
|
|
1751
1748
|
async signTransaction(transaction) {
|
|
1752
1749
|
if (!this.primaryWallet) {
|
|
@@ -1758,7 +1755,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1758
1755
|
return this.primaryWallet.signTransaction(transaction);
|
|
1759
1756
|
}
|
|
1760
1757
|
/**
|
|
1761
|
-
*
|
|
1758
|
+
* Sign transaction with wallet of specified chain type
|
|
1762
1759
|
*/
|
|
1763
1760
|
async signTransactionWithChainType(transaction, chainType) {
|
|
1764
1761
|
if (!chainType) {
|
|
@@ -1773,9 +1770,9 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1773
1770
|
}
|
|
1774
1771
|
return adapter.signTransaction(transaction);
|
|
1775
1772
|
}
|
|
1776
|
-
// =====
|
|
1773
|
+
// ===== Chain Switching =====
|
|
1777
1774
|
/**
|
|
1778
|
-
*
|
|
1775
|
+
* Request chain switch (EVM only)
|
|
1779
1776
|
*/
|
|
1780
1777
|
async requestSwitchChain(chainId, options) {
|
|
1781
1778
|
if (!this.primaryWallet) {
|
|
@@ -1796,9 +1793,9 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1796
1793
|
throw error;
|
|
1797
1794
|
}
|
|
1798
1795
|
}
|
|
1799
|
-
// =====
|
|
1796
|
+
// ===== Contract Calls =====
|
|
1800
1797
|
/**
|
|
1801
|
-
*
|
|
1798
|
+
* Read contract
|
|
1802
1799
|
*/
|
|
1803
1800
|
async readContract(address, abi, functionName, args, chainType) {
|
|
1804
1801
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1811,7 +1808,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1811
1808
|
return adapter.readContract({ address, abi, functionName, args });
|
|
1812
1809
|
}
|
|
1813
1810
|
/**
|
|
1814
|
-
*
|
|
1811
|
+
* Write contract
|
|
1815
1812
|
*/
|
|
1816
1813
|
async writeContract(address, abi, functionName, args, options, chainType) {
|
|
1817
1814
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1830,7 +1827,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1830
1827
|
});
|
|
1831
1828
|
}
|
|
1832
1829
|
/**
|
|
1833
|
-
*
|
|
1830
|
+
* Estimate gas
|
|
1834
1831
|
*/
|
|
1835
1832
|
async estimateGas(address, abi, functionName, args, chainType) {
|
|
1836
1833
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1843,7 +1840,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1843
1840
|
return adapter.estimateGas({ address, abi, functionName, args });
|
|
1844
1841
|
}
|
|
1845
1842
|
/**
|
|
1846
|
-
*
|
|
1843
|
+
* Wait for transaction confirmation
|
|
1847
1844
|
*/
|
|
1848
1845
|
async waitForTransaction(txHash, confirmations, chainType) {
|
|
1849
1846
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1855,9 +1852,9 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1855
1852
|
}
|
|
1856
1853
|
return adapter.waitForTransaction(txHash, confirmations);
|
|
1857
1854
|
}
|
|
1858
|
-
// ===== Provider
|
|
1855
|
+
// ===== Provider Access =====
|
|
1859
1856
|
/**
|
|
1860
|
-
*
|
|
1857
|
+
* Get primary wallet Provider
|
|
1861
1858
|
*/
|
|
1862
1859
|
getProvider() {
|
|
1863
1860
|
if (!this.primaryWallet) {
|
|
@@ -1866,7 +1863,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1866
1863
|
return this.primaryWallet.getProvider();
|
|
1867
1864
|
}
|
|
1868
1865
|
/**
|
|
1869
|
-
*
|
|
1866
|
+
* Get Provider by chain type
|
|
1870
1867
|
*/
|
|
1871
1868
|
getProviderByChainType(chainType) {
|
|
1872
1869
|
const adapter = this.connectedWallets.get(chainType);
|
|
@@ -1875,21 +1872,21 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1875
1872
|
}
|
|
1876
1873
|
return adapter.getProvider();
|
|
1877
1874
|
}
|
|
1878
|
-
// =====
|
|
1875
|
+
// ===== Private Methods =====
|
|
1879
1876
|
/**
|
|
1880
|
-
*
|
|
1877
|
+
* Set primary wallet
|
|
1881
1878
|
*/
|
|
1882
1879
|
setPrimaryWallet(adapter) {
|
|
1883
1880
|
this.primaryWallet = adapter;
|
|
1884
1881
|
}
|
|
1885
1882
|
/**
|
|
1886
|
-
*
|
|
1883
|
+
* Check if wallet supports chain switching
|
|
1887
1884
|
*/
|
|
1888
1885
|
canSwitchChain(adapter) {
|
|
1889
1886
|
return !!adapter.switchChain;
|
|
1890
1887
|
}
|
|
1891
1888
|
/**
|
|
1892
|
-
*
|
|
1889
|
+
* Setup adapter event listeners
|
|
1893
1890
|
*/
|
|
1894
1891
|
setupAdapterListeners(adapter, isPrimary) {
|
|
1895
1892
|
adapter.on("accountChanged", (account) => {
|
|
@@ -1930,15 +1927,15 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1930
1927
|
});
|
|
1931
1928
|
}
|
|
1932
1929
|
/**
|
|
1933
|
-
*
|
|
1930
|
+
* Remove adapter event listeners
|
|
1934
1931
|
*/
|
|
1935
1932
|
removeAdapterListeners(adapter) {
|
|
1936
1933
|
if (!adapter) return;
|
|
1937
1934
|
adapter.removeAllListeners();
|
|
1938
1935
|
}
|
|
1939
|
-
// =====
|
|
1936
|
+
// ===== Storage =====
|
|
1940
1937
|
/**
|
|
1941
|
-
*
|
|
1938
|
+
* Save to storage
|
|
1942
1939
|
*/
|
|
1943
1940
|
saveToStorage() {
|
|
1944
1941
|
if (typeof window === "undefined" || !this.config.enableStorage) {
|
|
@@ -1946,6 +1943,8 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1946
1943
|
}
|
|
1947
1944
|
const data = {
|
|
1948
1945
|
current: this.primaryWallet?.currentAccount?.universalAddress || null,
|
|
1946
|
+
primaryWalletType: this.primaryWallet?.type,
|
|
1947
|
+
primaryChainId: this.primaryWallet?.currentAccount?.chainId,
|
|
1949
1948
|
history: this.getHistoryRecords()
|
|
1950
1949
|
};
|
|
1951
1950
|
try {
|
|
@@ -1958,12 +1957,101 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1958
1957
|
}
|
|
1959
1958
|
}
|
|
1960
1959
|
/**
|
|
1961
|
-
*
|
|
1960
|
+
* Restore from storage
|
|
1961
|
+
* Returns a Promise that can be used for auto-reconnection
|
|
1962
1962
|
*/
|
|
1963
|
-
restoreFromStorage() {
|
|
1963
|
+
async restoreFromStorage() {
|
|
1964
|
+
if (typeof window === "undefined" || !this.config.enableStorage) {
|
|
1965
|
+
return null;
|
|
1966
|
+
}
|
|
1967
|
+
try {
|
|
1968
|
+
const stored = localStorage.getItem(`${this.config.storagePrefix}data`);
|
|
1969
|
+
if (!stored) {
|
|
1970
|
+
console.debug("[WalletManager] No stored wallet data found");
|
|
1971
|
+
return null;
|
|
1972
|
+
}
|
|
1973
|
+
const data = JSON.parse(stored);
|
|
1974
|
+
console.debug("[WalletManager] Restoring from storage:", data);
|
|
1975
|
+
if (!data.primaryWalletType || !data.current) {
|
|
1976
|
+
console.debug("[WalletManager] Missing primary wallet info in storage");
|
|
1977
|
+
return null;
|
|
1978
|
+
}
|
|
1979
|
+
const adapter = this.registry.getAdapter(data.primaryWalletType);
|
|
1980
|
+
if (!adapter) {
|
|
1981
|
+
console.debug("[WalletManager] Adapter not found for type:", data.primaryWalletType);
|
|
1982
|
+
return null;
|
|
1983
|
+
}
|
|
1984
|
+
const isAvailable = await adapter.isAvailable();
|
|
1985
|
+
if (!isAvailable) {
|
|
1986
|
+
console.debug("[WalletManager] Wallet not available:", data.primaryWalletType);
|
|
1987
|
+
return null;
|
|
1988
|
+
}
|
|
1989
|
+
console.debug("[WalletManager] Wallet is available, attempting restoration");
|
|
1990
|
+
if (adapter.chainType === ChainType.EVM && data.primaryWalletType === "metamask" /* METAMASK */) {
|
|
1991
|
+
try {
|
|
1992
|
+
const provider = typeof window !== "undefined" ? window.ethereum : null;
|
|
1993
|
+
if (provider) {
|
|
1994
|
+
const accounts = await provider.request({
|
|
1995
|
+
method: "eth_accounts"
|
|
1996
|
+
});
|
|
1997
|
+
console.debug("[WalletManager] Checking authorized accounts:", accounts);
|
|
1998
|
+
if (accounts && accounts.length > 0) {
|
|
1999
|
+
const savedAddress = data.current.split(":")[1];
|
|
2000
|
+
const currentAddress = accounts[0].toLowerCase();
|
|
2001
|
+
console.debug("[WalletManager] Comparing addresses - saved:", savedAddress, "current:", currentAddress);
|
|
2002
|
+
if (currentAddress === savedAddress.toLowerCase()) {
|
|
2003
|
+
console.debug("[WalletManager] Address matches, attempting connect (should be silent if already authorized)");
|
|
2004
|
+
try {
|
|
2005
|
+
const account2 = await adapter.connect(data.primaryChainId);
|
|
2006
|
+
this.setPrimaryWallet(adapter);
|
|
2007
|
+
this.connectedWallets.set(adapter.chainType, adapter);
|
|
2008
|
+
this.setupAdapterListeners(adapter, true);
|
|
2009
|
+
this.emit("accountChanged", account2);
|
|
2010
|
+
console.debug("[WalletManager] Connect successful");
|
|
2011
|
+
return account2;
|
|
2012
|
+
} catch (connectError) {
|
|
2013
|
+
console.debug("[WalletManager] Connect failed (might be user rejection):", connectError?.message);
|
|
2014
|
+
return null;
|
|
2015
|
+
}
|
|
2016
|
+
} else {
|
|
2017
|
+
console.debug("[WalletManager] Address mismatch, will try normal connect");
|
|
2018
|
+
}
|
|
2019
|
+
} else {
|
|
2020
|
+
console.debug("[WalletManager] No authorized accounts found");
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
} catch (silentError) {
|
|
2024
|
+
console.debug("Silent connection failed, trying normal connection:", silentError);
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
if (adapter.chainType === ChainType.TRON && data.primaryWalletType === "tronlink" /* TRONLINK */) {
|
|
2028
|
+
try {
|
|
2029
|
+
const tronWeb = adapter.getTronWeb?.();
|
|
2030
|
+
if (tronWeb && tronWeb.defaultAddress?.base58) {
|
|
2031
|
+
const account2 = await adapter.connect(data.primaryChainId);
|
|
2032
|
+
this.setPrimaryWallet(adapter);
|
|
2033
|
+
this.connectedWallets.set(adapter.chainType, adapter);
|
|
2034
|
+
this.setupAdapterListeners(adapter, true);
|
|
2035
|
+
this.emit("accountChanged", account2);
|
|
2036
|
+
return account2;
|
|
2037
|
+
}
|
|
2038
|
+
} catch (silentError) {
|
|
2039
|
+
console.debug("Silent TronLink connection failed:", silentError);
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
const account = await adapter.connect(data.primaryChainId);
|
|
2043
|
+
this.setPrimaryWallet(adapter);
|
|
2044
|
+
this.connectedWallets.set(adapter.chainType, adapter);
|
|
2045
|
+
this.setupAdapterListeners(adapter, true);
|
|
2046
|
+
this.emit("accountChanged", account);
|
|
2047
|
+
return account;
|
|
2048
|
+
} catch (error) {
|
|
2049
|
+
console.debug("Failed to restore wallet from storage:", error);
|
|
2050
|
+
return null;
|
|
2051
|
+
}
|
|
1964
2052
|
}
|
|
1965
2053
|
/**
|
|
1966
|
-
*
|
|
2054
|
+
* Clear storage
|
|
1967
2055
|
*/
|
|
1968
2056
|
clearStorage() {
|
|
1969
2057
|
if (typeof window === "undefined") {
|
|
@@ -1976,7 +2064,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1976
2064
|
}
|
|
1977
2065
|
}
|
|
1978
2066
|
/**
|
|
1979
|
-
*
|
|
2067
|
+
* Get history records
|
|
1980
2068
|
*/
|
|
1981
2069
|
getHistoryRecords() {
|
|
1982
2070
|
const records = [];
|
|
@@ -2179,12 +2267,12 @@ function getTronWallets() {
|
|
|
2179
2267
|
// src/detection/detector.ts
|
|
2180
2268
|
var WalletDetector = class {
|
|
2181
2269
|
/**
|
|
2182
|
-
*
|
|
2270
|
+
* Detect all wallet availability
|
|
2183
2271
|
*/
|
|
2184
2272
|
async detectAllWallets() {
|
|
2185
2273
|
const walletTypes = Object.values(WalletType).filter(
|
|
2186
2274
|
(type) => type !== "private-key" /* PRIVATE_KEY */
|
|
2187
|
-
//
|
|
2275
|
+
// Private key wallet does not need detection
|
|
2188
2276
|
);
|
|
2189
2277
|
const results = await Promise.all(
|
|
2190
2278
|
walletTypes.map((type) => this.detectWallet(type))
|
|
@@ -2192,7 +2280,7 @@ var WalletDetector = class {
|
|
|
2192
2280
|
return results;
|
|
2193
2281
|
}
|
|
2194
2282
|
/**
|
|
2195
|
-
*
|
|
2283
|
+
* Detect specific wallet
|
|
2196
2284
|
*/
|
|
2197
2285
|
async detectWallet(walletType) {
|
|
2198
2286
|
const metadata = SUPPORTED_WALLETS[walletType];
|
|
@@ -2200,7 +2288,7 @@ var WalletDetector = class {
|
|
|
2200
2288
|
return {
|
|
2201
2289
|
walletType,
|
|
2202
2290
|
chainType: ChainType.EVM,
|
|
2203
|
-
//
|
|
2291
|
+
// Default
|
|
2204
2292
|
isAvailable: false,
|
|
2205
2293
|
detected: false
|
|
2206
2294
|
};
|
|
@@ -2215,7 +2303,7 @@ var WalletDetector = class {
|
|
|
2215
2303
|
};
|
|
2216
2304
|
}
|
|
2217
2305
|
/**
|
|
2218
|
-
*
|
|
2306
|
+
* Determine if wallet is available
|
|
2219
2307
|
*/
|
|
2220
2308
|
async isWalletAvailable(walletType) {
|
|
2221
2309
|
if (typeof window === "undefined") {
|