tiwiflix-wallet-connector 1.6.2 → 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 CHANGED
@@ -8404,6 +8404,8 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8404
8404
  }
8405
8405
  catch (error) {
8406
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);
8407
8409
  // Don't retry on certain errors
8408
8410
  if (err.message.includes('No wallet connected') ||
8409
8411
  err.message.includes('No EVM adapter')) {
@@ -8425,31 +8427,28 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8425
8427
  console.log('[ConnectButton] useEffect: account or chain changed', { account, currentChainId });
8426
8428
  // For EVM wallets, only fetch TWC balance if on BSC
8427
8429
  if (account.chainType === 'evm' && currentChainId === 56) {
8428
- // First check state/cache for immediate display
8429
- const state = connector.getState();
8430
- let hasBalance = false;
8431
- if (state.twcBalance && state.twcBalance !== '0' && state.twcBalance !== '0.00') {
8432
- setTwcBalance(state.twcBalance);
8433
- setUsdValueStable(state.usdValue ?? null);
8434
- if (account.address) {
8435
- saveTWCBalanceToCache(account.address, state.twcBalance, state.usdValue ?? null);
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);
8436
8440
  }
8437
- setIsInitializing(false);
8438
- hasBalance = true;
8439
- }
8440
- else if (account.address) {
8441
- // Try cache first
8442
- const cached = loadTWCBalanceFromCache(account.address);
8443
- if (cached?.balance && cached.balance !== '0' && cached.balance !== '0.00') {
8444
- setTwcBalance(cached.balance);
8445
- setUsdValueStable(cached.usdValue);
8446
- setIsInitializing(false);
8447
- hasBalance = true;
8441
+ catch {
8442
+ return false;
8448
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);
8449
8450
  }
8450
- // Only fetch if we don't have a balance yet, or if the chain/network changed
8451
- if (!hasBalance || currentChainId !== null) {
8452
- console.log('[ConnectButton] Fetching TWC balance for BSC wallet:', account.address, currentChainId);
8451
+ else {
8453
8452
  fetchTWCBalanceWithRetry(2, 200).then((result) => {
8454
8453
  if (!isActive)
8455
8454
  return;
package/dist/index.js CHANGED
@@ -8406,6 +8406,8 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8406
8406
  }
8407
8407
  catch (error) {
8408
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);
8409
8411
  // Don't retry on certain errors
8410
8412
  if (err.message.includes('No wallet connected') ||
8411
8413
  err.message.includes('No EVM adapter')) {
@@ -8427,31 +8429,28 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8427
8429
  console.log('[ConnectButton] useEffect: account or chain changed', { account, currentChainId });
8428
8430
  // For EVM wallets, only fetch TWC balance if on BSC
8429
8431
  if (account.chainType === 'evm' && currentChainId === 56) {
8430
- // First check state/cache for immediate display
8431
- const state = connector.getState();
8432
- let hasBalance = false;
8433
- if (state.twcBalance && state.twcBalance !== '0' && state.twcBalance !== '0.00') {
8434
- setTwcBalance(state.twcBalance);
8435
- setUsdValueStable(state.usdValue ?? null);
8436
- if (account.address) {
8437
- saveTWCBalanceToCache(account.address, state.twcBalance, state.usdValue ?? null);
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);
8438
8442
  }
8439
- setIsInitializing(false);
8440
- hasBalance = true;
8441
- }
8442
- else if (account.address) {
8443
- // Try cache first
8444
- const cached = loadTWCBalanceFromCache(account.address);
8445
- if (cached?.balance && cached.balance !== '0' && cached.balance !== '0.00') {
8446
- setTwcBalance(cached.balance);
8447
- setUsdValueStable(cached.usdValue);
8448
- setIsInitializing(false);
8449
- hasBalance = true;
8443
+ catch {
8444
+ return false;
8450
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);
8451
8452
  }
8452
- // Only fetch if we don't have a balance yet, or if the chain/network changed
8453
- if (!hasBalance || currentChainId !== null) {
8454
- console.log('[ConnectButton] Fetching TWC balance for BSC wallet:', account.address, currentChainId);
8453
+ else {
8455
8454
  fetchTWCBalanceWithRetry(2, 200).then((result) => {
8456
8455
  if (!isActive)
8457
8456
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiwiflix-wallet-connector",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
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",