Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Implemented notification for user to backup Brave wallet #13504

Merged
merged 1 commit into from
Apr 26, 2018
Merged

Implemented notification for user to backup Brave wallet #13504

merged 1 commit into from
Apr 26, 2018

Conversation

jasonrsadler
Copy link
Contributor

@jasonrsadler jasonrsadler commented Mar 19, 2018

Resolves #13425
Unblocks #4847

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed. (Ask a Brave employee to help if you cannot access this document.)

Test Plan:

FOR QA ONLY:

  • Start Brave in staging environment and short interval timers from a console:
    LEDGER_ENVIRONMENT=staging LEDGER_NOTIFICATION=true npm start
  • Keep Note of counter on console
  • Enable Payments
  • Add funds to wallet
  • Counter will be count up to notification show (in ms)
  • After 2 minutes, notification will display. Dismiss notification
  • After additional 5 minutes (from first notification show), notification will display. Dismiss notification
  • Each additional 1 minutes after 2nd notification is shown, notification will display.
  • Notification will continue to be displayed 1 once a minute until a backup or recovery action occurs or notifications are opted out.
  • Notifications will not display if a backup or recovery action has occurred.

IN PRODUCTION:
Notifications will be displayed if the user has not backed up their keys and has not opted out:
after 7 days,
after another 14 days,
once a month thereafter

If user turns off ledger notifications or backs up their wallet (or recovers a wallet) then this notification will not show.

Backup or Recovery action consists of:
Preferences->Payments->Advanced Settings

  1. Click 'Backup Your Wallet'. Click 'Copy To Clipboard button'
  2. Click 'Backup Your Wallet'. Click 'Print Key'
  3. Click 'Backup Your Wallet'. Click 'Save Recovery File...' and save the file to disk
  4. Click 'Recover Your Wallet'. Enter a valid recovery key and click 'Recover'
  5. Click 'Recover Your Wallet'. Click 'Import Recovery Key'. Import a valid recovery file

unittest -- --grep="showBackupKeys" for simulated

Reviewer Checklist:

  • Request a security/privacy review as needed if one was not already requested.

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

@codecov-io
Copy link

codecov-io commented Mar 19, 2018

Codecov Report

Merging #13504 into master will increase coverage by 0.02%.
The diff coverage is 77.06%.

@@            Coverage Diff             @@
##           master   #13504      +/-   ##
==========================================
+ Coverage   56.54%   56.57%   +0.02%     
==========================================
  Files         283      284       +1     
  Lines       29036    29100      +64     
  Branches     4824     4845      +21     
==========================================
+ Hits        16419    16463      +44     
- Misses      12617    12637      +20
Flag Coverage Δ
#unittest 56.57% <77.06%> (+0.02%) ⬆️
Impacted Files Coverage Δ
app/sessionStore.js 85.71% <ø> (ø) ⬆️
js/constants/appConstants.js 100% <ø> (ø) ⬆️
app/common/lib/ledgerUtil.js 95.7% <ø> (ø) ⬆️
js/actions/appActions.js 18.83% <0%> (-0.11%) ⬇️
app/locale.js 35.77% <100%> (ø) ⬆️
app/common/state/aboutPreferencesState.js 100% <100%> (ø)
app/browser/reducers/ledgerReducer.js 44.7% <50%> (-0.3%) ⬇️
...rer/components/preferences/payment/ledgerBackup.js 36.58% <50%> (-0.26%) ⬇️
app/browser/api/ledger.js 63.15% <55.55%> (-0.15%) ⬇️
app/browser/api/ledgerNotifications.js 72.33% <70.37%> (+2.45%) ⬆️
... and 9 more

@@ -1063,6 +1063,9 @@ const backupKeys = (state, backupAction) => {

if (backupAction === 'print') {
tabs.create({url: appUrlUtil.aboutUrls.get('about:printkeys')})

// we do not check whether the user actually printed the backup word list
ledgerState.setBackupStatus(state, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to assign this call to the state, so that we actually save this change:

ledgerState.setBackupStatus(state, true) -> state = ledgerState.setBackupStatus(state, true)

@@ -1079,8 +1082,10 @@ const backupKeys = (state, backupAction) => {
if (file) {
try {
fs.writeFileSync(file, message)
ledgerState.setBackupStatus(state, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

} catch (e) {
console.error('Problem saving backup keys')
ledgerState.setBackupStatus(state, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@jasonrsadler
Copy link
Contributor Author

@NejcZdovc , how can I trigger notifications in development?

@NejcZdovc
Copy link
Contributor

@jasonrsadler which notifications?

@NejcZdovc NejcZdovc self-requested a review April 4, 2018 10:44
@NejcZdovc
Copy link
Contributor

NejcZdovc commented Apr 4, 2018

Oh I know which one. You can do it like this

appActions.createTabRequested({
  url: 'about:preferences#payments?ledgerBackupOverlayVisible',
  windowId: xx
})

Where xx is current window ID

@jasonrsadler
Copy link
Contributor Author

Yep. Got that. I meant the notification bar that comes down at the top of the webview?

@NejcZdovc
Copy link
Contributor

@jasonrsadler
Copy link
Contributor Author

Got it!

Thanks @NejcZdovc

@@ -230,7 +230,7 @@ const showEnabledNotifications = (state) => {
showReviewPublishers(now + ledgerUtil.milliseconds.day)
}
} else if (now - bootStamp > 7 * ledgerUtil.milliseconds.day) {
if (noBackupKeys(state) && shouldShowNotificationBackupKeys()) {
if (noBackupKeys(state) && shouldShowNotificationBackupKeys() && hasFunds(state)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrose17, during our coding session, we created hasFunds but the linter picked it up as unused. My assumption was the notification should be shown based on the original criteria and also (added above) if the user has actual funds in the wallet. Can you confirm this? Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an interesting question: my thinking is that we don't need hasFunds, it's a good idea for folks to keep a balance, regardless. wdyt?

@jasonrsadler jasonrsadler changed the title WIP -- issue #13425 -- TODO: appAction to bring up advanced settings Implemented notification for user to backup Brave wallet Apr 11, 2018
mrose17
mrose17 previously approved these changes Apr 11, 2018
Copy link
Member

@mrose17 mrose17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for including the security review issue. looks good to me. let's see what the security folks say.

@@ -230,7 +230,7 @@ const showEnabledNotifications = (state) => {
showReviewPublishers(now + ledgerUtil.milliseconds.day)
}
} else if (now - bootStamp > 7 * ledgerUtil.milliseconds.day) {
if (noBackupKeys(state) && shouldShowNotificationBackupKeys()) {
if (noBackupKeys(state) && shouldShowNotificationBackupKeys() && hasFunds(state)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an interesting question: my thinking is that we don't need hasFunds, it's a good idea for folks to keep a balance, regardless. wdyt?

@jasonrsadler
Copy link
Contributor Author

jasonrsadler commented Apr 11, 2018

"this is an interesting question: my thinking is that we don't need hasFunds, it's a good idea for folks to keep a balance, regardless. wdyt?"

I could go either way. My initial thinking:
The user has downloaded and is trying the browser out. 7 days goes by and they've played around with it. Enabled payments and all that good stuff. But they haven't added any funds. They get a notification to backup their wallet with no funds in it and they say "Sure, I'll do it. Just don't remind me again. There's really nothing of value (yet) to backup". So later, they decide they want to add funds to go out and completely forgot about backing up the wallet because it just didn't seem that important at the time. Now that they have funds, they may take it more seriously if they get the notification only after they've put funds into it.

@mrose17
Copy link
Member

mrose17 commented Apr 11, 2018

@jasonrsadler - agreed. why not DM mandar and get his take on it?

@jasonrsadler
Copy link
Contributor Author

jasonrsadler commented Apr 11, 2018

Per @mandar-brave - if the user has never added funds then don't show. Once the user has funds or has a zero balance but has added funds in the past then show.
Also suggested frequency from payments enable and user clicking to remind later: 7 days, 14 days, then once a month from that point until backup or opt out.

The question from the linked issue:
For existing users, since we have no way of knowing whether a backup has occurred or not, show it anyway and allow for opt out.

@mrose17
Copy link
Member

mrose17 commented Apr 11, 2018

great! please make it so!

@diracdeltas
Copy link
Member

can we make sure brave-intl/bat-client#52 gets merged before this so that the backup notification shows the new code words? otherwise users may see some offensive words.

@jasonrsadler
Copy link
Contributor Author

jasonrsadler commented Apr 11, 2018

@jasonrsadler
Copy link
Contributor Author

@NejcZdovc, is ledger.js -> onWalletProperties a good place to set a flag to tell us if the user has ever funded the wallet?

'payments.notification-backup-keys-count': 0, // number of times user has been notified to backup wallet
// the intervals in days that the user should be reminded to backup wallet
// if an out of bounds index is selected, it should default to monthly
'payments.notification-backup-keys-interval': [7, 14],
Copy link
Member

@diracdeltas diracdeltas Apr 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the settings / defaultSettings object is supposed to only be used for settings that are exposed in about:preferences such that the user can modify them.

can we avoid adding more non-user-exposed payments flags/timestamps to settings? unless i'm misunderstanding why they were added here in the first place.

seems like they should go in appState.ledger.about or appState.ledger.info (https://github.com/brave/browser-laptop/pull/13504/files#diff-b4e400e260f324745d12616a8c9c1fc6R185)

Copy link
Contributor Author

@jasonrsadler jasonrsadler Apr 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered about that myself. @mrose17 or @NejcZdovc would have to reply on that but I can move them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, let's move this into the state

@jasonrsadler jasonrsadler dismissed NejcZdovc’s stale review April 13, 2018 17:51

Changes were made

@jasonrsadler
Copy link
Contributor Author

@diracdeltas, would you give this another look?

state = aboutPreferencesState.setPreferencesProp(state, 'backupNotifyTimestamp', nextTime)
module.exports.showBackupKeys(nextTime)
}
if (process.env.LEDGER_NOTIFICATION) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.env.LEDGER_NOTIFICATION -> process.env.LEDGER_VERBOSE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you want to put this under verbose? It would be nice if QA saw just the time passed rather than filter through all the other messages. Also, when run in the future, you'll get the time thrown out to the console every 5 seconds.

Copy link
Contributor

@NejcZdovc NejcZdovc Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good point. Let's keep it like it is now

@@ -63,9 +72,12 @@ const init = () => {
}

const onInterval = (state) => {
if (process.env.LEDGER_NOTIFICATION) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.env.LEDGER_NOTIFICATION -> process.env.LEDGER_VERBOSE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@@ -1967,6 +1967,13 @@ const appActions = {
duration,
revisited
})
},

onLedgerBackupSuccess: function (success) {
Copy link
Contributor

@NejcZdovc NejcZdovc Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to pass variable in, where in reducer we just set true and not use this variable?

@@ -360,6 +360,11 @@ const ledgerState = {
return state.setIn(['about', 'preferences', 'updatedStamp'], date)
},

getRecoveryStatus: (state) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

@NejcZdovc NejcZdovc requested review from ryanml and NejcZdovc April 25, 2018 05:29
@bradleyrichter
Copy link
Contributor

@jasonrsadler WDYT?

[Turn Off Notifications] [Later] [Back Up Now]

@jasonrsadler
Copy link
Contributor Author

@bradleyrichter I'm good with that. Thanks.

@jasonrsadler
Copy link
Contributor Author

screen shot 2018-04-25 at 6 11 40 pm


class LedgerBackupContent extends ImmutableComponent {
copyToClipboard (text) {
aboutActions.setClipboard(text)
appActions.onLedgerBackupSuccess(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonrsadler this is the only thing that I found, so I will just fix it and then I will merge this PR

WIP -- ensure backup status is assigned to the state

WIP -- merging sync

Added appAction to show backup keys

Updated notifications text

Added condition for backup notification only if the user has funds

WIP -- Notification tests

WIP -- notification tests wip

WIP -- wip on tests

WIP -- added constants to appConfig and completed unittests

Fixed linting

Removed notification trigger from debug menu

WIP -- Updating wallet backup notification per criteria

Added tests. Removed redundant function.

spacing clean up

Moved payments settings from defaultSettings to payments field

Created aboutPreferencesState and moved ledger functions.

Added Preferences Prop helpers to aboutPreferencesState

Moved configs to state. bumped bat-client version

merge fix

Updated state.md

Remove redundant function and usage

Removed notification interval from state.

minor code corrections

lint

Updated for null checks and updated tests

Modifications for testing

Removed unused methods

Fixed spacing and reverted launch.json. Implemented process var for test

Updating for test plan. Corrected backup and recovery timestamp writes

Set clipboard action backup to set backup flag

Updated to use updatedStamp vice recoverySucceeded

lint

Updated tests to reflect state passing

Updated text for notification

Updated QA interval

lint

Adding context menu option to bookmark/history entries to add their respective sites to the ledger

Changes per CR, hiding context menu item when not applicable

Exposing addSiteVisit and shouldTrackTab for unit testing, add initial manual addition unit tests

Adding more tests for addSiteVisit/addNewLocation under manual addition

Updated text for dismiss button on notification
Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ code looks good and works great. Thank you

@NejcZdovc NejcZdovc merged commit a2256bc into brave:master Apr 26, 2018
NejcZdovc added a commit that referenced this pull request Apr 26, 2018
Implemented notification for user to backup Brave wallet
@NejcZdovc NejcZdovc added this to the 0.22.x Release 3 (Beta channel) milestone Apr 26, 2018
NejcZdovc added a commit that referenced this pull request Apr 26, 2018
Implemented notification for user to backup Brave wallet
@NejcZdovc
Copy link
Contributor

master a2256bc
0.23 4942965
0.22 99711a9

@jasonrsadler jasonrsadler deleted the gen-backup-remind branch April 26, 2018 10:08
@bsclifton
Copy link
Member

Will work on reverting this- we decided to not include this in the 0.22.x-release3 build

@bsclifton bsclifton removed this from the 0.22.x Release 3 (Beta channel) milestone May 15, 2018
bsclifton added a commit that referenced this pull request May 15, 2018
bsclifton added a commit that referenced this pull request May 15, 2018
@bsclifton
Copy link
Member

Reverted:
0.22.x-release3 b74e887
0.23.x f495fd4
master - will need to PR

@bsclifton bsclifton added this to the 0.22.x Release 3 (Beta channel) milestone May 15, 2018
bsclifton added a commit that referenced this pull request May 15, 2018
@bsclifton
Copy link
Member

Reverted the reverts after discussion and closed the PR to master which had the revert

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants