Page MenuHomePhabricator

[Cashtab] Replace magic number with constant
ClosedPublic

Authored by bytesofman on Dec 28 2023, 23:19.

Details

Reviewers
emack
Fabien
Group Reviewers
Restricted Project
Commits
rABCf502b7b831b7: [Cashtab] Replace magic number with constant
Summary

Replace hardcoded constant of 10 with a value set in constant config.

Test Plan

Confirm we are just replacing a magic number with a constant
npm test

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

emack requested changes to this revision.Dec 29 2023, 00:32
emack added a subscriber: emack.

A few extra refreshes seem to be happening which then confuses cashtab into momentarily thinking this is an empty wallet

This revision now requires changes to proceed.Dec 29 2023, 00:32

should implement this after upgrading chronik-client

Back out on load refresh change so this diff is only getting rid of magic number

bytesofman retitled this revision from [Cashtab] Sync utxo set on loading a wallet to [Cashtab] Replace magic number with constant.Jan 12 2024, 17:23
bytesofman edited the summary of this revision. (Show Details)
bytesofman edited the test plan for this revision. (Show Details)
bytesofman edited the summary of this revision. (Show Details)

remove unrelated line break

Fabien requested changes to this revision.Jan 12 2024, 18:44
Fabien added a subscriber: Fabien.
Fabien added inline comments.
cashtab/src/config/websocket.js
11 ↗(On Diff #44104)

It's impossible to guess what this does without reading the code, let alone guessing it's a refresh interval and what the unit is. This is a very bad name

This revision now requires changes to proceed.Jan 12 2024, 18:44
cashtab/src/config/websocket.js
11 ↗(On Diff #44107)

I don't get it. Why is this an interval if the goal is to trigger an immediate sync ? And how is this value relevant as a config option ?

bytesofman added inline comments.
cashtab/src/config/websocket.js
11 ↗(On Diff #44107)

This diff is step one in a broader overhaul of how Cashtab handles wallet refreshes. The current system was originally designed for bch-api, then persisted for some time because chronik websocket connections were unreliable.

Now that we are on chronik and have reliable websocket connections -- there is much room for improvement.

The way Cashtab works right now -- there is always an ongoing interval to update the wallet every 10s. When Cashtab detects an incoming tx from the websocket, it changes this interval from 10s to 10ms (almost immediate...maybe zero would work? I don't remember, from when I implemented this there was probably some reason to go with a low nonzero number).

So, the wallet immediately updates its utxo set on getting a tx. And in that function, flips the interval from 10ms back to 10s.

The long term vision here is to do this almost all with websockets. The whole "have a refresh interval running all the time in the background" approach should be deprecated in favor with some kind of routine that triggers in the event of a lost websocket connection.

Anyway this change is only replacing a magic number. Then will patch so wallet updates immediately on load, fixing a current bad ux issue in the extension (other diff in this stack).

Then refactors for optimizations.

Fabien requested changes to this revision.Jan 12 2024, 21:23
Fabien added inline comments.
cashtab/src/config/websocket.js
11 ↗(On Diff #44107)

Ok I better understand what this value is for, and now it's clear that it doesn't belong in a config file. This belongs in the place it's used with a proper comment explaining what it does and why it's not zero if needed. This value is not intended to be configurable.

This revision now requires changes to proceed.Jan 12 2024, 21:23
bytesofman marked an inline comment as done.

Remove param from config and define as a hook-specific constant

cashtab/src/hooks/useWallet.js
52 ↗(On Diff #44123)

Please comment what this is, what the unit is and why it can't be zero (if it really can't be zero)

websocketConfig instead of config.websocket which isn't a thing

Fabien requested changes to this revision.Jan 13 2024, 08:27
Fabien added inline comments.
cashtab/src/hooks/useWallet.js
124 ↗(On Diff #44139)

you have debug logs here

This revision now requires changes to proceed.Jan 13 2024, 08:27
This revision is now accepted and ready to land.Jan 16 2024, 00:05