From 0fe329e815e88aa2981b75b15772d0855059738c Mon Sep 17 00:00:00 2001 From: lendihop Date: Mon, 23 Dec 2024 13:52:40 +0100 Subject: [PATCH] rm optimal --- src/app/hooks/use-load-partners-promo.ts | 34 ------- .../Home/OtherComponents/Tokens/Tokens.tsx | 4 - src/app/store/partners-promotion/actions.ts | 12 --- src/app/store/partners-promotion/epics.ts | 22 ----- src/app/store/partners-promotion/reducers.ts | 16 +--- src/app/store/partners-promotion/selectors.ts | 2 - .../store/partners-promotion/state.mock.ts | 23 +---- src/app/store/partners-promotion/state.ts | 7 -- src/app/store/root-state.epics.ts | 2 - src/app/templates/activity/Activity.tsx | 2 - .../components/optimal-promotion.tsx | 93 ------------------- .../templates/partners-promotion/index.tsx | 16 +--- src/lib/ads/index.ts | 1 - src/lib/apis/optimal.ts | 65 ------------- .../components/notifications/index.tsx | 2 - 15 files changed, 4 insertions(+), 297 deletions(-) delete mode 100644 src/app/hooks/use-load-partners-promo.ts delete mode 100644 src/app/store/partners-promotion/epics.ts delete mode 100644 src/app/templates/partners-promotion/components/optimal-promotion.tsx delete mode 100644 src/lib/apis/optimal.ts diff --git a/src/app/hooks/use-load-partners-promo.ts b/src/app/hooks/use-load-partners-promo.ts deleted file mode 100644 index 62525497c3..0000000000 --- a/src/app/hooks/use-load-partners-promo.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { useEffect } from 'react'; - -import { useDispatch } from 'react-redux'; - -import { useAppEnv } from 'app/env'; -import { loadPartnersPromoAction } from 'app/store/partners-promotion/actions'; -import { useShouldShowPartnersPromoSelector } from 'app/store/partners-promotion/selectors'; -import { OptimalPromoVariantEnum } from 'lib/apis/optimal'; -import { useAccountPkh } from 'lib/temple/front'; - -/** - * Loads partners promo if it should be shown - * @param variant If specified, will be used instead of the default value. The default value is - * `OptimalPromoVariantEnum.Fullview` for full view and `OptimalPromoVariantEnum.Popup` for popup. - */ -export const useLoadPartnersPromo = (variant?: OptimalPromoVariantEnum) => { - const { popup } = useAppEnv(); - const accountAddress = useAccountPkh(); - const shouldShowPartnersPromoState = useShouldShowPartnersPromoSelector(); - const dispatch = useDispatch(); - - const finalVariant = variant ?? (popup ? OptimalPromoVariantEnum.Popup : OptimalPromoVariantEnum.Fullview); - - useEffect(() => { - if (shouldShowPartnersPromoState) { - dispatch( - loadPartnersPromoAction.submit({ - optimalPromoVariantEnum: finalVariant, - accountAddress - }) - ); - } - }, [shouldShowPartnersPromoState, accountAddress, dispatch, finalVariant]); -}; diff --git a/src/app/pages/Home/OtherComponents/Tokens/Tokens.tsx b/src/app/pages/Home/OtherComponents/Tokens/Tokens.tsx index ee4f1312de..7f22b6d948 100644 --- a/src/app/pages/Home/OtherComponents/Tokens/Tokens.tsx +++ b/src/app/pages/Home/OtherComponents/Tokens/Tokens.tsx @@ -6,7 +6,6 @@ import clsx from 'clsx'; import { SyncSpinner, Divider, Checkbox } from 'app/atoms'; import DropdownWrapper from 'app/atoms/DropdownWrapper'; import { useAppEnv } from 'app/env'; -import { useLoadPartnersPromo } from 'app/hooks/use-load-partners-promo'; import { useTokensListingLogic } from 'app/hooks/use-tokens-listing-logic'; import { ReactComponent as EditingIcon } from 'app/icons/editing.svg'; import { ReactComponent as SearchIcon } from 'app/icons/search.svg'; @@ -21,7 +20,6 @@ import { ButtonForManageDropdown } from 'app/templates/ManageDropdown'; import { PartnersPromotion, PartnersPromotionVariant } from 'app/templates/partners-promotion'; import SearchAssetField from 'app/templates/SearchAssetField'; import { setTestID } from 'lib/analytics'; -import { OptimalPromoVariantEnum } from 'lib/apis/optimal'; import { TEZ_TOKEN_SLUG, TEMPLE_TOKEN_SLUG } from 'lib/assets'; import { useEnabledAccountTokensSlugs } from 'lib/assets/hooks'; import { RECENT_TERMS_VERSION } from 'lib/constants'; @@ -118,8 +116,6 @@ export const TokensTab = memo(() => { return tokensJsx; }, [filteredAssets, activeAssetSlug, publicKeyHash, mainnetTokensScamSlugsRecord]); - useLoadPartnersPromo(OptimalPromoVariantEnum.Token); - useEffect(() => { if (activeIndex !== 0 && activeIndex >= filteredAssets.length) { setActiveIndex(0); diff --git a/src/app/store/partners-promotion/actions.ts b/src/app/store/partners-promotion/actions.ts index 77fa7356a3..b60c261e1e 100644 --- a/src/app/store/partners-promotion/actions.ts +++ b/src/app/store/partners-promotion/actions.ts @@ -1,22 +1,10 @@ import { createAction } from '@reduxjs/toolkit'; -import { OptimalPromotionType, OptimalPromoVariantEnum } from 'lib/apis/optimal'; -import { createActions } from 'lib/store'; - interface HidePromotionActionPayload { id: string; timestamp: number; } -export const loadPartnersPromoAction = createActions< - { - optimalPromoVariantEnum: OptimalPromoVariantEnum; - accountAddress: string; - }, - OptimalPromotionType, - string ->('partnersPromo/LOAD_PARTNERS'); - export const togglePartnersPromotionAction = createAction('partnersPromo/TOGGLE_PARTNERS_PROMO'); export const hidePromotionAction = createAction('advertising/PROMOTION_HIDING'); diff --git a/src/app/store/partners-promotion/epics.ts b/src/app/store/partners-promotion/epics.ts deleted file mode 100644 index 9ff6210593..0000000000 --- a/src/app/store/partners-promotion/epics.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { combineEpics, Epic } from 'redux-observable'; -import { of } from 'rxjs'; -import { catchError, map, switchMap } from 'rxjs/operators'; -import { ofType, toPayload } from 'ts-action-operators'; - -import { getOptimalPromotionImage$ } from 'lib/apis/optimal'; - -import { loadPartnersPromoAction } from './actions'; - -const loadPartnersPromotionEpic: Epic = action$ => - action$.pipe( - ofType(loadPartnersPromoAction.submit), - toPayload(), - switchMap(({ optimalPromoVariantEnum, accountAddress }) => - getOptimalPromotionImage$(optimalPromoVariantEnum, accountAddress).pipe( - map(optimalPromo => loadPartnersPromoAction.success(optimalPromo)), - catchError(() => of(loadPartnersPromoAction.fail('Promotion loading failed'))) - ) - ) - ); - -export const partnersPromotionEpics = combineEpics(loadPartnersPromotionEpic); diff --git a/src/app/store/partners-promotion/reducers.ts b/src/app/store/partners-promotion/reducers.ts index 28af1dc2d4..7bfcaa4cd7 100644 --- a/src/app/store/partners-promotion/reducers.ts +++ b/src/app/store/partners-promotion/reducers.ts @@ -3,24 +3,12 @@ import { persistReducer } from 'redux-persist'; import hardSet from 'redux-persist/lib/stateReconciler/hardSet'; import { AD_HIDING_TIMEOUT } from 'lib/constants'; -import { createEntity, storageConfig } from 'lib/store'; +import { storageConfig } from 'lib/store'; -import { hidePromotionAction, loadPartnersPromoAction, togglePartnersPromotionAction } from './actions'; +import { hidePromotionAction, togglePartnersPromotionAction } from './actions'; import { partnersPromotionInitialState, PartnersPromotionState } from './state'; const partnersPromotionReducer = createReducer(partnersPromotionInitialState, builder => { - builder.addCase(loadPartnersPromoAction.submit, state => ({ - ...state, - promotion: createEntity(state.promotion.data, true) - })); - builder.addCase(loadPartnersPromoAction.success, (state, { payload }) => ({ - ...state, - promotion: createEntity(payload, false) - })); - builder.addCase(loadPartnersPromoAction.fail, (state, { payload }) => ({ - ...state, - promotion: createEntity(state.promotion.data, false, payload) - })); builder.addCase(togglePartnersPromotionAction, (state, { payload }) => ({ ...state, shouldShowPromotion: payload, diff --git a/src/app/store/partners-promotion/selectors.ts b/src/app/store/partners-promotion/selectors.ts index 1ef6ee51f4..72a4844ea0 100644 --- a/src/app/store/partners-promotion/selectors.ts +++ b/src/app/store/partners-promotion/selectors.ts @@ -1,7 +1,5 @@ import { useSelector } from '..'; -export const usePartnersPromoSelector = () => useSelector(state => state.partnersPromotion.promotion); - export const useShouldShowPartnersPromoSelector = () => useSelector(({ partnersPromotion }) => partnersPromotion.shouldShowPromotion); diff --git a/src/app/store/partners-promotion/state.mock.ts b/src/app/store/partners-promotion/state.mock.ts index 5bd63afc3c..39401d72d4 100644 --- a/src/app/store/partners-promotion/state.mock.ts +++ b/src/app/store/partners-promotion/state.mock.ts @@ -1,29 +1,8 @@ -import { createEntity, mockPersistedState } from 'lib/store'; +import { mockPersistedState } from 'lib/store'; import type { PartnersPromotionState } from './state'; -export const mockPartnersPromotion = { - body: '', - campaign_type: '', - copy: { - headline: '', - cta: '', - content: '' - }, - display_type: '', - div_id: '', - html: [], - id: '', - image: '', - link: '', - nonce: '', - text: '', - view_time_url: '', - view_url: '' -}; - export const mockPartnersPromotionState = mockPersistedState({ - promotion: createEntity(mockPartnersPromotion), shouldShowPromotion: true, promotionHidingTimestamps: {} }); diff --git a/src/app/store/partners-promotion/state.ts b/src/app/store/partners-promotion/state.ts index f33db369d6..b38ce0bd2c 100644 --- a/src/app/store/partners-promotion/state.ts +++ b/src/app/store/partners-promotion/state.ts @@ -1,16 +1,9 @@ -import { OptimalPromotionType } from 'lib/apis/optimal'; -import { LoadableEntityState, createEntity } from 'lib/store'; - -import { mockPartnersPromotion } from './state.mock'; - export interface PartnersPromotionState { - promotion: LoadableEntityState; shouldShowPromotion: boolean; promotionHidingTimestamps: StringRecord; } export const partnersPromotionInitialState: PartnersPromotionState = { - promotion: createEntity(mockPartnersPromotion), shouldShowPromotion: false, promotionHidingTimestamps: {} }; diff --git a/src/app/store/root-state.epics.ts b/src/app/store/root-state.epics.ts index 48476c31a3..6472d1c665 100644 --- a/src/app/store/root-state.epics.ts +++ b/src/app/store/root-state.epics.ts @@ -12,7 +12,6 @@ import { buyWithCreditCardEpics } from './buy-with-credit-card/epics'; import { collectiblesEpics } from './collectibles/epics'; import { collectiblesMetadataEpics } from './collectibles-metadata/epics'; import { currencyEpics } from './currency/epics'; -import { partnersPromotionEpics } from './partners-promotion/epics'; import type { RootState } from './root-state.type'; import { swapEpics } from './swap/epics'; import { tokensMetadataEpics } from './tokens-metadata/epics'; @@ -22,7 +21,6 @@ const allEpics = combineEpics( advertisingEpics, notificationsEpics, swapEpics, - partnersPromotionEpics, balancesEpics, assetsEpics, tokensMetadataEpics, diff --git a/src/app/templates/activity/Activity.tsx b/src/app/templates/activity/Activity.tsx index de58919da5..76aad1c90b 100644 --- a/src/app/templates/activity/Activity.tsx +++ b/src/app/templates/activity/Activity.tsx @@ -5,7 +5,6 @@ import InfiniteScroll from 'react-infinite-scroll-component'; import { SyncSpinner } from 'app/atoms'; import { useAppEnv } from 'app/env'; -import { useLoadPartnersPromo } from 'app/hooks/use-load-partners-promo'; import { ReactComponent as LayersIcon } from 'app/icons/layers.svg'; import { useShouldShowPartnersPromoSelector } from 'app/store/partners-promotion/selectors'; import { PartnersPromotion, PartnersPromotionVariant } from 'app/templates/partners-promotion'; @@ -32,7 +31,6 @@ export const ActivityComponent: React.FC = ({ assetSlug }) => { const { publicKeyHash: accountAddress } = useAccount(); const shouldShowPartnersPromo = useShouldShowPartnersPromoSelector(); - useLoadPartnersPromo(); const promotion = useMemo(() => { if (shouldShowPartnersPromo) diff --git a/src/app/templates/partners-promotion/components/optimal-promotion.tsx b/src/app/templates/partners-promotion/components/optimal-promotion.tsx deleted file mode 100644 index 627c6a6bca..0000000000 --- a/src/app/templates/partners-promotion/components/optimal-promotion.tsx +++ /dev/null @@ -1,93 +0,0 @@ -import React, { memo, useCallback, useEffect, useRef, useState } from 'react'; - -import { useAdTimeout } from 'app/hooks/ads/use-ad-timeout'; -import { usePartnersPromoSelector } from 'app/store/partners-promotion/selectors'; -import { AdsProviderTitle } from 'lib/ads'; -import { isEmptyPromotion } from 'lib/apis/optimal'; -import { useTimeout } from 'lib/ui/hooks'; - -import { PartnersPromotionVariant, SingleProviderPromotionProps } from '../types'; - -import { ImagePromotionView } from './image-promotion-view'; -import { TextPromotionView } from './text-promotion-view'; - -export const OptimalPromotion = memo( - ({ isVisible, variant, pageName, onAdRectSeen, onClose, onReady, onError }) => { - const [isImageBroken, setIsImageBroken] = useState(false); - const [wasLoading, setWasLoading] = useState(false); - const [shouldPreventShowingPrevAd, setShouldPreventShowingPrevAd] = useState(true); - const { data: promo, error: errorFromStore, isLoading } = usePartnersPromoSelector(); - const prevIsLoadingRef = useRef(isLoading); - const promotionIsEmpty = isEmptyPromotion(promo); - const apiQueryFailed = (errorFromStore || promotionIsEmpty) && wasLoading; - - useAdTimeout((!errorFromStore && !promotionIsEmpty) || isLoading, onError, 2000); - - useEffect(() => { - if (wasLoading) { - setShouldPreventShowingPrevAd(false); - } - }, [wasLoading]); - useTimeout(() => setShouldPreventShowingPrevAd(false), 2000); - - useEffect(() => { - if (!isLoading && prevIsLoadingRef.current) { - setWasLoading(true); - } - prevIsLoadingRef.current = isLoading; - }, [isLoading]); - - useEffect(() => { - if (apiQueryFailed) { - onError(); - } else if (!promotionIsEmpty && !shouldPreventShowingPrevAd) { - onReady(); - } - }, [apiQueryFailed, onError, onReady, promotionIsEmpty, shouldPreventShowingPrevAd]); - - const onImageError = useCallback(() => { - setIsImageBroken(true); - onError(); - }, [onError]); - - if (errorFromStore || promotionIsEmpty || isImageBroken || shouldPreventShowingPrevAd) { - return null; - } - - const { link: href, image: imageSrc, copy } = promo; - const { headline, content } = copy; - - const providerTitle = AdsProviderTitle.Optimal; - - if (variant === PartnersPromotionVariant.Image) { - return ( - - Partners promotion - - ); - } - - return ( - - ); - } -); diff --git a/src/app/templates/partners-promotion/index.tsx b/src/app/templates/partners-promotion/index.tsx index 81fa8c4fa6..aac3690716 100644 --- a/src/app/templates/partners-promotion/index.tsx +++ b/src/app/templates/partners-promotion/index.tsx @@ -16,7 +16,6 @@ import { postAdImpression } from 'lib/apis/ads-api'; import { AD_HIDING_TIMEOUT } from 'lib/constants'; import { HypelabPromotion } from './components/hypelab-promotion'; -import { OptimalPromotion } from './components/optimal-promotion'; import { PersonaPromotion } from './components/persona-promotion'; import styles from './partners-promotion.module.css'; import { PartnersPromotionVariant } from './types'; @@ -48,7 +47,7 @@ export const PartnersPromotion = memo(({ variant, id, pa const isAnalyticsSentRef = useRef(false); const [isHiddenTemporarily, setIsHiddenTemporarily] = useState(shouldBeHiddenTemporarily(hiddenAt)); - const [providerName, setProviderName] = useState('Optimal'); + const [providerName, setProviderName] = useState('HypeLab'); const [adError, setAdError] = useState(false); const [adIsReady, setAdIsReady] = useState(false); @@ -85,7 +84,6 @@ export const PartnersPromotion = memo(({ variant, id, pa [id, dispatch] ); - const handleOptimalError = useCallback(() => setProviderName('HypeLab'), []); const handleHypelabError = useCallback( () => (withPersonaProvider ? setProviderName('Persona') : setAdError(true)), [withPersonaProvider] @@ -107,18 +105,6 @@ export const PartnersPromotion = memo(({ variant, id, pa > {(() => { switch (providerName) { - case 'Optimal': - return ( - - ); case 'HypeLab': return ( ; -type NormalPromotion = { - body: string; - campaign_type: string; - copy: { - headline: string; - cta: string; - content: string; - }; - display_type: string; - div_id: string; - html: Array; - id: string; - image: string; - link: string; - nonce: string; - text: string; - view_time_url: string; - view_url: string; -}; - -export type OptimalPromotionType = EmptyPromotion | NormalPromotion; - -export function isEmptyPromotion(promotion: OptimalPromotionType): promotion is EmptyPromotion { - return !('link' in promotion && 'image' in promotion && 'copy' in promotion); -} - -export const getOptimalPromotionImage$ = (variant: OptimalPromoVariantEnum, accountAddress: string) => - from( - optimalApi - .get('api/v1/decision', { - params: { - publisher: 'templewallet', // your-publisher-slug - ad_types: variant, - div_ids: 'ad', - wallets: `1729:${accountAddress}` - } - }) - .then(response => { - const { data } = response; - assertIsObject(data); - - return data; - }) - ); - -function assertIsObject(likelyAnObject: unknown): void { - const isObject = typeof likelyAnObject === 'object' && likelyAnObject !== null && !Array.isArray(likelyAnObject); - - if (!isObject) { - throw new Error('Received value is not an object'); - } -} diff --git a/src/lib/notifications/components/notifications/index.tsx b/src/lib/notifications/components/notifications/index.tsx index 322fce0779..8230c4bb82 100644 --- a/src/lib/notifications/components/notifications/index.tsx +++ b/src/lib/notifications/components/notifications/index.tsx @@ -3,7 +3,6 @@ import React, { useCallback } from 'react'; import { useDispatch } from 'react-redux'; import { DataPlaceholder } from 'app/atoms'; -import { useLoadPartnersPromo } from 'app/hooks/use-load-partners-promo'; import PageLayout from 'app/layouts/PageLayout'; import { useShouldShowPartnersPromoSelector } from 'app/store/partners-promotion/selectors'; import { PartnersPromotion, PartnersPromotionVariant } from 'app/templates/partners-promotion'; @@ -26,7 +25,6 @@ export const Notifications = () => { const viewAllNotifications = useCallback(() => void dispatch(viewAllNotificationsAction()), [dispatch]); useTimeout(viewAllNotifications, VIEW_ALL_NOTIFICATIONS_TIMEOUT, true, [notifications]); - useLoadPartnersPromo(); return (