diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index e19ada6545..0b9eaa7c9a 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -116,7 +116,6 @@ jobs: NODE_OPTIONS: '--max_old_space_size=4096' run: yarn build-prod - - name: Docker build and push uses: docker/build-push-action@v2 with: 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/Select.tsx b/src/components/Select.tsx deleted file mode 100644 index 3441fb4e8c..0000000000 --- a/src/components/Select.tsx +++ /dev/null @@ -1,179 +0,0 @@ -import { AnimatePresence, motion } from 'framer-motion' -import { CSSProperties, ReactNode, useEffect, useRef, useState } from 'react' -import styled from 'styled-components' - -import { useOnClickOutside } from 'hooks/useOnClickOutside' - -import { DropdownArrowIcon } from './ArrowRotate' - -const SelectWrapper = styled.div` - cursor: pointer; - border-radius: 12px; - background: ${({ theme }) => theme.buttonBlack}; - display: flex; - justify-content: space-between; - align-items: center; - position: relative; - font-size: 12px; - color: ${({ theme }) => theme.subText}; - padding: 12px; - :hover { - filter: brightness(1.2); - z-index: 10; - } -` - -const SelectMenu = styled(motion.div)` - position: absolute; - top: 40px; - left: 0; - right: 0; - margin: auto; - border-radius: 16px; - filter: drop-shadow(0px 4px 12px rgba(0, 0, 0, 0.36)); - z-index: 2; - background: ${({ theme }) => theme.tabActive}; - padding: 10px 0px; - width: max-content; -` - -const Option = styled.div<{ $selected: boolean }>` - padding: 10px 18px; - cursor: pointer; - font-size: 12px; - color: ${({ theme }) => theme.subText}; - white-space: nowrap; - &:hover { - background-color: ${({ theme }) => theme.background}; - } - font-weight: ${({ $selected }) => ($selected ? '500' : 'unset')}; -` - -const SelectedWrap = styled.div` - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - flex: 1; -` -export type SelectOption = { value?: string | number; label: ReactNode; onSelect?: () => void } - -const getOptionValue = (option: SelectOption | undefined) => { - if (!option) return '' - return typeof option !== 'object' ? option : option.value ?? '' -} -const getOptionLabel = (option: SelectOption | undefined) => { - if (!option) return '' - 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) -} - -function Select({ - options = [], - activeRender, - optionRender, - style = {}, - menuStyle = {}, - optionStyle = {}, - onChange, - value: selectedValue, - className, - forceMenuPlacementTop = false, - arrowColor, - dropdownRender, -}: { - value?: string | number - className?: string - options: SelectOption[] - dropdownRender?: (menu: ReactNode) => ReactNode - activeRender?: (selectedItem: SelectOption | undefined) => ReactNode - optionRender?: (option: SelectOption | undefined) => ReactNode - style?: CSSProperties - menuStyle?: CSSProperties - optionStyle?: CSSProperties - onChange?: (value: any) => void - forceMenuPlacementTop?: boolean - arrowColor?: string -}) { - const [selected, setSelected] = useState(getOptionValue(options?.[0])) - const [showMenu, setShowMenu] = useState(false) - const [menuPlacementTop, setForceMenuPlacementTop] = useState(forceMenuPlacementTop) - - useEffect(() => { - const findValue = options.find(item => getOptionValue(item) === selectedValue)?.value - setSelected(findValue || getOptionValue(options?.[0])) - }, [selectedValue, options]) - - useEffect(() => { - if (!refMenu?.current) return - if (!menuPlacementTop) setForceMenuPlacementTop(showMenu && isElementOverflowBottom(refMenu.current)) - }, [showMenu, menuPlacementTop]) - - const ref = useRef(null) - useOnClickOutside(ref, () => { - setShowMenu(false) - }) - const selectedInfo = options.find(item => getOptionValue(item) === selected) - const refMenu = useRef(null) - - const renderMenu = () => { - return options.map(item => { - const value = getOptionValue(item) - const onClick = (e: React.MouseEvent) => { - e.stopPropagation() - e.preventDefault() - setShowMenu(prev => !prev) - if (item.onSelect) item.onSelect?.() - else { - setSelected(value) - onChange?.(value) - } - } - return ( - - ) - }) - } - - return ( - { - setShowMenu(!showMenu) - }} - style={style} - className={className} - > - {activeRender ? activeRender(selectedInfo) : getOptionLabel(selectedInfo)} - - - {showMenu && ( - - {dropdownRender ? dropdownRender(renderMenu()) : renderMenu()} - - )} - - - ) -} - -export default styled(Select)`` diff --git a/src/pages/MyEarnings/MultipleChainSelectV2/ApplyButton.tsx b/src/components/Select/MultipleChainSelect/ApplyButton.tsx similarity index 100% rename from src/pages/MyEarnings/MultipleChainSelectV2/ApplyButton.tsx rename to src/components/Select/MultipleChainSelect/ApplyButton.tsx diff --git a/src/pages/MyEarnings/MultipleChainSelectV2/SelectButton.tsx b/src/components/Select/MultipleChainSelect/SelectButton.tsx similarity index 98% rename from src/pages/MyEarnings/MultipleChainSelectV2/SelectButton.tsx rename to src/components/Select/MultipleChainSelect/SelectButton.tsx index 9c64e2af52..3bf59f0d5c 100644 --- a/src/pages/MyEarnings/MultipleChainSelectV2/SelectButton.tsx +++ b/src/components/Select/MultipleChainSelect/SelectButton.tsx @@ -74,7 +74,6 @@ const SelectButton: React.FC = ({ selectedChainIds, chainIds, activeRende paddingRight: '8px', justifyContent: 'space-between', alignItems: 'center', - background: theme.background, userSelect: 'none', cursor: 'pointer', ...activeStyle, diff --git a/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx b/src/components/Select/MultipleChainSelect/index.tsx similarity index 96% rename from src/pages/MyEarnings/MultipleChainSelectV2/index.tsx rename to src/components/Select/MultipleChainSelect/index.tsx index 6be07bb188..23580e7505 100644 --- a/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx +++ b/src/components/Select/MultipleChainSelect/index.tsx @@ -7,7 +7,7 @@ import styled, { CSSProperties } from 'styled-components' import { ReactComponent as LogoKyber } from 'assets/svg/logo_kyber.svg' import Checkbox from 'components/CheckBox' -import Select from 'components/SelectV2' +import Select from 'components/Select' import { MouseoverTooltip } from 'components/Tooltip' import { NETWORKS_INFO } from 'constants/networks' import useChainsConfig from 'hooks/useChainsConfig' @@ -67,6 +67,14 @@ const Label = styled.span` user-select: none; ` +const StyledSelect = styled(Select)` + flex: 0 0 150px; + width: 150px; + position: relative; + border-radius: 18px; + background-color: ${({ theme }) => theme.buttonGray}; +` + const MultipleChainSelect: React.FC = ({ className, style, ...props }) => { const { comingSoonList = [], selectedChainIds = [], handleChangeChains, chainIds = [], onTracking } = props const options = chainIds.map(id => ({ value: id, label: id })) @@ -107,10 +115,10 @@ const MultipleChainSelect: React.FC = ({ className, st }, [selectedChains]) return ( -