Page MenuHomePhabricator

[Cashtab] Remove obsolete chain of functions handling initial wallet load
ClosedPublic

Authored by bytesofman on Jan 30 2024, 04:23.

Details

Summary

Set the wallet in localStorage as the valid wallet immediately on startup.

The getWallet function already handles validation and potential migration requirements. With chronik, we can always refresh the wallet state on startup -- since this does not cause a noticeable user lag (legacy bch-api + slpdb approach could take 20s).

Test Plan

npm test

The new tests in useWalletStorage.test.js still pass after the changes in this diff, showing that we are correctly loading a wallet from storage on startup and immediately calling the update routine.

Diff Detail

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

Event Timeline

actually we can do better

rebase, remove other obsolete functions

rebase issues

delete experimental tests introduced by this diff, now obsolete due to other diffs with good ones

bytesofman retitled this revision from [Cashtab] Fix antipattern in useWallet.js to [Cashtab] Remove obsolete chain of functions handling initial wallet load.Feb 1 2024, 23:12
bytesofman edited the summary of this revision. (Show Details)
bytesofman edited the test plan for this revision. (Show Details)
cashtab/src/hooks/useWallet.js
105 ↗(On Diff #44877)

this function is a holdover from when syncing a wallet on bootup could take 10-20s (the bch-api days)

At this point, we should just sync every wallet on load. chronik does it fast enough that no delay is detectable by the user.

1083 ↗(On Diff #44877)

i want to say this is some kind of artifact, like the above. but maybe it's just bad code.

1437 ↗(On Diff #44877)

condensed version of now-deleted loadWalletFromStorageOnStartup function, which was called by the silly handleUpdateWallet function

Tail of the build log:

      at warning (node_modules/rc-util/lib/warning.js:32:15)
      at call (node_modules/rc-util/lib/warning.js:52:5)
      at warningOnce (node_modules/rc-util/lib/warning.js:57:3)
      at warning (node_modules/antd/lib/_util/warning.js:23:26)
      at typeWarning (node_modules/antd/lib/_util/warning.js:57:49)
      at Function.typeWarning.deprecated (node_modules/antd/lib/_util/warning.js:62:5)
      at Group (node_modules/antd/lib/input/Group.js:42:13)
      at renderWithHooks (node_modules/react-dom/cjs/react-dom.development.js:16305:18)
      at updateFunctionComponent (node_modules/react-dom/cjs/react-dom.development.js:19588:20)
      at beginWork (node_modules/react-dom/cjs/react-dom.development.js:21601:16)
      at beginWork$1 (node_modules/react-dom/cjs/react-dom.development.js:27426:14)
      at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:26560:12)
      at workLoopSync (node_modules/react-dom/cjs/react-dom.development.js:26466:5)
      at renderRootSync (node_modules/react-dom/cjs/react-dom.development.js:26434:7)
      at performConcurrentWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:25738:74)
      at workLoop (node_modules/scheduler/cjs/scheduler.development.js:266:34)
      at flushWork (node_modules/scheduler/cjs/scheduler.development.js:239:14)
      at performWorkUntilDeadline (node_modules/scheduler/cjs/scheduler.development.js:533:21)
      at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)

    console.error
      Warning: [rc-collapse] `children` will be removed in next major version. Please use `items` instead.

      at warning (node_modules/rc-util/lib/warning.js:32:15)
      at call (node_modules/rc-util/lib/warning.js:52:5)
      at warningOnce (node_modules/rc-util/lib/warning.js:57:3)
      at node_modules/rc-collapse/lib/Collapse.js:72:24
      at renderWithHooks (node_modules/react-dom/cjs/react-dom.development.js:16305:18)
      at updateForwardRef (node_modules/react-dom/cjs/react-dom.development.js:19226:20)
      at beginWork (node_modules/react-dom/cjs/react-dom.development.js:21636:16)
      at beginWork$1 (node_modules/react-dom/cjs/react-dom.development.js:27426:14)
      at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:26560:12)
      at workLoopSync (node_modules/react-dom/cjs/react-dom.development.js:26466:5)
      at renderRootSync (node_modules/react-dom/cjs/react-dom.development.js:26434:7)
      at performConcurrentWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:25738:74)
      at workLoop (node_modules/scheduler/cjs/scheduler.development.js:266:34)
      at flushWork (node_modules/scheduler/cjs/scheduler.development.js:239:14)
      at performWorkUntilDeadline (node_modules/scheduler/cjs/scheduler.development.js:533:21)
      at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)


Summary of all failing tests
FAIL src/hooks/__tests__/useWallet.test.js
  ● Test suite failed to run

    Jest worker encountered 4 child process exceptions, exceeding retry limit

      at ChildProcessWorker.initialize (node_modules/jest-runner/node_modules/jest-worker/build/workers/ChildProcessWorker.js:181:21)


Test Suites: 1 failed, 25 passed, 26 total
Tests:       549 passed, 549 total
Snapshots:   0 total
Time:        40.242 s
Ran all test suites.
Jest did not exit one second after the test run has completed.

'This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
Build cashtab-tests failed with exit code 1

Tail of the build log:

      at warning (node_modules/rc-util/lib/warning.js:32:15)
      at call (node_modules/rc-util/lib/warning.js:52:5)
      at warningOnce (node_modules/rc-util/lib/warning.js:57:3)
      at warning (node_modules/antd/lib/_util/warning.js:23:26)
      at typeWarning (node_modules/antd/lib/_util/warning.js:57:49)
      at Function.typeWarning.deprecated (node_modules/antd/lib/_util/warning.js:62:5)
      at Group (node_modules/antd/lib/input/Group.js:42:13)
      at renderWithHooks (node_modules/react-dom/cjs/react-dom.development.js:16305:18)
      at updateFunctionComponent (node_modules/react-dom/cjs/react-dom.development.js:19588:20)
      at beginWork (node_modules/react-dom/cjs/react-dom.development.js:21601:16)
      at beginWork$1 (node_modules/react-dom/cjs/react-dom.development.js:27426:14)
      at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:26560:12)
      at workLoopSync (node_modules/react-dom/cjs/react-dom.development.js:26466:5)
      at renderRootSync (node_modules/react-dom/cjs/react-dom.development.js:26434:7)
      at performConcurrentWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:25738:74)
      at workLoop (node_modules/scheduler/cjs/scheduler.development.js:266:34)
      at flushWork (node_modules/scheduler/cjs/scheduler.development.js:239:14)
      at performWorkUntilDeadline (node_modules/scheduler/cjs/scheduler.development.js:533:21)
      at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)

    console.error
      Warning: [rc-collapse] `children` will be removed in next major version. Please use `items` instead.

      at warning (node_modules/rc-util/lib/warning.js:32:15)
      at call (node_modules/rc-util/lib/warning.js:52:5)
      at warningOnce (node_modules/rc-util/lib/warning.js:57:3)
      at node_modules/rc-collapse/lib/Collapse.js:72:24
      at renderWithHooks (node_modules/react-dom/cjs/react-dom.development.js:16305:18)
      at updateForwardRef (node_modules/react-dom/cjs/react-dom.development.js:19226:20)
      at beginWork (node_modules/react-dom/cjs/react-dom.development.js:21636:16)
      at beginWork$1 (node_modules/react-dom/cjs/react-dom.development.js:27426:14)
      at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:26560:12)
      at workLoopSync (node_modules/react-dom/cjs/react-dom.development.js:26466:5)
      at renderRootSync (node_modules/react-dom/cjs/react-dom.development.js:26434:7)
      at performConcurrentWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:25738:74)
      at workLoop (node_modules/scheduler/cjs/scheduler.development.js:266:34)
      at flushWork (node_modules/scheduler/cjs/scheduler.development.js:239:14)
      at performWorkUntilDeadline (node_modules/scheduler/cjs/scheduler.development.js:533:21)
      at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)


Summary of all failing tests
FAIL src/hooks/__tests__/useWallet.test.js
  ● Test suite failed to run

    Jest worker encountered 4 child process exceptions, exceeding retry limit

      at ChildProcessWorker.initialize (node_modules/jest-runner/node_modules/jest-worker/build/workers/ChildProcessWorker.js:181:21)


Test Suites: 1 failed, 25 passed, 26 total
Tests:       549 passed, 549 total
Snapshots:   0 total
Time:        40.242 s
Ran all test suites.
Jest did not exit one second after the test run has completed.

'This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
Build cashtab-tests failed with exit code 1

note this failure is related to experimental unit tests in useWallet.test.js that were removed, hence the passed build after this

This revision is now accepted and ready to land.Feb 2 2024, 07:50