Skip to content

Commit

Permalink
Merge pull request #555 from Magickbase/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored Sep 19, 2022
2 parents 70d214d + 7f2deda commit f89c4cd
Show file tree
Hide file tree
Showing 17 changed files with 295 additions and 241 deletions.
4 changes: 2 additions & 2 deletions components/ERC20TransferList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import RoundedAmount from 'components/RoundedAmount'
import TokenLogo from 'components/TokenLogo'
import ChangeIcon from 'assets/icons/change.svg'
import NoDataIcon from 'assets/icons/no-data.svg'
import { client, timeDistance, getBlockStatus, GraphQLSchema } from 'utils'
import { client, timeDistance, GraphQLSchema } from 'utils'
import styles from './styles.module.scss'

export type TransferListProps = {
Expand Down Expand Up @@ -190,7 +190,7 @@ const TransferList: React.FC<
</span>
</Tooltip>
<TxStatusIcon
status={getBlockStatus(item.block.status)}
status={item.block.status}
isSuccess={item.polyjuice.status === GraphQLSchema.PolyjuiceStatus.Succeed}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/MultiTokenActivityList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Pagination from 'components/SimplePagination'
import TxStatusIcon from 'components/TxStatusIcon'
import TransferDirection from 'components/TransferDirection'
import NoDataIcon from 'assets/icons/no-data.svg'
import { client, timeDistance, getBlockStatus, GraphQLSchema } from 'utils'
import { client, timeDistance, GraphQLSchema } from 'utils'
import styles from './styles.module.scss'

type ActivityListProps = {
Expand Down Expand Up @@ -135,7 +135,7 @@ const ActivityList: React.FC<
</span>
</Tooltip>
<TxStatusIcon
status={getBlockStatus(item.block.status)}
status={item.block.status}
isSuccess={item.polyjuice.status === GraphQLSchema.PolyjuiceStatus.Succeed}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/NFTActivityList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Pagination from 'components/SimplePagination'
import TxStatusIcon from 'components/TxStatusIcon'
import TransferDirection from 'components/TransferDirection'
import NoDataIcon from 'assets/icons/no-data.svg'
import { client, timeDistance, getBlockStatus, GraphQLSchema } from 'utils'
import { client, timeDistance, GraphQLSchema } from 'utils'
import styles from './styles.module.scss'

type ActivityListProps = {
Expand Down Expand Up @@ -132,7 +132,7 @@ const ActivityList: React.FC<
</span>
</Tooltip>
<TxStatusIcon
status={getBlockStatus(item.block.status)}
status={item.block.status}
isSuccess={item.polyjuice.status === GraphQLSchema.PolyjuiceStatus.Succeed}
/>
</div>
Expand Down
13 changes: 7 additions & 6 deletions components/PolyjuiceStatus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ import { useTranslation } from 'next-i18next'
import SuccessIcon from 'assets/icons/success.svg'
import PendingIcon from 'assets/icons/pending.svg'
import FailedIcon from 'assets/icons/failed.svg'
import { GraphQLSchema } from 'utils'
import styles from './styles.module.scss'

const PolyjuiceStatus: React.FC<{ status: 'succeed' | 'failed' | 'pending' | null }> = ({ status }) => {
const PolyjuiceStatus: React.FC<{ status: GraphQLSchema.PolyjuiceStatus | null }> = ({ status }) => {
const [t] = useTranslation('tx')

if (!status) {
return <span>-</span>
}

return (
<div className={styles.container} title={t(status)} data-status={status}>
{status === 'succeed' ? <SuccessIcon /> : null}
{status === 'failed' ? <FailedIcon /> : null}
{status === 'pending' ? <PendingIcon /> : null}
{t(status)}
<div className={styles.container} title={t(status.toLowerCase())} data-status={status.toLowerCase()}>
{status === GraphQLSchema.PolyjuiceStatus.Succeed ? <SuccessIcon /> : null}
{status === GraphQLSchema.PolyjuiceStatus.Failed ? <FailedIcon /> : null}
{status === GraphQLSchema.PolyjuiceStatus.Pending ? <PendingIcon /> : null}
{t(status.toLowerCase())}
</div>
)
}
Expand Down
4 changes: 2 additions & 2 deletions components/TxList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import FilterMenu from 'components/FilterMenu'
import RoundedAmount from 'components/RoundedAmount'
import NoDataIcon from 'assets/icons/no-data.svg'
import EmptyFilteredListIcon from 'assets/icons/empty-filtered-list.svg'
import { getBlockStatus, timeDistance, GraphQLSchema, client, PCKB_UDT_INFO } from 'utils'
import { timeDistance, GraphQLSchema, client, PCKB_UDT_INFO } from 'utils'
import styles from './styles.module.scss'

export type TxListProps = {
Expand Down Expand Up @@ -170,7 +170,7 @@ const TxList: React.FC<TxListProps & { maxCount?: string; pageSize?: number }> =
</div>
</Tooltip>
<TxStatusIcon
status={getBlockStatus(item.block?.status ?? GraphQLSchema.BlockStatus.Pending)}
status={item.block?.status}
isSuccess={
item.polyjuice ? item.polyjuice.status === GraphQLSchema.PolyjuiceStatus.Succeed : true
}
Expand Down
21 changes: 12 additions & 9 deletions components/TxStatusIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { useTranslation } from 'next-i18next'
import Tooltip from 'components/Tooltip'
import PendingIcon from 'assets/icons/pending.svg'
import CommittedIcon from 'assets/icons/committed.svg'
import FailedIcon from 'assets/icons/failed.svg'
import FinalizedIcon from 'assets/icons/finalized.svg'
import { useTranslation } from 'next-i18next'
import type { TxStatus } from 'utils'
import { GraphQLSchema } from 'utils'

const TxStatusIcon: React.FC<{ status: TxStatus; isSuccess?: boolean }> = ({ status, isSuccess = false }) => {
const TxStatusIcon: React.FC<{ status: GraphQLSchema.BlockStatus | null; isSuccess?: boolean }> = ({
status,
isSuccess = false,
}) => {
const [t] = useTranslation('common')

if (status === 'pending') {
if (status === GraphQLSchema.BlockStatus.Pending || !status) {
return (
<Tooltip title={t(status)} placement="top">
<Tooltip title={t('pending')} placement="top">
<PendingIcon />
</Tooltip>
)
Expand All @@ -21,18 +24,18 @@ const TxStatusIcon: React.FC<{ status: TxStatus; isSuccess?: boolean }> = ({ sta
return <FailedIcon style={{ flexShrink: 0 }} />
}

if (status === 'committed') {
if (status === GraphQLSchema.BlockStatus.Committed) {
return (
<Tooltip title={t(status)} placement="top">
<Tooltip title={t('committed')} placement="top">
<div style={{ display: 'flex', alignItems: 'center', flexShrink: 0 }}>
<CommittedIcon />
</div>
</Tooltip>
)
}
if (status === 'finalized') {
if (status === GraphQLSchema.BlockStatus.Finalized) {
return (
<Tooltip title={t(status)} placement="top">
<Tooltip title={t('finalized')} placement="top">
<div style={{ display: 'flex', alignItems: 'center', flexShrink: 0 }}>
<FinalizedIcon />
</div>
Expand Down
4 changes: 2 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Search from 'components/Search'
import Tooltip from 'components/Tooltip'
import BlockStateIcon from 'components/BlockStateIcon'
import TxStatusIcon from 'components/TxStatusIcon'
import { fetchHome, timeDistance, formatInt, client, GraphQLSchema, IS_MAINNET, getBlockStatus } from 'utils'
import { fetchHome, timeDistance, formatInt, client, GraphQLSchema, IS_MAINNET } from 'utils'
type State = API.Home.Parsed

// TODO: add polyjuice status
Expand Down Expand Up @@ -493,7 +493,7 @@ const TxList: React.FC<{ list: HomeLists['transactions']['entries']; isLoading:
</Box>
</Tooltip>
<TxStatusIcon
status={getBlockStatus(tx.block?.status)}
status={tx.block?.status}
isSuccess={
tx.polyjuice ? tx.polyjuice.status === GraphQLSchema.PolyjuiceStatus.Succeed : true
}
Expand Down
60 changes: 33 additions & 27 deletions pages/tokens/[type].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import HashLink from 'components/HashLink'
import TokenLogo from 'components/TokenLogo'
import Tooltip from 'components/Tooltip'
import FilterMenu from 'components/FilterMenu'
// import SortIcon from 'assets/icons/sort.svg'
import SortIcon from 'assets/icons/sort.svg'
import { SIZES } from 'components/PageSize'
import Amount from 'components/Amount'
import AddIcon from 'assets/icons/add.svg'
Expand Down Expand Up @@ -50,8 +50,17 @@ type TokenListProps = {
}

const tokenListQuery = gql`
query ($name: String, $type: UdtType, $before: String, $after: String, $limit: Int) {
udts(input: { type: $type, before: $before, after: $after, limit: $limit, fuzzy_name: $name }) {
query ($name: String, $type: UdtType, $before: String, $after: String, $limit: Int, $holder_count_sort: SortType) {
udts(
input: {
type: $type
before: $before
after: $after
limit: $limit
fuzzy_name: $name
sorter: [{ sort_type: $holder_count_sort, sort_value: EX_HOLDERS_COUNT }]
}
) {
entries {
id
bridge_account_id
Expand Down Expand Up @@ -83,7 +92,7 @@ interface Variables {
name: string | null
type: string
limit: number
// holder_count_sort: string
holder_count_sort: string
}

const fetchTokenList = (variables: Variables): Promise<TokenListProps['udts']> =>
Expand All @@ -104,7 +113,8 @@ const TokenList = () => {
after = null,
name = null,
page_size = SIZES[1],
/* holder_count_sort = 'DESC',*/ ...query
holder_count_sort = 'DESC',
...query
},
} = useRouter()
const theme = useTheme()
Expand All @@ -120,15 +130,15 @@ const TokenList = () => {
]

const { isLoading, data } = useQuery(
['tokens', type, before, after, name],
['tokens', type, before, after, name, page_size, holder_count_sort],
() =>
fetchTokenList({
type: type.toString().toUpperCase(),
before: before as string,
after: after as string,
name: name ? `${name}%` : null,
limit: Number.isNaN(+page_size) ? +SIZES[1] : +page_size,
// holder_count_sort: holder_count_sort as string,
holder_count_sort: holder_count_sort as string,
}),
{
refetchInterval: 10000,
Expand Down Expand Up @@ -222,26 +232,22 @@ const TokenList = () => {
<thead style={{ textTransform: 'capitalize', fontSize: isMobile ? 12 : 14 }}>
<tr style={{ borderTop: '1px solid #f0f0f0', borderBottom: '1px solid #f0f0f0' }}>
{headers.map(h => (
<th
key={h.key}
title={t(h.label ?? h.key)}
style={{
whiteSpace: 'nowrap',
}}
>
{t(h.label ?? h.key)}
{h.key === 'token' ? (
<span>
<FilterMenu filterKeys={[FILTER_KEYS[0]]} />
</span>
) : null}
{/* {h.key === 'holderCount' ? ( */}
{/* <SortIcon */}
{/* onClick={handleHolderCountSortClick} */}
{/* data-order={holder_count_sort} */}
{/* className={styles.sorter} */}
{/* /> */}
{/* ) : null} */}
<th key={h.key} title={t(h.label ?? h.key)}>
<span>
{t(h.label ?? h.key)}
{h.key === 'token' ? (
<span>
<FilterMenu filterKeys={[FILTER_KEYS[0]]} />
</span>
) : null}
{h.key === 'holderCount' ? (
<SortIcon
onClick={handleHolderCountSortClick}
data-order={holder_count_sort}
className={styles.sorter}
/>
) : null}
</span>
</th>
))}
</tr>
Expand Down
6 changes: 6 additions & 0 deletions pages/tokens/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
text-align: right;
}
}
th span {
line-height: 1;
display: inline-flex;
align-items: center;
}
}
form[data-role='filter-menu']:first-of-type {
left: 0;
Expand Down Expand Up @@ -53,6 +58,7 @@

.sorter {
cursor: pointer;
margin-left: 4px;

&[data-order='DESC'] {
transform: rotate(0.5turn);
Expand Down
Loading

1 comment on commit f89c4cd

@vercel
Copy link

@vercel vercel bot commented on f89c4cd Sep 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.