Skip to content

Commit

Permalink
TW-1492: Adapt ads to Mises extension (#1170)
Browse files Browse the repository at this point in the history
* TW-1492 Adapt ads to Mises extension

* TW-1492 Update @temple-wallet/extension-ads

* TW-1492 Revert project version change

* TW-1492 Additional fixtures

* TW-1492 Refactoring according to comments
  • Loading branch information
keshan3262 authored Jul 29, 2024
1 parent a4cfad4 commit 249afe0
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 60 deletions.
8 changes: 8 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@ TEMPLE_FIREBASE_CONFIG=
TEMPLE_FIREBASE_MESSAGING_VAPID_KEY=

HYPELAB_API_URL=
HYPELAB_MISES_SMALL_PLACEMENT_SLUG=
HYPELAB_SMALL_PLACEMENT_SLUG=
HYPELAB_MISES_HIGH_PLACEMENT_SLUG=
HYPELAB_HIGH_PLACEMENT_SLUG=
HYPELAB_MISES_WIDE_PLACEMENT_SLUG=
HYPELAB_WIDE_PLACEMENT_SLUG=
HYPELAB_MISES_NATIVE_PLACEMENT_SLUG=
HYPELAB_NATIVE_PLACEMENT_SLUG=
HYPELAB_PROPERTY_SLUG=
HYPELAB_ADS_WINDOW_URL=

PERSONA_ADS_API_KEY=
PERSONA_ADS_MISES_BANNER_UNIT_ID=
PERSONA_ADS_BANNER_UNIT_ID=
PERSONA_ADS_MISES_WIDE_BANNER_UNIT_ID=
PERSONA_ADS_WIDE_BANNER_UNIT_ID=
PERSONA_ADS_MISES_MEDIUM_BANNER_UNIT_ID=
PERSONA_ADS_MEDIUM_BANNER_UNIT_ID=
PERSONA_ADS_MISES_SQUARISH_BANNER_UNIT_ID=
PERSONA_ADS_SQUARISH_BANNER_UNIT_ID=

TEMPLE_ADS_ORIGIN_PASSPHRASE=
8 changes: 8 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,24 @@ jobs:
TEMPLE_FIREBASE_CONFIG: ${{ secrets.TEMPLE_FIREBASE_CONFIG }}
TEMPLE_FIREBASE_MESSAGING_VAPID_KEY: ${{ secrets.TEMPLE_FIREBASE_MESSAGING_VAPID_KEY }}
HYPELAB_API_URL: ${{ vars.HYPELAB_API_URL }}
HYPELAB_MISES_SMALL_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_SMALL_PLACEMENT_SLUG }}
HYPELAB_SMALL_PLACEMENT_SLUG: ${{ vars.HYPELAB_SMALL_PLACEMENT_SLUG }}
HYPELAB_MISES_HIGH_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_HIGH_PLACEMENT_SLUG }}
HYPELAB_HIGH_PLACEMENT_SLUG: ${{ vars.HYPELAB_HIGH_PLACEMENT_SLUG }}
HYPELAB_MISES_WIDE_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_WIDE_PLACEMENT_SLUG }}
HYPELAB_WIDE_PLACEMENT_SLUG: ${{ vars.HYPELAB_WIDE_PLACEMENT_SLUG }}
HYPELAB_MISES_NATIVE_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_NATIVE_PLACEMENT_SLUG }}
HYPELAB_NATIVE_PLACEMENT_SLUG: ${{ vars.HYPELAB_NATIVE_PLACEMENT_SLUG }}
HYPELAB_PROPERTY_SLUG: ${{ vars.HYPELAB_PROPERTY_SLUG }}
HYPELAB_ADS_WINDOW_URL: ${{ vars.HYPELAB_ADS_WINDOW_URL }}
PERSONA_ADS_API_KEY: ${{ vars.PERSONA_ADS_API_KEY }}
PERSONA_ADS_MISES_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_BANNER_UNIT_ID }}
PERSONA_ADS_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_WIDE_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_WIDE_BANNER_UNIT_ID }}
PERSONA_ADS_WIDE_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_WIDE_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_MEDIUM_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_MEDIUM_BANNER_UNIT_ID }}
PERSONA_ADS_MEDIUM_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MEDIUM_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_SQUARISH_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_SQUARISH_BANNER_UNIT_ID }}
PERSONA_ADS_SQUARISH_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_SQUARISH_BANNER_UNIT_ID }}
TEMPLE_ADS_ORIGIN_PASSPHRASE: ${{ vars.TEMPLE_ADS_ORIGIN_PASSPHRASE }}
CONVERSION_VERIFICATION_URL: ${{ vars.CONVERSION_VERIFICATION_URL }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/manual-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,24 @@ jobs:
TEMPLE_FIREBASE_CONFIG: ${{ secrets.TEMPLE_FIREBASE_CONFIG }}
TEMPLE_FIREBASE_MESSAGING_VAPID_KEY: ${{ secrets.TEMPLE_FIREBASE_MESSAGING_VAPID_KEY }}
HYPELAB_API_URL: ${{ vars.HYPELAB_API_URL }}
HYPELAB_MISES_SMALL_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_SMALL_PLACEMENT_SLUG }}
HYPELAB_SMALL_PLACEMENT_SLUG: ${{ vars.HYPELAB_SMALL_PLACEMENT_SLUG }}
HYPELAB_MISES_HIGH_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_HIGH_PLACEMENT_SLUG }}
HYPELAB_HIGH_PLACEMENT_SLUG: ${{ vars.HYPELAB_HIGH_PLACEMENT_SLUG }}
HYPELAB_MISES_WIDE_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_WIDE_PLACEMENT_SLUG }}
HYPELAB_WIDE_PLACEMENT_SLUG: ${{ vars.HYPELAB_WIDE_PLACEMENT_SLUG }}
HYPELAB_MISES_NATIVE_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_NATIVE_PLACEMENT_SLUG }}
HYPELAB_NATIVE_PLACEMENT_SLUG: ${{ vars.HYPELAB_NATIVE_PLACEMENT_SLUG }}
HYPELAB_PROPERTY_SLUG: ${{ vars.HYPELAB_PROPERTY_SLUG }}
HYPELAB_ADS_WINDOW_URL: ${{ vars.HYPELAB_ADS_WINDOW_URL }}
PERSONA_ADS_API_KEY: ${{ vars.PERSONA_ADS_API_KEY }}
PERSONA_ADS_MISES_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_BANNER_UNIT_ID }}
PERSONA_ADS_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_WIDE_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_WIDE_BANNER_UNIT_ID }}
PERSONA_ADS_WIDE_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_WIDE_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_MEDIUM_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_MEDIUM_BANNER_UNIT_ID }}
PERSONA_ADS_MEDIUM_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MEDIUM_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_SQUARISH_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_SQUARISH_BANNER_UNIT_ID }}
PERSONA_ADS_SQUARISH_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_SQUARISH_BANNER_UNIT_ID }}
TEMPLE_ADS_ORIGIN_PASSPHRASE: ${{ vars.TEMPLE_ADS_ORIGIN_PASSPHRASE }}
CONVERSION_VERIFICATION_URL: ${{ vars.CONVERSION_VERIFICATION_URL }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,24 @@ jobs:
TEMPLE_FIREBASE_CONFIG: ${{ secrets.TEMPLE_FIREBASE_CONFIG }}
TEMPLE_FIREBASE_MESSAGING_VAPID_KEY: ${{ secrets.TEMPLE_FIREBASE_MESSAGING_VAPID_KEY }}
HYPELAB_API_URL: ${{ vars.HYPELAB_API_URL }}
HYPELAB_MISES_SMALL_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_SMALL_PLACEMENT_SLUG }}
HYPELAB_SMALL_PLACEMENT_SLUG: ${{ vars.HYPELAB_SMALL_PLACEMENT_SLUG }}
HYPELAB_MISES_HIGH_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_HIGH_PLACEMENT_SLUG }}
HYPELAB_HIGH_PLACEMENT_SLUG: ${{ vars.HYPELAB_HIGH_PLACEMENT_SLUG }}
HYPELAB_MISES_WIDE_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_WIDE_PLACEMENT_SLUG }}
HYPELAB_WIDE_PLACEMENT_SLUG: ${{ vars.HYPELAB_WIDE_PLACEMENT_SLUG }}
HYPELAB_MISES_NATIVE_PLACEMENT_SLUG: ${{ vars.HYPELAB_MISES_NATIVE_PLACEMENT_SLUG }}
HYPELAB_NATIVE_PLACEMENT_SLUG: ${{ vars.HYPELAB_NATIVE_PLACEMENT_SLUG }}
HYPELAB_PROPERTY_SLUG: ${{ vars.HYPELAB_PROPERTY_SLUG }}
HYPELAB_ADS_WINDOW_URL: ${{ vars.HYPELAB_ADS_WINDOW_URL }}
PERSONA_ADS_API_KEY: ${{ vars.PERSONA_ADS_API_KEY }}
PERSONA_ADS_MISES_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_BANNER_UNIT_ID }}
PERSONA_ADS_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_WIDE_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_WIDE_BANNER_UNIT_ID }}
PERSONA_ADS_WIDE_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_WIDE_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_MEDIUM_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_MEDIUM_BANNER_UNIT_ID }}
PERSONA_ADS_MEDIUM_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MEDIUM_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_SQUARISH_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_MISES_SQUARISH_BANNER_UNIT_ID }}
PERSONA_ADS_SQUARISH_BANNER_UNIT_ID: ${{ vars.PERSONA_ADS_SQUARISH_BANNER_UNIT_ID }}
TEMPLE_ADS_ORIGIN_PASSPHRASE: ${{ vars.TEMPLE_ADS_ORIGIN_PASSPHRASE }}
CONVERSION_VERIFICATION_URL: ${{ vars.CONVERSION_VERIFICATION_URL }}
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/secrets-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ inputs:
required: true
HYPELAB_API_URL:
required: true
HYPELAB_MISES_SMALL_PLACEMENT_SLUG:
required: true
HYPELAB_SMALL_PLACEMENT_SLUG:
required: true
HYPELAB_MISES_HIGH_PLACEMENT_SLUG:
required: true
HYPELAB_HIGH_PLACEMENT_SLUG:
required: true
HYPELAB_MISES_WIDE_PLACEMENT_SLUG:
required: true
HYPELAB_WIDE_PLACEMENT_SLUG:
required: true
HYPELAB_MISES_NATIVE_PLACEMENT_SLUG:
required: true
HYPELAB_NATIVE_PLACEMENT_SLUG:
required: true
HYPELAB_PROPERTY_SLUG:
Expand All @@ -49,12 +57,20 @@ inputs:
required: true
PERSONA_ADS_API_KEY:
required: true
PERSONA_ADS_MISES_BANNER_UNIT_ID:
required: true
PERSONA_ADS_BANNER_UNIT_ID:
required: true
PERSONA_ADS_MISES_WIDE_BANNER_UNIT_ID:
required: true
PERSONA_ADS_WIDE_BANNER_UNIT_ID:
required: true
PERSONA_ADS_MISES_MEDIUM_BANNER_UNIT_ID:
required: true
PERSONA_ADS_MEDIUM_BANNER_UNIT_ID:
required: true
PERSONA_ADS_MISES_SQUARISH_BANNER_UNIT_ID:
required: true
PERSONA_ADS_SQUARISH_BANNER_UNIT_ID:
required: true
CONVERSION_VERIFICATION_URL:
Expand Down Expand Up @@ -132,17 +148,25 @@ runs:
TEMPLE_FIREBASE_MESSAGING_VAPID_KEY=${{ inputs.TEMPLE_FIREBASE_MESSAGING_VAPID_KEY }}
HYPELAB_API_URL=${{ inputs.HYPELAB_API_URL }}
HYPELAB_MISES_SMALL_PLACEMENT_SLUG=${{ inputs.HYPELAB_MISES_SMALL_PLACEMENT_SLUG }}
HYPELAB_SMALL_PLACEMENT_SLUG=${{ inputs.HYPELAB_SMALL_PLACEMENT_SLUG }}
HYPELAB_MISES_HIGH_PLACEMENT_SLUG=${{ inputs.HYPELAB_MISES_HIGH_PLACEMENT_SLUG }}
HYPELAB_HIGH_PLACEMENT_SLUG=${{ inputs.HYPELAB_HIGH_PLACEMENT_SLUG }}
HYPELAB_MISES_WIDE_PLACEMENT_SLUG=${{ inputs.HYPELAB_MISES_WIDE_PLACEMENT_SLUG }}
HYPELAB_WIDE_PLACEMENT_SLUG=${{ inputs.HYPELAB_WIDE_PLACEMENT_SLUG }}
HYPELAB_MISES_NATIVE_PLACEMENT_SLUG=${{ inputs.HYPELAB_MISES_NATIVE_PLACEMENT_SLUG }}
HYPELAB_NATIVE_PLACEMENT_SLUG=${{ inputs.HYPELAB_NATIVE_PLACEMENT_SLUG }}
HYPELAB_PROPERTY_SLUG=${{ inputs.HYPELAB_PROPERTY_SLUG }}
HYPELAB_ADS_WINDOW_URL=${{ inputs.HYPELAB_ADS_WINDOW_URL }}
PERSONA_ADS_API_KEY=${{ inputs.PERSONA_ADS_API_KEY }}
PERSONA_ADS_MISES_BANNER_UNIT_ID=${{ inputs.PERSONA_ADS_MISES_BANNER_UNIT_ID }}
PERSONA_ADS_BANNER_UNIT_ID=${{ inputs.PERSONA_ADS_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_WIDE_BANNER_UNIT_ID=${{ inputs.PERSONA_ADS_MISES_WIDE_BANNER_UNIT_ID }}
PERSONA_ADS_WIDE_BANNER_UNIT_ID=${{ inputs.PERSONA_ADS_WIDE_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_MEDIUM_BANNER_UNIT_ID=${{ inputs.PERSONA_ADS_MISES_MEDIUM_BANNER_UNIT_ID }}
PERSONA_ADS_MEDIUM_BANNER_UNIT_ID=${{ inputs.PERSONA_ADS_MEDIUM_BANNER_UNIT_ID }}
PERSONA_ADS_MISES_SQUARISH_BANNER_UNIT_ID=${{ inputs.PERSONA_ADS_MISES_SQUARISH_BANNER_UNIT_ID }}
PERSONA_ADS_SQUARISH_BANNER_UNIT_ID=${{ inputs.PERSONA_ADS_SQUARISH_BANNER_UNIT_ID }}
TEMPLE_ADS_ORIGIN_PASSPHRASE=${{ inputs.TEMPLE_ADS_ORIGIN_PASSPHRASE }}
CONVERSION_VERIFICATION_URL=${{ inputs.CONVERSION_VERIFICATION_URL }}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,6 @@
"follow-redirects": "^1.15.4"
},
"optionalDependencies": {
"@temple-wallet/extension-ads": "^6.3.2"
"@temple-wallet/extension-ads": "^7.1.0"
}
}
Binary file added public/misc/ad-banners/small-tkey-inpage-ad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/content-scripts/replace-ads/ads-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const getRulesFromContentScript = memoizee(
adPlacesRules: [],
permanentAdPlacesRules: [],
providersSelectors: [],
providersNegativeSelectors: [],
elementsToHideOrRemoveRules: [],
timestamp: 0
};
}
Expand Down
36 changes: 3 additions & 33 deletions src/content-scripts/replace-ads/persona-ad.iframe.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { getPersonaAdClient, PERSONA_STAGING_ADS_BANNER_UNIT_ID } from 'lib/ads/persona';
import { ADS_VIEWER_ADDRESS_STORAGE_KEY } from 'lib/constants';
import { EnvVars } from 'lib/env';
import { fetchFromStorage } from 'lib/storage';

type PersonaAdShape = 'regular' | 'medium' | 'wide' | 'squarish';

const CONTAINER_ID = 'container';

const usp = new URLSearchParams(window.location.search);
const id = usp.get('id');
const shape = usp.get('shape');
const slug = usp.get('slug') ?? PERSONA_STAGING_ADS_BANNER_UNIT_ID;

fetchFromStorage<string>(ADS_VIEWER_ADDRESS_STORAGE_KEY)
.then(accountPkhFromStorage => getPersonaAdClient(accountPkhFromStorage))
.then(({ client, environment }) => {
const adUnitId = getUnitId(shape as PersonaAdShape, environment === 'staging');

.then(({ client }) => {
return client.showBannerAd(
// @ts-expect-error // for missung `adConfig` prop
{ adUnitId, containerId: CONTAINER_ID },
{ adUnitId: slug, containerId: CONTAINER_ID },
errorMsg => {
throw new Error(String(errorMsg));
}
Expand All @@ -37,28 +32,3 @@ const postMessage = (message: object) =>
JSON.stringify({ ...message, id }),
'*' // This is required
);

const getUnitId = (shape: PersonaAdShape, isStaging: boolean) => {
if (isStaging)
switch (shape) {
case 'wide':
return '3a094192-4c7b-4761-a50c-bd9b6a67e987';
case 'medium':
return 'cf20c750-2fe4-4761-861f-b73b2247fd4d';
case 'squarish':
return 'bf498e26-eb16-4e35-8954-e65690f28819';
default:
return PERSONA_STAGING_ADS_BANNER_UNIT_ID;
}

switch (shape) {
case 'wide':
return EnvVars.PERSONA_ADS_WIDE_BANNER_UNIT_ID;
case 'medium':
return EnvVars.PERSONA_ADS_MEDIUM_BANNER_UNIT_ID;
case 'squarish':
return EnvVars.PERSONA_ADS_SQUARISH_BANNER_UNIT_ID;
default:
return EnvVars.PERSONA_ADS_BANNER_UNIT_ID;
}
};
Loading

0 comments on commit 249afe0

Please sign in to comment.