Skip to content
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

Merged
merged 12 commits into from
Aug 9, 2022
Merged

3box Replacement #15243

merged 12 commits into from
Aug 9, 2022

Conversation

segun
Copy link
Contributor

@segun segun commented Jul 14, 2022

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

Screenshot 2022-07-14 at 22 50 05

Screenshot 2022-07-14 at 22 49 42

Screenshot 2022-07-14 at 22 46 48

Pre-Merge Checklist

  • PR template is filled out
  • IF this PR fixes a bug, a test that would have caught the bug has been added
  • PR is linked to the appropriate GitHub issue
  • PR has been added to the appropriate release Milestone

+ If there are functional changes:

  • Manual testing complete & passed
  • "Extension QA Board" label has been applied

@segun segun added MV3 MV3-non_perf MV3 issues not related to performance. labels Jul 14, 2022
@segun segun requested a review from a team as a code owner July 14, 2022 19:10
@segun segun self-assigned this Jul 14, 2022
@segun segun requested a review from brad-decker July 14, 2022 19:10
@github-actions
Copy link
Contributor

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.

@metamaskbot
Copy link
Collaborator

Builds ready [58d1022]
Page Load Metrics (1870 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint892751253818
domContentLoaded16792268184113163
load16822291187013665
domInteractive16792268184113163

highlights:

storybook

@hilvmason hilvmason added PR - P1 identifies PRs deemed priority for Extension team and removed MV3 labels Jul 15, 2022
Copy link
Contributor

@darkwing darkwing left a 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.logs, just a few changes. Nice work!

async restoreUserData(jsonString) {
console.log('jsonString: ', jsonString);
const { preferences, addressBook } = JSON.parse(jsonString);
preferences && this.preferencesController.store.updateState(preferences);
Copy link
Contributor

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');
});
});
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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>
)}
Copy link
Contributor

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()}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

@hilvmason hilvmason removed the MV3-non_perf MV3 issues not related to performance. label Jul 18, 2022
"message": "Backup your data"
},
"backupUserDataDescription": {
"message": "Your data contains preferences and account addresses"
Copy link
Contributor

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.

"message": "Restore user data"
},
"restoreUserDataDescription": {
"message": "Restore user data from a previously backed up file"
Copy link
Contributor

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.

}

async restoreUserData(jsonString) {
console.log('jsonString: ', jsonString);
Copy link
Contributor

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.


const date = new Date();

const pz = (num) => prependZero(num, 2);
Copy link
Contributor

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);
Copy link
Contributor

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.

@NiranjanaBinoy
Copy link
Contributor

The entries for back up user data and restore user data need to be added to SETTINGS_CONSTANTS to enable the settings search.


return (
<div
ref={this.settingsRefs[0]}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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]}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

@jpuri
Copy link
Contributor

jpuri commented Jul 18, 2022

The approach looks good 👍
But I agree with most of the improvement suggestion by @NiranjanaBinoy and @darkwing

@segun segun requested review from darkwing and NiranjanaBinoy July 18, 2022 20:21
@metamaskbot
Copy link
Collaborator

Builds ready [4e0c64d]
Page Load Metrics (1813 ± 47 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint911801242010
domContentLoaded1647200217999445
load1647200218139847
domInteractive1647200217999445

highlights:

storybook


const downloadsFolder = `${process.cwd()}/test-artifacts/downloads`;

const createDownloadFolder = async () => {
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Member

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

@segun segun force-pushed the dev-olu-mv3-3box-replacement branch from 4e0c64d to 08c590c Compare July 19, 2022 19:31
@segun segun requested review from danjm and PeterYinusa July 19, 2022 19:31
@segun segun added the MV3 label Jul 20, 2022
@darkwing
Copy link
Contributor

darkwing commented Aug 1, 2022

I think the ActionableMessage of type success would work best for the successful restore message:
AM3box

@metamaskbot
Copy link
Collaborator

Builds ready [914f517]
Page Load Metrics (1819 ± 73 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint952861305225
domContentLoaded16612317181315173
load16612317181915373
domInteractive16612317181315173

highlights:

storybook


if (preferences && addressBook) {
this._trackMetaMetricsEvent({
event: 'User Restored Data From Backup',
Copy link
Contributor

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>
Copy link
Contributor

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

@segun segun force-pushed the dev-olu-mv3-3box-replacement branch from 968b34e to 8b99cb1 Compare August 4, 2022 18:21
segun added 11 commits August 5, 2022 20:37
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]>
rename event as per product suggestion.

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]>
@segun segun force-pushed the dev-olu-mv3-3box-replacement branch from 8b99cb1 to f50126f Compare August 5, 2022 16:39
@hilvmason hilvmason removed the MV3 label Aug 9, 2022
@PeterYinusa
Copy link
Contributor

@segun The name of the downloaded file needs to be updated in the e2e tests to be aligned with the changes here

Signed-off-by: Akintayo A. Olusegun <[email protected]>
@metamaskbot
Copy link
Collaborator

Builds ready [73bdbdd]
Page Load Metrics (1697 ± 34 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint891727194352169
domContentLoaded1605191816886732
load1605193816977134
domInteractive1604191816886732

highlights:

storybook

@segun segun merged commit 4f34e72 into develop Aug 9, 2022
@segun segun deleted the dev-olu-mv3-3box-replacement branch August 9, 2022 18:36
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-metrics PR - P1 identifies PRs deemed priority for Extension team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove 3box