Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sign-in-email
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Oct 16, 2023
2 parents 0d81954 + 6febaf0 commit 20cc289
Show file tree
Hide file tree
Showing 33 changed files with 713 additions and 833 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ItemWrapper = styled.div`
gap: 8px;
`
export const TokenInfo = ({
showPrice = true,
showPrice = false,
logoSize = '12px',
token,
}: {
Expand Down Expand Up @@ -73,7 +73,7 @@ function InboxItemBridge({
}

return (
<InboxItemWrapper isRead={isRead} onClick={onClick} style={{ ...style, paddingTop: '8px', gap: '6px' }}>
<InboxItemWrapper isRead={isRead} onClick={onClick} style={style}>
<InboxItemRow>
<RowItem>
<InboxIcon type={templateType} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function AnnouncementItem({
{!expand &&
minimalAssets.map((token, i) => (
<Fragment key={i}>
<TokenInfo token={token} showPrice={false} key={i} logoSize={'14px'} />
<TokenInfo token={token} key={i} logoSize={'14px'} />
{i === minimalAssets.length - 1 ? (minimalAssets.length < slice ? '' : ', ...') : ', '}
</Fragment>
))}
Expand Down
20 changes: 0 additions & 20 deletions src/components/Announcement/helper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { ChainId } from '@kyberswap/ks-sdk-core'
import { useCallback } from 'react'
import AnnouncementApi from 'services/announcement'

import { AnnouncementTemplatePopup, PopupContentAnnouncement, PopupItemType } from 'components/Announcement/type'
import { TIMES_IN_SECS } from 'constants/index'
import { useAppDispatch } from 'state/hooks'

const LsKey = 'ack-announcements'
export const getAnnouncementsAckMap = () => JSON.parse(localStorage[LsKey] || '{}')
Expand Down Expand Up @@ -42,20 +39,3 @@ export const isPopupCanShow = (
const isExpired = Date.now() < startAt * 1000 || Date.now() > endAt * 1000
return !isRead && !isExpired && isRightChain && isOwn
}

export const useInvalidateTags = (reducerPath: string) => {
const dispatch = useAppDispatch()
return useCallback(
(tag: string | string[]) => {
dispatch({
type: `${reducerPath}/invalidateTags`,
payload: Array.isArray(tag) ? tag : [tag],
})
},
[dispatch, reducerPath],
)
}

export const useInvalidateTagAnnouncement = () => {
return useInvalidateTags(AnnouncementApi.reducerPath)
}
3 changes: 2 additions & 1 deletion src/components/Announcement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import styled, { css } from 'styled-components'

import AnnouncementView, { Tab } from 'components/Announcement/AnnoucementView'
import DetailAnnouncementPopup from 'components/Announcement/Popups/DetailAnnouncementPopup'
import { formatNumberOfUnread, useInvalidateTagAnnouncement } from 'components/Announcement/helper'
import { formatNumberOfUnread } from 'components/Announcement/helper'
import { Announcement, PrivateAnnouncement } from 'components/Announcement/type'
import NotificationIcon from 'components/Icons/NotificationIcon'
import MenuFlyout from 'components/MenuFlyout'
import Modal from 'components/Modal'
import { RTK_QUERY_TAGS } from 'constants/index'
import useInterval from 'hooks/useInterval'
import { useInvalidateTagAnnouncement } from 'hooks/useInvalidateTags'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
import { ApplicationModal } from 'state/application/actions'
import { useDetailAnnouncement, useModalOpen, useToggleNotificationCenter } from 'state/application/hooks'
Expand Down
9 changes: 5 additions & 4 deletions src/components/Header/web3/WalletModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
useWalletModalToggle,
} from 'state/application/hooks'
import { useIsConnectingWallet } from 'state/authen/hooks'
import { ExternalLink } from 'theme'
import { isEVMWallet, isOverriddenWallet, isSolanaWallet } from 'utils'

import Option from './Option'
Expand Down Expand Up @@ -316,13 +317,13 @@ export default function WalletModal() {
<Text color={theme.subText}>
<Trans>
By connecting a wallet, you accept{' '}
<a href={TERM_FILES_PATH.KYBERSWAP_TERMS} onClick={e => e.stopPropagation()}>
<ExternalLink href={TERM_FILES_PATH.KYBERSWAP_TERMS} onClick={e => e.stopPropagation()}>
KyberSwap&lsquo;s Terms of Use
</a>{' '}
</ExternalLink>{' '}
and consent to its{' '}
<a href={TERM_FILES_PATH.PRIVACY_POLICY} onClick={e => e.stopPropagation()}>
<ExternalLink href={TERM_FILES_PATH.PRIVACY_POLICY} onClick={e => e.stopPropagation()}>
Privacy Policy
</a>
</ExternalLink>
. Last updated: {dayjs(TERM_FILES_PATH.VERSION).format('DD MMM YYYY')}
</Trans>
</Text>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ export default function Menu() {
)}

<MenuItem>
<a
<ExternalLink
href={TERM_FILES_PATH.KYBERSWAP_TERMS}
onClick={() => {
toggle()
Expand All @@ -482,10 +482,10 @@ export default function Menu() {
>
<FileText />
<Trans>Terms</Trans>
</a>
</ExternalLink>
</MenuItem>
<MenuItem>
<a
<ExternalLink
href={TERM_FILES_PATH.PRIVACY_POLICY}
onClick={() => {
toggle()
Expand All @@ -494,7 +494,7 @@ export default function Menu() {
>
<FileText />
<Trans>Privacy Policy</Trans>
</a>
</ExternalLink>
</MenuItem>
<MenuItem>
<ExternalLink
Expand Down
14 changes: 4 additions & 10 deletions src/components/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { Navigate } from 'react-router-dom'

import LocalLoader from 'components/LocalLoader'
import { RTK_QUERY_TAGS } from 'constants/index'
import kyberAIapi from 'pages/TrueSightV2/hooks/useKyberAIData'
import { useInvalidateTagKyberAi } from 'hooks/useInvalidateTags'
import { useSessionInfo } from 'state/authen/hooks'
import { useAppDispatch } from 'state/hooks'
import { useIsWhiteListKyberAI } from 'state/user/hooks'

type Props = {
Expand Down Expand Up @@ -33,20 +32,15 @@ export const ProtectedRouteKyberAI = ({
const { userInfo } = useSessionInfo()
const loadedPage = useRef(false)
const canAccessPage = isWhiteList || waitUtilAuthenEndOnly
const dispatch = useAppDispatch()
const invalidateTags = useInvalidateTagKyberAi()

useEffect(() => {
// change account sign in => refresh participant info
try {
refetch()
dispatch(
kyberAIapi.util.invalidateTags([
RTK_QUERY_TAGS.GET_WATCHLIST_TOKENS_KYBER_AI,
RTK_QUERY_TAGS.GET_WATCHLIST_INFO_KYBER_AI,
]),
)
invalidateTags([RTK_QUERY_TAGS.GET_WATCHLIST_TOKENS_KYBER_AI, RTK_QUERY_TAGS.GET_WATCHLIST_INFO_KYBER_AI])
} catch (error) {}
}, [userInfo?.identityId, refetch, dispatch])
}, [userInfo?.identityId, refetch, invalidateTags])

if (loading && !loadedPage.current) return <LocalLoader />
if (!canAccessPage) return <Navigate to={redirectUrl} replace />
Expand Down
43 changes: 10 additions & 33 deletions src/components/YourCampaignTransactionsModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import { CheckCircle, Copy, ExternalLink, Info, X } from 'react-feather'
import { useSelector } from 'react-redux'
import { useMedia } from 'react-use'
import { Flex, Text } from 'rebass'
import { useGetTxsCampaignQuery } from 'services/campaign'
import styled, { css } from 'styled-components'
import useSWR from 'swr'

import Modal from 'components/Modal'
import { CAMPAIGN_YOUR_TRANSACTIONS_ITEM_PER_PAGE, SWR_KEYS } from 'constants/index'
import { CAMPAIGN_YOUR_TRANSACTIONS_ITEM_PER_PAGE } from 'constants/index'
import { NETWORKS_INFO } from 'constants/networks'
import { useActiveWeb3React } from 'hooks'
import useCopyClipboard from 'hooks/useCopyClipboard'
import useTheme from 'hooks/useTheme'
import { AppState } from 'state'
import { ApplicationModal } from 'state/application/actions'
import { useModalOpen, useToggleYourCampaignTransactionsModal } from 'state/application/hooks'
import { CampaignProofData } from 'state/campaigns/actions'
import { getEtherscanLink } from 'utils'
import getShortenAddress from 'utils/getShortenAddress'

Expand All @@ -32,37 +31,15 @@ export default function YourCampaignTransactionsModal() {
const above768 = useMedia('(min-width: 768px)')

const selectedCampaign = useSelector((state: AppState) => state.campaigns.selectedCampaign)
const { data: userCampaignTransactions } = useSWR<CampaignProofData[]>(
account && selectedCampaign
? SWR_KEYS.getCampaignTransactions(
selectedCampaign.id,
CAMPAIGN_YOUR_TRANSACTIONS_ITEM_PER_PAGE,
CAMPAIGN_YOUR_TRANSACTIONS_ITEM_PER_PAGE * (currentPage - 1),
account,
)
: null,
async (url: string) => {
try {
const response = await fetch(url)
if (response.ok) {
const data = await response.json()
if (data && Array.isArray(data.data) && data.data.length) {
return data.data.map(
(item: any): CampaignProofData => ({
id: item.id,
chainId: parseInt(item.chainId),
utcTimestamp: new Date(item.time).getTime(),
txPoint: item.txPoint,
txHash: item.tx,
}),
)
}
}
return []
} catch (err) {
console.error(err)
}

const { data: userCampaignTransactions } = useGetTxsCampaignQuery(
{
campaignId: selectedCampaign?.id || 0,
limit: CAMPAIGN_YOUR_TRANSACTIONS_ITEM_PER_PAGE,
offset: CAMPAIGN_YOUR_TRANSACTIONS_ITEM_PER_PAGE * (currentPage - 1),
userAddress: account ?? '',
},
{ skip: !selectedCampaign?.id },
)

const [isCopied, setCopied] = useCopyClipboard()
Expand Down
6 changes: 3 additions & 3 deletions src/components/swapv2/LimitOrder/ListOrder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import { Trash } from 'react-feather'
import { useNavigate } from 'react-router-dom'
import { useMedia } from 'react-use'
import { Flex, Text } from 'rebass'
import limitOrderApi, { useGetListOrdersQuery } from 'services/limitOrder'
import { useGetListOrdersQuery } from 'services/limitOrder'
import styled from 'styled-components'

import { ReactComponent as NoDataIcon } from 'assets/svg/no-data.svg'
import { useInvalidateTags } from 'components/Announcement/helper'
import { ButtonLight } from 'components/Button'
import Column from 'components/Column'
import LocalLoader from 'components/LocalLoader'
Expand All @@ -22,6 +21,7 @@ import SubscribeNotificationButton from 'components/SubscribeButton'
import useRequestCancelOrder from 'components/swapv2/LimitOrder/ListOrder/useRequestCancelOrder'
import { EMPTY_ARRAY, RTK_QUERY_TAGS, TRANSACTION_STATE_DEFAULT } from 'constants/index'
import { useActiveWeb3React } from 'hooks'
import { useInvalidateTagLimitOrder } from 'hooks/useInvalidateTags'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
import useParsedQueryString from 'hooks/useParsedQueryString'
import useShowLoadingAtLeastTime from 'hooks/useShowLoadingAtLeastTime'
Expand Down Expand Up @@ -203,7 +203,7 @@ export default function ListLimitOrder() {
onReset()
}, [chainId, orderType])

const invalidateTag = useInvalidateTags(limitOrderApi.reducerPath)
const invalidateTag = useInvalidateTagLimitOrder()
const refetchOrders = useCallback(() => {
invalidateTag(RTK_QUERY_TAGS.GET_LIST_ORDERS)
}, [invalidateTag])
Expand Down
14 changes: 4 additions & 10 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { v4 as uuid } from 'uuid'

import { TransactionFlowState } from 'types/TransactionFlowState'

import { CAMPAIGN_BASE_URL as CAMPAIGN_BASE_DOMAIN } from './env'
import { CAMPAIGN_BASE_URL } from './env'
import * as ENV from './env'
import { EVM_MAINNET_NETWORKS, EVM_NETWORK, NETWORKS_INFO, SUPPORTED_NETWORKS, isEVM } from './networks'

Expand Down Expand Up @@ -186,16 +186,10 @@ export const CAMPAIGN_YOUR_TRANSACTIONS_ITEM_PER_PAGE = 10000
export const ELASTIC_BASE_FEE_UNIT = 100_000
export const KYBERSWAP_SOURCE = '{"source":"kyberswap"}'

export const CAMPAIGN_BASE_URL = `${CAMPAIGN_BASE_DOMAIN}/api/v1/campaigns`
export const SWR_KEYS = {
getGrantProgramLeaderBoard: (id: number | string) => `${CAMPAIGN_BASE_DOMAIN}/api/v1/competitions/${id}/leaderboard`,
getListGrantPrograms: `${CAMPAIGN_BASE_DOMAIN}/api/v1/competitions`,
getGrantProgram: (id: number | string) => `${CAMPAIGN_BASE_DOMAIN}/api/v1/competitions/${id}`,
getListCampaign: CAMPAIGN_BASE_URL,
getLeaderboard: (id: number) => CAMPAIGN_BASE_URL + '/' + id + '/leaderboard',
getLuckyWinners: (id: number) => CAMPAIGN_BASE_URL + '/' + id + '/lucky-winners',
getCampaignTransactions: (campaignId: number, limit: number, offset: number, account: string) =>
`${CAMPAIGN_BASE_URL}/${campaignId}/proofs?limit=${limit}&offset=${offset}&userAddress=${account}`,
getGrantProgramLeaderBoard: (id: number | string) => `${CAMPAIGN_BASE_URL}/api/v1/competitions/${id}/leaderboard`,
getListGrantPrograms: `${CAMPAIGN_BASE_URL}/api/v1/competitions`,
getGrantProgram: (id: number | string) => `${CAMPAIGN_BASE_URL}/api/v1/competitions/${id}`,
}

// https://www.nasdaq.com/glossary/b/bip
Expand Down
1 change: 1 addition & 0 deletions src/hooks/kyberdao/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ export function useVotingInfo() {
rewardStats: {
knc: rewardStats ? +rewardStats.pending?.totalAmountInKNC + +rewardStats.liquidated?.totalAmountInKNC : 0,
usd: rewardStats ? +rewardStats.pending?.totalAmountInUSD + +rewardStats.liquidated?.totalAmountInUSD : 0,
apr: rewardStats ? +rewardStats.apr : 0,
},
}
return result
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/kyberdao/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface VoteStat {
total_address_count: number
total_vote_count: number
votes: VoteDetail[] | null
quorum_status: number
}
export interface ProposalDetail {
cancelled: boolean
Expand Down Expand Up @@ -130,4 +131,5 @@ export interface RewardStats {
totalAmountInKNC: string
totalAmountInUSD: string
}
apr: string
}
28 changes: 28 additions & 0 deletions src/hooks/useInvalidateTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useCallback } from 'react'
import announcementApi from 'services/announcement'
import limitOrderApi from 'services/limitOrder'

import kyberAIApi from 'pages/TrueSightV2/hooks/useKyberAIData'
import { useAppDispatch } from 'state/hooks'

const useInvalidateTags = (api: any) => {
const dispatch = useAppDispatch()
return useCallback(
(tag: string | string[]) => {
dispatch(api.util.invalidateTags(Array.isArray(tag) ? tag : [tag]))
},
[dispatch, api],
)
}

export const useInvalidateTagAnnouncement = () => {
return useInvalidateTags(announcementApi)
}

export const useInvalidateTagKyberAi = () => {
return useInvalidateTags(kyberAIApi)
}

export const useInvalidateTagLimitOrder = () => {
return useInvalidateTags(limitOrderApi)
}
Loading

0 comments on commit 20cc289

Please sign in to comment.