diff --git a/web/cashtab/src/components/Common/Ticker.js b/web/cashtab/src/components/Common/Ticker.js --- a/web/cashtab/src/components/Common/Ticker.js +++ b/web/cashtab/src/components/Common/Ticker.js @@ -26,7 +26,7 @@ tokenDbUrl: 'https://tokendb.kingbch.com', txHistoryCount: 10, xecApiBatchSize: 20, - walletRefreshInterval: 1000, // 1000 = 1s + walletRefreshInterval: 30000, // 1000 = 1s defaultSettings: { fiatCurrency: 'usd', sendModal: false }, notificationDurationShort: 3, notificationDurationLong: 5, diff --git a/web/cashtab/src/hooks/useWallet.js b/web/cashtab/src/hooks/useWallet.js --- a/web/cashtab/src/hooks/useWallet.js +++ b/web/cashtab/src/hooks/useWallet.js @@ -33,7 +33,9 @@ const chronik = new ChronikClient(currency.chronikUrl); const useWallet = () => { - const [walletRefreshInterval] = useState(currency.walletRefreshInterval); + const [walletRefreshInterval, setWalletRefreshInterval] = useState( + currency.walletRefreshInterval, + ); const [wallet, setWallet] = useState(false); const [chronikWebsocket, setChronikWebsocket] = useState(null); const [contactList, setContactList] = useState(false); @@ -209,8 +211,15 @@ }; const update = async ({ wallet }) => { - //console.log(`tick()`); + console.log(`tick()`); //console.time("update"); + + // Check if walletRefreshInterval is set to 10, i.e. this was called by websocket tx detection + // If walletRefreshInterval is 10, set it back to the usual refresh rate + if (walletRefreshInterval === 10) { + console.log(`walletRefreshInterval is 10, reset`); + setWalletRefreshInterval(currency.walletRefreshInterval); + } try { if (!wallet) { return; @@ -248,6 +257,7 @@ utxos, previousUtxos, ); + console.log(`utxosHaveChanged`, utxosHaveChanged); // If the utxo set has not changed, if (!utxosHaveChanged) { @@ -278,6 +288,7 @@ wallet.state.utxos, utxos, ); + console.log(`utxosAdded`, utxosAdded); const utxosConsumed = whichUtxosWereConsumed( wallet.state.utxos, utxos, @@ -375,6 +386,7 @@ // Set wallet with new state field wallet.state = newState; + console.log(`newState`, newState); setWallet(wallet); // Write this state to indexedDb using localForage @@ -940,6 +952,10 @@ if (type !== 'AddedToMempool') { return; } + // If you see a tx from your subscribed addresses added to the mempool, then the wallet utxo set has changed + // Update it + setWalletRefreshInterval(10); + // get txid info const txid = msg.txid; const txDetails = await chronik.tx(txid);