-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-1496: [Mises] Ads impressions rework
- Loading branch information
Showing
16 changed files
with
155 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fetchFromStorage, putToStorage, removeFromStorage } from 'lib/storage'; | ||
|
||
const storageKey = 'APP_INSTALL_IDENTITY'; | ||
|
||
export interface AppInstallIdentity { | ||
version: string; | ||
/** TODO: Encrypt? How? Via password, provided by some private package? */ | ||
privateKey: string; | ||
publicKey: string; | ||
publicKeyHash: string; | ||
ts: number; | ||
} | ||
|
||
export const getStoredAppInstallIdentity = () => fetchFromStorage<AppInstallIdentity>(storageKey); | ||
|
||
export const putStoredAppInstallIdentity = (value: AppInstallIdentity) => | ||
putToStorage<AppInstallIdentity>(storageKey, value); | ||
|
||
export const removeStoredAppInstallIdentity = () => removeFromStorage(storageKey); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { InMemorySigner } from '@taquito/signer'; | ||
|
||
import { getStoredAppInstallIdentity } from 'app/storage/app-install-id'; | ||
import { postLinkAdsImpressions } from 'lib/apis/ads-api'; | ||
import { stringToHex } from 'lib/utils'; | ||
|
||
export async function performLinkingOfAdsImpressions(accountPkh: string) { | ||
const identity = await getStoredAppInstallIdentity(); | ||
if (!identity) throw new Error('App identity not found'); | ||
|
||
const { | ||
privateKey, | ||
// Actual installId will be derived by the API | ||
publicKey: installId | ||
} = identity; | ||
|
||
const signer = new InMemorySigner(privateKey); | ||
|
||
const msgBytes = stringToHex('LINK_ADS_IMPRESSIONS'); | ||
|
||
const signature = (await signer.sign(msgBytes)).sig; | ||
|
||
await postLinkAdsImpressions(accountPkh, installId, signature); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import axiosFetchAdapter from '@vespaiach/axios-fetch-adapter'; | ||
import axios from 'axios'; | ||
|
||
import { EnvVars } from 'lib/env'; | ||
|
||
export const axiosClient = axios.create({ | ||
baseURL: EnvVars.TEMPLE_ADS_API_URL, | ||
adapter: axiosFetchAdapter | ||
}); | ||
|
||
export async function postAdImpression(accountPkh: string, url: string, provider: string) { | ||
await axiosClient.post('/impression', { accountPkh, url, provider }); | ||
} | ||
|
||
export async function postAnonymousAdImpression(installId: string, url: string, provider: string) { | ||
await axiosClient.post('/impression', { installId, url, provider }); | ||
} | ||
|
||
export async function postLinkAdsImpressions(accountPkh: string, installId: string, signature: string) { | ||
await axiosClient.post('/link-impressions', { accountPkh, installId, signature }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters