Page MenuHomePhabricator

[Cashtab] [Alias] pt 3 - Implement isAliasAvailable function
ClosedPublic

Authored by emack on Dec 17 2022, 13:33.

Details

Summary

T2551

Depends on D12898

This diff fleshes out the isAliasAvailable and extractAliasesFromPaymentAddress functions.

extractAliasesFromPaymentAddress in particular is structured as follows:

loop through each inbound txs in alias payment address
    if the txs has an alias rego prefix in output[0] then
        loop through all outputs in that txs 
            tally up the payment values across all outputs going to payment address
            if alias <= 50 char and cumulative payment = expected fee then add alias to array
            (I didn't think minFee check was needed since by virtue of a valid rego fee it will always be higher than minFee)
return array of validated registered aliases

Debug statements kept in for this diff so you can see the list of registered aliases in the console log for validation.

[Cashtab] [Alias] pt 1 - Create scaffold for new Identity component
[Cashtab] [Alias] pt 2 - Implement registerNewAlias() to handle alias registration
[Cashtab] [Alias] pt 3 - Implement isAliasAvailable function
[Cashtab] [Alias] pt 4 - Implement isAddressRegistered function
[Cashtab] [Alias] pt 5 - Implement getAddressFromAlias function
[Cashtab] [Alias] pt 6 - Implement isLocalAliasStateLatest function
[Cashtab] [Alias] pt 7 - Enable alias lookup for Send XEC component
[Cashtab] [Alias] pt 8 - Enable alias lookup for Send Token component
[Cashtab] [Alias] pt 9 - Implement pricing mechanism
[Cashtab] [Alias] pt 10 - Server cron job
[Cashtab] [Alias] pt 11 - Upgrade tx history to recognize alias registration txs

Test Plan
  • npm test
  • npm start
  • comment out the const link = await registerNewAlias... block in Alias.js in order to initially test the alias availability checking logic and avoid spamming the address with test inputs.
  • input your desired alias and click Register Alias. Note the console log of currently registered aliases. If your alias was not in this list, verify console log displays the correct registration fee for this alias, a Progressing to alias registration console log message is displayed and the alias is rendered on the page with '(Pending)' attached.
  • use one of the existing aliases and click Register Alias. Verify an error notification indicating this is taken.
  • send some weird shit to this payment address and verify the availability logic does not fall over and the list of registered aliases in the console log is not updated with the weird shit
  • uncomment the const link = await registerNewAlias... block in Alias.js and test out the end to end registration of new and existing aliases and ensure the existing ones still trigger the error notification with no further progression to onchain registration.

Diff Detail

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
emack requested review of this revision.Dec 17 2022, 13:33

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  - 2
+ Received  + 2

@@ -54,11 +54,11 @@
                          className="ant-input-wrapper ant-input-group"
                        >
                          <span
                            className="ant-input-affix-wrapper"
                            hidden={null}
-                           onMouseDown={[Function]}
+                           onClick={[Function]}
                            style={null}
                          >
                            <span
                              className="ant-input-prefix"
                            >
@@ -161,11 +161,11 @@
                          className="ant-input-wrapper ant-input-group"
                        >
                          <span
                            className="ant-input-affix-wrapper"
                            hidden={null}
-                           onMouseDown={[Function]}
+                           onClick={[Function]}
                            style={null}
                          >
                            <span
                              className="ant-input-prefix"
                            />
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/SendToken.test.js:66:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/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  - 2
+ Received  + 2

@@ -162,11 +162,11 @@
                                  className="ant-input-wrapper ant-input-group"
                                >
                                  <span
                                    className="ant-input-affix-wrapper"
                                    hidden={null}
-                                   onMouseDown={[Function]}
+                                   onClick={[Function]}
                                    style={null}
                                  >
                                    <span
                                      className="ant-input-prefix"
                                    >
@@ -270,11 +270,11 @@
                              <span
                                className="ant-input-group ant-input-group-compact"
                              >
                                <span
                                  className="ant-input-affix-wrapper"
-                                 onMouseDown={[Function]}
+                                 onClick={[Function]}
                                  style={
                                    Object {
                                      "textAlign": "left",
                                      "width": "60%",
                                    }
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/Send.test.js:88:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/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  - 2
+ Received  + 2

@@ -157,11 +157,11 @@
                                  className="ant-input-wrapper ant-input-group"
                                >
                                  <span
                                    className="ant-input-affix-wrapper"
                                    hidden={null}
-                                   onMouseDown={[Function]}
+                                   onClick={[Function]}
                                    style={null}
                                  >
                                    <span
                                      className="ant-input-prefix"
                                    >
@@ -265,11 +265,11 @@
                              <span
                                className="ant-input-group ant-input-group-compact"
                              >
                                <span
                                  className="ant-input-affix-wrapper"
-                                 onMouseDown={[Function]}
+                                 onClick={[Function]}
                                  style={
                                    Object {
                                      "textAlign": "left",
                                      "width": "60%",
                                    }
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/Send.test.js:44:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/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  - 2
+ Received  + 2

@@ -157,11 +157,11 @@
                                  className="ant-input-wrapper ant-input-group"
                                >
                                  <span
                                    className="ant-input-affix-wrapper"
                                    hidden={null}
-                                   onMouseDown={[Function]}
+                                   onClick={[Function]}
                                    style={null}
                                  >
                                    <span
                                      className="ant-input-prefix"
                                    >
@@ -265,11 +265,11 @@
                              <span
                                className="ant-input-group ant-input-group-compact"
                              >
                                <span
                                  className="ant-input-affix-wrapper"
-                                 onMouseDown={[Function]}
+                                 onClick={[Function]}
                                  style={
                                    Object {
                                      "textAlign": "left",
                                      "width": "60%",
                                    }
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/Send.test.js:58:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/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  - 2
+ Received  + 2

@@ -157,11 +157,11 @@
                                  className="ant-input-wrapper ant-input-group"
                                >
                                  <span
                                    className="ant-input-affix-wrapper"
                                    hidden={null}
-                                   onMouseDown={[Function]}
+                                   onClick={[Function]}
                                    style={null}
                                  >
                                    <span
                                      className="ant-input-prefix"
                                    >
@@ -265,11 +265,11 @@
                              <span
                                className="ant-input-group ant-input-group-compact"
                              >
                                <span
                                  className="ant-input-affix-wrapper"
-                                 onMouseDown={[Function]}
+                                 onClick={[Function]}
                                  style={
                                    Object {
                                      "textAlign": "left",
                                      "width": "60%",
                                    }
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/Send.test.js:72:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/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  - 2
+ Received  + 2

@@ -152,11 +152,11 @@
                                  className="ant-input-wrapper ant-input-group"
                                >
                                  <span
                                    className="ant-input-affix-wrapper"
                                    hidden={null}
-                                   onMouseDown={[Function]}
+                                   onClick={[Function]}
                                    style={null}
                                  >
                                    <span
                                      className="ant-input-prefix"
                                    >
@@ -260,11 +260,11 @@
                              <span
                                className="ant-input-group ant-input-group-compact"
                              >
                                <span
                                  className="ant-input-affix-wrapper"
-                                 onMouseDown={[Function]}
+                                 onClick={[Function]}
                                  style={
                                    Object {
                                      "textAlign": "left",
                                      "width": "60%",
                                    }
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/Send.test.js:107:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/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

Failed tests logs:

====== CashTab Unit Tests:  Wallet without BCH balance ======
Error: expect(received).toMatchSnapshot()

Snapshot name: `Wallet without BCH balance 1`

- Snapshot  - 2
+ Received  + 2

@@ -157,11 +157,11 @@
                                  className="ant-input-wrapper ant-input-group"
                                >
                                  <span
                                    className="ant-input-affix-wrapper"
                                    hidden={null}
-                                   onMouseDown={[Function]}
+                                   onClick={[Function]}
                                    style={null}
                                  >
                                    <span
                                      className="ant-input-prefix"
                                    >
@@ -265,11 +265,11 @@
                              <span
                                className="ant-input-group ant-input-group-compact"
                              >
                                <span
                                  className="ant-input-affix-wrapper"
-                                 onMouseDown={[Function]}
+                                 onClick={[Function]}
                                  style={
                                    Object {
                                      "textAlign": "left",
                                      "width": "60%",
                                    }
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/Send.test.js:44:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/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  - 2
+ Received  + 2

@@ -157,11 +157,11 @@
                                  className="ant-input-wrapper ant-input-group"
                                >
                                  <span
                                    className="ant-input-affix-wrapper"
                                    hidden={null}
-                                   onMouseDown={[Function]}
+                                   onClick={[Function]}
                                    style={null}
                                  >
                                    <span
                                      className="ant-input-prefix"
                                    >
@@ -265,11 +265,11 @@
                              <span
                                className="ant-input-group ant-input-group-compact"
                              >
                                <span
                                  className="ant-input-affix-wrapper"
-                                 onMouseDown={[Function]}
+                                 onClick={[Function]}
                                  style={
                                    Object {
                                      "textAlign": "left",
                                      "width": "60%",
                                    }
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/Send.test.js:58:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/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  - 2
+ Received  + 2

@@ -157,11 +157,11 @@
                                  className="ant-input-wrapper ant-input-group"
                                >
                                  <span
                                    className="ant-input-affix-wrapper"
                                    hidden={null}
-                                   onMouseDown={[Function]}
+                                   onClick={[Function]}
                                    style={null}
                                  >
                                    <span
                                      className="ant-input-prefix"
                                    >
@@ -265,11 +265,11 @@
                              <span
                                className="ant-input-group ant-input-group-compact"
                              >
                                <span
                                  className="ant-input-affix-wrapper"
-                                 onMouseDown={[Function]}
+                                 onClick={[Function]}
                                  style={
                                    Object {
                                      "textAlign": "left",
                                      "width": "60%",
                                    }
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/Send.test.js:72:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/cashtab/node_modules/jest-runner/build/testWorker.js:133:12)
====== 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  - 2
+ Received  + 2

@@ -162,11 +162,11 @@
                                  className="ant-input-wrapper ant-input-group"
                                >
                                  <span
                                    className="ant-input-affix-wrapper"
                                    hidden={null}
-                                   onMouseDown={[Function]}
+                                   onClick={[Function]}
                                    style={null}
                                  >
                                    <span
                                      className="ant-input-prefix"
                                    >
@@ -270,11 +270,11 @@
                              <span
                                className="ant-input-group ant-input-group-compact"
                              >
                                <span
                                  className="ant-input-affix-wrapper"
-                                 onMouseDown={[Function]}
+                                 onClick={[Function]}
                                  style={
                                    Object {
                                      "textAlign": "left",
                                      "width": "60%",
                                    }
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/Send.test.js:88:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/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  - 2
+ Received  + 2

@@ -54,11 +54,11 @@
                          className="ant-input-wrapper ant-input-group"
                        >
                          <span
                            className="ant-input-affix-wrapper"
                            hidden={null}
-                           onMouseDown={[Function]}
+                           onClick={[Function]}
                            style={null}
                          >
                            <span
                              className="ant-input-prefix"
                            >
@@ -161,11 +161,11 @@
                          className="ant-input-wrapper ant-input-group"
                        >
                          <span
                            className="ant-input-affix-wrapper"
                            hidden={null}
-                           onMouseDown={[Function]}
+                           onClick={[Function]}
                            style={null}
                          >
                            <span
                              className="ant-input-prefix"
                            />
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/SendToken.test.js:66:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/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  - 2
+ Received  + 2

@@ -152,11 +152,11 @@
                                  className="ant-input-wrapper ant-input-group"
                                >
                                  <span
                                    className="ant-input-affix-wrapper"
                                    hidden={null}
-                                   onMouseDown={[Function]}
+                                   onClick={[Function]}
                                    style={null}
                                  >
                                    <span
                                      className="ant-input-prefix"
                                    >
@@ -260,11 +260,11 @@
                              <span
                                className="ant-input-group ant-input-group-compact"
                              >
                                <span
                                  className="ant-input-affix-wrapper"
-                                 onMouseDown={[Function]}
+                                 onClick={[Function]}
                                  style={
                                    Object {
                                      "textAlign": "left",
                                      "width": "60%",
                                    }
    at Object.<anonymous> (/work/web/cashtab/src/components/Send/__tests__/Send.test.js:107:18)
    at Promise.then.completed (/work/web/cashtab/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/work/web/cashtab/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at _runTest (/work/web/cashtab/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/work/web/cashtab/node_modules/jest-circus/build/run.js:66:9)
    at run (/work/web/cashtab/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)
    at jestAdapter (/work/web/cashtab/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
    at runTestInternal (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:389:16)
    at runTest (/work/web/cashtab/node_modules/jest-runner/build/runTest.js:475:34)
    at Object.worker (/work/web/cashtab/node_modules/jest-runner/build/testWorker.js:133:12)

Each failure log is accessible here:
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: Wallet with BCH balances and tokens and state field
CashTab Unit Tests: Without wallet defined

This comment was removed by emack.

updating these mf$#king snapshots

bytesofman added inline comments.
web/cashtab/src/components/Alias/Alias.js
81 ↗(On Diff #37349)

Alias ${aliasInput} is available. Broadcasting registration transaction.

113 ↗(On Diff #37349)

The alias state should always be an array. It's just that sometimes it's empty. So, in this case, you will be pushing into the array no matter what.

web/cashtab/src/components/Common/Ticker.js
13 ↗(On Diff #37349)

We don't want these hardcoded if they are for the same value. Vector for some weird bugs.

Will need to convert between them using available function in Cashtab.

web/cashtab/src/utils/chronik.js
16 ↗(On Diff #37349)

Step one should be check cache to see if this alias has already cached.

So, maybe step zero is set up a cache of all valid aliases.

validAliases = {
registeredAliases: [alias1, alias2, ... , aliasN]
validedThruBlockheight: <blockheight where registeredAliases is valid through>
}

Valid registered aliases will never be overwritten. So, we would always be able to check for valid aliases by only checking the tx history after the cached validedThruBlockheight

17 ↗(On Diff #37349)

ah ok got it. If this is coming later, ignore my comment above

21 ↗(On Diff #37349)

typo retrieve

40 ↗(On Diff #37349)

this section of the isAliasAvailable function should be its own function so that we can have unit tests with an input of aliasPaymentTxs

59 ↗(On Diff #37349)

As mentioned in review of last diff, we should only have one prefix here, .xec

89 ↗(On Diff #37349)

This should also be its own function with unit tests

This revision now requires changes to proceed.Dec 20 2022, 00:29
web/cashtab/src/utils/chronik.js
16 ↗(On Diff #37349)

update:

{
  validAliases = {registeredAliases: [{alias: alias1, address: address1}, {alias: alias2, address: address2}, ... , {alias: aliasN, address: addressN}] 
  validThruBlockheight: <blockheight where registeredAliases is valid through>
}
emack edited the test plan for this revision. (Show Details)
emack marked 10 inline comments as done.
  • added inline payment address to hash160 conversions in Chronik.js
  • standalone extractAliasesFromPaymentAddress and isAliasRegistered functions and corresponding unit tests and mocks added
  • changed the forEeach loop in isAliasRegistered() logic into a for loop due to need to break mid loop
  • adjusted alias array state update logic
  • caching mechanism planned in part 6 which will be implemented across the app

removed redundant alias array update

bytesofman added inline comments.
web/cashtab/src/utils/chronik.js
65

We should also confirm length is <= 50 chars here. So, good reason to keep this constant in currency.ticker since it will be used in more than one place.

76

User could pay the correct fee with multiple outputs to the correct address. We need to find the total amount of XEC sent to the payment address in this tx by iterating over all of the outputs, not just checking [1]

This revision now requires changes to proceed.Dec 22 2022, 00:20
emack marked an inline comment as done.
  • refactored extractAliasesFromPaymentAddress to the following logic:
loop through each inbound txs in alias payment address
    if the txs has an alias rego prefix in output[0] then
        loop through all outputs in that txs 
            tally up the payment values across all outputs going to payment address
            if alias <= 50 char and cumulative payment = expected fee then add alias to array
            (I didn't think minFee check was needed since by virtue of a valid rego fee it will always be higher than minFee)
return array of validated registered aliases
  • added a new txs (index 0) to mockTxHistoryOfAliasPaymentAddress in the chronikTxHistory.js mock containing an OP_RETURN script with a 51 char alias. Existing extractAliasesFromPaymentAddress unit tests should still pass with no change as this should not be extracted due to invalid alias length.
emack edited the summary of this revision. (Show Details)

When trying to register the same alias twice in quick succession, UI locks up

image.png (347×567 px, 22 KB)

Screenshot on trying to send this tx for the second time

image.png (88×567 px, 20 KB)

Dev console

I was also able to repeat this. But, if I try to register another alias, and then go back to the one just registered, the app will catch all the duplicates.

e.g. register chicken4, then register gnc, then register chicken4 again --> app behaves correctly, chicken4 registration is not allowed
but, register chicken4, wait 10s, register chicken4 again --> UI locks up as screenshots above show

web/cashtab/src/utils/chronik.js
67 ↗(On Diff #37546)

We can just call this getAliases

There's only one payment address so no need to mention it

72 ↗(On Diff #37546)

linter thing, I actually don't know if one is preferred or not, but everywhere else in Cashtab we use i+=1 and not i++

seems like it's generally best practice to avoid i++ in js due to some ambiguities: https://stackoverflow.com/questions/29885719/i-vs-i-in-a-javascript-for-loop

let's stick with i+=1

105 ↗(On Diff #37546)

hm, maybe you were right about us needing to save this as a constant. We'll be calling toHash160 a lot of times in this function, would be better to just have it in currency.ticker

This revision now requires changes to proceed.Jan 17 2023, 23:30
emack marked 3 inline comments as done.
  • renamed extractAliasesFromPaymentAddress function to getAliases
  • updated increment in for loops
  • added alias payment hash160 address as a constant in Ticker and updated references in chronik.js
  • resolved bug with duplicated registrations in quick succession
This revision is now accepted and ready to land.Jan 18 2023, 14:20