mirror of
https://github.com/andrei0x309/yup-live-chrome-extension.git
synced 2024-11-09 18:10:57 +00:00
rf: last reward notif
This commit is contained in:
parent
3343a2ff57
commit
3e2d00e95e
@ -1,11 +1,11 @@
|
||||
import { SEND_AUTH_NOTIF } from '@/constants/messeges';
|
||||
import { initStorage } from '@/utils/storage'
|
||||
import { getStore, setProfile, setNotifStorageNotifs, setSettings, getNotifStorage, setNotifStorageLastRewardNotif } from '@/utils/storage'
|
||||
import { getStore, setProfile, setNotifStorageNotifs, setSettings, setNotifStorageLastRewardNotif, getNotifStorageLastRewardNotif } from '@/utils/storage'
|
||||
import type { Notification } from '@/utils/types';
|
||||
import { API_BASE } from '@/constants/config';
|
||||
import { getNotifications } from '@/utils/notifications';
|
||||
import { setBadge } from '@/utils/chrome-misc'
|
||||
import { closeTo, getTimeRemaining } from '@/utils/time';
|
||||
import { closeTo } from '@/utils/time';
|
||||
import { getActionUsage } from '@/utils/user';
|
||||
// Disable conflict with yup extension
|
||||
const yupExtensionId = 'nhmeoaahigiljjdkoagafdccikgojjoi'
|
||||
@ -65,18 +65,19 @@ const alarmHandler = async () => {
|
||||
if (store.settings?.chromeNotifWhenReward && notSeen.some(notif => notif.action === 'reward')) {
|
||||
const rewardNotif = notSeen.find(notif => notif.action === 'reward')
|
||||
if (rewardNotif) {
|
||||
const storeReward = (await getNotifStorage()).lastRewardNotif
|
||||
if (!storeReward || (storeReward.id !== rewardNotif._id &&
|
||||
!closeTo(new Date(storeReward.createdAt), new Date(rewardNotif.createdAt), 2e4))) {
|
||||
const storeReward = (await getNotifStorageLastRewardNotif())
|
||||
|
||||
if (!storeReward || (storeReward.id !== rewardNotif._id
|
||||
&& !closeTo(new Date(storeReward.createdAt), new Date(rewardNotif.createdAt), 2e4)
|
||||
)) {
|
||||
{
|
||||
setNotifStorageLastRewardNotif({ createdAt: rewardNotif.createdAt, id: rewardNotif._id }).then(() => {
|
||||
chrome.notifications.create({
|
||||
await setNotifStorageLastRewardNotif({ createdAt: rewardNotif.createdAt, id: rewardNotif._id });
|
||||
await chrome.notifications.create({
|
||||
type: 'basic',
|
||||
iconUrl: chrome.runtime.getURL('src/assets/icons/yup_ext_128.png'),
|
||||
title: 'Yup Live Extension',
|
||||
message: `You have been alocated a future reward of ${rewardNotif.quantity} YUP`,
|
||||
})
|
||||
}).catch(console.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,13 +51,16 @@ export const storageDefault = {
|
||||
}
|
||||
|
||||
export const storageNotifsDefault = {
|
||||
lastRewardNotif: {
|
||||
createdAt: 0,
|
||||
id: '',
|
||||
},
|
||||
notifs: []
|
||||
}
|
||||
|
||||
export const lastRewardNotifDefault = {
|
||||
createdAt: 0,
|
||||
id: '',
|
||||
}
|
||||
|
||||
|
||||
|
||||
export type StorageType = typeof storageDefault
|
||||
|
||||
export const wipeStorage = async () => {
|
||||
@ -75,12 +78,15 @@ export const initStorage = async () => {
|
||||
console.info('Storage initialized')
|
||||
}
|
||||
const notifs = await chrome.storage.local.get('notifs')
|
||||
const updateNotifs = { ...storageNotifsDefault, ...notifs }
|
||||
const updateNotifsCondition = !notifs.notifs || !notifs.lastRewardNotif
|
||||
if(updateNotifsCondition) {
|
||||
await chrome.storage.local.set({ notifs: updateNotifs })
|
||||
const lastRewardNotif = await chrome.storage.local.get('lastRewardNotif')
|
||||
if(!notifs.notifs) {
|
||||
await chrome.storage.local.set({ notifs: storageNotifsDefault })
|
||||
console.info('Notifs storage initialized')
|
||||
}
|
||||
if(!lastRewardNotif.lastRewardNotif) {
|
||||
await chrome.storage.local.set({ lastRewardNotif: lastRewardNotifDefault })
|
||||
console.info('Last reward notif storage initialized')
|
||||
}
|
||||
}
|
||||
|
||||
export const getNotifStorage = async () => {
|
||||
@ -93,9 +99,14 @@ export const setNotifStorageNotifs = async (notifs: any[]) => {
|
||||
await chrome.storage.local.set({ ...notifsStorage, notifs: notifs })
|
||||
}
|
||||
|
||||
export const getNotifStorageLastRewardNotif = async () => {
|
||||
const notifsStorage = await chrome.storage.local.get('lastRewardNotif')
|
||||
return notifsStorage ? notifsStorage.lastRewardNotif : lastRewardNotifDefault
|
||||
}
|
||||
|
||||
export const setNotifStorageLastRewardNotif = async (lastRewardNotif) => {
|
||||
const notifsStorage = await getNotifStorage()
|
||||
await chrome.storage.local.set({ ...notifsStorage, ...{ notifs: { lastRewardNotif } } })
|
||||
const lastReward = await getNotifStorageLastRewardNotif()
|
||||
chrome.storage.local.set({ lastRewardNotif: { ...lastReward, ...lastRewardNotif } })
|
||||
}
|
||||
|
||||
export const setAuth = async (auth) => {
|
||||
|
Loading…
Reference in New Issue
Block a user