diff --git a/README.md b/README.md index 6e2993f..c48e0e6 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ You must provide a valid `.env` file with the following fields: API_SERVER= API_KEY= AMPLITUDE_KEY= +PROMOTIONAL_URL= ``` ## Release diff --git a/src/helpers/showPopup.ts b/src/helpers/showPopup.ts index 887181a..df671da 100644 --- a/src/helpers/showPopup.ts +++ b/src/helpers/showPopup.ts @@ -1,4 +1,4 @@ -import { getEnableHooks, isMutedAddresses } from '../shared/storage'; +import { getEnableHooks, getPromotionCounter, isMutedAddresses, setPromotionCounter } from '../shared/storage'; import { TransactionEvent } from '../types/internal'; import { getActiveTabUrl } from './getActiveTab'; @@ -9,6 +9,8 @@ const EXTENSION_HEIGHT = 600; const FOCUS_TIMEOUT = 20; const RETRIES_COUNT = 25; +const REQUIRED_PROMOTION_COUNT = 5; + async function getPosition() { const latestWindow = await chrome.windows.getLastFocused(); @@ -68,7 +70,6 @@ export const showPopup = async (chainId: string, event: TransactionEvent) => { const searchParams = new URLSearchParams(data); const popupUrl = `walletpopup.html?${searchParams.toString()}`; - // const currentWindow = await chrome.windows.getCurrent(); const popupWindow = await chrome.windows.create({ url: popupUrl, @@ -90,9 +91,35 @@ export const showPopup = async (chainId: string, event: TransactionEvent) => { // Focus Blockfence window chrome.windows.update(popupWindow.id, { focused: true }); } + + // const currentWindow = + showPromotion(); } }; +export const showPromotion = async () => { + if (!process.env.PROMOTIONAL_URL) return; + const promotionCounter = await getPromotionCounter(); + setPromotionCounter(promotionCounter + 1); + + if (promotionCounter !== REQUIRED_PROMOTION_COUNT) { + return; + } + + const popupUrl = `process.env.PROMOTIONAL_URL`; + const { top, left } = await getPosition(); + + await chrome.windows.create({ + url: popupUrl, + type: 'popup', + top, + left, + width: 300, + height: EXTENSION_HEIGHT, + focused: true, + }); +}; + function closeWindowWithOther(targetWindowId: number, listeningWindowId: number) { function handler(tabId: number, removeInfo: chrome.tabs.TabRemoveInfo) { if (removeInfo.windowId === listeningWindowId) { diff --git a/src/shared/storage.tsx b/src/shared/storage.tsx index 8bad728..fa4387b 100644 --- a/src/shared/storage.tsx +++ b/src/shared/storage.tsx @@ -35,3 +35,12 @@ export const getPrefferedChinId = async () => { export const setPreferredChainId = async (chainId: string) => { await chrome.storage.local.set({ preferredChainId: chainId }); }; + +export const getPromotionCounter = async () => { + const storage = await chrome.storage.local.get({ counter: true }); + return storage.counter || 0; +}; + +export const setPromotionCounter = async (counter: number) => { + await chrome.storage.local.set({ counter }); +};