-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3box Replacement #15243
3box Replacement #15243
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from needing to remove the console.log
s, just a few changes. Nice work!
app/scripts/controllers/backup.js
Outdated
async restoreUserData(jsonString) { | ||
console.log('jsonString: ', jsonString); | ||
const { preferences, addressBook } = JSON.parse(jsonString); | ||
preferences && this.preferencesController.store.updateState(preferences); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit but I think the following looks a little bit cleaner:
if (preferences) {
this.preferencesController....
}
const selectedAddress = backupController.preferencesController.getSelectedAddress(); | ||
assert.equal(selectedAddress, '0x01'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add restoreUserData
and backupUserData
tests to ensure that we get expected outcomes in each case, since those are the bulk of the work with this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi David,
I can't seem to find a way to mock window functions in sinon for backup so I spoke with @PeterYinusa and we agreed to do an e2e test instead.
I've however added a unit test for restore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The e2e suggestion was made to ensure we have some coverage, but is not a replacement for a unit test.
<span className="settings-page__error-text"> | ||
{t('restoreFailed')} | ||
</span> | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit cleaner:
{showResultMessage && restoreSuccessful && (
<span className="settings-page__content-description">
{t('restoreSuccessful')}
</span>
)}
{showResultMessage && !restoreSuccessful && (
<span className="settings-page__error-text">
{t('restoreFailed')}
</span>
)}
{showResultMessage && (
<span className={classnames({
'settings-page__content-description': restoreSuccessful,
'settings-page__error-text': !restoreSuccessful,
})}>
{restoreSuccessful ? t('restoreSuccessful') : t('restoreFailed')}
</span>
)}
@@ -724,6 +833,8 @@ export default class AdvancedTab extends PureComponent { | |||
return ( | |||
<div className="settings-page__body"> | |||
{warning ? <div className="settings-tab__error">{warning}</div> : null} | |||
{this.renderUserDataBackup()} | |||
{this.renderRestoreUserData()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure whether renderUserDataBackup
and renderRestoreUserData
should be the first entry on the Advanced Tab since the 3box toggle is the 4th entry from the end. Does it make sense to move them closer to the 3box toggle itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danjm suggested we put it at the top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can ignore my previous suggestion and follow @NiranjanaBinoy's suggestion here
app/_locales/en/messages.json
Outdated
"message": "Backup your data" | ||
}, | ||
"backupUserDataDescription": { | ||
"message": "Your data contains preferences and account addresses" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think something like this might be more transparent for the user?
You can backup user settings containing preferences and account addresses into a JSON file.
app/_locales/en/messages.json
Outdated
"message": "Restore user data" | ||
}, | ||
"restoreUserDataDescription": { | ||
"message": "Restore user data from a previously backed up file" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update this message to You can restore user settings containing preferences and account addresses from a previously backed up JSON file.
or something similar.
app/scripts/controllers/backup.js
Outdated
} | ||
|
||
async restoreUserData(jsonString) { | ||
console.log('jsonString: ', jsonString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log
needs to be removed.
app/scripts/controllers/backup.js
Outdated
|
||
const date = new Date(); | ||
|
||
const pz = (num) => prependZero(num, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it wouldn't make much difference, but can we update the constant name to prefixZero
or something similar instead of pz
.
@@ -51,6 +51,7 @@ export default class ComposableObservableStore extends ObservableStore { | |||
updateStructure(config) { | |||
this.config = config; | |||
this.removeAllListeners(); | |||
console.log('Config: ', config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log
needs to be removed.
The entries for |
|
||
return ( | ||
<div | ||
ref={this.settingsRefs[0]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref={this.settingsRefs[0]} | |
ref={this.settingsRefs[15]} |
The index added currently is a duplicate value as 0 is used for the state log entry
const { t } = this.context; | ||
return ( | ||
<div | ||
ref={this.settingsRefs[0]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref={this.settingsRefs[0]} | |
ref={this.settingsRefs[14]} |
The index added currently is a duplicate value as 0 is used for the state log entry
The approach looks good 👍 |
Builds ready [4e0c64d]Page Load Metrics (1813 ± 47 ms)
highlights:storybook
|
test/e2e/tests/backup.spec.js
Outdated
|
||
const downloadsFolder = `${process.cwd()}/test-artifacts/downloads`; | ||
|
||
const createDownloadFolder = async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reuse this method as we now have this in both the state-logs.spec.js and now backup.spec.js
date.getMinutes(), | ||
)}_${prefixZero(date.getDay())}.json`; | ||
|
||
exportAsFile(userDataFileName, result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move the exportAsFile
to a utility file in the shared/
directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, this could be called from the UI. This utility uses the DOM, so it won't work in the MV3 service worker anyway
4e0c64d
to
08c590c
Compare
Builds ready [914f517]
Page Load Metrics (1819 ± 73 ms)
highlights:storybook
|
app/scripts/controllers/backup.js
Outdated
|
||
if (preferences && addressBook) { | ||
this._trackMetaMetricsEvent({ | ||
event: 'User Restored Data From Backup', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change this to User Data Imported
so it pairs well with the export event
// })} | ||
// > | ||
// {restoreSuccessful ? t('restoreSuccessful') : t('restoreFailed')} | ||
// </span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this needs to be removed
968b34e
to
8b99cb1
Compare
Signed-off-by: Akintayo A. Olusegun <[email protected]> Tests for prependZero (utils.js) Signed-off-by: Akintayo A. Olusegun <[email protected]> Fix advancedtab test Signed-off-by: Akintayo A. Olusegun <[email protected]> backup controller tests Signed-off-by: Akintayo A. Olusegun <[email protected]> Lint fixes Signed-off-by: Akintayo A. Olusegun <[email protected]> Backup controller don't have a store. Signed-off-by: Akintayo A. Olusegun <[email protected]> Restore from file. Signed-off-by: Akintayo A. Olusegun <[email protected]> Advanced Tab tests Signed-off-by: Akintayo A. Olusegun <[email protected]> Lint fix Signed-off-by: Akintayo A. Olusegun <[email protected]> e2e tests for backup unit tests for restore. Signed-off-by: Akintayo A. Olusegun <[email protected]> Fix comments on PR. Signed-off-by: Akintayo A. Olusegun <[email protected]> restore style Signed-off-by: Akintayo A. Olusegun <[email protected]> Lint fixes Signed-off-by: Akintayo A. Olusegun <[email protected]> We should move the exportAsFile to a utility file in the shared/ directory Signed-off-by: Akintayo A. Olusegun <[email protected]> Move export as file to shared folder Signed-off-by: Akintayo A. Olusegun <[email protected]> Refactor create download folder methods Signed-off-by: Akintayo A. Olusegun <[email protected]> Lint fixes. Signed-off-by: Akintayo A. Olusegun <[email protected]> Move the backup/restore buttons closer to 3box Signed-off-by: Akintayo A. Olusegun <[email protected]> Change descriptions Add to search Signed-off-by: Akintayo A. Olusegun <[email protected]> refactor code to use if instead of && Signed-off-by: Akintayo A. Olusegun <[email protected]> Lint fixes Signed-off-by: Akintayo A. Olusegun <[email protected]> Restore button should change cursor to pointer. Signed-off-by: Akintayo A. Olusegun <[email protected]> Fix restore not uploading same file twice. Signed-off-by: Akintayo A. Olusegun <[email protected]> Do not backup these items in preferences identities lostIdentities selectedAddress Signed-off-by: Akintayo A. Olusegun <[email protected]> lint fixes. Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
rename event as per product suggestion. Signed-off-by: Akintayo A. Olusegun <[email protected]>
message Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
8b99cb1
to
f50126f
Compare
Signed-off-by: Akintayo A. Olusegun <[email protected]>
Builds ready [73bdbdd]
Page Load Metrics (1697 ± 34 ms)
highlights:storybook
|
Explanation
Provides a button on top of the Advanced Settings for users to backup and restore the same settings that used to be backed up on 3box.
This is because 3box is being removed from the extension #14571
More Information
Fixes #14888
Screenshots/Screencaps
Pre-Merge Checklist
+ If there are functional changes: