Page MenuHomePhabricator

[Cashtab] More ts implementation as prep for wallet upgrade
Needs ReviewPublic

Authored by bytesofman on Fri, Nov 15, 06:01.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

Convert useWallet and dependencies to ts. Patch bugs discovered in ts implementation.

Ended up being quite a large diff.

I don't think there is much point in splitting it up, since everything is interdependent, and the integration tests confirm expected behavior. If something goes wrong, we can revert it all.

Summary of changes

  • New types for legacy wallets. Complicated implementation as these overlap in various ways.
  • Update wallet migration and storage functions to work with the types.
  • Patch some bugs discovered during ts implementation, for example parseInt() being used on something that was already a number in useWallet.js.
  • Some cleanup on wallet loading and migration in useWallet.js brought on by issues discovered in ts implementation
  • Major update of mocked wallets -- all tx history is now ChronikClient and type checked; all legacy wallets are appropriate legacy types.

Impact

  • Makes future wallet upgrades easier, esp if we want to support other cryptocurrencies like Doge
  • We need to add publickey into the wallet as it is needed for agora methods, cumbersome to always calculate it with Ecc every time we need it.
  • Now that ChronikClient has stable types, important to get Cashtab fully converted to ts
Test Plan

npm test

this diff is live at https://cashtab-local-dev.netlify.app/

Diff Detail

Repository
rABC Bitcoin ABC
Branch
pubkey-in-wallet
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 31157
Build 61815: Build Diffcashtab-tests
Build 61814: arc lint + arc unit

Event Timeline

Tail of the build log:

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

> ecash-lib@0.2.1 build
> tsc && tsc -p ./tsconfig.build.json && cp -r ./src/ffi ./dist

Installing ecash-agora dependencies...
/work/modules/ecash-agora /work/modules/ecash-lib /work/modules/ecash-lib-wasm /work/modules/ecash-script /work/modules/chronik-client /work/modules/mock-chronik-client /work/modules/ecashaddrjs /work/abc-ci-builds/cashtab-tests

added 364 packages, and audited 367 packages in 2s

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

1 moderate severity vulnerability

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

> ecash-agora@0.1.1 build
> tsc && tsc -p ./tsconfig.build.json

/work/cashtab /work/modules/ecash-agora /work/modules/ecash-lib /work/modules/ecash-lib-wasm /work/modules/ecash-script /work/modules/chronik-client /work/modules/mock-chronik-client /work/modules/ecashaddrjs /work/abc-ci-builds/cashtab-tests

added 1485 packages, and audited 3331 packages in 25s

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

3 vulnerabilities (2 moderate, 1 high)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

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

Creating an optimized production build...

Treating warnings as errors because process.env.CI = true.
Most CI servers set it automatically.

Failed to compile.

[eslint] 
src/chronik/index.ts
  Line 210:13:  Forbidden non-null assertion  @typescript-eslint/no-non-null-assertion
  Line 210:31:  Forbidden non-null assertion  @typescript-eslint/no-non-null-assertion

src/wallet/useWallet.ts
  Line 57:5:  'MsgBlockClient' is defined but never used  @typescript-eslint/no-unused-vars


Build cashtab-tests failed with exit code 1

Fixing types, more ts conversion, tests passing

Tail of the build log:

/work/modules/ecash-agora /work/modules/ecash-lib /work/modules/ecash-lib-wasm /work/modules/ecash-script /work/modules/chronik-client /work/modules/mock-chronik-client /work/modules/ecashaddrjs /work/abc-ci-builds/cashtab-tests

added 364 packages, and audited 367 packages in 1s

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

1 moderate severity vulnerability

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

> ecash-agora@0.1.1 build
> tsc && tsc -p ./tsconfig.build.json

/work/cashtab /work/modules/ecash-agora /work/modules/ecash-lib /work/modules/ecash-lib-wasm /work/modules/ecash-script /work/modules/chronik-client /work/modules/mock-chronik-client /work/modules/ecashaddrjs /work/abc-ci-builds/cashtab-tests

added 1485 packages, and audited 3331 packages in 25s

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

3 vulnerabilities (2 moderate, 1 high)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

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

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

TS2769: No overload matches this call.
  Overload 1 of 4, '(iterable?: Iterable<readonly [string, string]> | null | undefined): Map<string, string>', gave the following error.
    Argument of type 'LegacyTokenState[] | [string, string][]' is not assignable to parameter of type 'Iterable<readonly [string, string]> | null | undefined'.
      Type 'LegacyTokenState[]' is not assignable to type 'Iterable<readonly [string, string]>'.
        The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
          Type 'IteratorResult<LegacyTokenState, any>' is not assignable to type 'IteratorResult<readonly [string, string], any>'.
            Type 'IteratorYieldResult<LegacyTokenState>' is not assignable to type 'IteratorResult<readonly [string, string], any>'.
              Type 'IteratorYieldResult<LegacyTokenState>' is not assignable to type 'IteratorYieldResult<readonly [string, string]>'.
                Type 'LegacyTokenState' is not assignable to type 'readonly [string, string]'.
  Overload 2 of 4, '(entries?: readonly (readonly [string, string])[] | null | undefined): Map<string, string>', gave the following error.
    Argument of type 'LegacyTokenState[] | [string, string][]' is not assignable to parameter of type 'readonly (readonly [string, string])[] | null | undefined'.
      Type 'LegacyTokenState[]' is not assignable to type 'readonly (readonly [string, string])[]'.
        Type 'LegacyTokenState' is not assignable to type 'readonly [string, string]'.
    127 |         state: {
    128 |             ...storedCashtabWallet.state,
  > 129 |             tokens: new Map(storedCashtabWallet.state.tokens),
        |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    130 |         },
    131 |     };
    132 | };


Build cashtab-tests failed with exit code 1

Tail of the build log:

> ecash-lib@0.2.1 build
> tsc && tsc -p ./tsconfig.build.json && cp -r ./src/ffi ./dist

Installing ecash-agora dependencies...
/work/modules/ecash-agora /work/modules/ecash-lib /work/modules/ecash-lib-wasm /work/modules/ecash-script /work/modules/chronik-client /work/modules/mock-chronik-client /work/modules/ecashaddrjs /work/abc-ci-builds/cashtab-tests

added 364 packages, and audited 367 packages in 1s

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

1 moderate severity vulnerability

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

> ecash-agora@0.1.1 build
> tsc && tsc -p ./tsconfig.build.json

/work/cashtab /work/modules/ecash-agora /work/modules/ecash-lib /work/modules/ecash-lib-wasm /work/modules/ecash-script /work/modules/chronik-client /work/modules/mock-chronik-client /work/modules/ecashaddrjs /work/abc-ci-builds/cashtab-tests

added 1485 packages, and audited 3331 packages in 24s

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

3 vulnerabilities (2 moderate, 1 high)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

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

Creating an optimized production build...

Treating warnings as errors because process.env.CI = true.
Most CI servers set it automatically.

Failed to compile.

[eslint] 
src/chronik/index.ts
  Line 210:13:  Forbidden non-null assertion  @typescript-eslint/no-non-null-assertion
  Line 210:31:  Forbidden non-null assertion  @typescript-eslint/no-non-null-assertion

src/helpers/index.ts
  Line 16:5:  'LegacyCashtabWallet_Pre_2_1_0' is defined but never used  @typescript-eslint/no-unused-vars
  Line 17:5:  'LegacyCashtabWallet_Pre_2_9_0' is defined but never used  @typescript-eslint/no-unused-vars

src/wallet/useWallet.ts
  Line 57:5:  'MsgBlockClient' is defined but never used  @typescript-eslint/no-unused-vars


Build cashtab-tests failed with exit code 1
bytesofman edited the test plan for this revision. (Show Details)
bytesofman edited the summary of this revision. (Show Details)