Page MenuHomePhabricator

[Cashtab] Update loadCashtabState to not take params
ClosedPublic

Authored by bytesofman on Feb 20 2024, 21:04.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABC2b6db903ce65: [Cashtab] Update loadCashtabState to not take params
Summary

Quickly ran into problems with param based approach here when tried to work on a second one.

setState is an async function. But, in react, there is not a practical way to await this. You can reliably trigger actions to happen when state changes, e.g. a callback or useEffect. However this would make for a long daisy chain of loading functions to get everything we need into cashtabState.

Because we always want to load all of the localforage stuff at the same time on startup, we do not need to use a key...value approach and various customizations depending on the key. Instead, go through and load/validate/migrate everything.

Note: for now, we still have only implemented contactList in the new cashtabState general object.

Test Plan

npm test

Diff Detail

Repository
rABC Bitcoin ABC
Branch
improve-cashtab-standardize-db
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 27371
Build 54305: Build Diffcashtab-tests
Build 54304: arc lint + arc unit

Event Timeline

bytesofman added inline comments.
cashtab/src/components/__tests__/AppIntegrations.test.js
130 ↗(On Diff #45430)

Now we get undefined from await localforage.getItem('contactList') if it has not been set yet. undefined is not a valid contact list so it is migrated to the default as expected -- []

cashtab/src/hooks/useWallet.js
276 ↗(On Diff #45430)

have always wrapped this in try...catch in Cashtab and console.log err msg. However, have never actually seen this error, and it is always untested.

So, stop doing this. If there is an error it will throw.

This revision is now accepted and ready to land.Feb 21 2024, 08:24

rebase, handle case of not finding an item in localforage

Failed tests logs:

====== CashTab Unit Tests: useWallet hook rendering in different localforage states Cashtab loads wallet, settings, cache, and contactlist as expected defaults if localforage is empty ======
Error: expect(received).toStrictEqual(expected) // deep equality

- Expected  - 1
+ Received  + 6

  Object {
-   "contactList": Array [],
+   "contactList": Array [
+     Object {
+       "address": "ecash:qp89xgjhcqdnzzemts0aj378nfe2mhu9yvxj9nhgg6",
+       "name": "test",
+     },
+   ],
  }

Ignored nodes: comments, script, style
<html>
  <head />
  <body>
    <div />
  </body>
</html>
    at toStrictEqual (/work/cashtab/src/hooks/__tests__/useWalletStorage.test.js:75:49)
    at runWithExpensiveErrorDiagnosticsDisabled (/work/cashtab/node_modules/@testing-library/dom/dist/config.js:47:12)
    at checkCallback (/work/cashtab/node_modules/@testing-library/dom/dist/wait-for.js:124:77)
    at checkRealTimersCallback (/work/cashtab/node_modules/@testing-library/dom/dist/wait-for.js:118:16)
    at Timeout.task [as _onTimeout] (/work/cashtab/node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)
    at listOnTimeout (node:internal/timers:573:17)
    at processTimers (node:internal/timers:514:7)

Each failure log is accessible here:
CashTab Unit Tests: useWallet hook rendering in different localforage states Cashtab loads wallet, settings, cache, and contactlist as expected defaults if localforage is empty

Failed tests logs:

====== CashTab Unit Tests: useWallet hook rendering in different localforage states Cashtab loads wallet, settings, cache, and contactlist as expected defaults if localforage is empty ======
Error: expect(received).toStrictEqual(expected) // deep equality

- Expected  - 1
+ Received  + 6

  Object {
-   "contactList": Array [],
+   "contactList": Array [
+     Object {
+       "address": "ecash:qp89xgjhcqdnzzemts0aj378nfe2mhu9yvxj9nhgg6",
+       "name": "test",
+     },
+   ],
  }

Ignored nodes: comments, script, style
<html>
  <head />
  <body>
    <div />
  </body>
</html>
    at toStrictEqual (/work/cashtab/src/hooks/__tests__/useWalletStorage.test.js:75:49)
    at runWithExpensiveErrorDiagnosticsDisabled (/work/cashtab/node_modules/@testing-library/dom/dist/config.js:47:12)
    at checkCallback (/work/cashtab/node_modules/@testing-library/dom/dist/wait-for.js:124:77)
    at checkRealTimersCallback (/work/cashtab/node_modules/@testing-library/dom/dist/wait-for.js:118:16)
    at Timeout.task [as _onTimeout] (/work/cashtab/node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)
    at listOnTimeout (node:internal/timers:573:17)
    at processTimers (node:internal/timers:514:7)

Each failure log is accessible here:
CashTab Unit Tests: useWallet hook rendering in different localforage states Cashtab loads wallet, settings, cache, and contactlist as expected defaults if localforage is empty

PiRK requested changes to this revision.Feb 21 2024, 15:26

the tests are failing now

This revision now requires changes to proceed.Feb 21 2024, 15:26

investigating this test failure

pending upgrades to useWalletStorage from T3444

package-lock.json still has changes from upgrades unrelated to this diff

remove debug logs and unrelated changes

still package-lock.json issues

Tail of the build log:

/work/cashtab /work/abc-ci-builds/cashtab-tests
npm ERR! code EUSAGE
npm ERR! 
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm ERR! 
npm ERR! Invalid: lock file's @testing-library/jest-dom@5.17.0 does not satisfy @testing-library/jest-dom@6.4.2
npm ERR! Missing: dom-accessibility-api@0.6.3 from lock file
npm ERR! 
npm ERR! Clean install a project
npm ERR! 
npm ERR! Usage:
npm ERR! npm ci
npm ERR! 
npm ERR! Options:
npm ERR! [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
npm ERR! [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
npm ERR! [--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
npm ERR! [--strict-peer-deps] [--foreground-scripts] [--ignore-scripts] [--no-audit]
npm ERR! [--no-bin-links] [--no-fund] [--dry-run]
npm ERR! [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
npm ERR! [-ws|--workspaces] [--include-workspace-root] [--install-links]
npm ERR! 
npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
npm ERR! 
npm ERR! Run "npm help ci" for more info

npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-02-23T12_12_31_839Z-debug-0.log
Build cashtab-tests failed with exit code 1

Tail of the build log:

/work/cashtab /work/abc-ci-builds/cashtab-tests
npm WARN deprecated rollup-plugin-terser@7.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
npm WARN deprecated @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
npm WARN deprecated @babel/plugin-proposal-numeric-separator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.
npm WARN deprecated @babel/plugin-proposal-private-methods@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-methods instead.
npm WARN deprecated abab@2.0.6: Use your platform's native atob() and btoa() methods instead
npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
npm WARN deprecated @babel/plugin-proposal-private-property-in-object@7.21.11: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-property-in-object instead.
npm WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm WARN deprecated domexception@4.0.0: Use your platform's native DOMException instead
npm WARN deprecated @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
npm WARN deprecated workbox-cacheable-response@6.6.0: workbox-background-sync@6.6.0
npm WARN deprecated workbox-google-analytics@6.6.0: It is not compatible with newer versions of GA starting with v4, as long as you are using GAv3 it should be ok, but the package is not longer being maintained

added 1910 packages, and audited 1911 packages in 24s

265 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

> cashtab@1.1.40 build
> node scripts/build.js

Creating an optimized production build...
Failed to compile.

Failed to minify the bundle. Error: static/js/main.79b480eb.js from Terser plugin
Cannot read properties of undefined (reading 'TYPE')
TypeError: Cannot read properties of undefined (reading 'TYPE')
    at /work/cashtab/scripts/build.js:172:31
    at finalCallback (/work/cashtab/node_modules/webpack/lib/Compiler.js:454:32)
    at /work/cashtab/node_modules/webpack/lib/Compiler.js:471:13
    at Hook.eval [as callAsync] (eval at create (/work/cashtab/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/work/cashtab/node_modules/tapable/lib/Hook.js:18:14)
    at onCompiled (/work/cashtab/node_modules/webpack/lib/Compiler.js:469:21)
    at /work/cashtab/node_modules/webpack/lib/Compiler.js:1213:17
    at Hook.eval [as callAsync] (eval at create (/work/cashtab/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/work/cashtab/node_modules/tapable/lib/Hook.js:18:14)
    at /work/cashtab/node_modules/webpack/lib/Compiler.js:1209:33
    at finalCallback (/work/cashtab/node_modules/webpack/lib/Compilation.js:2802:11)
    at /work/cashtab/node_modules/webpack/lib/Compilation.js:3107:11
    at Hook.eval [as callAsync] (eval at create (/work/cashtab/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/work/cashtab/node_modules/tapable/lib/Hook.js:18:14)
    at /work/cashtab/node_modules/webpack/lib/Compilation.js:3100:38
    at eval (eval at create (/work/cashtab/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at eval (eval at create (/work/cashtab/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)
Read more here: https://cra.link/failed-to-minify

Build cashtab-tests failed with exit code 1

failures appear related to package-lock.json inconsistencies from testing upgraded deps in this diff. will wait on D15524 before rebasing this.

This revision is now accepted and ready to land.Feb 24 2024, 12:24