Skip to content

Commit

Permalink
Points: notifications toggle (#5329)
Browse files Browse the repository at this point in the history
  • Loading branch information
benisgold authored Jan 20, 2024
1 parent 75c371b commit fb71200
Show file tree
Hide file tree
Showing 26 changed files with 698 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function SwapActionButton({
screen: Routes.MAIN_EXCHANGE_SCREEN,
};
} else {
console.log(asset);
return {
params: {
defaultInputAsset: asset,
Expand Down
2 changes: 2 additions & 0 deletions src/config/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const MINTS = 'Mints';
export const POINTS = 'Points';
export const REMOTE_PROMO_SHEETS = 'RemotePromoSheets';
export const REMOTE_CARDS = 'RemoteCards';
export const POINTS_NOTIFICATIONS_TOGGLE = 'PointsNotificationsToggle';

/**
* A developer setting that pushes log lines to an array in-memory so that
Expand Down Expand Up @@ -53,6 +54,7 @@ export const defaultConfig: Record<string, ExperimentalValue> = {
[POINTS]: { settings: true, value: false },
[REMOTE_PROMO_SHEETS]: { settings: true, value: false },
[REMOTE_CARDS]: { settings: true, value: false },
[POINTS_NOTIFICATIONS_TOGGLE]: { settings: true, value: false },
};

const storageKey = 'config';
Expand Down
5 changes: 5 additions & 0 deletions src/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,10 @@
"get_started": "Get Started",
"invalid_code": "Invalid Code"
},
"notifications": {
"enable": "Enable Points Notifications",
"disable": "Disable Points Notifications"
},
"points": {
"referral_code": "Referral Code",
"share_link": "Share Link",
Expand Down Expand Up @@ -1711,6 +1715,7 @@
"notifications": "Notifications",
"notifications_section": {
"my_wallets": "My Wallets",
"points": "Points",
"watched_wallets": "Watched Wallets",
"allow_notifications": "Allow Notifications",
"sent": "Sent",
Expand Down
8 changes: 4 additions & 4 deletions src/migrations/migrations/migrateNotificationSettingsToV2.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Migration, MigrationName } from '@/migrations/types';
import {
getAllNotificationSettingsFromStorage,
setAllNotificationSettingsToStorage,
getAllWalletNotificationSettingsFromStorage,
setAllWalletNotificationSettingsToStorage,
} from '@/notifications/settings/storage';

export function migrateNotificationSettingsToV2(): Migration {
return {
name: MigrationName.migrateNotificationSettingsToVersion2,
async migrate() {
const walletSettings = getAllNotificationSettingsFromStorage();
const walletSettings = getAllWalletNotificationSettingsFromStorage();
let settingsVersion = 1;

if (
Expand All @@ -27,7 +27,7 @@ export function migrateNotificationSettingsToV2(): Migration {
...wallet,
successfullyFinishedInitialSubscription: true,
}));
setAllNotificationSettingsToStorage(newSettings);
setAllWalletNotificationSettingsToStorage(newSettings);
}
return;
},
Expand Down
5 changes: 4 additions & 1 deletion src/model/remoteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ interface RainbowConfig extends Record<string, string | boolean | number> {
rpc_proxy_enabled: boolean;
remote_cards_enabled: boolean;
remote_promo_enabled: boolean;
points_notifications_toggle: boolean;
}

const DEFAULT_CONFIG: RainbowConfig = {
Expand Down Expand Up @@ -137,6 +138,7 @@ const DEFAULT_CONFIG: RainbowConfig = {
rpc_proxy_enabled: true,
remote_cards_enabled: false,
remote_promo_enabled: false,
points_notifications_toggle: true,
};

export async function fetchRemoteConfig(): Promise<RainbowConfig> {
Expand Down Expand Up @@ -179,7 +181,8 @@ export async function fetchRemoteConfig(): Promise<RainbowConfig> {
key === 'points_fully_enabled' ||
key === 'rpc_proxy_enabled' ||
key === 'remote_promo_enabled' ||
key === 'remote_cards_enabled'
key === 'remote_cards_enabled' ||
key === 'points_notifications_toggle'
) {
config[key] = entry.asBoolean();
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/model/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import {
import {
AddressWithRelationship,
initializeNotificationSettingsForAddresses,
NotificationRelationship,
WalletNotificationRelationship,
} from '@/notifications/settings';
import { DebugContext } from '@/logger/debugContext';
import { IS_ANDROID } from '@/env';
Expand Down Expand Up @@ -980,8 +980,8 @@ export const createWallet = async ({
// create notifications settings entry for newly created wallet
const relationship =
type === EthereumWalletType.readOnly
? NotificationRelationship.WATCHER
: NotificationRelationship.OWNER;
? WalletNotificationRelationship.WATCHER
: WalletNotificationRelationship.OWNER;
const addressesWithRelationship: AddressWithRelationship[] = addresses.map(
account => ({
relationship,
Expand Down Expand Up @@ -1345,7 +1345,7 @@ export const generateAccount = async (
{
address: walletAddress,
// Wallet or account created from within the app is attached to a seed phrase so it's an owned wallet
relationship: NotificationRelationship.OWNER,
relationship: WalletNotificationRelationship.OWNER,
},
]);

Expand Down
14 changes: 9 additions & 5 deletions src/notifications/NotificationsHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ import {
} from '@/notifications/analytics';
import {
AddressWithRelationship,
NotificationRelationship,
WalletNotificationRelationship,
} from '@/notifications/settings';
import { initializeNotificationSettingsForAllAddressesAndCleanupSettingsForRemovedWallets } from '@/notifications/settings/initialization';
import {
initializeGlobalNotificationSettings,
initializeNotificationSettingsForAllAddressesAndCleanupSettingsForRemovedWallets,
} from '@/notifications/settings/initialization';
import { logger } from '@/logger';
import { setHasPendingDeeplinkPendingRedirect } from '@/walletConnect';

Expand Down Expand Up @@ -381,15 +384,16 @@ export const NotificationsHandler = ({ walletReady }: Props) => {
address,
relationship:
wallet.type === walletTypes.readOnly
? NotificationRelationship.WATCHER
: NotificationRelationship.OWNER,
? WalletNotificationRelationship.WATCHER
: WalletNotificationRelationship.OWNER,
})
)
);

initializeGlobalNotificationSettings();
initializeNotificationSettingsForAllAddressesAndCleanupSettingsForRemovedWallets(
addresses
);

alreadyRanInitialization.current = true;
}
}, [dispatch, walletReady]);
Expand Down
24 changes: 12 additions & 12 deletions src/notifications/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { MinimalNotification } from '@/notifications/types';
import { getPermissionStatus } from '@/notifications/permissions';
import messaging from '@react-native-firebase/messaging';
import {
NotificationRelationship,
WalletNotificationRelationship,
WALLET_GROUPS_STORAGE_KEY,
WALLET_TOPICS_STORAGE_KEY,
GroupSettings,
NotificationRelationshipType,
NotificationTopicType,
WalletNotificationRelationshipType,
WalletNotificationTopicType,
WalletNotificationSettings,
notificationSettingsStorage,
} from '@/notifications/settings';
Expand All @@ -25,10 +25,10 @@ export const trackTappedPushNotification = (
};

export const trackChangedNotificationSettings = (
chainId: number,
topic: NotificationTopicType,
type: NotificationRelationshipType,
action: 'subscribe' | 'unsubscribe'
topic: WalletNotificationTopicType,
action: 'subscribe' | 'unsubscribe',
chainId?: number,
type?: WalletNotificationRelationshipType
) => {
analytics.track('Changed Notification Settings', {
chainId,
Expand Down Expand Up @@ -80,8 +80,8 @@ export const trackWalletsSubscribedForNotifications = () => {
const { imported, watched } = countWalletsWithNotificationsTurnedOn(wallets);

trackNumberOfWalletsWithNotificationsTurnedOn(
groups[NotificationRelationship.OWNER] ? imported : 0,
groups[NotificationRelationship.WATCHER] ? watched : 0
groups[WalletNotificationRelationship.OWNER] ? imported : 0,
groups[WalletNotificationRelationship.WATCHER] ? watched : 0
);
};

Expand Down Expand Up @@ -118,8 +118,8 @@ const onGroupStateChange = (state: GroupSettings) => {
const { imported, watched } = countWalletsWithNotificationsTurnedOn(wallets);

trackNumberOfWalletsWithNotificationsTurnedOn(
state[NotificationRelationship.OWNER] ? imported : 0,
state[NotificationRelationship.WATCHER] ? watched : 0
state[WalletNotificationRelationship.OWNER] ? imported : 0,
state[WalletNotificationRelationship.WATCHER] ? watched : 0
);
};

Expand All @@ -137,7 +137,7 @@ const countWalletsWithNotificationsTurnedOn = (

wallets.forEach(entry => {
if (!entry.enabled) return;
if (entry.type === NotificationRelationship.OWNER) imported += 1;
if (entry.type === WalletNotificationRelationship.OWNER) imported += 1;
else watched += 1;
});

Expand Down
Loading

0 comments on commit fb71200

Please sign in to comment.