Page MenuHomePhabricator

[Cashtab] Hide msgs from unknown senders option
ClosedPublic

Authored by kieran709 on Jun 14 2022, 17:55.

Details

Reviewers
bytesofman
Group Reviewers
Restricted Project
Commits
rABC771befc108a6: [Cashtab] Hide msgs from unknown senders option
Summary

A setting should be added to allow users to hide messages from addresses not in their contacts list behind a 'show message' button. Related to T2418.

Test Plan

cd web/cashtab && npm start
in the browser:
observe that all messages are visible by default
navigate to settings tab and toggle 'show messages' off
receive a cashtab message from an address not in contact list
receive an encrypted message from an address not in contact list
receive a message from an address that IS in contact list
receive an encrypted message from an address that IS in the contact list

from the home tab:
observe that mesages from contacts are displayed
observe that the 'show message' button is displaying for messages that aren't from contacts
click the 'show message' button on both the encrypted and unencrypted message
observe that the messages are displayed, along with a warning that the sender is not a contact

Diff Detail

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

Event Timeline

This has the same issue as D11602. Need to get a function to handle partially valid cashtab settings.

This revision now requires changes to proceed.Jun 14 2022, 22:31

Rebased to master, updated validation test for parseInvalidSettingsForMigration function to include new default setting and added logic to hide the 'Hide' button on outgoing messages.

Rebase after landing D11602

This revision now requires changes to proceed.Jul 26 2022, 21:33

Rebased per review feedback

Get in the habit of keeping the dev console open during testing so you can catch these React errors.

web/cashtab/src/components/Home/Tx.js
766 ↗(On Diff #34547)

See other comment

786 ↗(On Diff #34547)

See other comment

812 ↗(On Diff #34547)

See other comment

831 ↗(On Diff #34547)

See other comment

857 ↗(On Diff #34547)

The <Link> component needs a to prop, and should not be used for cases like this where you are triggering some sort of functionality rather than navigating somewhere. Replace with a <button>, or ideally a custom styled component button.

image.png (589×561 px, 126 KB)

This revision now requires changes to proceed.Jul 28 2022, 16:03

Replaced Links with custom styled button component. Small styling changes have been made to accommodate the new button component. Updated snapshots.

bytesofman requested changes to this revision.Aug 2 2022, 17:34
bytesofman added inline comments.
web/cashtab/src/components/Configure/Configure.js
1882 ↗(On Diff #34556)

Not sure why the removal of <SettingsLinkCtn> is part of this diff...is this not solved by a rebase?

Was this container removed as part of this diff?

I am seeing it in the latest master. Why was this removed?

web/cashtab/src/components/Home/Tx.js
698 ↗(On Diff #34556)

Why null and not false?

769 ↗(On Diff #34556)

Above, you have the app displaying something {!cashtabSettings.showMessages &&

Here, you have the app displaying something {cashtabSettings.showMessages && (

It will always be one or the other. So, it is better practice to use conditional rendering like

`{cashtabSettings.showMessages ? <>the thing to show if it's true<> : <>the thing to show if it's false<>}

This revision now requires changes to proceed.Aug 2 2022, 17:34

Responding to review feedback

bytesofman requested changes to this revision.Aug 5 2022, 17:18
bytesofman added inline comments.
web/cashtab/src/components/Home/Tx.js
384 ↗(On Diff #34594)

This should be passed into the Tx component as a prop, because it does not differ for each tx.

  1. In Home.js, pass cashtabSettings as a prop to <TxHistory>
  2. In TxHistory.js, pass cashtabSettings as a prop to <Tx>
  3. Remove the WalletContext import in Tx.js and use the prop
This revision now requires changes to proceed.Aug 5 2022, 17:18

Responding to review feedback

bytesofman added inline comments.
web/cashtab/src/components/Home/Tx.js
729 ↗(On Diff #34646)

Seems like a confusing boolean. The boolean showMessages, if true, creates a condition where messages are hidden by default?

Am I reading this right?

773 ↗(On Diff #34646)

If you are saying "if this, display a bunch of components, otherwise display an empty string"

needs to be a good reason to just display the empty string. Otherwise, use

{data.opReturnMessage && !data.isEncryptedMessage && (

Maybe I misinterpreted the code when I earlier asked to use the ? : conditional style. It should always be used if there are 2 cases and you are displaying one thing or the other.

If you are displaying something or nothing, use &&

816 ↗(On Diff #34646)

see above

838 ↗(On Diff #34646)

The presence or absence of this <UnauthorizedDecryptionMessage> component seems to be the only difference in code between

{/*encrypted and wallet is authorized to view OP_RETURN Message*/}

and

{/*encrypted but wallet is not authorized to view OP_RETURN Message*/}

Yet all of this other surrounding stuff is duplicated.

Conditional rendering should be limited only to what is necessary. This also makes the code easier to read -- it's quite difficult to review this code and find out exactly what is changing depending on the conditions.

In this case, you can have conditional rendering inside this component, either showing

<p>
 {data.opReturnMessage}
</p>

or

<UnauthorizedDecryptionMessage>
{data.opReturnMessage}
</UnauthorizedDecryptionMessage>

depending on data.decryptionSuccess

Another, probably better approach would be to have a styled component <DecryptedMsg> that accepts authorized={data.decryptionSuccess} as a boolean prop. Then add a styled component rule to change the styling...conventional <p> if authorized={true} and <UnauthorizedDecryptionMessage> otherwise.

There are some other styled components in Cashtab that use this type of logic.

You should always be looking to write the absolute minimum code required to implement a change.

This revision now requires changes to proceed.Aug 15 2022, 23:06

Per review feedback:

Changed showMessage setting to hideMessagesFromUnknownSenders - I believe this orignally was a result of the toggle reading "Show Messages From Unknown Senders," until it was decided to turn the option off by default.

Removed unnecessary conditional rendering at ln 773 & 816.

Created styled component DecryptedMessage which accepts authorized={data.decryptionSuccess} as a boolean prop. If the msg cannot be decrypted, styling for UnauthorizedDecryptionMessage is used, otherwise, the regular <p> styling is used.

Unrelated to feedback:
Hide button no longer appears for encrypted messages as there is nothing to hide.

bytesofman added inline comments.
web/cashtab/src/components/Home/Tx.js
1007 ↗(On Diff #34710)

note that cashtabSettings is a boolean (false) when the app first loads, as loading them from localstorage is async.

Proptypes should reflect this

Again, need to always run with the dev console open and check for these types of msgs:

image.png (630×564 px, 140 KB)

web/cashtab/src/components/Home/TxHistory.js
42 ↗(On Diff #34710)

same as above

This revision now requires changes to proceed.Aug 18 2022, 21:25

Responding to review feedback

This revision is now accepted and ready to land.Aug 18 2022, 21:58