tiwiflix-wallet-connector 1.5.3 → 1.5.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.esm.js CHANGED
@@ -2344,11 +2344,6 @@ class WalletConnector {
2344
2344
  ...savedState,
2345
2345
  error: null, // Don't restore errors
2346
2346
  };
2347
- // PATCH: Prevent invalid connected state
2348
- if (this.state.status === ConnectionStatus.CONNECTED && !this.state.account) {
2349
- this.state.status = ConnectionStatus.DISCONNECTED;
2350
- this.state.wallet = null;
2351
- }
2352
2347
  }
2353
2348
  this.eventEmitter = new EventEmitter$1();
2354
2349
  // Initialize advanced SDK management
@@ -8064,8 +8059,6 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8064
8059
  });
8065
8060
  }
8066
8061
  // Subscribe to events
8067
- // Prevent repeated onConnect calls for the same account
8068
- const lastOnConnectAddress = React.useRef(null);
8069
8062
  const unsubscribeAccount = connector.on(WalletEvent.ACCOUNT_CHANGED, async (acc) => {
8070
8063
  setAccount(acc);
8071
8064
  // Don't set isInitializing to false yet - wait for balance to load
@@ -8078,7 +8071,8 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8078
8071
  }
8079
8072
  }
8080
8073
  if (acc && acc.chainType === 'ton') {
8081
- setTwcBalance('0');
8074
+ // For TON: fetch both balance and NFTs
8075
+ setTwcBalance('0'); // TON wallets don't have TWC
8082
8076
  try {
8083
8077
  await Promise.all([
8084
8078
  fetchTONBalance(acc),
@@ -8102,15 +8096,18 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8102
8096
  }
8103
8097
  }
8104
8098
  else if (acc) {
8099
+ // No fetchBalance, check for TWC balance
8105
8100
  const state = connector.getState();
8106
8101
  if (state.twcBalance && state.twcBalance !== '0' && state.twcBalance !== '0.00') {
8107
8102
  setTwcBalance(state.twcBalance);
8108
8103
  setUsdValueStable(state.usdValue ?? null);
8104
+ // Save to cache
8109
8105
  if (acc.address) {
8110
8106
  saveTWCBalanceToCache(acc.address, state.twcBalance, state.usdValue ?? null);
8111
8107
  }
8112
8108
  }
8113
8109
  else if (acc.address) {
8110
+ // Try to load from cache as fallback
8114
8111
  const cached = loadTWCBalanceFromCache(acc.address);
8115
8112
  if (cached?.balance) {
8116
8113
  setTwcBalance(cached.balance);
@@ -8123,10 +8120,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8123
8120
  setIsInitializing(false);
8124
8121
  }
8125
8122
  if (acc && onConnect) {
8126
- if (lastOnConnectAddress.current !== acc.address) {
8127
- onConnect(acc);
8128
- lastOnConnectAddress.current = acc.address;
8129
- }
8123
+ onConnect(acc);
8130
8124
  }
8131
8125
  });
8132
8126
  const unsubscribeStatus = connector.on(WalletEvent.STATUS_CHANGED, (newStatus) => {
@@ -8361,19 +8355,16 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8361
8355
  useEffect(() => {
8362
8356
  if (account && fetchBalance) {
8363
8357
  setBalanceLoading(true);
8364
- loadBalance().then((hasRealBalance) => {
8365
- setBalanceLoading(false);
8366
- // For TON wallets, always stop initializing after balance fetch completes (even if balance is 0)
8367
- // For other chains, only stop if we got a real balance
8368
- if (account.chainType === 'ton' || hasRealBalance) {
8369
- setIsInitializing(false);
8370
- }
8371
- }).catch(() => {
8358
+ loadBalance()
8359
+ .then(() => {
8360
+ // Always stop initializing once balance request completes
8361
+ })
8362
+ .catch(() => {
8363
+ // Ignore errors, we still clear loading states
8364
+ })
8365
+ .finally(() => {
8372
8366
  setBalanceLoading(false);
8373
- // Always stop initializing on error for TON
8374
- if (account.chainType === 'ton') {
8375
- setIsInitializing(false);
8376
- }
8367
+ setIsInitializing(false);
8377
8368
  });
8378
8369
  }
8379
8370
  else if (account && !fetchBalance) {
@@ -8636,15 +8627,6 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8636
8627
  isBalanceResolved = !balanceLoading && !isInitializing;
8637
8628
  }
8638
8629
  const waitingForBalance = account && !isBalanceResolved;
8639
- // Patch: If account is null and status is disconnected, always stop initializing/loading
8640
- if (!account && status === ConnectionStatus.DISCONNECTED && (isInitializing || isConnecting || balanceLoading)) {
8641
- if (isInitializing)
8642
- setIsInitializing(false);
8643
- if (isConnecting)
8644
- setIsConnecting(false);
8645
- if (balanceLoading)
8646
- setBalanceLoading(false);
8647
- }
8648
8630
  const isCheckingConnection = isInitializing || waitingForBalance || ((status === ConnectionStatus.CONNECTING || isConnecting) && !account);
8649
8631
  const isActuallyConnecting = (status === ConnectionStatus.CONNECTING || isConnecting) && account && isBalanceResolved;
8650
8632
  // Check connection state
package/dist/index.js CHANGED
@@ -2346,11 +2346,6 @@ class WalletConnector {
2346
2346
  ...savedState,
2347
2347
  error: null, // Don't restore errors
2348
2348
  };
2349
- // PATCH: Prevent invalid connected state
2350
- if (this.state.status === exports.ConnectionStatus.CONNECTED && !this.state.account) {
2351
- this.state.status = exports.ConnectionStatus.DISCONNECTED;
2352
- this.state.wallet = null;
2353
- }
2354
2349
  }
2355
2350
  this.eventEmitter = new EventEmitter$1();
2356
2351
  // Initialize advanced SDK management
@@ -8066,8 +8061,6 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8066
8061
  });
8067
8062
  }
8068
8063
  // Subscribe to events
8069
- // Prevent repeated onConnect calls for the same account
8070
- const lastOnConnectAddress = React.useRef(null);
8071
8064
  const unsubscribeAccount = connector.on(exports.WalletEvent.ACCOUNT_CHANGED, async (acc) => {
8072
8065
  setAccount(acc);
8073
8066
  // Don't set isInitializing to false yet - wait for balance to load
@@ -8080,7 +8073,8 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8080
8073
  }
8081
8074
  }
8082
8075
  if (acc && acc.chainType === 'ton') {
8083
- setTwcBalance('0');
8076
+ // For TON: fetch both balance and NFTs
8077
+ setTwcBalance('0'); // TON wallets don't have TWC
8084
8078
  try {
8085
8079
  await Promise.all([
8086
8080
  fetchTONBalance(acc),
@@ -8104,15 +8098,18 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8104
8098
  }
8105
8099
  }
8106
8100
  else if (acc) {
8101
+ // No fetchBalance, check for TWC balance
8107
8102
  const state = connector.getState();
8108
8103
  if (state.twcBalance && state.twcBalance !== '0' && state.twcBalance !== '0.00') {
8109
8104
  setTwcBalance(state.twcBalance);
8110
8105
  setUsdValueStable(state.usdValue ?? null);
8106
+ // Save to cache
8111
8107
  if (acc.address) {
8112
8108
  saveTWCBalanceToCache(acc.address, state.twcBalance, state.usdValue ?? null);
8113
8109
  }
8114
8110
  }
8115
8111
  else if (acc.address) {
8112
+ // Try to load from cache as fallback
8116
8113
  const cached = loadTWCBalanceFromCache(acc.address);
8117
8114
  if (cached?.balance) {
8118
8115
  setTwcBalance(cached.balance);
@@ -8125,10 +8122,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8125
8122
  setIsInitializing(false);
8126
8123
  }
8127
8124
  if (acc && onConnect) {
8128
- if (lastOnConnectAddress.current !== acc.address) {
8129
- onConnect(acc);
8130
- lastOnConnectAddress.current = acc.address;
8131
- }
8125
+ onConnect(acc);
8132
8126
  }
8133
8127
  });
8134
8128
  const unsubscribeStatus = connector.on(exports.WalletEvent.STATUS_CHANGED, (newStatus) => {
@@ -8363,19 +8357,16 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8363
8357
  React.useEffect(() => {
8364
8358
  if (account && fetchBalance) {
8365
8359
  setBalanceLoading(true);
8366
- loadBalance().then((hasRealBalance) => {
8367
- setBalanceLoading(false);
8368
- // For TON wallets, always stop initializing after balance fetch completes (even if balance is 0)
8369
- // For other chains, only stop if we got a real balance
8370
- if (account.chainType === 'ton' || hasRealBalance) {
8371
- setIsInitializing(false);
8372
- }
8373
- }).catch(() => {
8360
+ loadBalance()
8361
+ .then(() => {
8362
+ // Always stop initializing once balance request completes
8363
+ })
8364
+ .catch(() => {
8365
+ // Ignore errors, we still clear loading states
8366
+ })
8367
+ .finally(() => {
8374
8368
  setBalanceLoading(false);
8375
- // Always stop initializing on error for TON
8376
- if (account.chainType === 'ton') {
8377
- setIsInitializing(false);
8378
- }
8369
+ setIsInitializing(false);
8379
8370
  });
8380
8371
  }
8381
8372
  else if (account && !fetchBalance) {
@@ -8638,15 +8629,6 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
8638
8629
  isBalanceResolved = !balanceLoading && !isInitializing;
8639
8630
  }
8640
8631
  const waitingForBalance = account && !isBalanceResolved;
8641
- // Patch: If account is null and status is disconnected, always stop initializing/loading
8642
- if (!account && status === exports.ConnectionStatus.DISCONNECTED && (isInitializing || isConnecting || balanceLoading)) {
8643
- if (isInitializing)
8644
- setIsInitializing(false);
8645
- if (isConnecting)
8646
- setIsConnecting(false);
8647
- if (balanceLoading)
8648
- setBalanceLoading(false);
8649
- }
8650
8632
  const isCheckingConnection = isInitializing || waitingForBalance || ((status === exports.ConnectionStatus.CONNECTING || isConnecting) && !account);
8651
8633
  const isActuallyConnecting = (status === exports.ConnectionStatus.CONNECTING || isConnecting) && account && isBalanceResolved;
8652
8634
  // Check connection state
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiwiflix-wallet-connector",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
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",