From 063beb0e51d05db8d3770ea2cea670ba939e3cf9 Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Tue, 10 Oct 2023 12:19:16 -0700 Subject: [PATCH 01/11] Nitpick on notification scenes --- .../scenes/CurrencyNotificationScene.tsx | 37 ++++++++----------- src/components/scenes/NotificationScene.tsx | 15 ++++---- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/components/scenes/CurrencyNotificationScene.tsx b/src/components/scenes/CurrencyNotificationScene.tsx index 60c17827a4b..fe275303822 100644 --- a/src/components/scenes/CurrencyNotificationScene.tsx +++ b/src/components/scenes/CurrencyNotificationScene.tsx @@ -24,12 +24,12 @@ export const CurrencyNotificationScene = (props: Props) => { const defaultIsoFiat = useSelector((state: RootState) => state.ui.settings.defaultIsoFiat) const settings = useSelector((state: RootState) => state.notificationSettings) - const toggleHourlySetting = useHandler(async () => { + const handleHourlyPress = useHandler(async () => { const newEvent = newPriceChangeEvent(currencyInfo, defaultIsoFiat, !settings.plugins[pluginId].hourlyChange, !!settings.plugins[pluginId].dailyChange) await updateSettings(newEvent) }) - const toggleDailySetting = useHandler(async () => { + const handleDailyPress = useHandler(async () => { const newEvent = newPriceChangeEvent(currencyInfo, defaultIsoFiat, !!settings.plugins[pluginId].hourlyChange, !settings.plugins[pluginId].dailyChange) await updateSettings(newEvent) }) @@ -49,27 +49,22 @@ export const CurrencyNotificationScene = (props: Props) => { [dispatch] ) - const rows = React.useMemo( - () => [ - , - - ], - [pluginId, settings, toggleDailySetting, toggleHourlySetting] - ) - return ( - {rows} + + + + ) } diff --git a/src/components/scenes/NotificationScene.tsx b/src/components/scenes/NotificationScene.tsx index f7785abd2f2..2c82409dab4 100644 --- a/src/components/scenes/NotificationScene.tsx +++ b/src/components/scenes/NotificationScene.tsx @@ -63,15 +63,16 @@ export const NotificationScene = (props: Props) => { {pluginIds.map(pluginId => { const { currencyInfo } = currencyConfigs[pluginId] - const onPress = () => - !settings.ignorePriceChanges - ? navigation.navigate('currencyNotificationSettings', { - currencyInfo - }) - : undefined + const handlePress = () => { + if (!settings.ignorePriceChanges) { + navigation.navigate('currencyNotificationSettings', { + currencyInfo + }) + } + } return ( - + ) From 736b2e5be79cc067d0a1b4beab976a92f5cce06b Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Tue, 10 Oct 2023 12:38:25 -0700 Subject: [PATCH 02/11] Dry CurrencyNotificationScene --- .../scenes/CurrencyNotificationScene.tsx | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/components/scenes/CurrencyNotificationScene.tsx b/src/components/scenes/CurrencyNotificationScene.tsx index fe275303822..5da87366334 100644 --- a/src/components/scenes/CurrencyNotificationScene.tsx +++ b/src/components/scenes/CurrencyNotificationScene.tsx @@ -3,7 +3,6 @@ import { ScrollView } from 'react-native' import { sprintf } from 'sprintf-js' import { newPriceChangeEvent, serverSettingsToNotificationSettings, setDeviceSettings } from '../../actions/NotificationActions' -import { NewPushEvent } from '../../controllers/action-queue/types/pushApiTypes' import { useHandler } from '../../hooks/useHandler' import { lstrings } from '../../locales/strings' import { RootState } from '../../reducers/RootReducer' @@ -24,30 +23,23 @@ export const CurrencyNotificationScene = (props: Props) => { const defaultIsoFiat = useSelector((state: RootState) => state.ui.settings.defaultIsoFiat) const settings = useSelector((state: RootState) => state.notificationSettings) - const handleHourlyPress = useHandler(async () => { - const newEvent = newPriceChangeEvent(currencyInfo, defaultIsoFiat, !settings.plugins[pluginId].hourlyChange, !!settings.plugins[pluginId].dailyChange) - await updateSettings(newEvent) - }) - - const handleDailyPress = useHandler(async () => { - const newEvent = newPriceChangeEvent(currencyInfo, defaultIsoFiat, !!settings.plugins[pluginId].hourlyChange, !settings.plugins[pluginId].dailyChange) - await updateSettings(newEvent) - }) - - const updateSettings = React.useCallback( - async (event: NewPushEvent) => { - try { - const newSettings = await dispatch(setDeviceSettings({ createEvents: [event] })) - dispatch({ - type: 'NOTIFICATION_SETTINGS_UPDATE', - data: serverSettingsToNotificationSettings(newSettings) - }) - } catch (e: any) { - showError(`Failed to reach notification server: ${e}`) - } - }, - [dispatch] - ) + const updateSettings = (settingChange: 'hourly' | 'daily') => async () => { + const hourly = settingChange === 'hourly' ? !settings.plugins[pluginId].hourlyChange : !!settings.plugins[pluginId].hourlyChange + const daily = settingChange === 'daily' ? !settings.plugins[pluginId].dailyChange : !!settings.plugins[pluginId].dailyChange + const event = newPriceChangeEvent(currencyInfo, defaultIsoFiat, hourly, daily) + try { + const newSettings = await dispatch(setDeviceSettings({ createEvents: [event] })) + dispatch({ + type: 'NOTIFICATION_SETTINGS_UPDATE', + data: serverSettingsToNotificationSettings(newSettings) + }) + } catch (e: any) { + showError(`Failed to reach notification server: ${e}`) + } + } + + const handleHourlyPress = useHandler(updateSettings('hourly')) + const handleDailyPress = useHandler(updateSettings('daily')) return ( From 4a7c334482b18474e8013318b7a8c3d50e4e358c Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Tue, 10 Oct 2023 12:42:00 -0700 Subject: [PATCH 03/11] Hide currency notification setting for keys-only currencies --- src/components/scenes/NotificationScene.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/scenes/NotificationScene.tsx b/src/components/scenes/NotificationScene.tsx index 2c82409dab4..5b7d630fb6b 100644 --- a/src/components/scenes/NotificationScene.tsx +++ b/src/components/scenes/NotificationScene.tsx @@ -3,6 +3,7 @@ import { ScrollView } from 'react-native' import { NotificationSettings, serverSettingsToNotificationSettings, setDeviceSettings } from '../../actions/NotificationActions' import { CryptoIcon } from '../../components/icons/CryptoIcon' +import { SPECIAL_CURRENCY_INFO } from '../../constants/WalletAndCurrencyConstants' import { useWatch } from '../../hooks/useWatch' import { lstrings } from '../../locales/strings' import { useDispatch, useSelector } from '../../types/reactRedux' @@ -62,6 +63,7 @@ export const NotificationScene = (props: Props) => { /> {pluginIds.map(pluginId => { const { currencyInfo } = currencyConfigs[pluginId] + const { keysOnlyMode = false } = SPECIAL_CURRENCY_INFO[pluginId] ?? {} const handlePress = () => { if (!settings.ignorePriceChanges) { @@ -71,6 +73,8 @@ export const NotificationScene = (props: Props) => { } } + if (keysOnlyMode) return null + return ( From f1c60bd4b0d3c9dbecafbb555627c954f74f64fb Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Tue, 10 Oct 2023 13:34:52 -0700 Subject: [PATCH 04/11] Add DevicePayload type --- src/actions/NotificationActions.ts | 8 ++++---- src/controllers/action-queue/types/pushApiTypes.ts | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/actions/NotificationActions.ts b/src/actions/NotificationActions.ts index 26e43e6f8c2..b816f8a7051 100644 --- a/src/actions/NotificationActions.ts +++ b/src/actions/NotificationActions.ts @@ -5,7 +5,7 @@ import { getUniqueId } from 'react-native-device-info' import { base64 } from 'rfc4648' import { sprintf } from 'sprintf-js' -import { asDevicePayload, DeviceUpdatePayload, NewPushEvent } from '../controllers/action-queue/types/pushApiTypes' +import { asDevicePayload, DevicePayload, DeviceUpdatePayload, NewPushEvent } from '../controllers/action-queue/types/pushApiTypes' import { asPriceChangeTrigger } from '../controllers/action-queue/types/pushCleaners' import { PriceChangeTrigger } from '../controllers/action-queue/types/pushTypes' import { ENV } from '../env' @@ -33,7 +33,7 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio return async (dispatch, getState) => { const state = getState() const { defaultIsoFiat } = state.ui.settings - let v2Settings: ReturnType = { + let v2Settings: DevicePayload = { loginIds: [], events: [], ignoreMarketing: false, @@ -140,7 +140,7 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio } } -export const serverSettingsToNotificationSettings = (serverSettings: ReturnType): NotificationSettings => { +export const serverSettingsToNotificationSettings = (serverSettings: DevicePayload): NotificationSettings => { const data: NotificationSettings = { ignoreMarketing: serverSettings.ignoreMarketing, ignorePriceChanges: serverSettings.ignorePriceChanges, @@ -163,7 +163,7 @@ export const serverSettingsToNotificationSettings = (serverSettings: ReturnType< return data } -export function setDeviceSettings(data: DeviceUpdatePayload): ThunkAction>> { +export function setDeviceSettings(data: DeviceUpdatePayload): ThunkAction> { return async (dispatch, getState) => { const state = getState() diff --git a/src/controllers/action-queue/types/pushApiTypes.ts b/src/controllers/action-queue/types/pushApiTypes.ts index b6465f2a26e..1d9e6cc83d1 100644 --- a/src/controllers/action-queue/types/pushApiTypes.ts +++ b/src/controllers/action-queue/types/pushApiTypes.ts @@ -150,6 +150,7 @@ export const asDevicePayload = asPushServerResponse( loginIds: asArray(asBase64) }) ) +export type DevicePayload = ReturnType /** * POST /v2/login response payload. From 243a8271f3048cd14cf75ec49aedf8a9d5113848 Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Tue, 10 Oct 2023 13:47:23 -0700 Subject: [PATCH 05/11] Abstract notification settings update imperatives --- src/actions/NotificationActions.ts | 13 +++++++++++-- src/components/scenes/CurrencyNotificationScene.tsx | 8 ++------ src/components/scenes/LoginScene.tsx | 8 ++------ src/components/scenes/NotificationScene.tsx | 8 ++------ 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/actions/NotificationActions.ts b/src/actions/NotificationActions.ts index b816f8a7051..11ae247beee 100644 --- a/src/actions/NotificationActions.ts +++ b/src/actions/NotificationActions.ts @@ -140,7 +140,16 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio } } -export const serverSettingsToNotificationSettings = (serverSettings: DevicePayload): NotificationSettings => { +export function updateNotificationSettings(data: DeviceUpdatePayload): ThunkAction> { + return async dispatch => { + dispatch({ + type: 'NOTIFICATION_SETTINGS_UPDATE', + data: serverSettingsToNotificationSettings(await dispatch(setDeviceSettings(data))) + }) + } +} + +const serverSettingsToNotificationSettings = (serverSettings: DevicePayload): NotificationSettings => { const data: NotificationSettings = { ignoreMarketing: serverSettings.ignoreMarketing, ignorePriceChanges: serverSettings.ignorePriceChanges, @@ -163,7 +172,7 @@ export const serverSettingsToNotificationSettings = (serverSettings: DevicePaylo return data } -export function setDeviceSettings(data: DeviceUpdatePayload): ThunkAction> { +function setDeviceSettings(data: DeviceUpdatePayload): ThunkAction> { return async (dispatch, getState) => { const state = getState() diff --git a/src/components/scenes/CurrencyNotificationScene.tsx b/src/components/scenes/CurrencyNotificationScene.tsx index 5da87366334..76c2b81bd9a 100644 --- a/src/components/scenes/CurrencyNotificationScene.tsx +++ b/src/components/scenes/CurrencyNotificationScene.tsx @@ -2,7 +2,7 @@ import * as React from 'react' import { ScrollView } from 'react-native' import { sprintf } from 'sprintf-js' -import { newPriceChangeEvent, serverSettingsToNotificationSettings, setDeviceSettings } from '../../actions/NotificationActions' +import { newPriceChangeEvent, updateNotificationSettings } from '../../actions/NotificationActions' import { useHandler } from '../../hooks/useHandler' import { lstrings } from '../../locales/strings' import { RootState } from '../../reducers/RootReducer' @@ -28,11 +28,7 @@ export const CurrencyNotificationScene = (props: Props) => { const daily = settingChange === 'daily' ? !settings.plugins[pluginId].dailyChange : !!settings.plugins[pluginId].dailyChange const event = newPriceChangeEvent(currencyInfo, defaultIsoFiat, hourly, daily) try { - const newSettings = await dispatch(setDeviceSettings({ createEvents: [event] })) - dispatch({ - type: 'NOTIFICATION_SETTINGS_UPDATE', - data: serverSettingsToNotificationSettings(newSettings) - }) + await dispatch(updateNotificationSettings({ createEvents: [event] })) } catch (e: any) { showError(`Failed to reach notification server: ${e}`) } diff --git a/src/components/scenes/LoginScene.tsx b/src/components/scenes/LoginScene.tsx index 36e267b0323..204974f8d28 100644 --- a/src/components/scenes/LoginScene.tsx +++ b/src/components/scenes/LoginScene.tsx @@ -8,7 +8,7 @@ import { BlurView } from 'rn-id-blurview' import { showSendLogsModal } from '../../actions/LogActions' import { initializeAccount, logoutRequest } from '../../actions/LoginActions' -import { serverSettingsToNotificationSettings, setDeviceSettings } from '../../actions/NotificationActions' +import { updateNotificationSettings } from '../../actions/NotificationActions' import { cacheStyles, Theme, useTheme } from '../../components/services/ThemeContext' import { ENV } from '../../env' import { ExperimentConfig, getExperimentConfig } from '../../experimentConfig' @@ -166,11 +166,7 @@ export function LoginSceneComponent(props: Props) { if (notificationPermissionsInfo) { try { - const newSettings = await dispatch(setDeviceSettings(notificationPermissionsInfo.notificationOptIns)) - dispatch({ - type: 'NOTIFICATION_SETTINGS_UPDATE', - data: serverSettingsToNotificationSettings(newSettings) - }) + await dispatch(updateNotificationSettings(notificationPermissionsInfo.notificationOptIns)) } catch (e) { trackError(e, 'LoginScene:onLogin:setDeviceSettings') console.error(e) diff --git a/src/components/scenes/NotificationScene.tsx b/src/components/scenes/NotificationScene.tsx index 5b7d630fb6b..020aefe1102 100644 --- a/src/components/scenes/NotificationScene.tsx +++ b/src/components/scenes/NotificationScene.tsx @@ -1,7 +1,7 @@ import * as React from 'react' import { ScrollView } from 'react-native' -import { NotificationSettings, serverSettingsToNotificationSettings, setDeviceSettings } from '../../actions/NotificationActions' +import { NotificationSettings, updateNotificationSettings } from '../../actions/NotificationActions' import { CryptoIcon } from '../../components/icons/CryptoIcon' import { SPECIAL_CURRENCY_INFO } from '../../constants/WalletAndCurrencyConstants' import { useWatch } from '../../hooks/useWatch' @@ -28,11 +28,7 @@ export const NotificationScene = (props: Props) => { const handlePressToggleSetting = async (toggleSetting: NotificationSettingToggleSetting) => { try { - const newSettings = await dispatch(setDeviceSettings({ [toggleSetting]: !settings[toggleSetting] })) - dispatch({ - type: 'NOTIFICATION_SETTINGS_UPDATE', - data: serverSettingsToNotificationSettings(newSettings) - }) + await dispatch(updateNotificationSettings({ [toggleSetting]: !settings[toggleSetting] })) } catch (e: any) { showError(`Failed to reach notification server: ${e}`) } From b422c18dd1ccc36848bac3ffa5ac083152b7fb06 Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Tue, 10 Oct 2023 13:58:34 -0700 Subject: [PATCH 06/11] Convert setDeviceSettings from a thunk --- src/actions/NotificationActions.ts | 55 +++++++++++++++--------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/actions/NotificationActions.ts b/src/actions/NotificationActions.ts index 11ae247beee..06a6c397c76 100644 --- a/src/actions/NotificationActions.ts +++ b/src/actions/NotificationActions.ts @@ -1,6 +1,6 @@ import messaging from '@react-native-firebase/messaging' import { asMaybe } from 'cleaners' -import { EdgeCurrencyInfo } from 'edge-core-js' +import { EdgeContext, EdgeCurrencyInfo } from 'edge-core-js' import { getUniqueId } from 'react-native-device-info' import { base64 } from 'rfc4648' import { sprintf } from 'sprintf-js' @@ -126,7 +126,7 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio } if (createEvents.length > 0) { - v2Settings = await dispatch(setDeviceSettings({ createEvents })) + v2Settings = await updateServerSettings(state.core.context, { createEvents }) } } catch (e: any) { // If this fails we don't need to bother the user just log and move on. @@ -141,10 +141,11 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio } export function updateNotificationSettings(data: DeviceUpdatePayload): ThunkAction> { - return async dispatch => { + return async (dispatch, getState) => { + const state = getState() dispatch({ type: 'NOTIFICATION_SETTINGS_UPDATE', - data: serverSettingsToNotificationSettings(await dispatch(setDeviceSettings(data))) + data: serverSettingsToNotificationSettings(await updateServerSettings(state.core.context, data)) }) } } @@ -172,32 +173,30 @@ const serverSettingsToNotificationSettings = (serverSettings: DevicePayload): No return data } -function setDeviceSettings(data: DeviceUpdatePayload): ThunkAction> { - return async (dispatch, getState) => { - const state = getState() - - const deviceToken = await messaging() - .getToken() - .catch(() => '') - - const body = { - apiKey: ENV.AIRBITZ_API_KEY, - deviceId: state.core.context.clientId, - deviceToken, - data: { ...data, loginIds: state.core.context.localUsers.map(row => base64.stringify(base58.parse(row.loginId))) } - } - const opts = { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify(body) - } +async function updateServerSettings(context: EdgeContext, data: DeviceUpdatePayload): Promise { + const deviceId = context.clientId + const loginIds = context.localUsers.map(row => base64.stringify(base58.parse(row.loginId))) + const deviceToken = await messaging() + .getToken() + .catch(() => '') + + const body = { + apiKey: ENV.AIRBITZ_API_KEY, + deviceId, + deviceToken, + data: { ...data, loginIds } + } + const opts = { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(body) + } - const response = await fetchPush('v2/device/update/', opts) + const response = await fetchPush('v2/device/update/', opts) - return asDevicePayload(await response.text()) - } + return asDevicePayload(await response.text()) } export const newPriceChangeEvent = ( From 0466d5fbbba4832c37597a8bf560a2949843794e Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Tue, 10 Oct 2023 14:00:42 -0700 Subject: [PATCH 07/11] Rename `v2Settings` identifier --- src/actions/NotificationActions.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/actions/NotificationActions.ts b/src/actions/NotificationActions.ts index 06a6c397c76..f075cc43f65 100644 --- a/src/actions/NotificationActions.ts +++ b/src/actions/NotificationActions.ts @@ -33,7 +33,7 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio return async (dispatch, getState) => { const state = getState() const { defaultIsoFiat } = state.ui.settings - let v2Settings: DevicePayload = { + let serverSettings: DevicePayload = { loginIds: [], events: [], ignoreMarketing: false, @@ -59,19 +59,19 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio } const response = await fetchPush('v2/device/', opts) - v2Settings = asDevicePayload(await response.text()) + serverSettings = asDevicePayload(await response.text()) const currencyWallets = state.core.account.currencyWallets const activeCurrencyInfos = getActiveWalletCurrencyInfos(currencyWallets) const createEvents: NewPushEvent[] = [] - if (v2Settings.events.length !== 0) { + if (serverSettings.events.length !== 0) { // v2 settings exist already, see if we need to add new ones const missingInfos: { [pluginId: string]: EdgeCurrencyInfo } = {} for (const currencyInfo of activeCurrencyInfos) { if ( - !v2Settings.events.some(event => { + !serverSettings.events.some(event => { if (event.trigger.type === 'price-change' && event.trigger.pluginId === currencyInfo.pluginId) { // An event for this plugin exists already we need to check if the user is changing the default fiat currency if (changeFiat && !event.trigger.currencyPair.includes(defaultIsoFiat)) return false @@ -126,7 +126,7 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio } if (createEvents.length > 0) { - v2Settings = await updateServerSettings(state.core.context, { createEvents }) + serverSettings = await updateServerSettings(state.core.context, { createEvents }) } } catch (e: any) { // If this fails we don't need to bother the user just log and move on. @@ -135,7 +135,7 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio dispatch({ type: 'NOTIFICATION_SETTINGS_UPDATE', - data: serverSettingsToNotificationSettings(v2Settings) + data: serverSettingsToNotificationSettings(serverSettings) }) } } From 0a097d387cfede6311313d7aa0443fb2cfdb1388 Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Tue, 10 Oct 2023 14:01:38 -0700 Subject: [PATCH 08/11] Remove redundant `missingInfo` map --- src/actions/NotificationActions.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/actions/NotificationActions.ts b/src/actions/NotificationActions.ts index f075cc43f65..cfc4ce55254 100644 --- a/src/actions/NotificationActions.ts +++ b/src/actions/NotificationActions.ts @@ -68,7 +68,6 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio if (serverSettings.events.length !== 0) { // v2 settings exist already, see if we need to add new ones - const missingInfos: { [pluginId: string]: EdgeCurrencyInfo } = {} for (const currencyInfo of activeCurrencyInfos) { if ( !serverSettings.events.some(event => { @@ -81,10 +80,10 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio } }) ) { - missingInfos[currencyInfo.pluginId] = currencyInfo + // Add new push event + createEvents.push(newPriceChangeEvent(currencyInfo, defaultIsoFiat, true, true)) } } - Object.keys(missingInfos).forEach(pluginId => createEvents.push(newPriceChangeEvent(missingInfos[pluginId], defaultIsoFiat, true, true))) } else { // No v2 settings exist so let's check v1 const userId = state.core.account.rootLoginId From 13ab3ca6efa1f25858c071374f8678f887c97756 Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Tue, 10 Oct 2023 14:14:37 -0700 Subject: [PATCH 09/11] Reduce update condition into an expression for readability --- src/actions/NotificationActions.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/actions/NotificationActions.ts b/src/actions/NotificationActions.ts index cfc4ce55254..ca7cf3bcbf4 100644 --- a/src/actions/NotificationActions.ts +++ b/src/actions/NotificationActions.ts @@ -70,15 +70,13 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio // v2 settings exist already, see if we need to add new ones for (const currencyInfo of activeCurrencyInfos) { if ( - !serverSettings.events.some(event => { - if (event.trigger.type === 'price-change' && event.trigger.pluginId === currencyInfo.pluginId) { - // An event for this plugin exists already we need to check if the user is changing the default fiat currency - if (changeFiat && !event.trigger.currencyPair.includes(defaultIsoFiat)) return false - return true - } else { - return false - } - }) + !serverSettings.events.some( + event => + event.trigger.type === 'price-change' && + event.trigger.pluginId === currencyInfo.pluginId && + // An event for this plugin exists already, so we need to check if the user is changing the default fiat currency + (!changeFiat || event.trigger.currencyPair.includes(defaultIsoFiat)) + ) ) { // Add new push event createEvents.push(newPriceChangeEvent(currencyInfo, defaultIsoFiat, true, true)) From 828e5377a0cb172e3a3f64e257ef7343f7fde877 Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Tue, 10 Oct 2023 14:28:53 -0700 Subject: [PATCH 10/11] Remove price-change push event subscription for deprecated currencies --- CHANGELOG.md | 1 + src/actions/NotificationActions.ts | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27af3f81de1..13388ec8598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - changed: Banxa sell to use new widget - changed: Replace deprecated memo handling with `EdgeMemo` in SendScene2 - changed: Re-enable Piratechain +- changed: Remove price-change push notification subscriptions for keys-only currencies - fixed: Crash in react-native-linear-gradient when app built with Xcode 15 ## 3.19.0 diff --git a/src/actions/NotificationActions.ts b/src/actions/NotificationActions.ts index ca7cf3bcbf4..ab0799e07e3 100644 --- a/src/actions/NotificationActions.ts +++ b/src/actions/NotificationActions.ts @@ -5,6 +5,7 @@ import { getUniqueId } from 'react-native-device-info' import { base64 } from 'rfc4648' import { sprintf } from 'sprintf-js' +import { SPECIAL_CURRENCY_INFO } from '../constants/WalletAndCurrencyConstants' import { asDevicePayload, DevicePayload, DeviceUpdatePayload, NewPushEvent } from '../controllers/action-queue/types/pushApiTypes' import { asPriceChangeTrigger } from '../controllers/action-queue/types/pushCleaners' import { PriceChangeTrigger } from '../controllers/action-queue/types/pushTypes' @@ -65,16 +66,19 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio const activeCurrencyInfos = getActiveWalletCurrencyInfos(currencyWallets) const createEvents: NewPushEvent[] = [] + const removeEvents: string[] = [] if (serverSettings.events.length !== 0) { // v2 settings exist already, see if we need to add new ones for (const currencyInfo of activeCurrencyInfos) { if ( + // Must not be deprecated + !SPECIAL_CURRENCY_INFO[currencyInfo.pluginId].keysOnlyMode && + // Must not already be present with current fiat setting !serverSettings.events.some( event => event.trigger.type === 'price-change' && event.trigger.pluginId === currencyInfo.pluginId && - // An event for this plugin exists already, so we need to check if the user is changing the default fiat currency (!changeFiat || event.trigger.currencyPair.includes(defaultIsoFiat)) ) ) { @@ -82,6 +86,17 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio createEvents.push(newPriceChangeEvent(currencyInfo, defaultIsoFiat, true, true)) } } + + // See if we need to remove any deprecated currencies (keys-only) + for (const event of serverSettings.events) { + const { trigger } = event + if (trigger.type === 'price-change') { + const currencyInfo = activeCurrencyInfos.find(currencyInfo => currencyInfo.pluginId === trigger.pluginId) + if (currencyInfo != null && SPECIAL_CURRENCY_INFO[currencyInfo.pluginId].keysOnlyMode) { + removeEvents.push(event.eventId) + } + } + } } else { // No v2 settings exist so let's check v1 const userId = state.core.account.rootLoginId @@ -122,8 +137,8 @@ export function registerNotificationsV2(changeFiat: boolean = false): ThunkActio } } - if (createEvents.length > 0) { - serverSettings = await updateServerSettings(state.core.context, { createEvents }) + if (createEvents.length > 0 || removeEvents.length > 0) { + serverSettings = await updateServerSettings(state.core.context, { createEvents, removeEvents }) } } catch (e: any) { // If this fails we don't need to bother the user just log and move on. From 8b0cb3be9db09a982d04bda6b6b989aeb278a911 Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Tue, 10 Oct 2023 14:35:14 -0700 Subject: [PATCH 11/11] Format CHANGELOG.md using `prettier` --- CHANGELOG.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13388ec8598..a6698b889cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -256,7 +256,7 @@ - changed: Disable Firebase AD ID - changed: Upgrade to ESLint v8 - removed: Unused React-based partner plugins -- fixed: Rename "View Xpub address" to "Private View Key" for Pirate Chain and Zcash +- fixed: Rename "View Xpub address" to "Private View Key" for Pirate Chain and Zcash - fixed: Private view key modal warning text for other currencies besides Monero - fixed: Handle unhandled promises - fixed: Wallet list row sync circle component recycling @@ -351,7 +351,7 @@ - Fixed: Fix broken max-spend for zkSync - Deprecate WalletConnect v1 - EVM/ALGO: Add parseWalletConnectV2Payload to parse out amounts from WalletConnect v2 payloads -ZEC: Update checkpoints + ZEC: Update checkpoints - Upgrade edge-login-ui-rn to v2.3.3 - fixed: Modal close button covering modal submit buttons while Android keyboard is open - fixed: Username availability check error would incorrectly show in some cases @@ -851,6 +851,7 @@ ZEC: Update checkpoints - changed: Make sensitive account & wallet properties, like keys, non-enumerable. - changed: Use the pluginId as the wallet logging prefix, instead of the currency code. - Upgrade edge-currency-accountbased to v0.22.4 + - Convert library to React Native Module - This package will automatically install itself using React Native autolinking and no longer requires Webpack for integration - Plugins are broken out and can be loaded individually @@ -877,6 +878,7 @@ ZEC: Update checkpoints - EVM: Remove recursion from getMaxSpendable - Replace remaining json-schema usage with cleaners - Update checkpoint files + - Upgrade edge-currency-monero to v0.5.5 - Add getMaxSpendable - Upgrade edge-core-js to v0.19.36 @@ -1331,7 +1333,7 @@ ZEC: Update checkpoints - LetsExchange: Fix min amount currency display - Upgrade edge-core-js to v0.19.23 - Upgrade edge-login-ui-rn v0.10.7 - changed: Update forget account description text + changed: Update forget account description text - changed: Update PIN description text - changed: Add titles for resecure password/pin scenes - changed: Add SKIP button for resecure password and pin scenes @@ -1470,7 +1472,7 @@ ZEC: Update checkpoints - Fix FTM network fees test - Fix ftmInfo.js filename - Add timeout to getSupportedCurrencies test to prevent hanging -Upgrade edge-currency-bitcoin to v4.9.23 + Upgrade edge-currency-bitcoin to v4.9.23 - DASH: Recognize the Instantlock for incoming Dash transactions - Work around Android PBKDF2 failures - Upgrade edge-currency-monero to v0.4.1 @@ -2288,7 +2290,7 @@ Upgrade edge-currency-bitcoin to v4.9.23 - Upgrade to edge-core-js v0.17.29 - Upgrade to Webpack 5 - Upgrade edge-login-ui-rn to v0.9.0 - - *Breaking change*: This release contains a breaking change that was not indicated in the minor version update: + - _Breaking change_: This release contains a breaking change that was not indicated in the minor version update: - rn: Prompt for notification permissions to support security features - rn: Update modal colors - Upgrade edge-currency-monero to v0.2.10 @@ -2989,7 +2991,8 @@ Upgrade edge-currency-bitcoin to v4.9.23 - New transaction details screen - Enhanced deeplinking capabilities - Bug fixes and visual enhancements -- ***BREAKING CHANGE*** Upgrade edge-core-js to v0.17.0 +- **_BREAKING CHANGE_** Upgrade edge-core-js to v0.17.0 + - This release also renames all `pluginName` instances to `pluginId`. This affects all plugin types, but the core contains compatibility code so old currency plugins continue working (but not for rate or swap plugins, which are easier to just upgrade). - Breaking changes to the swap API: - Return a new `EdgeSwapResult` structure from `EdgeSwapQuote.approve`. This now contains the `destinationAddress` and `orderId` that used to exist on the `EdgeSwapQuote` type. @@ -3006,11 +3009,13 @@ Upgrade edge-currency-bitcoin to v4.9.23 - Remove deprecated `EdgeIo.WebSocket`. - Upgrade edge-exchange-plugins to v0.10.2 + - Add Switchain swap plugin. - Pass promo codes to Changelly, ChangeNow, and Godex. - Fix ChangeNow on Android & add better logging. - Upgrade edge-currency-accountbased to v0.7.2 + - Add cleaners v0.2.0 type checking - Fix duplicate FIO address after registration - Reprioritize EOS Hyperion nodes to resolve transaction history view issue