tiwiflix-wallet-connector 1.5.4 → 1.5.5
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 +51 -16
- package/dist/index.js +51 -16
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -2508,9 +2508,37 @@ class WalletConnector {
|
|
|
2508
2508
|
});
|
|
2509
2509
|
this.eventEmitter.emit(WalletEvent.CONNECTED, account);
|
|
2510
2510
|
}
|
|
2511
|
+
else {
|
|
2512
|
+
// No account found - user likely cancelled or connection failed
|
|
2513
|
+
this.debugTools.info('WALLET_CONNECTOR', 'No account found after visibility change - resetting state');
|
|
2514
|
+
clearTimeout(connectionTimeout);
|
|
2515
|
+
clearTimeout(safetyTimeout);
|
|
2516
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
2517
|
+
this.updateState({
|
|
2518
|
+
status: ConnectionStatus.DISCONNECTED,
|
|
2519
|
+
wallet: null,
|
|
2520
|
+
error: new Error('Connection cancelled or failed'),
|
|
2521
|
+
});
|
|
2522
|
+
this.eventEmitter.emit(WalletEvent.ERROR, new Error('Connection cancelled or failed'));
|
|
2523
|
+
}
|
|
2511
2524
|
}
|
|
2512
2525
|
catch (err) {
|
|
2513
2526
|
this.debugTools.warn('WALLET_CONNECTOR', 'Failed to check account on visibility change', err);
|
|
2527
|
+
// On error checking account, reset state after a longer delay
|
|
2528
|
+
setTimeout(() => {
|
|
2529
|
+
if (this.state.status === ConnectionStatus.CONNECTING) {
|
|
2530
|
+
this.debugTools.info('WALLET_CONNECTOR', 'Still connecting after visibility check error - resetting state');
|
|
2531
|
+
clearTimeout(connectionTimeout);
|
|
2532
|
+
clearTimeout(safetyTimeout);
|
|
2533
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
2534
|
+
this.updateState({
|
|
2535
|
+
status: ConnectionStatus.DISCONNECTED,
|
|
2536
|
+
wallet: null,
|
|
2537
|
+
error: new Error('Connection timeout'),
|
|
2538
|
+
});
|
|
2539
|
+
this.eventEmitter.emit(WalletEvent.ERROR, new Error('Connection timeout'));
|
|
2540
|
+
}
|
|
2541
|
+
}, 3000); // Give it 3 more seconds
|
|
2514
2542
|
}
|
|
2515
2543
|
}
|
|
2516
2544
|
}, 1000);
|
|
@@ -7856,6 +7884,8 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7856
7884
|
// Get initial state
|
|
7857
7885
|
const initialState = connector.getState();
|
|
7858
7886
|
setStatus(initialState.status);
|
|
7887
|
+
// Safety: Clear isConnecting on mount (in case it was stuck from previous session)
|
|
7888
|
+
setIsConnecting(false);
|
|
7859
7889
|
// Only set wallets once to prevent re-renders
|
|
7860
7890
|
if (!walletsRef.current) {
|
|
7861
7891
|
walletsRef.current = connector.getAllWallets();
|
|
@@ -8061,6 +8091,8 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8061
8091
|
// Subscribe to events
|
|
8062
8092
|
const unsubscribeAccount = connector.on(WalletEvent.ACCOUNT_CHANGED, async (acc) => {
|
|
8063
8093
|
setAccount(acc);
|
|
8094
|
+
// Clear isConnecting when account changes (connection succeeded)
|
|
8095
|
+
setIsConnecting(false);
|
|
8064
8096
|
// Don't set isInitializing to false yet - wait for balance to load
|
|
8065
8097
|
// Load cached balance for new account immediately
|
|
8066
8098
|
if (acc?.address) {
|
|
@@ -8125,9 +8157,14 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8125
8157
|
});
|
|
8126
8158
|
const unsubscribeStatus = connector.on(WalletEvent.STATUS_CHANGED, (newStatus) => {
|
|
8127
8159
|
setStatus(newStatus);
|
|
8128
|
-
// If status changes to disconnected, stop initializing
|
|
8160
|
+
// If status changes to disconnected, stop initializing and connecting
|
|
8129
8161
|
if (newStatus === ConnectionStatus.DISCONNECTED) {
|
|
8130
8162
|
setIsInitializing(false);
|
|
8163
|
+
setIsConnecting(false);
|
|
8164
|
+
}
|
|
8165
|
+
// If status changes to connected, clear connecting state
|
|
8166
|
+
if (newStatus === ConnectionStatus.CONNECTED) {
|
|
8167
|
+
setIsConnecting(false);
|
|
8131
8168
|
}
|
|
8132
8169
|
});
|
|
8133
8170
|
const unsubscribeDisconnect = connector.on(WalletEvent.DISCONNECTED, () => {
|
|
@@ -8478,6 +8515,11 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8478
8515
|
const handleConnect = useCallback(async (walletType) => {
|
|
8479
8516
|
setIsConnecting(true);
|
|
8480
8517
|
setError(null);
|
|
8518
|
+
// Safety timeout: ensure isConnecting is cleared after 75 seconds maximum
|
|
8519
|
+
const safetyTimeout = setTimeout(() => {
|
|
8520
|
+
setIsConnecting(false);
|
|
8521
|
+
setIsInitializing(false);
|
|
8522
|
+
}, 75000);
|
|
8481
8523
|
// Close modal BEFORE connecting for TON wallets and WalletConnect
|
|
8482
8524
|
// so external modals can show
|
|
8483
8525
|
const isTonWallet = ['tonkeeper', 'tonhub', 'mytonwallet'].includes(walletType);
|
|
@@ -8491,27 +8533,20 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8491
8533
|
setShowSendModal(false);
|
|
8492
8534
|
}
|
|
8493
8535
|
try {
|
|
8494
|
-
|
|
8495
|
-
|
|
8496
|
-
|
|
8497
|
-
|
|
8498
|
-
setIsInitializing(false);
|
|
8499
|
-
}
|
|
8500
|
-
else {
|
|
8501
|
-
// Fallback: get account after connection
|
|
8502
|
-
const newAccount = await connector.getAccount();
|
|
8503
|
-
if (newAccount) {
|
|
8504
|
-
setAccount(newAccount);
|
|
8505
|
-
setIsInitializing(false);
|
|
8506
|
-
}
|
|
8507
|
-
}
|
|
8536
|
+
// connector.connect() returns void - state updates happen via events
|
|
8537
|
+
await connector.connect(walletType);
|
|
8538
|
+
// Connection succeeded - state is updated via ACCOUNT_CHANGED event
|
|
8539
|
+
// which also clears isConnecting
|
|
8508
8540
|
// Close modal after connection for non-TON/walletconnect wallets
|
|
8509
8541
|
if (!isTonWallet && !isWalletConnect) {
|
|
8510
8542
|
setShowModal(false);
|
|
8511
8543
|
}
|
|
8512
|
-
|
|
8544
|
+
// Clear safety timeout on success
|
|
8545
|
+
clearTimeout(safetyTimeout);
|
|
8513
8546
|
}
|
|
8514
8547
|
catch (err) {
|
|
8548
|
+
// Clear safety timeout on error
|
|
8549
|
+
clearTimeout(safetyTimeout);
|
|
8515
8550
|
// Always clear connection state on error
|
|
8516
8551
|
setAccount(null);
|
|
8517
8552
|
setStatus(ConnectionStatus.DISCONNECTED);
|
package/dist/index.js
CHANGED
|
@@ -2510,9 +2510,37 @@ class WalletConnector {
|
|
|
2510
2510
|
});
|
|
2511
2511
|
this.eventEmitter.emit(exports.WalletEvent.CONNECTED, account);
|
|
2512
2512
|
}
|
|
2513
|
+
else {
|
|
2514
|
+
// No account found - user likely cancelled or connection failed
|
|
2515
|
+
this.debugTools.info('WALLET_CONNECTOR', 'No account found after visibility change - resetting state');
|
|
2516
|
+
clearTimeout(connectionTimeout);
|
|
2517
|
+
clearTimeout(safetyTimeout);
|
|
2518
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
2519
|
+
this.updateState({
|
|
2520
|
+
status: exports.ConnectionStatus.DISCONNECTED,
|
|
2521
|
+
wallet: null,
|
|
2522
|
+
error: new Error('Connection cancelled or failed'),
|
|
2523
|
+
});
|
|
2524
|
+
this.eventEmitter.emit(exports.WalletEvent.ERROR, new Error('Connection cancelled or failed'));
|
|
2525
|
+
}
|
|
2513
2526
|
}
|
|
2514
2527
|
catch (err) {
|
|
2515
2528
|
this.debugTools.warn('WALLET_CONNECTOR', 'Failed to check account on visibility change', err);
|
|
2529
|
+
// On error checking account, reset state after a longer delay
|
|
2530
|
+
setTimeout(() => {
|
|
2531
|
+
if (this.state.status === exports.ConnectionStatus.CONNECTING) {
|
|
2532
|
+
this.debugTools.info('WALLET_CONNECTOR', 'Still connecting after visibility check error - resetting state');
|
|
2533
|
+
clearTimeout(connectionTimeout);
|
|
2534
|
+
clearTimeout(safetyTimeout);
|
|
2535
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
2536
|
+
this.updateState({
|
|
2537
|
+
status: exports.ConnectionStatus.DISCONNECTED,
|
|
2538
|
+
wallet: null,
|
|
2539
|
+
error: new Error('Connection timeout'),
|
|
2540
|
+
});
|
|
2541
|
+
this.eventEmitter.emit(exports.WalletEvent.ERROR, new Error('Connection timeout'));
|
|
2542
|
+
}
|
|
2543
|
+
}, 3000); // Give it 3 more seconds
|
|
2516
2544
|
}
|
|
2517
2545
|
}
|
|
2518
2546
|
}, 1000);
|
|
@@ -7858,6 +7886,8 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7858
7886
|
// Get initial state
|
|
7859
7887
|
const initialState = connector.getState();
|
|
7860
7888
|
setStatus(initialState.status);
|
|
7889
|
+
// Safety: Clear isConnecting on mount (in case it was stuck from previous session)
|
|
7890
|
+
setIsConnecting(false);
|
|
7861
7891
|
// Only set wallets once to prevent re-renders
|
|
7862
7892
|
if (!walletsRef.current) {
|
|
7863
7893
|
walletsRef.current = connector.getAllWallets();
|
|
@@ -8063,6 +8093,8 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8063
8093
|
// Subscribe to events
|
|
8064
8094
|
const unsubscribeAccount = connector.on(exports.WalletEvent.ACCOUNT_CHANGED, async (acc) => {
|
|
8065
8095
|
setAccount(acc);
|
|
8096
|
+
// Clear isConnecting when account changes (connection succeeded)
|
|
8097
|
+
setIsConnecting(false);
|
|
8066
8098
|
// Don't set isInitializing to false yet - wait for balance to load
|
|
8067
8099
|
// Load cached balance for new account immediately
|
|
8068
8100
|
if (acc?.address) {
|
|
@@ -8127,9 +8159,14 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8127
8159
|
});
|
|
8128
8160
|
const unsubscribeStatus = connector.on(exports.WalletEvent.STATUS_CHANGED, (newStatus) => {
|
|
8129
8161
|
setStatus(newStatus);
|
|
8130
|
-
// If status changes to disconnected, stop initializing
|
|
8162
|
+
// If status changes to disconnected, stop initializing and connecting
|
|
8131
8163
|
if (newStatus === exports.ConnectionStatus.DISCONNECTED) {
|
|
8132
8164
|
setIsInitializing(false);
|
|
8165
|
+
setIsConnecting(false);
|
|
8166
|
+
}
|
|
8167
|
+
// If status changes to connected, clear connecting state
|
|
8168
|
+
if (newStatus === exports.ConnectionStatus.CONNECTED) {
|
|
8169
|
+
setIsConnecting(false);
|
|
8133
8170
|
}
|
|
8134
8171
|
});
|
|
8135
8172
|
const unsubscribeDisconnect = connector.on(exports.WalletEvent.DISCONNECTED, () => {
|
|
@@ -8480,6 +8517,11 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8480
8517
|
const handleConnect = React.useCallback(async (walletType) => {
|
|
8481
8518
|
setIsConnecting(true);
|
|
8482
8519
|
setError(null);
|
|
8520
|
+
// Safety timeout: ensure isConnecting is cleared after 75 seconds maximum
|
|
8521
|
+
const safetyTimeout = setTimeout(() => {
|
|
8522
|
+
setIsConnecting(false);
|
|
8523
|
+
setIsInitializing(false);
|
|
8524
|
+
}, 75000);
|
|
8483
8525
|
// Close modal BEFORE connecting for TON wallets and WalletConnect
|
|
8484
8526
|
// so external modals can show
|
|
8485
8527
|
const isTonWallet = ['tonkeeper', 'tonhub', 'mytonwallet'].includes(walletType);
|
|
@@ -8493,27 +8535,20 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8493
8535
|
setShowSendModal(false);
|
|
8494
8536
|
}
|
|
8495
8537
|
try {
|
|
8496
|
-
|
|
8497
|
-
|
|
8498
|
-
|
|
8499
|
-
|
|
8500
|
-
setIsInitializing(false);
|
|
8501
|
-
}
|
|
8502
|
-
else {
|
|
8503
|
-
// Fallback: get account after connection
|
|
8504
|
-
const newAccount = await connector.getAccount();
|
|
8505
|
-
if (newAccount) {
|
|
8506
|
-
setAccount(newAccount);
|
|
8507
|
-
setIsInitializing(false);
|
|
8508
|
-
}
|
|
8509
|
-
}
|
|
8538
|
+
// connector.connect() returns void - state updates happen via events
|
|
8539
|
+
await connector.connect(walletType);
|
|
8540
|
+
// Connection succeeded - state is updated via ACCOUNT_CHANGED event
|
|
8541
|
+
// which also clears isConnecting
|
|
8510
8542
|
// Close modal after connection for non-TON/walletconnect wallets
|
|
8511
8543
|
if (!isTonWallet && !isWalletConnect) {
|
|
8512
8544
|
setShowModal(false);
|
|
8513
8545
|
}
|
|
8514
|
-
|
|
8546
|
+
// Clear safety timeout on success
|
|
8547
|
+
clearTimeout(safetyTimeout);
|
|
8515
8548
|
}
|
|
8516
8549
|
catch (err) {
|
|
8550
|
+
// Clear safety timeout on error
|
|
8551
|
+
clearTimeout(safetyTimeout);
|
|
8517
8552
|
// Always clear connection state on error
|
|
8518
8553
|
setAccount(null);
|
|
8519
8554
|
setStatus(exports.ConnectionStatus.DISCONNECTED);
|
package/package.json
CHANGED