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

Upgrade to new notifications endpoint #6190

Merged
merged 42 commits into from
Oct 17, 2024
Merged

Upgrade to new notifications endpoint #6190

merged 42 commits into from
Oct 17, 2024

Conversation

jinchung
Copy link
Member

@jinchung jinchung commented Oct 10, 2024

Fixes APP-887

What changed (plus any additional context for devs)

  • Adds support for the new notifications endpoint (REST PUT) which adds support for select L2 notifications
  • Removes the old explorer redux (which used websockets) which is no longer needed
  • Moves support for global notification topics (e.g, points) to the new endpoint as well
  • Migrates existing users to the new endpoint

Please note: APP-985 is still a known issue

Screen recordings / screenshots

RPReplay_Final1728594734.MP4

What to test

https://www.notion.so/rainbowdotme/Notifications-upgrade-642eae49b0eb45b2a65cd89c367fed00#27a7325fd6894d9d9de645300fcdae2f

@jinchung jinchung changed the title @jin/notifs 5 global Upgrade to new notifications endpoint Oct 10, 2024
Copy link

linear bot commented Oct 10, 2024

@jinchung jinchung requested review from walmat and derHowie October 10, 2024 20:20
@jinchung jinchung marked this pull request as ready for review October 10, 2024 20:20
@@ -48,7 +48,6 @@ export { default as useGas } from './useGas';
export { default as useHeight } from './useHeight';
export { default as useHideSplashScreen } from './useHideSplashScreen';
export { default as useImageMetadata } from './useImageMetadata';
export { default as useInitializeAccountData } from './useInitializeAccountData';
Copy link
Member Author

Choose a reason for hiding this comment

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

related to removal of redux explorer

if (walletSettings.length) {
const newSettings = walletSettings.map(wallet => ({
...wallet,
successfullyFinishedInitialSubscription: false,
Copy link
Member Author

Choose a reason for hiding this comment

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

main change: reset the successfullyFinishedInitialSubscription flag so we know to resubscribe using the new endpoint (after it successfully resubscribes, it'll get set back to true)

@@ -255,8 +252,7 @@ export const NotificationsHandler = ({ walletReady }: Props) => {
})
)
);
initializeGlobalNotificationSettings();
initializeNotificationSettingsForAllAddressesAndCleanupSettingsForRemovedWallets(addresses);
initializeNotificationSettingsForAllAddresses(addresses);
Copy link
Member Author

Choose a reason for hiding this comment

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

initializeNotificationSettingsForAllAddresses will now handle the global notification initialization as well since it's all put together in one payload to the backend

) => {
analytics.track('Changed Notification Settings', {
chainId,
export const trackChangedGlobalNotificationSettings = (topic: GlobalNotificationTopicType, enableTopic: boolean) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

renamed this since this was only used for the global notif changes

useEffect(() => () => {
listener.remove();
});
useEffect(() => {
Copy link
Member Author

Choose a reason for hiding this comment

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

needed to add this into the useEffect because of the async nature of listener changes, which was causing the returned walletNotificationSettings to not necessarily be in sync with the results after a setWalletNotificationSettings

Copy link
Contributor

Choose a reason for hiding this comment

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

nice eye


const queue = _prepareSubscriptionQueueAndCreateInitialSettings(addresses, initializationState);
const createInitialSettingsForAllAddresses = (addresses: AddressWithRelationship[]) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

this function uses needsUpdate flag so that we only resubscribe when we need to (e.g, if successfullyFinishedInitialSubscription is set to false or if a wallet address that we have is missing from the existing notification settings)

@brunobar79
Copy link
Member

Launch in simulator or device for d8ae563

Copy link
Contributor

@walmat walmat left a comment

Choose a reason for hiding this comment

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

Mostly looks good. Main concerns:

  1. comparisons between addresses should be toLowerCase() just in case they differ in case values only
  2. JSON.parse erratic behavior when not what we expect
  3. creating a shared util for checking status === RESULTS.GRANTED || status === RESULTS.LIMITED since it's used in many places
  4. shortcutting the need for getFCMToken after we know we have just saved it by returning the token value from saveFCMToken

src/hooks/useResetAccountState.ts Outdated Show resolved Hide resolved
src/notifications/settings/firebase.ts Outdated Show resolved Hide resolved
src/notifications/settings/firebase.ts Outdated Show resolved Hide resolved
useEffect(() => () => {
listener.remove();
});
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice eye

src/notifications/permissions.ts Outdated Show resolved Hide resolved
src/notifications/settings/settings.ts Outdated Show resolved Hide resolved
src/notifications/settings/settings.ts Outdated Show resolved Hide resolved
src/screens/NotificationsPromoSheet/index.tsx Outdated Show resolved Hide resolved
Copy link
Member

@derHowie derHowie left a comment

Choose a reason for hiding this comment

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

Great stuff

I followed your testing instructions here: https://www.notion.so/rainbowdotme/Notifications-upgrade-642eae49b0eb45b2a65cd89c367fed00#27a7325fd6894d9d9de645300fcdae2f

Everything behaved as expected except for one step. In the 'Toggling / changing the notifications settings in the app' section I saw an issue when toggling my group of watched wallets the first time. I saw a spinner for a while, then eventually received an error message indicating that the request had failed. However, it appeared later that the watched wallets had had their notification setting enabled.

My guess is that your PUT timed out but eventually we picked up the change. Would that make sense?

src/notifications/settings/settings.ts Outdated Show resolved Hide resolved
@@ -61,8 +59,8 @@ export default function useInitializeWallet() {
try {
PerformanceTracking.startMeasuring(PerformanceMetrics.useInitializeWallet);
logger.debug('[useInitializeWallet]: Start wallet setup');
await resetAccountState();
logger.debug('[useInitializeWallet]: resetAccountState ran ok');
dispatch(requestsResetState());
Copy link
Member Author

Choose a reason for hiding this comment

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

the resetAccountState function only has the WC v1 requests resetting logic left - so using this function directly instead

const dispatch = useDispatch();

const onNetworkChange = useCallback(
async (chainId: ChainId) => {
await resetAccountState();
Copy link
Member Author

Choose a reason for hiding this comment

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

resetAccountState only has the resetting of WC v1 requests now - given that this doesn't change based on accountSetting's network anymore since we don't support testnets at the moment, and given that we will be removing WC v1, I am preemptively removing this here

@brunobar79
Copy link
Member

Launch in simulator or device for fa8a228

@jinchung jinchung requested a review from walmat October 16, 2024 17:42
@brunobar79
Copy link
Member

Launch in simulator or device for bc2d20e

@derHowie
Copy link
Member

not rerequesting, but the newest changes lgtm ✅

…setting in it; use this reset function directly instead
@jinchung jinchung force-pushed the @jin/notifs-5-global branch from 604262a to a61a1a5 Compare October 17, 2024 15:22
@jinchung jinchung merged commit 2518dd8 into develop Oct 17, 2024
8 checks passed
@jinchung jinchung deleted the @jin/notifs-5-global branch October 17, 2024 16:08
@jinchung
Copy link
Member Author

merged early as all tests had passed except for lint, and now lint passed in the final run.

@brunobar79
Copy link
Member

Launch in simulator or device for 703607d

Copy link

sentry-io bot commented Oct 18, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ Error: [notifications]: Error while getting and saving FCM token Promise$argument_0(src/notifications/permissions) View Issue
  • ‼️ Error: [wallet]: Error generating account for keychain consoleTransport(src/logger/index) View Issue
  • ‼️ Error: [wallet]: Error in getPrivateKey consoleTransport(src/logger/index) View Issue
  • ‼️ Error: KC unavailable for PKEY lookup consoleTransport(src/logger/index) View Issue
  • ‼️ Error: [wallet]: Error in getPrivateKey consoleTransport(src/logger/index) View Issue

Did you find this useful? React with a 👍 or 👎

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

Successfully merging this pull request may close these issues.

4 participants