tiwiflix-wallet-connector 1.5.9 → 1.6.1
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 +68 -109
- package/dist/index.js +68 -109
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -3529,9 +3529,13 @@ class MetamaskAdapter extends EVMBaseAdapter {
|
|
|
3529
3529
|
// Debug mode - safe environment check for browser
|
|
3530
3530
|
this.debugMode = isDevelopmentMode();
|
|
3531
3531
|
}
|
|
3532
|
-
//
|
|
3532
|
+
// Only show MetaMask as available if detected
|
|
3533
3533
|
isAvailable() {
|
|
3534
|
-
|
|
3534
|
+
if (typeof window === 'undefined')
|
|
3535
|
+
return false;
|
|
3536
|
+
// Check for injected MetaMask provider
|
|
3537
|
+
const provider = this.getInjectedProvider();
|
|
3538
|
+
return !!provider;
|
|
3535
3539
|
}
|
|
3536
3540
|
/**
|
|
3537
3541
|
* Debug logging utility
|
|
@@ -5077,13 +5081,10 @@ class TONBaseAdapter extends BaseWalletAdapter {
|
|
|
5077
5081
|
return 'https://app.tiwiflix.xyz/manifest.json';
|
|
5078
5082
|
}
|
|
5079
5083
|
isAvailable() {
|
|
5080
|
-
//
|
|
5084
|
+
// Only show TON wallet as available if a TON wallet is detected (extension or injected)
|
|
5081
5085
|
if (typeof window === 'undefined')
|
|
5082
5086
|
return false;
|
|
5083
|
-
|
|
5084
|
-
// So we should always return true in browser environment
|
|
5085
|
-
// The SDK will be loaded dynamically during connect()
|
|
5086
|
-
return true;
|
|
5087
|
+
return this.checkForTonWalletExtensions();
|
|
5087
5088
|
}
|
|
5088
5089
|
/**
|
|
5089
5090
|
* @deprecated No longer used - TonConnect UI is loaded dynamically
|
|
@@ -7516,20 +7517,6 @@ const TWCBalanceModal = ({ isOpen, onClose, twcBalance, usdValue, colors, isDark
|
|
|
7516
7517
|
|
|
7517
7518
|
const tonApiCache = new Map();
|
|
7518
7519
|
const CACHE_DURATION = 30000; // 30 seconds
|
|
7519
|
-
const defaultStyles = {
|
|
7520
|
-
button: {
|
|
7521
|
-
padding: '10px 20px',
|
|
7522
|
-
borderRadius: '14px',
|
|
7523
|
-
border: 'none',
|
|
7524
|
-
backgroundColor: '#3396FF', // This will be overridden by theme colors in actual usage
|
|
7525
|
-
color: 'white',
|
|
7526
|
-
fontWeight: '500',
|
|
7527
|
-
fontSize: '14px',
|
|
7528
|
-
cursor: 'pointer',
|
|
7529
|
-
transition: 'all 0.15s ease',
|
|
7530
|
-
fontFamily: 'Lexend, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
7531
|
-
boxShadow: '0 4px 14px 0 rgba(51, 150, 255, 0.39)',
|
|
7532
|
-
}};
|
|
7533
7520
|
const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className, style, showBalance = false, modalPosition = 'center', theme = 'auto', buttonText = 'Connect Wallet Now', getExplorerUrl, }) => {
|
|
7534
7521
|
// Always fetch balance automatically when wallet is connected
|
|
7535
7522
|
// Balance is always fetched automatically from the chain
|
|
@@ -7824,7 +7811,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7824
7811
|
}, 4000); // force-resolve after 4s
|
|
7825
7812
|
return () => clearTimeout(timeout);
|
|
7826
7813
|
}, [isInitializing, balanceLoading, isConnecting]);
|
|
7827
|
-
//
|
|
7814
|
+
// Remove network restriction: allow all EVM networks to connect
|
|
7828
7815
|
useEffect(() => {
|
|
7829
7816
|
const checkChain = async () => {
|
|
7830
7817
|
if (!account || account.chainType !== 'evm') {
|
|
@@ -7835,16 +7822,13 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7835
7822
|
try {
|
|
7836
7823
|
const chainId = await connector.getCurrentChain();
|
|
7837
7824
|
setCurrentChainId(chainId);
|
|
7838
|
-
//
|
|
7839
|
-
|
|
7840
|
-
setIsWrongNetwork(!isBSC && chainId !== null);
|
|
7825
|
+
// No restriction: allow all EVM networks
|
|
7826
|
+
setIsWrongNetwork(false);
|
|
7841
7827
|
}
|
|
7842
7828
|
catch (err) {
|
|
7843
7829
|
}
|
|
7844
7830
|
};
|
|
7845
7831
|
checkChain();
|
|
7846
|
-
// Also periodically check if still connected to EVM wallet
|
|
7847
|
-
// This handles cases where chain is changed from wallet UI
|
|
7848
7832
|
if (account && account.chainType === 'evm') {
|
|
7849
7833
|
const interval = setInterval(checkChain, 2000);
|
|
7850
7834
|
return () => clearInterval(interval);
|
|
@@ -8395,7 +8379,13 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8395
8379
|
}
|
|
8396
8380
|
}, [account]);
|
|
8397
8381
|
const fetchTWCBalanceWithRetry = useCallback(async (maxRetries = 3, initialDelay = 200) => {
|
|
8382
|
+
// Only fetch TWC balance if wallet is on BSC (chainId 56)
|
|
8398
8383
|
try {
|
|
8384
|
+
const state = connector.getState();
|
|
8385
|
+
if (state.account?.chainType !== 'evm' || state.chainId !== 56) {
|
|
8386
|
+
// Not on BSC, do not fetch TWC balance
|
|
8387
|
+
return null;
|
|
8388
|
+
}
|
|
8399
8389
|
const twcBalance = await connector.getTWCBalance();
|
|
8400
8390
|
return {
|
|
8401
8391
|
balance: twcBalance.amount || '0',
|
|
@@ -8417,14 +8407,14 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8417
8407
|
}
|
|
8418
8408
|
return null;
|
|
8419
8409
|
}, [connector]);
|
|
8420
|
-
// Load balance when account changes
|
|
8410
|
+
// Load balance when account or network (chain) changes
|
|
8421
8411
|
useEffect(() => {
|
|
8422
8412
|
let isActive = true;
|
|
8423
8413
|
// Only log and run effect if account is not null
|
|
8424
8414
|
if (account) {
|
|
8425
|
-
console.log('[ConnectButton] useEffect: account changed', { account });
|
|
8426
|
-
// For EVM wallets,
|
|
8427
|
-
if (account.chainType === 'evm') {
|
|
8415
|
+
console.log('[ConnectButton] useEffect: account or chain changed', { account, currentChainId });
|
|
8416
|
+
// For EVM wallets, only fetch TWC balance if on BSC
|
|
8417
|
+
if (account.chainType === 'evm' && currentChainId === 56) {
|
|
8428
8418
|
// First check state/cache for immediate display
|
|
8429
8419
|
const state = connector.getState();
|
|
8430
8420
|
let hasBalance = false;
|
|
@@ -8447,9 +8437,9 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8447
8437
|
hasBalance = true;
|
|
8448
8438
|
}
|
|
8449
8439
|
}
|
|
8450
|
-
// Only fetch if we don't have a balance yet
|
|
8451
|
-
if (!hasBalance) {
|
|
8452
|
-
console.log('[ConnectButton] Fetching TWC balance for
|
|
8440
|
+
// Only fetch if we don't have a balance yet, or if the chain/network changed
|
|
8441
|
+
if (!hasBalance || currentChainId !== null) {
|
|
8442
|
+
console.log('[ConnectButton] Fetching TWC balance for BSC wallet:', account.address, currentChainId);
|
|
8453
8443
|
fetchTWCBalanceWithRetry(2, 200).then((result) => {
|
|
8454
8444
|
if (!isActive)
|
|
8455
8445
|
return;
|
|
@@ -8467,16 +8457,23 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8467
8457
|
setTwcBalance('0');
|
|
8468
8458
|
setUsdValueStable(null);
|
|
8469
8459
|
setIsInitializing(false);
|
|
8470
|
-
console.warn('[ConnectButton] No TWC balance found for
|
|
8460
|
+
console.warn('[ConnectButton] No TWC balance found for BSC wallet:', account.address);
|
|
8471
8461
|
}
|
|
8472
8462
|
}).catch(() => {
|
|
8473
8463
|
if (!isActive)
|
|
8474
8464
|
return;
|
|
8475
8465
|
setIsInitializing(false);
|
|
8476
|
-
console.error('[ConnectButton] Error fetching TWC balance for
|
|
8466
|
+
console.error('[ConnectButton] Error fetching TWC balance for BSC wallet:', account.address);
|
|
8477
8467
|
});
|
|
8478
8468
|
}
|
|
8479
8469
|
}
|
|
8470
|
+
else if (account.chainType === 'evm' && currentChainId !== 56) {
|
|
8471
|
+
// EVM wallet but not on BSC, do not fetch TWC balance, do not show switch chain
|
|
8472
|
+
setTwcBalance(null);
|
|
8473
|
+
setUsdValueStable(null);
|
|
8474
|
+
setIsInitializing(false);
|
|
8475
|
+
// Do not show error or prompt
|
|
8476
|
+
}
|
|
8480
8477
|
else {
|
|
8481
8478
|
// Non-EVM wallet, just check state
|
|
8482
8479
|
const state = connector.getState();
|
|
@@ -8497,7 +8494,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8497
8494
|
isActive = false;
|
|
8498
8495
|
};
|
|
8499
8496
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8500
|
-
}, [account?.address]);
|
|
8497
|
+
}, [account?.address, currentChainId]);
|
|
8501
8498
|
// Polling mechanism as fallback to ensure TWC balance is always fetched
|
|
8502
8499
|
useEffect(() => {
|
|
8503
8500
|
if (!account || account.chainType !== 'evm') {
|
|
@@ -8664,7 +8661,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8664
8661
|
alert('Address copied to clipboard!');
|
|
8665
8662
|
}
|
|
8666
8663
|
}, [account]);
|
|
8667
|
-
|
|
8664
|
+
useCallback(async () => {
|
|
8668
8665
|
try {
|
|
8669
8666
|
// Try to switch to BSC Mainnet (56)
|
|
8670
8667
|
await connector.switchChain(56);
|
|
@@ -8689,85 +8686,47 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8689
8686
|
}, [connector, account]);
|
|
8690
8687
|
// Render button based on connection status
|
|
8691
8688
|
const renderButton = () => {
|
|
8692
|
-
//
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
(
|
|
8697
|
-
// Treat balance loading as background; only gate on initial connection.
|
|
8698
|
-
const isCheckingConnection = isInitializing || ((status === ConnectionStatus.CONNECTING || isConnecting) && !account);
|
|
8699
|
-
const isActuallyConnecting = (status === ConnectionStatus.CONNECTING || isConnecting) && !!account && !isInitializing;
|
|
8700
|
-
// Check connection state
|
|
8701
|
-
if (isCheckingConnection) {
|
|
8702
|
-
// Show loading connected button structure while checking connection
|
|
8703
|
-
const isMobile = isMobileViewport();
|
|
8704
|
-
// Loading spinner component
|
|
8705
|
-
const LoadingSpinner = () => (jsxs(Fragment, { children: [jsx("div", { style: {
|
|
8706
|
-
width: isMobile ? '12px' : '14px',
|
|
8707
|
-
height: isMobile ? '12px' : '14px',
|
|
8708
|
-
border: '2px solid rgba(255, 255, 255, 0.3)',
|
|
8709
|
-
borderTopColor: '#FFFFFF',
|
|
8710
|
-
borderRadius: '50%',
|
|
8711
|
-
animation: 'spin 0.8s linear infinite',
|
|
8712
|
-
} }), jsx("style", { children: `
|
|
8713
|
-
@keyframes spin {
|
|
8714
|
-
to { transform: rotate(360deg); }
|
|
8715
|
-
}
|
|
8716
|
-
` })] }));
|
|
8717
|
-
return (jsx("button", { onClick: () => setShowDetailsModal(false), style: {
|
|
8689
|
+
// Only show connect button if we are fully initialized and truly disconnected
|
|
8690
|
+
if (!isInitializing && (!account || status === ConnectionStatus.DISCONNECTED)) {
|
|
8691
|
+
// Wallet icon SVG component
|
|
8692
|
+
const WalletIcon = () => (jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", style: { display: 'block' }, children: [jsx("path", { d: "M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1" }), jsx("path", { d: "M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4" })] }));
|
|
8693
|
+
return (jsxs("button", { onClick: () => handleOpenModal(), style: {
|
|
8718
8694
|
display: 'flex',
|
|
8719
8695
|
alignItems: 'center',
|
|
8720
|
-
|
|
8721
|
-
padding:
|
|
8722
|
-
borderRadius: '
|
|
8696
|
+
gap: '10px',
|
|
8697
|
+
padding: '12px 12px',
|
|
8698
|
+
borderRadius: '12px',
|
|
8723
8699
|
border: 'none',
|
|
8724
|
-
|
|
8725
|
-
|
|
8726
|
-
|
|
8727
|
-
|
|
8700
|
+
backgroundColor: '#FF9814',
|
|
8701
|
+
color: '#000000',
|
|
8702
|
+
fontWeight: '700',
|
|
8703
|
+
fontSize: '15px',
|
|
8704
|
+
cursor: 'pointer',
|
|
8705
|
+
transition: 'all 0.15s ease',
|
|
8728
8706
|
fontFamily: 'Lexend, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
8707
|
+
boxShadow: '0 2px 8px rgba(255, 152, 20, 0.3)',
|
|
8729
8708
|
...style,
|
|
8730
|
-
}, className: className,
|
|
8731
|
-
|
|
8732
|
-
|
|
8733
|
-
|
|
8734
|
-
|
|
8735
|
-
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
8739
|
-
fontFamily: 'Lexend, sans-serif',
|
|
8740
|
-
flexShrink: 0,
|
|
8741
|
-
}, children: "TWC" })] })] }) }));
|
|
8709
|
+
}, className: className, onMouseEnter: (e) => {
|
|
8710
|
+
e.currentTarget.style.backgroundColor = '#E8870F';
|
|
8711
|
+
e.currentTarget.style.transform = 'translateY(-1px)';
|
|
8712
|
+
e.currentTarget.style.boxShadow = '0 4px 12px rgba(255, 152, 20, 0.4)';
|
|
8713
|
+
}, onMouseLeave: (e) => {
|
|
8714
|
+
e.currentTarget.style.backgroundColor = '#FF9814';
|
|
8715
|
+
e.currentTarget.style.transform = 'translateY(0)';
|
|
8716
|
+
e.currentTarget.style.boxShadow = '0 2px 8px rgba(255, 152, 20, 0.3)';
|
|
8717
|
+
}, children: [jsx("span", { style: { color: '#000000', display: 'flex', alignItems: 'center' }, children: jsx(WalletIcon, {}) }), jsx("span", { style: { color: '#000000', fontWeight: '500', fontSize: '14px' }, children: buttonText })] }));
|
|
8742
8718
|
}
|
|
8743
|
-
|
|
8744
|
-
|
|
8719
|
+
// ...existing code...
|
|
8720
|
+
// All other states (including loading, connecting, connected) should only show the connected button or loading spinner if account is present or initializing is true
|
|
8721
|
+
// If initializing, show nothing (or a spinner if desired)
|
|
8722
|
+
if (isInitializing) {
|
|
8723
|
+
// Optionally, you can show a spinner or skeleton here, but do not show connect/disconnect buttons
|
|
8724
|
+
return null;
|
|
8745
8725
|
}
|
|
8726
|
+
// ...existing code...
|
|
8727
|
+
// The rest of the renderButton logic (wrong network, connected, etc.) remains unchanged
|
|
8746
8728
|
if (account) {
|
|
8747
|
-
//
|
|
8748
|
-
if (isWrongNetwork) {
|
|
8749
|
-
return (jsx("button", { onClick: handleSwitchToBSC, style: {
|
|
8750
|
-
padding: '10px 16px',
|
|
8751
|
-
borderRadius: '16px',
|
|
8752
|
-
border: 'none',
|
|
8753
|
-
backgroundColor: '#F59E0B',
|
|
8754
|
-
display: 'flex',
|
|
8755
|
-
alignItems: 'center',
|
|
8756
|
-
gap: '10px',
|
|
8757
|
-
cursor: 'pointer',
|
|
8758
|
-
transition: 'all 0.15s ease',
|
|
8759
|
-
fontFamily: 'Lexend, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
8760
|
-
...style,
|
|
8761
|
-
}, className: className, onMouseEnter: (e) => {
|
|
8762
|
-
e.currentTarget.style.backgroundColor = '#D97706';
|
|
8763
|
-
e.currentTarget.style.transform = 'translateY(-1px)';
|
|
8764
|
-
e.currentTarget.style.boxShadow = '0 4px 12px rgba(245, 158, 11, 0.4)';
|
|
8765
|
-
}, onMouseLeave: (e) => {
|
|
8766
|
-
e.currentTarget.style.backgroundColor = '#F59E0B';
|
|
8767
|
-
e.currentTarget.style.transform = 'translateY(0)';
|
|
8768
|
-
e.currentTarget.style.boxShadow = 'none';
|
|
8769
|
-
}, children: jsx("span", { style: { fontSize: '13px', fontWeight: '600', color: 'white' }, children: "\uD83D\uDD04 Switch to BSC" }) }));
|
|
8770
|
-
}
|
|
8729
|
+
// ...existing code...
|
|
8771
8730
|
// Show normal connected button - styled to match design
|
|
8772
8731
|
// Parse balance amount and symbol separately
|
|
8773
8732
|
// For TON: show TON balance (not TWC, not NFT count in button)
|
package/dist/index.js
CHANGED
|
@@ -3531,9 +3531,13 @@ class MetamaskAdapter extends EVMBaseAdapter {
|
|
|
3531
3531
|
// Debug mode - safe environment check for browser
|
|
3532
3532
|
this.debugMode = isDevelopmentMode();
|
|
3533
3533
|
}
|
|
3534
|
-
//
|
|
3534
|
+
// Only show MetaMask as available if detected
|
|
3535
3535
|
isAvailable() {
|
|
3536
|
-
|
|
3536
|
+
if (typeof window === 'undefined')
|
|
3537
|
+
return false;
|
|
3538
|
+
// Check for injected MetaMask provider
|
|
3539
|
+
const provider = this.getInjectedProvider();
|
|
3540
|
+
return !!provider;
|
|
3537
3541
|
}
|
|
3538
3542
|
/**
|
|
3539
3543
|
* Debug logging utility
|
|
@@ -5079,13 +5083,10 @@ class TONBaseAdapter extends BaseWalletAdapter {
|
|
|
5079
5083
|
return 'https://app.tiwiflix.xyz/manifest.json';
|
|
5080
5084
|
}
|
|
5081
5085
|
isAvailable() {
|
|
5082
|
-
//
|
|
5086
|
+
// Only show TON wallet as available if a TON wallet is detected (extension or injected)
|
|
5083
5087
|
if (typeof window === 'undefined')
|
|
5084
5088
|
return false;
|
|
5085
|
-
|
|
5086
|
-
// So we should always return true in browser environment
|
|
5087
|
-
// The SDK will be loaded dynamically during connect()
|
|
5088
|
-
return true;
|
|
5089
|
+
return this.checkForTonWalletExtensions();
|
|
5089
5090
|
}
|
|
5090
5091
|
/**
|
|
5091
5092
|
* @deprecated No longer used - TonConnect UI is loaded dynamically
|
|
@@ -7518,20 +7519,6 @@ const TWCBalanceModal = ({ isOpen, onClose, twcBalance, usdValue, colors, isDark
|
|
|
7518
7519
|
|
|
7519
7520
|
const tonApiCache = new Map();
|
|
7520
7521
|
const CACHE_DURATION = 30000; // 30 seconds
|
|
7521
|
-
const defaultStyles = {
|
|
7522
|
-
button: {
|
|
7523
|
-
padding: '10px 20px',
|
|
7524
|
-
borderRadius: '14px',
|
|
7525
|
-
border: 'none',
|
|
7526
|
-
backgroundColor: '#3396FF', // This will be overridden by theme colors in actual usage
|
|
7527
|
-
color: 'white',
|
|
7528
|
-
fontWeight: '500',
|
|
7529
|
-
fontSize: '14px',
|
|
7530
|
-
cursor: 'pointer',
|
|
7531
|
-
transition: 'all 0.15s ease',
|
|
7532
|
-
fontFamily: 'Lexend, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
7533
|
-
boxShadow: '0 4px 14px 0 rgba(51, 150, 255, 0.39)',
|
|
7534
|
-
}};
|
|
7535
7522
|
const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className, style, showBalance = false, modalPosition = 'center', theme = 'auto', buttonText = 'Connect Wallet Now', getExplorerUrl, }) => {
|
|
7536
7523
|
// Always fetch balance automatically when wallet is connected
|
|
7537
7524
|
// Balance is always fetched automatically from the chain
|
|
@@ -7826,7 +7813,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7826
7813
|
}, 4000); // force-resolve after 4s
|
|
7827
7814
|
return () => clearTimeout(timeout);
|
|
7828
7815
|
}, [isInitializing, balanceLoading, isConnecting]);
|
|
7829
|
-
//
|
|
7816
|
+
// Remove network restriction: allow all EVM networks to connect
|
|
7830
7817
|
React.useEffect(() => {
|
|
7831
7818
|
const checkChain = async () => {
|
|
7832
7819
|
if (!account || account.chainType !== 'evm') {
|
|
@@ -7837,16 +7824,13 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
7837
7824
|
try {
|
|
7838
7825
|
const chainId = await connector.getCurrentChain();
|
|
7839
7826
|
setCurrentChainId(chainId);
|
|
7840
|
-
//
|
|
7841
|
-
|
|
7842
|
-
setIsWrongNetwork(!isBSC && chainId !== null);
|
|
7827
|
+
// No restriction: allow all EVM networks
|
|
7828
|
+
setIsWrongNetwork(false);
|
|
7843
7829
|
}
|
|
7844
7830
|
catch (err) {
|
|
7845
7831
|
}
|
|
7846
7832
|
};
|
|
7847
7833
|
checkChain();
|
|
7848
|
-
// Also periodically check if still connected to EVM wallet
|
|
7849
|
-
// This handles cases where chain is changed from wallet UI
|
|
7850
7834
|
if (account && account.chainType === 'evm') {
|
|
7851
7835
|
const interval = setInterval(checkChain, 2000);
|
|
7852
7836
|
return () => clearInterval(interval);
|
|
@@ -8397,7 +8381,13 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8397
8381
|
}
|
|
8398
8382
|
}, [account]);
|
|
8399
8383
|
const fetchTWCBalanceWithRetry = React.useCallback(async (maxRetries = 3, initialDelay = 200) => {
|
|
8384
|
+
// Only fetch TWC balance if wallet is on BSC (chainId 56)
|
|
8400
8385
|
try {
|
|
8386
|
+
const state = connector.getState();
|
|
8387
|
+
if (state.account?.chainType !== 'evm' || state.chainId !== 56) {
|
|
8388
|
+
// Not on BSC, do not fetch TWC balance
|
|
8389
|
+
return null;
|
|
8390
|
+
}
|
|
8401
8391
|
const twcBalance = await connector.getTWCBalance();
|
|
8402
8392
|
return {
|
|
8403
8393
|
balance: twcBalance.amount || '0',
|
|
@@ -8419,14 +8409,14 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8419
8409
|
}
|
|
8420
8410
|
return null;
|
|
8421
8411
|
}, [connector]);
|
|
8422
|
-
// Load balance when account changes
|
|
8412
|
+
// Load balance when account or network (chain) changes
|
|
8423
8413
|
React.useEffect(() => {
|
|
8424
8414
|
let isActive = true;
|
|
8425
8415
|
// Only log and run effect if account is not null
|
|
8426
8416
|
if (account) {
|
|
8427
|
-
console.log('[ConnectButton] useEffect: account changed', { account });
|
|
8428
|
-
// For EVM wallets,
|
|
8429
|
-
if (account.chainType === 'evm') {
|
|
8417
|
+
console.log('[ConnectButton] useEffect: account or chain changed', { account, currentChainId });
|
|
8418
|
+
// For EVM wallets, only fetch TWC balance if on BSC
|
|
8419
|
+
if (account.chainType === 'evm' && currentChainId === 56) {
|
|
8430
8420
|
// First check state/cache for immediate display
|
|
8431
8421
|
const state = connector.getState();
|
|
8432
8422
|
let hasBalance = false;
|
|
@@ -8449,9 +8439,9 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8449
8439
|
hasBalance = true;
|
|
8450
8440
|
}
|
|
8451
8441
|
}
|
|
8452
|
-
// Only fetch if we don't have a balance yet
|
|
8453
|
-
if (!hasBalance) {
|
|
8454
|
-
console.log('[ConnectButton] Fetching TWC balance for
|
|
8442
|
+
// Only fetch if we don't have a balance yet, or if the chain/network changed
|
|
8443
|
+
if (!hasBalance || currentChainId !== null) {
|
|
8444
|
+
console.log('[ConnectButton] Fetching TWC balance for BSC wallet:', account.address, currentChainId);
|
|
8455
8445
|
fetchTWCBalanceWithRetry(2, 200).then((result) => {
|
|
8456
8446
|
if (!isActive)
|
|
8457
8447
|
return;
|
|
@@ -8469,16 +8459,23 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8469
8459
|
setTwcBalance('0');
|
|
8470
8460
|
setUsdValueStable(null);
|
|
8471
8461
|
setIsInitializing(false);
|
|
8472
|
-
console.warn('[ConnectButton] No TWC balance found for
|
|
8462
|
+
console.warn('[ConnectButton] No TWC balance found for BSC wallet:', account.address);
|
|
8473
8463
|
}
|
|
8474
8464
|
}).catch(() => {
|
|
8475
8465
|
if (!isActive)
|
|
8476
8466
|
return;
|
|
8477
8467
|
setIsInitializing(false);
|
|
8478
|
-
console.error('[ConnectButton] Error fetching TWC balance for
|
|
8468
|
+
console.error('[ConnectButton] Error fetching TWC balance for BSC wallet:', account.address);
|
|
8479
8469
|
});
|
|
8480
8470
|
}
|
|
8481
8471
|
}
|
|
8472
|
+
else if (account.chainType === 'evm' && currentChainId !== 56) {
|
|
8473
|
+
// EVM wallet but not on BSC, do not fetch TWC balance, do not show switch chain
|
|
8474
|
+
setTwcBalance(null);
|
|
8475
|
+
setUsdValueStable(null);
|
|
8476
|
+
setIsInitializing(false);
|
|
8477
|
+
// Do not show error or prompt
|
|
8478
|
+
}
|
|
8482
8479
|
else {
|
|
8483
8480
|
// Non-EVM wallet, just check state
|
|
8484
8481
|
const state = connector.getState();
|
|
@@ -8499,7 +8496,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8499
8496
|
isActive = false;
|
|
8500
8497
|
};
|
|
8501
8498
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8502
|
-
}, [account?.address]);
|
|
8499
|
+
}, [account?.address, currentChainId]);
|
|
8503
8500
|
// Polling mechanism as fallback to ensure TWC balance is always fetched
|
|
8504
8501
|
React.useEffect(() => {
|
|
8505
8502
|
if (!account || account.chainType !== 'evm') {
|
|
@@ -8666,7 +8663,7 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8666
8663
|
alert('Address copied to clipboard!');
|
|
8667
8664
|
}
|
|
8668
8665
|
}, [account]);
|
|
8669
|
-
|
|
8666
|
+
React.useCallback(async () => {
|
|
8670
8667
|
try {
|
|
8671
8668
|
// Try to switch to BSC Mainnet (56)
|
|
8672
8669
|
await connector.switchChain(56);
|
|
@@ -8691,85 +8688,47 @@ const ConnectButton = ({ connector, onConnect, onDisconnect, onError, className,
|
|
|
8691
8688
|
}, [connector, account]);
|
|
8692
8689
|
// Render button based on connection status
|
|
8693
8690
|
const renderButton = () => {
|
|
8694
|
-
//
|
|
8695
|
-
|
|
8696
|
-
|
|
8697
|
-
|
|
8698
|
-
(
|
|
8699
|
-
// Treat balance loading as background; only gate on initial connection.
|
|
8700
|
-
const isCheckingConnection = isInitializing || ((status === exports.ConnectionStatus.CONNECTING || isConnecting) && !account);
|
|
8701
|
-
const isActuallyConnecting = (status === exports.ConnectionStatus.CONNECTING || isConnecting) && !!account && !isInitializing;
|
|
8702
|
-
// Check connection state
|
|
8703
|
-
if (isCheckingConnection) {
|
|
8704
|
-
// Show loading connected button structure while checking connection
|
|
8705
|
-
const isMobile = isMobileViewport();
|
|
8706
|
-
// Loading spinner component
|
|
8707
|
-
const LoadingSpinner = () => (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { style: {
|
|
8708
|
-
width: isMobile ? '12px' : '14px',
|
|
8709
|
-
height: isMobile ? '12px' : '14px',
|
|
8710
|
-
border: '2px solid rgba(255, 255, 255, 0.3)',
|
|
8711
|
-
borderTopColor: '#FFFFFF',
|
|
8712
|
-
borderRadius: '50%',
|
|
8713
|
-
animation: 'spin 0.8s linear infinite',
|
|
8714
|
-
} }), jsxRuntime.jsx("style", { children: `
|
|
8715
|
-
@keyframes spin {
|
|
8716
|
-
to { transform: rotate(360deg); }
|
|
8717
|
-
}
|
|
8718
|
-
` })] }));
|
|
8719
|
-
return (jsxRuntime.jsx("button", { onClick: () => setShowDetailsModal(false), style: {
|
|
8691
|
+
// Only show connect button if we are fully initialized and truly disconnected
|
|
8692
|
+
if (!isInitializing && (!account || status === exports.ConnectionStatus.DISCONNECTED)) {
|
|
8693
|
+
// Wallet icon SVG component
|
|
8694
|
+
const WalletIcon = () => (jsxRuntime.jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", style: { display: 'block' }, children: [jsxRuntime.jsx("path", { d: "M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1" }), jsxRuntime.jsx("path", { d: "M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4" })] }));
|
|
8695
|
+
return (jsxRuntime.jsxs("button", { onClick: () => handleOpenModal(), style: {
|
|
8720
8696
|
display: 'flex',
|
|
8721
8697
|
alignItems: 'center',
|
|
8722
|
-
|
|
8723
|
-
padding:
|
|
8724
|
-
borderRadius: '
|
|
8698
|
+
gap: '10px',
|
|
8699
|
+
padding: '12px 12px',
|
|
8700
|
+
borderRadius: '12px',
|
|
8725
8701
|
border: 'none',
|
|
8726
|
-
|
|
8727
|
-
|
|
8728
|
-
|
|
8729
|
-
|
|
8702
|
+
backgroundColor: '#FF9814',
|
|
8703
|
+
color: '#000000',
|
|
8704
|
+
fontWeight: '700',
|
|
8705
|
+
fontSize: '15px',
|
|
8706
|
+
cursor: 'pointer',
|
|
8707
|
+
transition: 'all 0.15s ease',
|
|
8730
8708
|
fontFamily: 'Lexend, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
8709
|
+
boxShadow: '0 2px 8px rgba(255, 152, 20, 0.3)',
|
|
8731
8710
|
...style,
|
|
8732
|
-
}, className: className,
|
|
8733
|
-
|
|
8734
|
-
|
|
8735
|
-
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
8739
|
-
|
|
8740
|
-
|
|
8741
|
-
fontFamily: 'Lexend, sans-serif',
|
|
8742
|
-
flexShrink: 0,
|
|
8743
|
-
}, children: "TWC" })] })] }) }));
|
|
8711
|
+
}, className: className, onMouseEnter: (e) => {
|
|
8712
|
+
e.currentTarget.style.backgroundColor = '#E8870F';
|
|
8713
|
+
e.currentTarget.style.transform = 'translateY(-1px)';
|
|
8714
|
+
e.currentTarget.style.boxShadow = '0 4px 12px rgba(255, 152, 20, 0.4)';
|
|
8715
|
+
}, onMouseLeave: (e) => {
|
|
8716
|
+
e.currentTarget.style.backgroundColor = '#FF9814';
|
|
8717
|
+
e.currentTarget.style.transform = 'translateY(0)';
|
|
8718
|
+
e.currentTarget.style.boxShadow = '0 2px 8px rgba(255, 152, 20, 0.3)';
|
|
8719
|
+
}, children: [jsxRuntime.jsx("span", { style: { color: '#000000', display: 'flex', alignItems: 'center' }, children: jsxRuntime.jsx(WalletIcon, {}) }), jsxRuntime.jsx("span", { style: { color: '#000000', fontWeight: '500', fontSize: '14px' }, children: buttonText })] }));
|
|
8744
8720
|
}
|
|
8745
|
-
|
|
8746
|
-
|
|
8721
|
+
// ...existing code...
|
|
8722
|
+
// All other states (including loading, connecting, connected) should only show the connected button or loading spinner if account is present or initializing is true
|
|
8723
|
+
// If initializing, show nothing (or a spinner if desired)
|
|
8724
|
+
if (isInitializing) {
|
|
8725
|
+
// Optionally, you can show a spinner or skeleton here, but do not show connect/disconnect buttons
|
|
8726
|
+
return null;
|
|
8747
8727
|
}
|
|
8728
|
+
// ...existing code...
|
|
8729
|
+
// The rest of the renderButton logic (wrong network, connected, etc.) remains unchanged
|
|
8748
8730
|
if (account) {
|
|
8749
|
-
//
|
|
8750
|
-
if (isWrongNetwork) {
|
|
8751
|
-
return (jsxRuntime.jsx("button", { onClick: handleSwitchToBSC, style: {
|
|
8752
|
-
padding: '10px 16px',
|
|
8753
|
-
borderRadius: '16px',
|
|
8754
|
-
border: 'none',
|
|
8755
|
-
backgroundColor: '#F59E0B',
|
|
8756
|
-
display: 'flex',
|
|
8757
|
-
alignItems: 'center',
|
|
8758
|
-
gap: '10px',
|
|
8759
|
-
cursor: 'pointer',
|
|
8760
|
-
transition: 'all 0.15s ease',
|
|
8761
|
-
fontFamily: 'Lexend, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
8762
|
-
...style,
|
|
8763
|
-
}, className: className, onMouseEnter: (e) => {
|
|
8764
|
-
e.currentTarget.style.backgroundColor = '#D97706';
|
|
8765
|
-
e.currentTarget.style.transform = 'translateY(-1px)';
|
|
8766
|
-
e.currentTarget.style.boxShadow = '0 4px 12px rgba(245, 158, 11, 0.4)';
|
|
8767
|
-
}, onMouseLeave: (e) => {
|
|
8768
|
-
e.currentTarget.style.backgroundColor = '#F59E0B';
|
|
8769
|
-
e.currentTarget.style.transform = 'translateY(0)';
|
|
8770
|
-
e.currentTarget.style.boxShadow = 'none';
|
|
8771
|
-
}, children: jsxRuntime.jsx("span", { style: { fontSize: '13px', fontWeight: '600', color: 'white' }, children: "\uD83D\uDD04 Switch to BSC" }) }));
|
|
8772
|
-
}
|
|
8731
|
+
// ...existing code...
|
|
8773
8732
|
// Show normal connected button - styled to match design
|
|
8774
8733
|
// Parse balance amount and symbol separately
|
|
8775
8734
|
// For TON: show TON balance (not TWC, not NFT count in button)
|
package/package.json
CHANGED