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

feat: account syncing various updates #28541

Merged
merged 26 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8a6691c
improv: use profile-sync-controller config for user storage paths + w…
mathieuartu Nov 19, 2024
5346252
Merge branch 'develop' into improv/account_syncing_various_updates
mathieuartu Nov 19, 2024
104219f
fix: yarn.lock
mathieuartu Nov 19, 2024
0d8ecbd
fix: regex escaping
mathieuartu Nov 19, 2024
c7dc7f7
Update LavaMoat policies
metamaskbot Nov 19, 2024
b5b2f33
fix: unit test
mathieuartu Nov 19, 2024
c6ca069
Merge branch 'develop' into improv/account_syncing_various_updates
mathieuartu Nov 19, 2024
b4eab67
fix: tests
mathieuartu Nov 19, 2024
52592ed
Merge branch 'improv/account_syncing_various_updates' of github.com:M…
mathieuartu Nov 19, 2024
8560b40
fix: bump profile-sync-controller and update code accordingly
mathieuartu Nov 19, 2024
33e992f
Merge branch 'develop' into improv/account_syncing_various_updates
mathieuartu Nov 19, 2024
61b6e70
fix: test helper
mathieuartu Nov 19, 2024
aa5992f
Merge branch 'improv/account_syncing_various_updates' of github.com:M…
mathieuartu Nov 19, 2024
4a1ddb2
fix: test
mathieuartu Nov 19, 2024
7896fc1
Merge branch 'develop' into improv/account_syncing_various_updates
mathieuartu Nov 19, 2024
af3ae62
fix: e2e & integration
mathieuartu Nov 19, 2024
44b2874
Merge branch 'improv/account_syncing_various_updates' of github.com:M…
mathieuartu Nov 19, 2024
d3081ac
fix: e2e test
mathieuartu Nov 19, 2024
32286e0
Merge branch 'develop' into improv/account_syncing_various_updates
mathieuartu Nov 20, 2024
97e2787
fix: yarn.lock
mathieuartu Nov 20, 2024
a743f3a
Merge branch 'improv/account_syncing_various_updates' of github.com:M…
mathieuartu Nov 20, 2024
d6c5aef
Merge branch 'develop' into improv/account_syncing_various_updates
mathieuartu Nov 20, 2024
0ed48a0
Merge branch 'develop' into improv/account_syncing_various_updates
mathieuartu Nov 20, 2024
570ee0a
feat: add analytics event
mathieuartu Nov 20, 2024
d3e1925
Merge branch 'improv/account_syncing_various_updates' of github.com:M…
mathieuartu Nov 20, 2024
c2f24fd
Merge branch 'develop' into improv/account_syncing_various_updates
mathieuartu Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ export const SENTRY_BACKGROUND_STATE = {
UserStorageController: {
isProfileSyncingEnabled: true,
isProfileSyncingUpdateLoading: false,
hasAccountSyncingSyncedAtLeastOnce: false,
isAccountSyncingReadyToBeDispatched: false,
Prithpal-Sooriya marked this conversation as resolved.
Show resolved Hide resolved
},
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
...MMI_SENTRY_BACKGROUND_STATE,
Expand Down
87 changes: 53 additions & 34 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,16 @@ export default class MetamaskController extends EventEmitter {
},
});
},
onAccountSyncErroneousSituation: (profileId, situationMessage) => {
this.metaMetricsController.trackEvent({
category: MetaMetricsEventCategory.ProfileSyncing,
event: MetaMetricsEventName.AccountsSyncErroneousSituation,
properties: {
profile_id: profileId,
situation_message: situationMessage,
},
});
},
},
},
env: {
Expand Down Expand Up @@ -1765,10 +1775,11 @@ export default class MetamaskController extends EventEmitter {
if (!prevCompletedOnboarding && currCompletedOnboarding) {
const { address } = this.accountsController.getSelectedAccount();

this._addAccountsWithBalance();
await this._addAccountsWithBalance();

this.postOnboardingInitialization();
this.triggerNetworkrequests();

// execute once the token detection on the post-onboarding
await this.tokenDetectionController.detectTokens({
selectedAddress: address,
Expand Down Expand Up @@ -4438,43 +4449,51 @@ export default class MetamaskController extends EventEmitter {
}

async _addAccountsWithBalance() {
// Scan accounts until we find an empty one
const chainId = getCurrentChainId({
metamask: this.networkController.state,
});
const ethQuery = new EthQuery(this.provider);
const accounts = await this.keyringController.getAccounts();
let address = accounts[accounts.length - 1];

for (let count = accounts.length; ; count++) {
const balance = await this.getBalance(address, ethQuery);

if (balance === '0x0') {
// This account has no balance, so check for tokens
await this.tokenDetectionController.detectTokens({
chainIds: [chainId],
selectedAddress: address,
});
try {
// Scan accounts until we find an empty one
const chainId = getCurrentChainId({
metamask: this.networkController.state,
});
const ethQuery = new EthQuery(this.provider);
const accounts = await this.keyringController.getAccounts();
let address = accounts[accounts.length - 1];

for (let count = accounts.length; ; count++) {
const balance = await this.getBalance(address, ethQuery);

const tokens =
this.tokensController.state.allTokens?.[chainId]?.[address];
const detectedTokens =
this.tokensController.state.allDetectedTokens?.[chainId]?.[address];

if (
(tokens?.length ?? 0) === 0 &&
(detectedTokens?.length ?? 0) === 0
) {
// This account has no balance or tokens
if (count !== 1) {
await this.removeAccount(address);
if (balance === '0x0') {
// This account has no balance, so check for tokens
await this.tokenDetectionController.detectTokens({
chainIds: [chainId],
selectedAddress: address,
});

const tokens =
this.tokensController.state.allTokens?.[chainId]?.[address];
const detectedTokens =
this.tokensController.state.allDetectedTokens?.[chainId]?.[address];

if (
(tokens?.length ?? 0) === 0 &&
(detectedTokens?.length ?? 0) === 0
) {
// This account has no balance or tokens
if (count !== 1) {
await this.removeAccount(address);
}
break;
Copy link
Contributor Author

@mathieuartu mathieuartu Nov 19, 2024

Choose a reason for hiding this comment

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

This whole function appears to be fully modified but it has just been wrapped in a try - catch - finally block

}
break;
}
}

// This account has assets, so check the next one
address = await this.keyringController.addNewAccount(count);
// This account has assets, so check the next one
address = await this.keyringController.addNewAccount(count);
}
} catch (e) {
log.warn(`Failed to add accounts with balance. Error: ${e}`);
} finally {
await this.userStorageController.setIsAccountSyncingReadyToBeDispatched(
true,
);
}
}

Expand Down
32 changes: 2 additions & 30 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1919,40 +1919,12 @@
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": true,
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true,
"@metamask/json-rpc-engine": true,
"@metamask/rpc-errors": true,
"@metamask/safe-event-emitter": true,
"uuid": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true,
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": true,
"@metamask/safe-event-emitter": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": true,
"@metamask/rpc-errors>fast-safe-stringify": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/network-controller>@metamask/json-rpc-engine": {
"packages": {
"@metamask/network-controller>@metamask/rpc-errors": true,
Expand Down
32 changes: 2 additions & 30 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1919,40 +1919,12 @@
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": true,
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true,
"@metamask/json-rpc-engine": true,
"@metamask/rpc-errors": true,
"@metamask/safe-event-emitter": true,
"uuid": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true,
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": true,
"@metamask/safe-event-emitter": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": true,
"@metamask/rpc-errors>fast-safe-stringify": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/network-controller>@metamask/json-rpc-engine": {
"packages": {
"@metamask/network-controller>@metamask/rpc-errors": true,
Expand Down
32 changes: 2 additions & 30 deletions lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1919,40 +1919,12 @@
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": true,
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true,
"@metamask/json-rpc-engine": true,
"@metamask/rpc-errors": true,
"@metamask/safe-event-emitter": true,
"uuid": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true,
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": true,
"@metamask/safe-event-emitter": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": true,
"@metamask/rpc-errors>fast-safe-stringify": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/network-controller>@metamask/json-rpc-engine": {
"packages": {
"@metamask/network-controller>@metamask/rpc-errors": true,
Expand Down
32 changes: 2 additions & 30 deletions lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2011,40 +2011,12 @@
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": true,
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true,
"@metamask/json-rpc-engine": true,
"@metamask/rpc-errors": true,
"@metamask/safe-event-emitter": true,
"uuid": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/json-rpc-engine": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": true,
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": true,
"@metamask/safe-event-emitter": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/rpc-errors": {
"packages": {
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": true,
"@metamask/rpc-errors>fast-safe-stringify": true
}
},
"@metamask/network-controller>@metamask/eth-json-rpc-provider>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/network-controller>@metamask/json-rpc-engine": {
"packages": {
"@metamask/network-controller>@metamask/rpc-errors": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
"@metamask/post-message-stream": "^8.0.0",
"@metamask/ppom-validator": "0.35.1",
"@metamask/preinstalled-example-snap": "^0.2.0",
"@metamask/profile-sync-controller": "^0.9.7",
"@metamask/profile-sync-controller": "^1.0.2",
"@metamask/providers": "^14.0.2",
"@metamask/queued-request-controller": "^7.0.1",
"@metamask/rate-limit-controller": "^6.0.0",
Expand Down
1 change: 1 addition & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ export enum MetaMetricsEventName {
AccountRenamed = 'Account Renamed',
AccountsSyncAdded = 'Accounts Sync Added',
AccountsSyncNameUpdated = 'Accounts Sync Name Updated',
AccountsSyncErroneousSituation = 'Accounts Sync Erroneous Situation',
ActivityDetailsOpened = 'Activity Details Opened',
ActivityDetailsClosed = 'Activity Details Closed',
AnalyticsPreferenceSelected = 'Analytics Preference Selected',
Expand Down
Loading