From 8f4411fb4f60129ff22fa5da23e872ed0d3492b9 Mon Sep 17 00:00:00 2001 From: XiaoYhun Date: Fri, 6 Oct 2023 13:49:24 +0700 Subject: [PATCH 1/4] fix kyberai banner --- src/components/KyberAITokenBanner/index.tsx | 58 ++++++------------- src/components/SelectV2.tsx | 56 ++++++++---------- .../MultipleChainSelectV2/index.tsx | 2 +- .../TrueSightV2/components/SimpleTooltip.tsx | 1 + .../components/TokenFilter/index.tsx | 4 +- .../TrueSightV2/hooks/useKyberAIData.tsx | 3 +- .../TrueSightV2/pages/TokenAnalysisList.tsx | 3 +- src/pages/TrueSightV2/types/index.tsx | 31 ++++++++++ 8 files changed, 78 insertions(+), 80 deletions(-) diff --git a/src/components/KyberAITokenBanner/index.tsx b/src/components/KyberAITokenBanner/index.tsx index 7f4696f0f7..b4662bcd10 100644 --- a/src/components/KyberAITokenBanner/index.tsx +++ b/src/components/KyberAITokenBanner/index.tsx @@ -20,7 +20,6 @@ import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel' import useTheme from 'hooks/useTheme' import KyberScoreMeter from 'pages/TrueSightV2/components/KyberScoreMeter' import { NETWORK_TO_CHAINID } from 'pages/TrueSightV2/constants' -import { SUPPORTED_NETWORK_KYBERAI } from 'pages/TrueSightV2/constants/index' import { useTokenOverviewQuery } from 'pages/TrueSightV2/hooks/useKyberAIData' import { calculateValueToColor } from 'pages/TrueSightV2/utils' import { useIsWhiteListKyberAI, useShowKyberAIBanner } from 'state/user/hooks' @@ -36,7 +35,6 @@ const KyberAITokenBanner = ({ const { chainId, account } = useActiveWeb3React() const { isWhiteList } = useIsWhiteListKyberAI() const isShowKyberAIBanner = useShowKyberAIBanner() - const { mixpanelHandler } = useMixpanel() const chain = Object.keys(NETWORK_TO_CHAINID).find(i => NETWORK_TO_CHAINID[i] === chainId) const above768 = useMedia(`(min-width:${MEDIA_WIDTHS.upToSmall}px)`) @@ -68,7 +66,7 @@ const KyberAITokenBanner = ({ { skip: !account || !isWhiteList || !chain || !isShowKyberAIBanner, refetchOnMountOrArgChange: true }, ) - const token: { kyberScore?: number; label?: string; address?: string; logo?: string; symbol?: string } | undefined = + const token: { kyberScore?: number; label?: string; assetId?: number; logo?: string; symbol?: string } | undefined = useMemo(() => { if (staticMode) { return undefined @@ -88,7 +86,7 @@ const KyberAITokenBanner = ({ return { kyberScore: token?.kyberScore?.score, label: token?.kyberScore?.label, - address: '', //todo + assetId: token?.assetId, logo: token?.logo, symbol: token?.symbol, } @@ -99,24 +97,23 @@ const KyberAITokenBanner = ({ if (staticMode && isStableCoin(currencyIn?.wrapped.address.toLowerCase())) return null const staticModeCurrency = !currencyIn || KNC[chainId].equals(currencyIn) ? NativeCurrencies[chainId] : currencyIn const color = staticMode ? theme.primary : calculateValueToColor(token?.kyberScore || 0, theme) + + const handleBannerClick = () => { + if (staticMode) { + window.open(APP_PATHS.KYBERAI_ABOUT, '_blank') + } else { + if (!token) return + window.open(APP_PATHS.KYBERAI_EXPLORE + '/' + token?.assetId, '_blank') + } + mixpanelHandler(MIXPANEL_TYPE.KYBERAI_SWAP_INSIGHT_CLICK, { + input_token: token0?.symbol?.toUpperCase(), + output_token: token1?.symbol?.toUpperCase(), + }) + } return ( {above768 ? ( - { - mixpanelHandler(MIXPANEL_TYPE.KYBERAI_SWAP_INSIGHT_CLICK, { - input_token: token0?.symbol?.toUpperCase(), - output_token: token1?.symbol?.toUpperCase(), - }) - staticMode - ? window.open(APP_PATHS.KYBERAI_ABOUT, '_blank') - : window.open( - APP_PATHS.KYBERAI_EXPLORE + '/' + SUPPORTED_NETWORK_KYBERAI[chainId] + '/' + token?.address, - '_blank', - ) - }} - > + {staticMode ? ( @@ -172,19 +169,7 @@ const KyberAITokenBanner = ({ {' '} here!{' '} - { - mixpanelHandler(MIXPANEL_TYPE.KYBERAI_SWAP_INSIGHT_CLICK, { - input_token: token0?.symbol?.toUpperCase(), - output_token: token1?.symbol?.toUpperCase(), - }) - - //navigate(APP_PATHS.KYBERAI_EXPLORE + '/' + SUPPORTED_NETWORK_KYBERAI[chainId] + '/' + token?.address) - }} - /> +
@@ -193,14 +178,7 @@ const KyberAITokenBanner = ({ { - mixpanelHandler(MIXPANEL_TYPE.KYBERAI_SWAP_INSIGHT_CLICK, { - input_token: token0?.symbol?.toUpperCase(), - output_token: token1?.symbol?.toUpperCase(), - }) - // window.open( - // APP_PATHS.KYBERAI_EXPLORE + '/' + SUPPORTED_NETWORK_KYBERAI[chainId] + '/' + token?.address, - // '_blank', - // ) + handleBannerClick }} > diff --git a/src/components/SelectV2.tsx b/src/components/SelectV2.tsx index ea18a5b388..89b2257e59 100644 --- a/src/components/SelectV2.tsx +++ b/src/components/SelectV2.tsx @@ -26,12 +26,8 @@ const SelectWrapper = styled.div` ` const SelectMenu = styled(motion.div)` - position: absolute; - top: 0px; - left: 0; - right: 0; - margin: auto; border-radius: 16px; + overflow: hidden; filter: drop-shadow(0px 4px 12px rgba(0, 0, 0, 0.36)); z-index: 2; background: ${({ theme }) => theme.tabActive}; @@ -69,11 +65,6 @@ const getOptionLabel = (option: SelectOption | undefined) => { return typeof option !== 'object' ? option : option.label || option.value } -// function isElementOverflowBottom(el: HTMLElement) { -// const rect = el.getBoundingClientRect() -// return rect.bottom >= (window.innerHeight || document?.documentElement?.clientHeight) -// } - const defaultOffset: [number, number] = [0 /* skidding */, 2 /* distance */] function Select({ options = [], @@ -115,11 +106,10 @@ function Select({ useEffect(() => { if (!refMenu?.current) return - // if (!menuPlacementTop) setForceMenuPlacementTop(showMenu && isElementOverflowBottom(refMenu.current)) }, [showMenu, menuPlacementTop]) - const [referenceElement, setReferenceElement] = useState(null) + const ref = useRef(null) - useOnClickOutside(referenceElement as any, () => { + useOnClickOutside(ref, () => { setShowMenu(false) onHideMenu?.() }) @@ -132,7 +122,7 @@ function Select({ const onClick = (e: React.MouseEvent) => { e.stopPropagation() e.preventDefault() - setShowMenu(prev => !prev) + setShowMenu(false) if (item.onSelect) item.onSelect?.() else { setSelected(value) @@ -155,25 +145,18 @@ function Select({ const [popperElement, setPopperElement] = useState(null) - const { styles, update } = usePopper(referenceElement, popperElement, { + const { styles } = usePopper(ref.current, popperElement, { placement: 'bottom', strategy: 'fixed', modifiers: [{ name: 'offset', options: { offset: defaultOffset } }], }) - const updateCallback = useCallback(() => { - update?.() - }, [update]) - - useInterval(updateCallback, showMenu ? 100 : null) - return ( { - setShowMenu(!showMenu) + setShowMenu(true) }} style={style} className={className} @@ -183,17 +166,24 @@ function Select({ {showMenu && ( - - {dropdownRender ? dropdownRender(renderMenu()) : renderMenu()} - + +
{dropdownRender ? dropdownRender(renderMenu()) : renderMenu()}
+
+
)}
diff --git a/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx b/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx index 6be07bb188..6b67d01a5e 100644 --- a/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx +++ b/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx @@ -110,7 +110,7 @@ const MultipleChainSelect: React.FC = ({ className, st