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

fix: accounts not syncing between devices bug #11801

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Jonathansoufer
Copy link
Contributor

@Jonathansoufer Jonathansoufer commented Oct 15, 2024

Description

This PR fixed an issue preventing mobile accounts to sync its states (enable/disable) with other clients (platform and extension). NOTIFY-1218

Related issues

Fixes:

Manual testing steps

  1. Import the same SRP on Mobile
  2. Make sure all accounts are visible on both devices/platforms. If not, import all accounts
  3. Switch Notifications state in account "A" on extension.
  4. Go to Notifications Settings on mobile and see if the state is propagated.
  5. Switch back on mobile
  6. Go to extension and see if state is propagated.

Screenshots/Recordings

Before

After

account-sync-fix.mov

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@Jonathansoufer Jonathansoufer added needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) team-mobile-platform team-notifications Notifications team labels Oct 15, 2024
@Jonathansoufer Jonathansoufer self-assigned this Oct 15, 2024
@Jonathansoufer Jonathansoufer requested review from a team as code owners October 15, 2024 17:42
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.

@github-actions github-actions bot added the team-snaps-platform Snaps Platform team label Oct 15, 2024
@Jonathansoufer Jonathansoufer added the Run Smoke E2E Triggers smoke e2e on Bitrise label Oct 15, 2024
Copy link
Contributor

github-actions bot commented Oct 15, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 2f35518
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/dc24a3c7-b7c3-42d3-b268-deea8a0e379d

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@Jonathansoufer Jonathansoufer added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Oct 15, 2024
@Jonathansoufer Jonathansoufer added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 15, 2024
Copy link
Contributor

github-actions bot commented Oct 15, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 9598c7e
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/666f3359-603e-478f-98a6-a7b78908840b

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Copy link

sonarcloud bot commented Oct 15, 2024

}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const memoAccounts = useMemo(() => accounts.map((account) => account.address),[accounts]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Question around this usage of useMemo, (and the useCallback in this file).

I know you didn't implement it but is it needed?

If we're not having performance issues around these functions then it can be removed. We have a lot of useMemo and useCallback usage in the app and we're allocating device memory to each one. Removing any unnecessary usage would be great.

Comment on lines -150 to +109
useEffect(() => {
const updateAndfetchAccountSettings = useCallback(async () => {
try {
const memoAccounts: string[] = memoizedAccounts;
update(memoAccounts);
} catch {
setError('Failed to get account settings');
} finally {
setLoading(false);
Engine.context.NotificationServicesController.checkAccountsPresence(
memoAccounts,
).then((result) => {
dispatch(updateAccountState(result));
return result;
});
} catch (err) {
Logger.log(err, 'Failed to get account settings');
}
}, [memoizedAccounts, update]);
}, [dispatch, memoAccounts]);

return {
data,
initialLoading: loading,
error,
accountsBeingUpdated,
update,
};
return { updateAndfetchAccountSettings };
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. Do we need to wrap this in a useCallback?

@Daniel-Cross
Copy link
Contributor

Looks good @Jonathansoufer, just a couple of comments.

Also, what's the purpose of the skip-sonar-cloud label? I see you're hitting the quality gate threshold, I would prefer it if we ran as many checks as possible against all changes.

// refetch the account settings from the controller
await updateAndfetchAccountSettings();
// refetch the notifications from the controller
await refetch();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to execute this sequentially, or can it be done in parallel using Promise.all? Doing it in parallel could potentially improve performance.

return result;
});
} catch (err) {
Logger.log(err, 'Failed to get account settings');
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed the use of then() alongside a try-catch block for handling the asynchronous function. To maintain consistency and clarity, it might be a good idea to choose between using one of the following approaches:
Using then() and catch(): This will maintain the current promise-chaining style:

Engine.context.NotificationServicesController.checkAccountsPresence(memoAccounts)
  .then((result) => {
    dispatch(updateAccountState(result));
    return result;
  })
  .catch((err) => {
    Logger.log('Failed to get account settings:', err);
  });

Using async/await with try-catch: This will make the asynchronous handling more streamlined:

try {
  const result = await Engine.context.NotificationServicesController.checkAccountsPresence(memoAccounts);
  dispatch(updateAccountState(result));
  return result;
} catch (err) {
  Logger.log('Failed to get account settings:', err);
}

Both methods are valid, but it's important to stick to one approach for consistency

@salimtb
Copy link
Contributor

salimtb commented Oct 16, 2024

great work @Jonathansoufer , i just left two small comments regarding consistency and perf improvement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) Run Smoke E2E Triggers smoke e2e on Bitrise skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-mobile-platform team-notifications Notifications team team-snaps-platform Snaps Platform team
Projects
Status: Needs dev review
Development

Successfully merging this pull request may close these issues.

5 participants