tiwiflix-wallet-connector 1.6.4 → 1.6.6

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 CHANGED
@@ -7517,31 +7517,41 @@ const TWCBalanceModal = ({ isOpen, onClose, twcBalance, usdValue, colors, isDark
7517
7517
  }, children: "Learn More" })] })] }) }));
7518
7518
  };
7519
7519
 
7520
- // Track previous connection status to detect new connections
7521
- const prevStatusRef = useRef(null);
7522
- // Listen for connector status changes and fetch TWC balance after WalletConnect connects
7523
- useEffect(() => {
7524
- const status = connector?.getState?.().status;
7525
- const account = connector?.getState?.().account;
7526
- const chainId = connector?.getState?.().chainId;
7527
- // Only trigger on transition to CONNECTED
7528
- if (status === 'connected' && prevStatusRef.current !== 'connected' && account && account.chainType === 'evm' && chainId === 56) {
7529
- // Fetch TWC balance immediately after connection
7530
- const cacheKey = `tiwiflix_twc_balance_cache_${account.address}`;
7531
- fetchTWCBalanceWithRetry(2, 200).then((result) => {
7532
- if (result && result.balance !== '0' && result.balance !== '0.00') {
7533
- setTwcBalance(result.balance);
7534
- setUsdValueStable(result.usdValue);
7535
- if (account.address) {
7536
- localStorage.setItem(cacheKey, JSON.stringify({ balance: result.balance, usdValue: result.usdValue, timestamp: Date.now() }));
7537
- }
7538
- setIsInitializing(false);
7539
- console.log('[ConnectButton] TWC balance fetched after WalletConnect connect:', result);
7540
- }
7541
- });
7520
+ // Debug log overlay for mobile
7521
+ function showDebugLog(msg) {
7522
+ if (typeof window === 'undefined')
7523
+ return;
7524
+ let logDiv = document.getElementById('twc-debug-log');
7525
+ if (!logDiv) {
7526
+ logDiv = document.createElement('div');
7527
+ logDiv.id = 'twc-debug-log';
7528
+ logDiv.style.position = 'fixed';
7529
+ logDiv.style.bottom = '10px';
7530
+ logDiv.style.left = '10px';
7531
+ logDiv.style.right = '10px';
7532
+ logDiv.style.maxHeight = '40vh';
7533
+ logDiv.style.overflowY = 'auto';
7534
+ logDiv.style.background = 'rgba(0,0,0,0.85)';
7535
+ logDiv.style.color = '#fff';
7536
+ logDiv.style.fontSize = '12px';
7537
+ logDiv.style.zIndex = '99999';
7538
+ logDiv.style.padding = '8px 12px';
7539
+ logDiv.style.borderRadius = '8px';
7540
+ logDiv.style.pointerEvents = 'auto';
7541
+ logDiv.style.fontFamily = 'monospace';
7542
+ logDiv.style.boxShadow = '0 2px 12px rgba(0,0,0,0.3)';
7543
+ logDiv.innerHTML = '';
7544
+ document.body.appendChild(logDiv);
7545
+ }
7546
+ const now = new Date();
7547
+ const time = now.toLocaleTimeString();
7548
+ logDiv.innerHTML = `<div>[${time}] ${msg}</div>` + logDiv.innerHTML;
7549
+ // Limit to 30 log lines
7550
+ const lines = logDiv.innerHTML.split('<div>');
7551
+ if (lines.length > 30) {
7552
+ logDiv.innerHTML = lines.slice(0, 30).join('<div>');
7542
7553
  }
7543
- prevStatusRef.current = status;
7544
- }, [connector, fetchTWCBalanceWithRetry]);
7554
+ }
7545
7555
  const tonApiCache = new Map();
7546
7556
  const CACHE_DURATION = 30000; // 30 seconds
7547
7557
  const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className, style, showBalance = false, modalPosition = 'center', theme = 'auto', buttonText = 'Connect Wallet', getExplorerUrl, }) => {
@@ -8444,6 +8454,30 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8444
8454
  }
8445
8455
  return null;
8446
8456
  }, [connector]);
8457
+ const prevStatusRef = useRef(null);
8458
+ // Listen for connector status changes and fetch TWC balance after WalletConnect connects
8459
+ useEffect(() => {
8460
+ const status = connector?.getState?.().status;
8461
+ const account = connector?.getState?.().account;
8462
+ const chainId = connector?.getState?.().chainId;
8463
+ // Only trigger on transition to CONNECTED
8464
+ if (status === 'connected' && prevStatusRef.current !== 'connected' && account && account.chainType === 'evm' && chainId === 56) {
8465
+ // Fetch TWC balance immediately after connection
8466
+ const cacheKey = `tiwiflix_twc_balance_cache_${account.address}`;
8467
+ fetchTWCBalanceWithRetry(2, 200).then((result) => {
8468
+ showDebugLog(`[ConnectButton] TWC balance fetch after WalletConnect connect: status=${status}, account=${account?.address}, chainId=${chainId}, result=${JSON.stringify(result)}`);
8469
+ if (result && result.balance !== '0' && result.balance !== '0.00') {
8470
+ setTwcBalance(result.balance);
8471
+ setUsdValueStable(result.usdValue);
8472
+ if (account.address) {
8473
+ localStorage.setItem(cacheKey, JSON.stringify({ balance: result.balance, usdValue: result.usdValue, timestamp: Date.now() }));
8474
+ }
8475
+ setIsInitializing(false);
8476
+ }
8477
+ });
8478
+ }
8479
+ prevStatusRef.current = status;
8480
+ }, [connector, fetchTWCBalanceWithRetry]);
8447
8481
  // Load balance when account or network (chain) changes
8448
8482
  useEffect(() => {
8449
8483
  let isActive = true;
@@ -8469,7 +8503,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8469
8503
  setTwcBalance(cache.balance);
8470
8504
  setUsdValueStable(cache.usdValue);
8471
8505
  setIsInitializing(false);
8472
- console.log('[ConnectButton] Using localStorage cached TWC balance:', cache);
8506
+ showDebugLog(`[ConnectButton] Using localStorage cached TWC balance: ${JSON.stringify(cache)}`);
8473
8507
  // Fetch in background to update cache, but don't reset UI while fetching
8474
8508
  fetchTWCBalanceWithRetry(2, 200).then((result) => {
8475
8509
  if (!isActive)
@@ -8482,7 +8516,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8482
8516
  localStorage.setItem(cacheKey, JSON.stringify({ balance: result.balance, usdValue: result.usdValue, timestamp: Date.now() }));
8483
8517
  }
8484
8518
  setIsInitializing(false);
8485
- console.log('[ConnectButton] TWC balance updated after background fetch:', result);
8519
+ showDebugLog(`[ConnectButton] TWC balance updated after background fetch: ${JSON.stringify(result)}`);
8486
8520
  }
8487
8521
  }).catch(() => {
8488
8522
  // Ignore errors in background fetch
@@ -8502,19 +8536,19 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8502
8536
  localStorage.setItem(cacheKey, JSON.stringify({ balance: result.balance, usdValue: result.usdValue, timestamp: Date.now() }));
8503
8537
  }
8504
8538
  setIsInitializing(false);
8505
- console.log('[ConnectButton] TWC balance fetched and cached:', result);
8539
+ showDebugLog(`[ConnectButton] TWC balance fetched and cached: ${JSON.stringify(result)}`);
8506
8540
  }
8507
8541
  else {
8508
8542
  setTwcBalance('0');
8509
8543
  setUsdValueStable(null);
8510
8544
  setIsInitializing(false);
8511
- console.warn('[ConnectButton] No TWC balance found for BSC wallet:', account.address);
8545
+ showDebugLog(`[ConnectButton] No TWC balance found for BSC wallet: ${account.address}`);
8512
8546
  }
8513
8547
  }).catch(() => {
8514
8548
  if (!isActive)
8515
8549
  return;
8516
8550
  setIsInitializing(false);
8517
- console.error('[ConnectButton] Error fetching TWC balance for BSC wallet:', account.address);
8551
+ showDebugLog(`[ConnectButton] Error fetching TWC balance for BSC wallet: ${account.address}`);
8518
8552
  });
8519
8553
  }
8520
8554
  }
package/dist/index.js CHANGED
@@ -7519,31 +7519,41 @@ const TWCBalanceModal = ({ isOpen, onClose, twcBalance, usdValue, colors, isDark
7519
7519
  }, children: "Learn More" })] })] }) }));
7520
7520
  };
7521
7521
 
7522
- // Track previous connection status to detect new connections
7523
- const prevStatusRef = React.useRef(null);
7524
- // Listen for connector status changes and fetch TWC balance after WalletConnect connects
7525
- React.useEffect(() => {
7526
- const status = connector?.getState?.().status;
7527
- const account = connector?.getState?.().account;
7528
- const chainId = connector?.getState?.().chainId;
7529
- // Only trigger on transition to CONNECTED
7530
- if (status === 'connected' && prevStatusRef.current !== 'connected' && account && account.chainType === 'evm' && chainId === 56) {
7531
- // Fetch TWC balance immediately after connection
7532
- const cacheKey = `tiwiflix_twc_balance_cache_${account.address}`;
7533
- fetchTWCBalanceWithRetry(2, 200).then((result) => {
7534
- if (result && result.balance !== '0' && result.balance !== '0.00') {
7535
- setTwcBalance(result.balance);
7536
- setUsdValueStable(result.usdValue);
7537
- if (account.address) {
7538
- localStorage.setItem(cacheKey, JSON.stringify({ balance: result.balance, usdValue: result.usdValue, timestamp: Date.now() }));
7539
- }
7540
- setIsInitializing(false);
7541
- console.log('[ConnectButton] TWC balance fetched after WalletConnect connect:', result);
7542
- }
7543
- });
7522
+ // Debug log overlay for mobile
7523
+ function showDebugLog(msg) {
7524
+ if (typeof window === 'undefined')
7525
+ return;
7526
+ let logDiv = document.getElementById('twc-debug-log');
7527
+ if (!logDiv) {
7528
+ logDiv = document.createElement('div');
7529
+ logDiv.id = 'twc-debug-log';
7530
+ logDiv.style.position = 'fixed';
7531
+ logDiv.style.bottom = '10px';
7532
+ logDiv.style.left = '10px';
7533
+ logDiv.style.right = '10px';
7534
+ logDiv.style.maxHeight = '40vh';
7535
+ logDiv.style.overflowY = 'auto';
7536
+ logDiv.style.background = 'rgba(0,0,0,0.85)';
7537
+ logDiv.style.color = '#fff';
7538
+ logDiv.style.fontSize = '12px';
7539
+ logDiv.style.zIndex = '99999';
7540
+ logDiv.style.padding = '8px 12px';
7541
+ logDiv.style.borderRadius = '8px';
7542
+ logDiv.style.pointerEvents = 'auto';
7543
+ logDiv.style.fontFamily = 'monospace';
7544
+ logDiv.style.boxShadow = '0 2px 12px rgba(0,0,0,0.3)';
7545
+ logDiv.innerHTML = '';
7546
+ document.body.appendChild(logDiv);
7547
+ }
7548
+ const now = new Date();
7549
+ const time = now.toLocaleTimeString();
7550
+ logDiv.innerHTML = `<div>[${time}] ${msg}</div>` + logDiv.innerHTML;
7551
+ // Limit to 30 log lines
7552
+ const lines = logDiv.innerHTML.split('<div>');
7553
+ if (lines.length > 30) {
7554
+ logDiv.innerHTML = lines.slice(0, 30).join('<div>');
7544
7555
  }
7545
- prevStatusRef.current = status;
7546
- }, [connector, fetchTWCBalanceWithRetry]);
7556
+ }
7547
7557
  const tonApiCache = new Map();
7548
7558
  const CACHE_DURATION = 30000; // 30 seconds
7549
7559
  const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className, style, showBalance = false, modalPosition = 'center', theme = 'auto', buttonText = 'Connect Wallet', getExplorerUrl, }) => {
@@ -8446,6 +8456,30 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8446
8456
  }
8447
8457
  return null;
8448
8458
  }, [connector]);
8459
+ const prevStatusRef = React.useRef(null);
8460
+ // Listen for connector status changes and fetch TWC balance after WalletConnect connects
8461
+ React.useEffect(() => {
8462
+ const status = connector?.getState?.().status;
8463
+ const account = connector?.getState?.().account;
8464
+ const chainId = connector?.getState?.().chainId;
8465
+ // Only trigger on transition to CONNECTED
8466
+ if (status === 'connected' && prevStatusRef.current !== 'connected' && account && account.chainType === 'evm' && chainId === 56) {
8467
+ // Fetch TWC balance immediately after connection
8468
+ const cacheKey = `tiwiflix_twc_balance_cache_${account.address}`;
8469
+ fetchTWCBalanceWithRetry(2, 200).then((result) => {
8470
+ showDebugLog(`[ConnectButton] TWC balance fetch after WalletConnect connect: status=${status}, account=${account?.address}, chainId=${chainId}, result=${JSON.stringify(result)}`);
8471
+ if (result && result.balance !== '0' && result.balance !== '0.00') {
8472
+ setTwcBalance(result.balance);
8473
+ setUsdValueStable(result.usdValue);
8474
+ if (account.address) {
8475
+ localStorage.setItem(cacheKey, JSON.stringify({ balance: result.balance, usdValue: result.usdValue, timestamp: Date.now() }));
8476
+ }
8477
+ setIsInitializing(false);
8478
+ }
8479
+ });
8480
+ }
8481
+ prevStatusRef.current = status;
8482
+ }, [connector, fetchTWCBalanceWithRetry]);
8449
8483
  // Load balance when account or network (chain) changes
8450
8484
  React.useEffect(() => {
8451
8485
  let isActive = true;
@@ -8471,7 +8505,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8471
8505
  setTwcBalance(cache.balance);
8472
8506
  setUsdValueStable(cache.usdValue);
8473
8507
  setIsInitializing(false);
8474
- console.log('[ConnectButton] Using localStorage cached TWC balance:', cache);
8508
+ showDebugLog(`[ConnectButton] Using localStorage cached TWC balance: ${JSON.stringify(cache)}`);
8475
8509
  // Fetch in background to update cache, but don't reset UI while fetching
8476
8510
  fetchTWCBalanceWithRetry(2, 200).then((result) => {
8477
8511
  if (!isActive)
@@ -8484,7 +8518,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8484
8518
  localStorage.setItem(cacheKey, JSON.stringify({ balance: result.balance, usdValue: result.usdValue, timestamp: Date.now() }));
8485
8519
  }
8486
8520
  setIsInitializing(false);
8487
- console.log('[ConnectButton] TWC balance updated after background fetch:', result);
8521
+ showDebugLog(`[ConnectButton] TWC balance updated after background fetch: ${JSON.stringify(result)}`);
8488
8522
  }
8489
8523
  }).catch(() => {
8490
8524
  // Ignore errors in background fetch
@@ -8504,19 +8538,19 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8504
8538
  localStorage.setItem(cacheKey, JSON.stringify({ balance: result.balance, usdValue: result.usdValue, timestamp: Date.now() }));
8505
8539
  }
8506
8540
  setIsInitializing(false);
8507
- console.log('[ConnectButton] TWC balance fetched and cached:', result);
8541
+ showDebugLog(`[ConnectButton] TWC balance fetched and cached: ${JSON.stringify(result)}`);
8508
8542
  }
8509
8543
  else {
8510
8544
  setTwcBalance('0');
8511
8545
  setUsdValueStable(null);
8512
8546
  setIsInitializing(false);
8513
- console.warn('[ConnectButton] No TWC balance found for BSC wallet:', account.address);
8547
+ showDebugLog(`[ConnectButton] No TWC balance found for BSC wallet: ${account.address}`);
8514
8548
  }
8515
8549
  }).catch(() => {
8516
8550
  if (!isActive)
8517
8551
  return;
8518
8552
  setIsInitializing(false);
8519
- console.error('[ConnectButton] Error fetching TWC balance for BSC wallet:', account.address);
8553
+ showDebugLog(`[ConnectButton] Error fetching TWC balance for BSC wallet: ${account.address}`);
8520
8554
  });
8521
8555
  }
8522
8556
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiwiflix-wallet-connector",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "description": "Multi-chain wallet connector for Tiwiflix supporting EVM, TON, Solana, and Tron wallets",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",