Skip to content

Commit

Permalink
fix: refetch after storage clear
Browse files Browse the repository at this point in the history
  • Loading branch information
kalfada committed Aug 29, 2024
1 parent f529db6 commit 2496cd3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bringweb3/chrome-extension-kit": patch
---

Fix refetch on case someone clear the storage
15 changes: 9 additions & 6 deletions extension-files/bringweb3-sdk/bringInitBackground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const updateCache = async (apiKey: string) => {
chrome.alarms.create(UPDATE_CACHE_ALARM_NAME, {
delayInMinutes: delay
})
return res.relevantDomains
}

const checkNotifications = async (apiKey: string, tabId: number, cashbackUrl: string | undefined, isAfterActivation?: boolean) => {
Expand Down Expand Up @@ -79,9 +80,12 @@ const getDomain = (url: string) => {
return url.replace(/^(https?:\/\/)?(www\.)?/, '');
}

const getRelevantDomain = async (url: string | undefined) => {
const relevantDomains = await storage.get('relevantDomains')
console.log({ relevantDomains });
const getRelevantDomain = async (url: string | undefined, apiKey: string) => {
let relevantDomains = await storage.get('relevantDomains')

if (relevantDomains === undefined) {
relevantDomains = await updateCache(apiKey)
}

if (!url || !relevantDomains || !relevantDomains.length) return ''
const domain = getDomain(url)
Expand Down Expand Up @@ -240,7 +244,7 @@ const bringInitBackground = async ({ identifier, apiEndpoint, cashbackPagePath }
storage.set('optOut', Date.now() + time)
break;
case 'CLOSE':
const domain = await getRelevantDomain(sender.tab?.url || sender.origin)
const domain = await getRelevantDomain(sender.tab?.url || sender.origin, identifier)
if (!domain) break;
addQuietDomain(domain, time)
break;
Expand Down Expand Up @@ -270,8 +274,7 @@ const bringInitBackground = async ({ identifier, apiEndpoint, cashbackPagePath }

urlsDict[tabId] = url

const match = await getRelevantDomain(tab.url);
console.log({ match });
const match = await getRelevantDomain(tab.url, identifier);

if (!match || !match.length) {
await showNotification(identifier, tabId, cashbackPagePath)
Expand Down

0 comments on commit 2496cd3

Please sign in to comment.