Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: new type of Inbox - kyber AI watch list #2264

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
638dd95
update assetId and hooks to use new params
XiaoYhun Sep 18, 2023
44713ae
wip
nguyenhoaidanh Sep 19, 2023
1538773
wip
nguyenhoaidanh Sep 19, 2023
e05a8b0
done ui, wait for api
nguyenhoaidanh Sep 19, 2023
fe55bf7
add variant select in explore page
XiaoYhun Sep 20, 2023
b60bb29
Merge branch 'main' into adapt-with-new-asset-api
XiaoYhun Sep 20, 2023
4c85b7c
revert watchlist updates
XiaoYhun Sep 20, 2023
32ebd93
fix failed errors
XiaoYhun Sep 20, 2023
b95d831
Merge remote-tracking branch 'origin/adapt-with-new-asset-api' into i…
nguyenhoaidanh Sep 20, 2023
11c0b0c
fix conflict
nguyenhoaidanh Sep 20, 2023
5b010a0
rename
nguyenhoaidanh Sep 21, 2023
6648d43
Merge branch 'main' into inbox-watchlist
nguyenhoaidanh Sep 21, 2023
81026ef
chore: move folder noti
nguyenhoaidanh Sep 24, 2023
407c892
Merge branch 'move-folter-noti' into inbox-watchlist
nguyenhoaidanh Sep 24, 2023
bc16ce4
refactor
nguyenhoaidanh Sep 24, 2023
51359f3
connect real type
nguyenhoaidanh Sep 25, 2023
49c7227
update template
nguyenhoaidanh Sep 26, 2023
95f6d3b
Merge branch 'main' into inbox-watchlist
nguyenhoaidanh Sep 26, 2023
87b8564
resolve conflict
nguyenhoaidanh Sep 26, 2023
7fbb0d0
build
nguyenhoaidanh Sep 26, 2023
1147fdf
fix: css
nguyenhoaidanh Sep 26, 2023
55ca329
fix error
nguyenhoaidanh Sep 26, 2023
376e766
fix format
nguyenhoaidanh Sep 26, 2023
ed6a628
revert
nguyenhoaidanh Sep 26, 2023
e6646ef
Merge branch 'main' into inbox-watchlist
nguyenhoaidanh Sep 26, 2023
9e20c26
Merge remote-tracking branch 'origin/main' into inbox-watchlist
nguyenhoaidanh Sep 27, 2023
8073d6f
fix: when asset too small
nguyenhoaidanh Sep 27, 2023
c5f5523
add template type
nguyenhoaidanh Sep 27, 2023
efd19a0
refactor type
nguyenhoaidanh Sep 27, 2023
0f75f8c
check for elastic pool
nguyenhoaidanh Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Announcement/AnnoucementView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export default function AnnouncementView({
height={height}
width={width}
itemCount={itemCount}
itemSize={isMyInboxTab ? 116 : 126}
itemSize={isMyInboxTab ? 120 : 126}
onItemsRendered={onItemsRendered}
ref={ref}
>
Expand Down
1 change: 1 addition & 0 deletions src/components/Announcement/PrivateAnnoucement/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const mapIcon: Partial<{ [type in PrivateAnnouncementType]: ReactNode }> = {
[PrivateAnnouncementType.LIMIT_ORDER]: <LimitOrderIcon />,
[PrivateAnnouncementType.ELASTIC_POOLS]: <LiquidityIcon />,
[PrivateAnnouncementType.KYBER_AI]: <ApeIcon size={18} />,
[PrivateAnnouncementType.KYBER_AI_WATCHLIST]: <ApeIcon size={18} />,
[PrivateAnnouncementType.PRICE_ALERT]: <AlarmIcon style={{ width: 17, height: 17 }} />,
[PrivateAnnouncementType.DIRECT_MESSAGE]: <Bell style={{ width: 17, height: 17 }} />,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Trans } from '@lingui/macro'
import { useNavigate } from 'react-router-dom'
import { Flex, Text } from 'rebass'
import styled from 'styled-components'

import { PrivateAnnouncementProp } from 'components/Announcement/PrivateAnnoucement'
import InboxIcon from 'components/Announcement/PrivateAnnoucement/Icon'
import { Dot, InboxItemRow, InboxItemWrapper, RowItem, Title } from 'components/Announcement/PrivateAnnoucement/styled'
import { AnnouncementTemplateTrendingSoon } from 'components/Announcement/type'
import { AnnouncementTemplateKyberAI } from 'components/Announcement/type'
import DiscoverIcon from 'components/Icons/DiscoverIcon'
import Icon from 'components/Icons/Icon'
import DeltaTokenAmount from 'components/WalletPopup/Transactions/DeltaTokenAmount'
import { TokenLogoWithShadow } from 'components/Logo'
import { APP_PATHS } from 'constants/index'
import useTheme from 'hooks/useTheme'

Expand All @@ -18,12 +19,31 @@ const ItemWrapper = styled.div<{ color: string }>`
gap: 4px;
color: ${({ color }) => color};
`
const TokenDetail = ({
color,
symbol,
logoURL,
fontSize,
}: {
color: string
logoURL: string
symbol: string
fontSize: string
}) => (
<Flex color={color} alignItems={'center'} sx={{ gap: '4px', fontSize }}>
<TokenLogoWithShadow srcs={[logoURL]} size={fontSize} />
{symbol}
</Flex>
)

export const TokenInfo = ({
templateBody,
type,
fontSize = '12px',
}: {
templateBody: AnnouncementTemplateTrendingSoon
templateBody: AnnouncementTemplateKyberAI
type: 'bullish' | 'bearish' | 'trending'
fontSize?: string
}) => {
const theme = useTheme()
const {
Expand All @@ -41,9 +61,12 @@ export const TokenInfo = ({
case 'bullish':
return (
<ItemWrapper color={theme.apr}>
<Icon id="bullish" size={14} /> <Trans>Bullish:</Trans>
<DeltaTokenAmount
amount={null}
<Icon id="bullish" size={14} />{' '}
<Text as="span" fontSize={fontSize}>
<Trans>Bullish:</Trans>
</Text>
<TokenDetail
fontSize={fontSize}
logoURL={bullishTokenLogoURL}
color={theme.text}
symbol={`${bullishTokenSymbol} (${bullishTokenScore})`}
Expand All @@ -53,9 +76,12 @@ export const TokenInfo = ({
case 'bearish':
return (
<ItemWrapper color={theme.red}>
<Icon id="bearish" size={12} /> <Trans>Bearish:</Trans>
<DeltaTokenAmount
amount={null}
<Icon id="bearish" size={12} />{' '}
<Text as="span" fontSize={fontSize}>
<Trans>Bearish:</Trans>
</Text>
<TokenDetail
fontSize={fontSize}
logoURL={bearishTokenLogoURL}
color={theme.text}
symbol={`${bearishTokenSymbol} (${bearishTokenScore})`}
Expand All @@ -65,9 +91,12 @@ export const TokenInfo = ({
case 'trending':
return (
<ItemWrapper color={theme.text}>
<DiscoverIcon size={12} /> <Trans>Trending Soon:</Trans>
<DeltaTokenAmount
amount={null}
<DiscoverIcon size={12} />{' '}
<Text as="span" fontSize={fontSize}>
<Trans>Trending Soon:</Trans>
</Text>
<TokenDetail
fontSize={fontSize}
logoURL={trendingSoonTokenLogoURL}
color={theme.text}
symbol={`${trendingSoonTokenSymbol} (${trendingSoonTokenScore})`}
Expand All @@ -83,7 +112,7 @@ function InboxItemBridge({
style,
time,
title,
}: PrivateAnnouncementProp<AnnouncementTemplateTrendingSoon>) {
}: PrivateAnnouncementProp<AnnouncementTemplateKyberAI>) {
const { templateBody, isRead, templateType } = announcement

const navigate = useNavigate()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { useNavigate } from 'react-router-dom'
import { Text } from 'rebass'
import styled from 'styled-components'

import { PrivateAnnouncementProp } from 'components/Announcement/PrivateAnnoucement'
import InboxIcon from 'components/Announcement/PrivateAnnoucement/Icon'
import { Dot, InboxItemRow, InboxItemWrapper, RowItem, Title } from 'components/Announcement/PrivateAnnoucement/styled'
import { AnnouncementTemplateKyberAIWatchlist, TokenInfoWatchlist } from 'components/Announcement/type'
import Column from 'components/Column'
import { TokenLogoWithShadow } from 'components/Logo'
import { APP_PATHS } from 'constants/index'
import useTheme from 'hooks/useTheme'
import { calculateValueToColor, getTypeByKyberScore } from 'pages/TrueSightV2/utils'
import { formatDisplayNumber } from 'utils/numbers'

const ItemWrapper = styled.div`
display: flex;
align-items: center;
gap: 8px;
`
export const TokenInfo = ({
showPrice = true,
logoSize = '12px',
token,
}: {
showPrice?: boolean
logoSize?: string
token: TokenInfoWatchlist
}) => {
const theme = useTheme()
const { logoURL, symbol, price, priceChange, kyberScore } = token || {}
return (
<ItemWrapper>
<TokenLogoWithShadow srcs={[logoURL]} size={logoSize} />
<Column gap="4px" fontSize={logoSize}>
<Text color={theme.text}>
{symbol}{' '}
<Text as="span" color={calculateValueToColor(+kyberScore, theme)}>
{kyberScore} ({getTypeByKyberScore(+kyberScore)})
</Text>
</Text>
{showPrice && (
<Text>
<Text as="span" color={theme.text}>
{formatDisplayNumber(price, { style: 'currency', significantDigits: 4 })}
</Text>{' '}
<Text as="span" color={+priceChange > 0 ? theme.apr : theme.red}>
({+priceChange > 0 && '+'}
{formatDisplayNumber(+priceChange / 100, { style: 'percent', fractionDigits: 2, allowNegative: true })})
</Text>
</Text>
)}
</Column>
</ItemWrapper>
)
}

function InboxItemBridge({
announcement,
onRead,
style,
time,
title,
}: PrivateAnnouncementProp<AnnouncementTemplateKyberAIWatchlist>) {
const { templateBody, isRead, templateType } = announcement
const { assets = [] } = templateBody || {}
const [token1, token2, token3] = assets

const navigate = useNavigate()
const onClick = () => {
navigate(APP_PATHS.KYBERAI_RANKINGS)
onRead(announcement, 'kyberAI_watchlist')
}

return (
<InboxItemWrapper isRead={isRead} onClick={onClick} style={{ ...style, paddingTop: '8px', gap: '6px' }}>
<InboxItemRow>
<RowItem>
<InboxIcon type={templateType} />
<Title isRead={isRead}>{title}</Title>
{!isRead && <Dot />}
</RowItem>
</InboxItemRow>

<InboxItemRow>
{token1 && <TokenInfo token={token1} />}
{token2 && <TokenInfo token={token2} />}
</InboxItemRow>

<InboxItemRow style={{ alignItems: 'center' }}>
{token3 ? <TokenInfo token={token3} /> : <div />}
{time}
</InboxItemRow>
</InboxItemWrapper>
)
}
export default InboxItemBridge
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { useNavigate } from 'react-router-dom'
import { Flex } from 'rebass'

import InboxIcon from 'components/Announcement/PrivateAnnoucement/Icon'
import { TokenInfo } from 'components/Announcement/PrivateAnnoucement/InboxItemTrendingSoon'
import { TokenInfo } from 'components/Announcement/PrivateAnnoucement/InboxItemKyberAI'
import { PrivateAnnouncementPropCenter } from 'components/Announcement/PrivateAnnoucement/NotificationCenter'
import { AnnouncementTemplateTrendingSoon } from 'components/Announcement/type'
import { AnnouncementTemplateKyberAI } from 'components/Announcement/type'
import { APP_PATHS } from 'constants/index'
import useTheme from 'hooks/useTheme'
import { formatTime } from 'utils/time'
Expand All @@ -15,7 +15,7 @@ import { Desc, Time, Title, Wrapper } from './styled'
export default function AnnouncementItem({
announcement,
title,
}: PrivateAnnouncementPropCenter<AnnouncementTemplateTrendingSoon>) {
}: PrivateAnnouncementPropCenter<AnnouncementTemplateKyberAI>) {
const { sentAt, templateType, templateBody } = announcement
const theme = useTheme()
const navigate = useNavigate()
Expand All @@ -32,10 +32,10 @@ export default function AnnouncementItem({
</Flex>
</Flex>
<Desc style={{ gap: 6, flexWrap: 'wrap', color: theme.subText }}>
<Trans>Here are our top tokens by KyberAI</Trans>
<TokenInfo templateBody={templateBody} type="bullish" />,
<TokenInfo templateBody={templateBody} type="bearish" />,
<TokenInfo templateBody={templateBody} type="trending" />
<Trans>Here are our top tokens by KyberAI:</Trans>
<TokenInfo templateBody={templateBody} type="bullish" fontSize="14px" />,
<TokenInfo templateBody={templateBody} type="bearish" fontSize="14px" />,
<TokenInfo templateBody={templateBody} type="trending" fontSize="14px" />
</Desc>
</Wrapper>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Trans } from '@lingui/macro'
import { Fragment, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { Flex } from 'rebass'
import styled from 'styled-components'

import { ReactComponent as DropdownSVG } from 'assets/svg/down.svg'
import InboxIcon from 'components/Announcement/PrivateAnnoucement/Icon'
import { TokenInfo } from 'components/Announcement/PrivateAnnoucement/InboxItemKyberAIWatchList'
import { PrivateAnnouncementPropCenter } from 'components/Announcement/PrivateAnnoucement/NotificationCenter'
import { AnnouncementTemplateKyberAIWatchlist } from 'components/Announcement/type'
import { APP_PATHS } from 'constants/index'
import useTheme from 'hooks/useTheme'
import { formatTime } from 'utils/time'

import { ArrowWrapper, Desc, Time, Title, Wrapper } from './styled'

const Detail = styled.div`
display: grid;
width: 100%;
grid-template-columns: 1fr 1fr;
gap: 12px;
`

export default function AnnouncementItem({
announcement,
title,
}: PrivateAnnouncementPropCenter<AnnouncementTemplateKyberAIWatchlist>) {
const { sentAt, templateType, templateBody } = announcement
const { assets = [] } = templateBody || {}
const theme = useTheme()
const navigate = useNavigate()
const [expand, setExpand] = useState(false)
const slice = 3
const minimalAssets = assets.slice(0, slice)

return (
<Wrapper onClick={() => setExpand(!expand)}>
<Flex justifyContent="space-between" width="100%">
<Title onClick={() => navigate(APP_PATHS.KYBERAI_RANKINGS)}>
<InboxIcon type={templateType} />
{title}
</Title>
<Flex alignItems={'center'}>
<Time>{formatTime(sentAt)} </Time>
<ArrowWrapper data-expanded={expand}>
<DropdownSVG />
</ArrowWrapper>
</Flex>
</Flex>
<Desc style={{ gap: 6, flexWrap: 'wrap', color: theme.subText }}>
<Trans>Here is an update on the tokens in your watchlist:</Trans>
{!expand &&
minimalAssets.map((token, i) => (
<Fragment key={i}>
<TokenInfo token={token} showPrice={false} key={i} logoSize={'14px'} />
{i === minimalAssets.length - 1 ? (minimalAssets.length < slice ? '' : ', ...') : ', '}
</Fragment>
))}
</Desc>
{expand && (
<Detail>
{assets.map((token, i) => (
<TokenInfo token={token} key={i} showPrice logoSize={'14px'} />
))}
</Detail>
)}
</Wrapper>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,7 @@ import { NETWORKS_INFO } from 'constants/networks'
import useTheme from 'hooks/useTheme'
import { formatTime } from 'utils/time'

import { Desc, Time, Title, Wrapper } from './styled'

const ArrowWrapper = styled.div`
width: 20px;
height: 20px;
color: ${({ theme }) => theme.subText};
display: flex;
justify-content: center;
align-items: center;
svg {
transition: all 150ms ease-in-out;
}
&[data-expanded='true'] {
svg {
transform: rotate(180deg);
}
}
`
import { ArrowWrapper, Desc, Time, Title, Wrapper } from './styled'

const Detail = styled(Desc)`
flex-direction: column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { AnnouncementTemplate, PrivateAnnouncement, PrivateAnnouncementType } fr

import Bridge from './Bridge'
import CrossChain from './CrossChain'
import KyberAI from './KyberAI'
import KyberAIWatchlist from './KyberAIWatchlist'
import LimitOrder from './LimitOrder'
import PoolPosition from './PoolPosition'
import PriceAlert from './PriceAlert'
import PrivateMessage from './PrivateMessage'
import TrendingSoon from './TrendingSoon'

export type PrivateAnnouncementPropCenter<T extends AnnouncementTemplate = AnnouncementTemplate> = {
announcement: PrivateAnnouncement<T>
Expand All @@ -24,7 +25,8 @@ const ANNOUNCEMENT_MAP_IN_CENTER = {
[PrivateAnnouncementType.LIMIT_ORDER]: LimitOrder,
[PrivateAnnouncementType.BRIDGE_ASSET]: Bridge,
[PrivateAnnouncementType.CROSS_CHAIN]: CrossChain,
[PrivateAnnouncementType.KYBER_AI]: TrendingSoon,
[PrivateAnnouncementType.KYBER_AI]: KyberAI,
[PrivateAnnouncementType.KYBER_AI_WATCHLIST]: KyberAIWatchlist,
[PrivateAnnouncementType.PRICE_ALERT]: PriceAlert,
[PrivateAnnouncementType.DIRECT_MESSAGE]: PrivateMessage,
} as PrivateAnnouncementCenterMap
Expand Down
Loading
Loading