tiwiflix-wallet-connector 1.6.1 → 1.6.3
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.esm.js +35 -26
- package/dist/index.js +35 -26
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -7367,7 +7367,9 @@ const WalletSelectModal = ({ isOpen, onClose, onSelectWallet, availableWallets,
|
|
|
7367
7367
|
flexShrink: 0,
|
|
7368
7368
|
fontFamily: 'Lexend, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
7369
7369
|
pointerEvents: 'none',
|
|
7370
|
-
}, children: "Connected" })) :
|
|
7370
|
+
}, children: "Connected" })) : (
|
|
7371
|
+
// For TON wallets on mobile, do not show Detected/Install button
|
|
7372
|
+
!(isMobile && wallet.chainType === 'ton') ? (isInstalled ? (jsx("button", { style: {
|
|
7371
7373
|
fontSize: '11px',
|
|
7372
7374
|
fontWeight: '600',
|
|
7373
7375
|
color: '#2BEE6C',
|
|
@@ -7391,7 +7393,7 @@ const WalletSelectModal = ({ isOpen, onClose, onSelectWallet, availableWallets,
|
|
|
7391
7393
|
flexShrink: 0,
|
|
7392
7394
|
fontFamily: 'Lexend, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
7393
7395
|
pointerEvents: 'none',
|
|
7394
|
-
}, children: "Install" }))] }, wallet.type));
|
|
7396
|
+
}, children: "Install" }))) : null)] }, wallet.type));
|
|
7395
7397
|
})] }, chain))) }), jsx("div", { style: {
|
|
7396
7398
|
padding: '16px 20px',
|
|
7397
7399
|
borderTop: `1px solid ${colors.border}`,
|
|
@@ -7517,7 +7519,7 @@ const TWCBalanceModal = ({ isOpen, onClose, twcBalance, usdValue, colors, isDark
|
|
|
7517
7519
|
|
|
7518
7520
|
const tonApiCache = new Map();
|
|
7519
7521
|
const CACHE_DURATION = 30000; // 30 seconds
|
|
7520
|
-
const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className, style, showBalance = false, modalPosition = 'center', theme = 'auto', buttonText = 'Connect Wallet
|
|
7522
|
+
const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className, style, showBalance = false, modalPosition = 'center', theme = 'auto', buttonText = 'Connect Wallet', getExplorerUrl, }) => {
|
|
7521
7523
|
// Always fetch balance automatically when wallet is connected
|
|
7522
7524
|
// Balance is always fetched automatically from the chain
|
|
7523
7525
|
// Detect dark mode
|
|
@@ -7822,7 +7824,15 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7822
7824
|
try {
|
|
7823
7825
|
const chainId = await connector.getCurrentChain();
|
|
7824
7826
|
setCurrentChainId(chainId);
|
|
7825
|
-
|
|
7827
|
+
if (chainId !== 56) {
|
|
7828
|
+
// Automatically switch to BSC
|
|
7829
|
+
try {
|
|
7830
|
+
await connector.switchChain(56);
|
|
7831
|
+
}
|
|
7832
|
+
catch (err) {
|
|
7833
|
+
// Optionally handle error (user rejected, etc.)
|
|
7834
|
+
}
|
|
7835
|
+
}
|
|
7826
7836
|
setIsWrongNetwork(false);
|
|
7827
7837
|
}
|
|
7828
7838
|
catch (err) {
|
|
@@ -8394,6 +8404,8 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8394
8404
|
}
|
|
8395
8405
|
catch (error) {
|
|
8396
8406
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
8407
|
+
// Log error for debugging WalletConnect issues
|
|
8408
|
+
console.error('[ConnectButton] Error fetching TWC balance:', err);
|
|
8397
8409
|
// Don't retry on certain errors
|
|
8398
8410
|
if (err.message.includes('No wallet connected') ||
|
|
8399
8411
|
err.message.includes('No EVM adapter')) {
|
|
@@ -8415,31 +8427,28 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8415
8427
|
console.log('[ConnectButton] useEffect: account or chain changed', { account, currentChainId });
|
|
8416
8428
|
// For EVM wallets, only fetch TWC balance if on BSC
|
|
8417
8429
|
if (account.chainType === 'evm' && currentChainId === 56) {
|
|
8418
|
-
//
|
|
8419
|
-
const
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8430
|
+
// Check cache first (30s TTL)
|
|
8431
|
+
const cache = loadTWCBalanceFromCache(account.address);
|
|
8432
|
+
const cacheValid = cache && typeof cache.balance === 'string' && cache.balance !== '0' && cache.balance !== '0.00' && cache.usdValue !== undefined && (() => {
|
|
8433
|
+
const cacheKey = `tiwiflix_twc_balance_cache_${account.address}`;
|
|
8434
|
+
const raw = localStorage.getItem(cacheKey);
|
|
8435
|
+
if (!raw)
|
|
8436
|
+
return false;
|
|
8437
|
+
try {
|
|
8438
|
+
const parsed = JSON.parse(raw);
|
|
8439
|
+
return parsed.timestamp && (Date.now() - parsed.timestamp < 30000);
|
|
8426
8440
|
}
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
}
|
|
8430
|
-
else if (account.address) {
|
|
8431
|
-
// Try cache first
|
|
8432
|
-
const cached = loadTWCBalanceFromCache(account.address);
|
|
8433
|
-
if (cached?.balance && cached.balance !== '0' && cached.balance !== '0.00') {
|
|
8434
|
-
setTwcBalance(cached.balance);
|
|
8435
|
-
setUsdValueStable(cached.usdValue);
|
|
8436
|
-
setIsInitializing(false);
|
|
8437
|
-
hasBalance = true;
|
|
8441
|
+
catch {
|
|
8442
|
+
return false;
|
|
8438
8443
|
}
|
|
8444
|
+
})();
|
|
8445
|
+
if (cacheValid) {
|
|
8446
|
+
setTwcBalance(cache.balance);
|
|
8447
|
+
setUsdValueStable(cache.usdValue);
|
|
8448
|
+
setIsInitializing(false);
|
|
8449
|
+
console.log('[ConnectButton] Using cached TWC balance:', cache);
|
|
8439
8450
|
}
|
|
8440
|
-
|
|
8441
|
-
if (!hasBalance || currentChainId !== null) {
|
|
8442
|
-
console.log('[ConnectButton] Fetching TWC balance for BSC wallet:', account.address, currentChainId);
|
|
8451
|
+
else {
|
|
8443
8452
|
fetchTWCBalanceWithRetry(2, 200).then((result) => {
|
|
8444
8453
|
if (!isActive)
|
|
8445
8454
|
return;
|
package/dist/index.js
CHANGED
|
@@ -7369,7 +7369,9 @@ const WalletSelectModal = ({ isOpen, onClose, onSelectWallet, availableWallets,
|
|
|
7369
7369
|
flexShrink: 0,
|
|
7370
7370
|
fontFamily: 'Lexend, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
7371
7371
|
pointerEvents: 'none',
|
|
7372
|
-
}, children: "Connected" })) :
|
|
7372
|
+
}, children: "Connected" })) : (
|
|
7373
|
+
// For TON wallets on mobile, do not show Detected/Install button
|
|
7374
|
+
!(isMobile && wallet.chainType === 'ton') ? (isInstalled ? (jsxRuntime.jsx("button", { style: {
|
|
7373
7375
|
fontSize: '11px',
|
|
7374
7376
|
fontWeight: '600',
|
|
7375
7377
|
color: '#2BEE6C',
|
|
@@ -7393,7 +7395,7 @@ const WalletSelectModal = ({ isOpen, onClose, onSelectWallet, availableWallets,
|
|
|
7393
7395
|
flexShrink: 0,
|
|
7394
7396
|
fontFamily: 'Lexend, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
7395
7397
|
pointerEvents: 'none',
|
|
7396
|
-
}, children: "Install" }))] }, wallet.type));
|
|
7398
|
+
}, children: "Install" }))) : null)] }, wallet.type));
|
|
7397
7399
|
})] }, chain))) }), jsxRuntime.jsx("div", { style: {
|
|
7398
7400
|
padding: '16px 20px',
|
|
7399
7401
|
borderTop: `1px solid ${colors.border}`,
|
|
@@ -7519,7 +7521,7 @@ const TWCBalanceModal = ({ isOpen, onClose, twcBalance, usdValue, colors, isDark
|
|
|
7519
7521
|
|
|
7520
7522
|
const tonApiCache = new Map();
|
|
7521
7523
|
const CACHE_DURATION = 30000; // 30 seconds
|
|
7522
|
-
const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className, style, showBalance = false, modalPosition = 'center', theme = 'auto', buttonText = 'Connect Wallet
|
|
7524
|
+
const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className, style, showBalance = false, modalPosition = 'center', theme = 'auto', buttonText = 'Connect Wallet', getExplorerUrl, }) => {
|
|
7523
7525
|
// Always fetch balance automatically when wallet is connected
|
|
7524
7526
|
// Balance is always fetched automatically from the chain
|
|
7525
7527
|
// Detect dark mode
|
|
@@ -7824,7 +7826,15 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7824
7826
|
try {
|
|
7825
7827
|
const chainId = await connector.getCurrentChain();
|
|
7826
7828
|
setCurrentChainId(chainId);
|
|
7827
|
-
|
|
7829
|
+
if (chainId !== 56) {
|
|
7830
|
+
// Automatically switch to BSC
|
|
7831
|
+
try {
|
|
7832
|
+
await connector.switchChain(56);
|
|
7833
|
+
}
|
|
7834
|
+
catch (err) {
|
|
7835
|
+
// Optionally handle error (user rejected, etc.)
|
|
7836
|
+
}
|
|
7837
|
+
}
|
|
7828
7838
|
setIsWrongNetwork(false);
|
|
7829
7839
|
}
|
|
7830
7840
|
catch (err) {
|
|
@@ -8396,6 +8406,8 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8396
8406
|
}
|
|
8397
8407
|
catch (error) {
|
|
8398
8408
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
8409
|
+
// Log error for debugging WalletConnect issues
|
|
8410
|
+
console.error('[ConnectButton] Error fetching TWC balance:', err);
|
|
8399
8411
|
// Don't retry on certain errors
|
|
8400
8412
|
if (err.message.includes('No wallet connected') ||
|
|
8401
8413
|
err.message.includes('No EVM adapter')) {
|
|
@@ -8417,31 +8429,28 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8417
8429
|
console.log('[ConnectButton] useEffect: account or chain changed', { account, currentChainId });
|
|
8418
8430
|
// For EVM wallets, only fetch TWC balance if on BSC
|
|
8419
8431
|
if (account.chainType === 'evm' && currentChainId === 56) {
|
|
8420
|
-
//
|
|
8421
|
-
const
|
|
8422
|
-
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8426
|
-
|
|
8427
|
-
|
|
8432
|
+
// Check cache first (30s TTL)
|
|
8433
|
+
const cache = loadTWCBalanceFromCache(account.address);
|
|
8434
|
+
const cacheValid = cache && typeof cache.balance === 'string' && cache.balance !== '0' && cache.balance !== '0.00' && cache.usdValue !== undefined && (() => {
|
|
8435
|
+
const cacheKey = `tiwiflix_twc_balance_cache_${account.address}`;
|
|
8436
|
+
const raw = localStorage.getItem(cacheKey);
|
|
8437
|
+
if (!raw)
|
|
8438
|
+
return false;
|
|
8439
|
+
try {
|
|
8440
|
+
const parsed = JSON.parse(raw);
|
|
8441
|
+
return parsed.timestamp && (Date.now() - parsed.timestamp < 30000);
|
|
8428
8442
|
}
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
}
|
|
8432
|
-
else if (account.address) {
|
|
8433
|
-
// Try cache first
|
|
8434
|
-
const cached = loadTWCBalanceFromCache(account.address);
|
|
8435
|
-
if (cached?.balance && cached.balance !== '0' && cached.balance !== '0.00') {
|
|
8436
|
-
setTwcBalance(cached.balance);
|
|
8437
|
-
setUsdValueStable(cached.usdValue);
|
|
8438
|
-
setIsInitializing(false);
|
|
8439
|
-
hasBalance = true;
|
|
8443
|
+
catch {
|
|
8444
|
+
return false;
|
|
8440
8445
|
}
|
|
8446
|
+
})();
|
|
8447
|
+
if (cacheValid) {
|
|
8448
|
+
setTwcBalance(cache.balance);
|
|
8449
|
+
setUsdValueStable(cache.usdValue);
|
|
8450
|
+
setIsInitializing(false);
|
|
8451
|
+
console.log('[ConnectButton] Using cached TWC balance:', cache);
|
|
8441
8452
|
}
|
|
8442
|
-
|
|
8443
|
-
if (!hasBalance || currentChainId !== null) {
|
|
8444
|
-
console.log('[ConnectButton] Fetching TWC balance for BSC wallet:', account.address, currentChainId);
|
|
8453
|
+
else {
|
|
8445
8454
|
fetchTWCBalanceWithRetry(2, 200).then((result) => {
|
|
8446
8455
|
if (!isActive)
|
|
8447
8456
|
return;
|
package/package.json
CHANGED