Skip to content

Commit

Permalink
Update return values for notif settings functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung committed Nov 29, 2023
1 parent 93de206 commit cbd8978
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/notifications/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@ import { publishWalletSettings } from '@/notifications/settings/firebase';
3. Excludes that wallet from the array and saves the new array.
4. Updates the notification subscription
*/
export const removeNotificationSettingsForWallet = async (
address: string
): Promise<void> => {
export const removeNotificationSettingsForWallet = async (address: string) => {
const allSettings = getAllNotificationSettingsFromStorage();
const settingsForWallet = allSettings.find(
(wallet: WalletNotificationSettings) => wallet.address === address
);

if (!settingsForWallet) {
return Promise.resolve();
return;
}

const newSettings = allSettings.filter(
(wallet: WalletNotificationSettings) => wallet.address !== address
);

publishAndSaveWalletSettings(newSettings, true);
publishAndSaveWalletSettings(newSettings);
};

/**
Expand All @@ -42,7 +40,7 @@ export const removeNotificationSettingsForWallet = async (
export async function toggleGroupNotifications(
wallets: WalletNotificationSettings[],
enableNotifications: boolean
) {
): Promise<boolean> {
const allSettings = getAllNotificationSettingsFromStorage();
const toBeUpdated = new Map<string, boolean>();
wallets.forEach(entry => {
Expand All @@ -61,7 +59,7 @@ export async function toggleGroupNotifications(
return walletSetting;
});

publishAndSaveWalletSettings(proposedSettings);
return publishAndSaveWalletSettings(proposedSettings, true);
}

/**
Expand All @@ -71,7 +69,7 @@ export async function toggleTopicForWallet(
address: string,
topic: NotificationTopicType,
enableTopic: boolean
) {
): Promise<boolean> {
const allSettings = getAllNotificationSettingsFromStorage();
const newSettings = allSettings.map(walletSetting => {
if (walletSetting.address !== address) {
Expand All @@ -86,18 +84,20 @@ export async function toggleTopicForWallet(
},
};
});
publishAndSaveWalletSettings(newSettings);
return publishAndSaveWalletSettings(newSettings, true);
}

export const publishAndSaveWalletSettings = async (
proposedSettings: WalletNotificationSettings[],
skipPreSave: boolean = false
): Promise<void> => {
): Promise<boolean> => {
if (!skipPreSave) {
setAllNotificationSettingsToStorage(proposedSettings);
}
const finalizedSettings = await publishWalletSettings(proposedSettings);
if (finalizedSettings) {
setAllNotificationSettingsToStorage(finalizedSettings);
return true;
}
return false;
};

0 comments on commit cbd8978

Please sign in to comment.