Page MenuHomePhabricator

[Cashtab] Support alias registration of user input addresses
ClosedPublic

Authored by bytesofman on May 8 2023, 18:10.

Details

Summary

T3060

Support user input of address for alias registration

The Alias.js screen loads with a checkbox selected indicating that the alias will be registered to the active wallet's address.

The user may uncheck this box and enter an address of their choosing, P2SH or P2PKH. User input is validated.

Note: alias-server has not yet been updated to parse these txs.

Test Plan

npm test
In components/common/Ticker.js, change the aliasSettings.aliasEnabled bool to true
npm start
Navigate to the Alias.js screen. Confirm checkbox is checked.
Register an alias without unchecking the box.
Uncheck the box.
Confirm alias address input form appears.
Enter an invalid address and confirm validation error.
Enter a valid address and confirm validation error disappears, 'Register Alias' button is enabled (if alias input is valid)
Register this alias
Try registering to a p2sh address, like the IFP address ecash:prfhcnyqnl5cgrnmlfmms675w93ld7mvvqd0y8lz07

Diff Detail

Repository
rABC Bitcoin ABC
Branch
alias-support-address-input
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 23663
Build 46940: Build Diffcashtab-tests
Build 46939: arc lint + arc unit

Event Timeline

Failed tests logs:

====== CashTab Unit Tests:  Wallet with BCH balances and tokens and state field ======
Error: expect(received).toMatchSnapshot()

Snapshot name: `Wallet with BCH balances and tokens and state field 1`

- Snapshot  - 1
+ Received  + 1

@@ -94,11 +94,11 @@
                              name="address"
                              onBlur={[Function]}
                              onChange={[Function]}
                              onFocus={[Function]}
                              onKeyDown={[Function]}
-                             placeholder="Address or Alias"
+                             placeholder="Address"
                              required={true}
                              style={null}
                              type="text"
                              value=""
                            />
    at Object.<anonymous> (/work/cashtab/src/components/Send/__tests__/SendToken.test.js:66:18)
    at Promise.then.completed (/work/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at _runTest (/work/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/cashtab/node_modules/jest-runner/build/testWorker.js:133:12)Error: expect(received).toMatchSnapshot()

Snapshot name: `Wallet with BCH balances and tokens and state field 1`

- Snapshot  - 1
+ Received  + 1

@@ -197,11 +197,11 @@
                                      name="address"
                                      onBlur={[Function]}
                                      onChange={[Function]}
                                      onFocus={[Function]}
                                      onKeyDown={[Function]}
-                                     placeholder="Address or Alias"
+                                     placeholder="Address"
                                      required={true}
                                      style={null}
                                      type="text"
                                      value=""
                                    />
    at Object.<anonymous> (/work/cashtab/src/components/Send/__tests__/Send.test.js:88:18)
    at Promise.then.completed (/work/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at _runTest (/work/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/cashtab/node_modules/jest-runner/build/testWorker.js:133:12)
====== CashTab Unit Tests:  Wallet without BCH balance ======
Error: expect(received).toMatchSnapshot()

Snapshot name: `Wallet without BCH balance 1`

- Snapshot  - 1
+ Received  + 1

@@ -192,11 +192,11 @@
                                      name="address"
                                      onBlur={[Function]}
                                      onChange={[Function]}
                                      onFocus={[Function]}
                                      onKeyDown={[Function]}
-                                     placeholder="Address or Alias"
+                                     placeholder="Address"
                                      required={true}
                                      style={null}
                                      type="text"
                                      value=""
                                    />
    at Object.<anonymous> (/work/cashtab/src/components/Send/__tests__/Send.test.js:44:18)
    at Promise.then.completed (/work/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at _runTest (/work/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/cashtab/node_modules/jest-runner/build/testWorker.js:133:12)
====== CashTab Unit Tests:  Wallet with BCH balances ======
Error: expect(received).toMatchSnapshot()

Snapshot name: `Wallet with BCH balances 1`

- Snapshot  - 1
+ Received  + 1

@@ -192,11 +192,11 @@
                                      name="address"
                                      onBlur={[Function]}
                                      onChange={[Function]}
                                      onFocus={[Function]}
                                      onKeyDown={[Function]}
-                                     placeholder="Address or Alias"
+                                     placeholder="Address"
                                      required={true}
                                      style={null}
                                      type="text"
                                      value=""
                                    />
    at Object.<anonymous> (/work/cashtab/src/components/Send/__tests__/Send.test.js:58:18)
    at Promise.then.completed (/work/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at _runTest (/work/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/cashtab/node_modules/jest-runner/build/testWorker.js:133:12)
====== CashTab Unit Tests:  Wallet with BCH balances and tokens ======
Error: expect(received).toMatchSnapshot()

Snapshot name: `Wallet with BCH balances and tokens 1`

- Snapshot  - 1
+ Received  + 1

@@ -192,11 +192,11 @@
                                      name="address"
                                      onBlur={[Function]}
                                      onChange={[Function]}
                                      onFocus={[Function]}
                                      onKeyDown={[Function]}
-                                     placeholder="Address or Alias"
+                                     placeholder="Address"
                                      required={true}
                                      style={null}
                                      type="text"
                                      value=""
                                    />
    at Object.<anonymous> (/work/cashtab/src/components/Send/__tests__/Send.test.js:72:18)
    at Promise.then.completed (/work/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at _runTest (/work/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/cashtab/node_modules/jest-runner/build/testWorker.js:133:12)
====== CashTab Unit Tests:  Without wallet defined ======
Error: expect(received).toMatchSnapshot()

Snapshot name: `Without wallet defined 1`

- Snapshot  - 1
+ Received  + 1

@@ -187,11 +187,11 @@
                                      name="address"
                                      onBlur={[Function]}
                                      onChange={[Function]}
                                      onFocus={[Function]}
                                      onKeyDown={[Function]}
-                                     placeholder="Address or Alias"
+                                     placeholder="Address"
                                      required={true}
                                      style={null}
                                      type="text"
                                      value=""
                                    />
    at Object.<anonymous> (/work/cashtab/src/components/Send/__tests__/Send.test.js:107:18)
    at Promise.then.completed (/work/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at _runTest (/work/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/cashtab/node_modules/jest-runner/build/testWorker.js:133:12)

Each failure log is accessible here:
CashTab Unit Tests: Wallet with BCH balances and tokens and state field
CashTab Unit Tests: Wallet without BCH balance
CashTab Unit Tests: Wallet with BCH balances
CashTab Unit Tests: Wallet with BCH balances and tokens
CashTab Unit Tests: Without wallet defined

Fabien requested changes to this revision.May 9 2023, 07:50
Fabien added a subscriber: Fabien.
Fabien added inline comments.
cashtab/src/components/Alias/Alias.js
117 ↗(On Diff #40229)

Macro notaloop:

307 ↗(On Diff #40229)
311 ↗(On Diff #40229)

IMO that's not very useful as a comment. You're documenting the test fixtures in the function itself, which is unrelated

313 ↗(On Diff #40229)
348 ↗(On Diff #40229)

Dito

367 ↗(On Diff #40229)

You should trim before you check for validity, not after, so that leading/trailing whitespaces that often occur during copy/pasting are ignored.
Also why do you need this check at all ? If value is an empty string the address will be invalid. If not that's a bug and it needs to be fixed separately.

This revision now requires changes to proceed.May 9 2023, 07:50

@bot preview-cashtab

Note that it's not possible to test this as Ticker.js must be manually updated to enable the Alias screen

I could push diffs with this set to true, which would allow previews to work. But then might accidentally land one with aliases enabled.

This revision is now accepted and ready to land.May 10 2023, 14:13