Skip to content

Commit

Permalink
TW-1504: [Mises] Temple ads native prompt (#1174)
Browse files Browse the repository at this point in the history
* TW-1504: [Mises] Temple ads native prompt

* TW-1504: [Mises] Temple ads native prompt. Refactor

* TW-1504: [Mises] Temple ads native prompt. + === true check
  • Loading branch information
alex-tsx authored Jul 29, 2024
1 parent 249afe0 commit 42d1c94
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/app/storage/app-install-id.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchFromStorage, putToStorage } from 'lib/storage';

const storageKey = 'APP_INSTALL_IDENTITY';
export const APP_INSTALL_IDENTITY_STORAGE_KEY = 'APP_INSTALL_IDENTITY';

interface AppInstallIdentity {
version: string;
Expand All @@ -10,7 +10,7 @@ interface AppInstallIdentity {
ts: string;
}

export const getStoredAppInstallIdentity = () => fetchFromStorage<AppInstallIdentity>(storageKey);
export const getStoredAppInstallIdentity = () => fetchFromStorage<AppInstallIdentity>(APP_INSTALL_IDENTITY_STORAGE_KEY);

export const putStoredAppInstallIdentity = (value: AppInstallIdentity) =>
putToStorage<AppInstallIdentity>(storageKey, value);
putToStorage<AppInstallIdentity>(APP_INSTALL_IDENTITY_STORAGE_KEY, value);
6 changes: 6 additions & 0 deletions src/app/storage/mises-browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { fetchFromStorage } from 'lib/storage';

export const MISES_INSTALL_ENABLED_ADS_STORAGE_KEY = 'MISES_ACCEPT_TOS';

export const getMisesInstallEnabledAds = () =>
fetchFromStorage<'true'>(MISES_INSTALL_ENABLED_ADS_STORAGE_KEY).then(r => r === 'true' || r === true);
6 changes: 5 additions & 1 deletion src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import PackageJSON from '../../package.json';

export const APP_VERSION = PackageJSON.version;

/** Only Mises browser among supported vendors counts as a mobile platform */
/**
* Only Mises browser among supported vendors counts as a mobile platform
*
* `navigator.userAgentData.brands.find(b => b.brand === 'Mises')` will be available in future versions.
*/
// @ts-expect-error
export const IS_MISES_BROWSER = Boolean(navigator.userAgentData?.mobile);

Expand Down
10 changes: 7 additions & 3 deletions src/lib/temple/reset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getStoredAppInstallIdentity, putStoredAppInstallIdentity } from 'app/storage/app-install-id';
import { APP_INSTALL_IDENTITY_STORAGE_KEY } from 'app/storage/app-install-id';
import { MISES_INSTALL_ENABLED_ADS_STORAGE_KEY } from 'app/storage/mises-browser';
import { browser } from 'lib/browser';
import * as Repo from 'lib/temple/repo';

Expand All @@ -10,9 +11,12 @@ export async function clearAllStorages() {
export async function clearAsyncStorages() {
await Repo.db.delete();
await Repo.db.open();
const appIdentity = await getStoredAppInstallIdentity();
const keptRecord = await browser.storage.local.get([
APP_INSTALL_IDENTITY_STORAGE_KEY,
MISES_INSTALL_ENABLED_ADS_STORAGE_KEY
]);
await browser.storage.local.clear();
if (appIdentity) putStoredAppInstallIdentity(appIdentity);
await browser.storage.local.set(keptRecord);
await browser.storage.session?.clear();
}

Expand Down
4 changes: 2 additions & 2 deletions src/replaceAds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import browser from 'webextension-polyfill';

import { getMisesInstallEnabledAds } from 'app/storage/mises-browser';
import { configureAds } from 'lib/ads/configure-ads';
import { importExtensionAdsModule } from 'lib/ads/import-extension-ads-module';
import {
Expand All @@ -8,7 +9,6 @@ import {
WEBSITES_ANALYTICS_ENABLED,
ADS_VIEWER_ADDRESS_STORAGE_KEY
} from 'lib/constants';
import { IS_MISES_BROWSER } from 'lib/env';
import { fetchFromStorage } from 'lib/storage';

import { getRulesFromContentScript, clearRulesCache } from './content-scripts/replace-ads';
Expand Down Expand Up @@ -60,5 +60,5 @@ async function checkIfShouldReplaceAds() {

if (accountPkhFromStorage) return await fetchFromStorage<boolean>(WEBSITES_ANALYTICS_ENABLED);

return IS_MISES_BROWSER;
return await getMisesInstallEnabledAds();
}

0 comments on commit 42d1c94

Please sign in to comment.