Skip to content

Commit 809d7a8

Browse files
authored
fix: mf-5978 price chart loading status and some other issues (#11950)
1 parent a222f04 commit 809d7a8

File tree

11 files changed

+92
-84
lines changed

11 files changed

+92
-84
lines changed

packages/plugins/FileService/src/locale/zh-TW.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/plugins/FileService/src/locale/zh-TW.po

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { useRef } from 'react'
2-
import { Stack, Typography } from '@mui/material'
3-
import { LoadingBase, makeStyles } from '@masknet/theme'
1+
import { useRef, type HTMLProps } from 'react'
2+
import { Box, Stack } from '@mui/material'
3+
import { makeStyles } from '@masknet/theme'
44
import { openWindow } from '@masknet/shared-base-ui'
5-
import { useDimension, usePriceLineChart, type Dimension } from '@masknet/shared'
5+
import { EmptyStatus, LoadingStatus, useDimension, usePriceLineChart, type Dimension } from '@masknet/shared'
66
import type { Coin, Currency, Stat } from '../../types/index.js'
7-
import { Trans } from '@lingui/macro'
87

98
const DEFAULT_DIMENSION: Dimension = {
109
top: 32,
@@ -15,20 +14,19 @@ const DEFAULT_DIMENSION: Dimension = {
1514
height: 190,
1615
}
1716

18-
const useStyles = makeStyles<PriceChartProps>()((theme, { stats, coin }) => {
17+
const useStyles = makeStyles()((theme) => {
1918
return {
2019
root: {
2120
position: 'relative',
22-
cursor: stats.length && coin?.platform_url ? 'pointer' : 'default',
21+
},
22+
chart: {
23+
display: 'flex',
24+
alignItems: 'center',
25+
justifyContent: 'center',
2326
},
2427
svg: {
2528
display: 'block',
2629
},
27-
progress: {
28-
position: 'absolute',
29-
left: 275,
30-
top: 85,
31-
},
3230
placeholder: {
3331
paddingTop: theme.spacing(10),
3432
paddingBottom: theme.spacing(10),
@@ -37,7 +35,7 @@ const useStyles = makeStyles<PriceChartProps>()((theme, { stats, coin }) => {
3735
}
3836
})
3937

40-
interface PriceChartProps extends withClasses<'root'> {
38+
interface PriceChartProps extends HTMLProps<HTMLDivElement> {
4139
coin?: Coin
4240
currency: Currency
4341
stats: Stat[]
@@ -49,48 +47,52 @@ interface PriceChartProps extends withClasses<'root'> {
4947
}
5048

5149
export function PriceChart(props: PriceChartProps) {
52-
const { classes } = useStyles(props, { props })
50+
const { stats, loading, currency, children, coin, className, ...rest } = props
51+
const { classes, cx } = useStyles()
5352
const rootRef = useRef<HTMLDivElement>(null)
5453
const svgRef = useRef<SVGSVGElement>(null)
5554

5655
useDimension(svgRef, DEFAULT_DIMENSION)
5756

5857
usePriceLineChart(
5958
svgRef,
60-
props.stats.map(([date, price]) => ({
59+
stats.map(([date, price]) => ({
6160
date: new Date(date),
6261
value: price,
6362
})),
6463
DEFAULT_DIMENSION,
6564
'x-trader-price-line-chart',
66-
{ sign: props.currency.name ?? 'USD' },
65+
{ sign: currency.name ?? 'USD' },
6766
)
6867

6968
return (
70-
<div className={classes.root} ref={rootRef}>
71-
{props.loading && props.stats.length ?
72-
<LoadingBase className={classes.progress} color="primary" size={15} />
73-
: null}
74-
69+
<Box
70+
className={cx(classes.root, className)}
71+
{...rest}
72+
ref={rootRef}
73+
sx={{
74+
cursor: stats.length && coin?.platform_url ? 'pointer' : 'default',
75+
}}>
7576
<Stack gap={2}>
76-
{props.stats.length ?
77-
<svg
78-
className={classes.svg}
79-
ref={svgRef}
80-
width={DEFAULT_DIMENSION.width}
81-
height={DEFAULT_DIMENSION.height}
82-
viewBox={`0 0 ${DEFAULT_DIMENSION.width} ${DEFAULT_DIMENSION.height}`}
83-
preserveAspectRatio="xMidYMid meet"
84-
onClick={() => {
85-
props.stats.length && openWindow(props.coin?.platform_url)
86-
}}
87-
/>
88-
: <Typography className={classes.placeholder} align="center" color="textSecondary">
89-
<Trans>No Data</Trans>
90-
</Typography>
91-
}
92-
{props.children}
77+
<Box className={classes.chart} height={DEFAULT_DIMENSION.height}>
78+
{loading ?
79+
<LoadingStatus iconSize={36} />
80+
: stats.length ?
81+
<svg
82+
className={classes.svg}
83+
ref={svgRef}
84+
width={DEFAULT_DIMENSION.width}
85+
height={DEFAULT_DIMENSION.height}
86+
viewBox={`0 0 ${DEFAULT_DIMENSION.width} ${DEFAULT_DIMENSION.height}`}
87+
preserveAspectRatio="xMidYMid meet"
88+
onClick={() => {
89+
stats.length && openWindow(coin?.platform_url)
90+
}}
91+
/>
92+
: <EmptyStatus className={classes.placeholder} />}
93+
</Box>
94+
{children}
9395
</Stack>
94-
</div>
96+
</Box>
9597
)
9698
}

packages/plugins/Trader/src/SiteAdaptor/trending/TrendingView.tsx

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
import { useEffect, useMemo, useState, useContext, useCallback, useLayoutEffect } from 'react'
2-
import { compact, first } from 'lodash-es'
3-
import { TabContext } from '@mui/lab'
4-
import { Box, useTheme } from '@mui/system'
5-
import { Stack, Tab, ThemeProvider } from '@mui/material'
1+
import { Trans } from '@lingui/macro'
62
import { useIsMinimalMode } from '@masknet/plugin-infra/content-script'
7-
import { useChainContext } from '@masknet/web3-hooks-base'
8-
import { ChainId } from '@masknet/web3-shared-evm'
9-
import { SourceType, TokenType } from '@masknet/web3-shared-base'
10-
import type { Web3Helper } from '@masknet/web3-helpers'
113
import { NFTList, PluginCardFrameMini, PluginEnableBoundary } from '@masknet/shared'
12-
import { EMPTY_LIST, PluginID, NetworkPluginID, type SocialIdentity, Days } from '@masknet/shared-base'
4+
import { Days, EMPTY_LIST, NetworkPluginID, PluginID, type SocialIdentity } from '@masknet/shared-base'
135
import { useRenderPhraseCallbackOnDepsChange } from '@masknet/shared-base-ui'
146
import { makeStyles, MaskLightTheme, MaskTabList, useTabs } from '@masknet/theme'
7+
import type { Web3Helper } from '@masknet/web3-helpers'
8+
import { useChainContext } from '@masknet/web3-hooks-base'
159
import type { TrendingAPI } from '@masknet/web3-providers/types'
10+
import { SourceType, TokenType } from '@masknet/web3-shared-base'
11+
import { ChainId } from '@masknet/web3-shared-evm'
1612
import { Telemetry } from '@masknet/web3-telemetry'
17-
import { EventType, EventID } from '@masknet/web3-telemetry/types'
18-
import { TrendingViewContext } from './context.js'
13+
import { EventID, EventType } from '@masknet/web3-telemetry/types'
14+
import { TabContext } from '@mui/lab'
15+
import { Stack, Tab, ThemeProvider } from '@mui/material'
16+
import { Box, useTheme } from '@mui/system'
17+
import { compact, first } from 'lodash-es'
18+
import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useState } from 'react'
1919
import { usePriceStats } from '../../trending/usePriceStats.js'
2020
import { useTrendingById } from '../../trending/useTrending.js'
21+
import { ContentTab } from '../../types/index.js'
2122
import { CoinMarketPanel } from './CoinMarketPanel.js'
23+
import { TrendingViewContext } from './context.js'
24+
import { FailedTrendingView } from './FailedTrendingView.js'
25+
import { NonFungibleTickersTable } from './NonFungibleTickersTable.js'
2226
import { PriceChart } from './PriceChart.js'
2327
import { DEFAULT_RANGE_OPTIONS, PriceChartDaysControl } from './PriceChartDaysControl.js'
2428
import { TickersTable } from './TickersTable.js'
2529
import { TrendingViewDeck } from './TrendingViewDeck.js'
26-
import { NonFungibleTickersTable } from './NonFungibleTickersTable.js'
2730
import { TrendingViewSkeleton } from './TrendingViewSkeleton.js'
28-
import { ContentTab } from '../../types/index.js'
29-
import { FailedTrendingView } from './FailedTrendingView.js'
30-
import { Trans } from '@lingui/macro'
3131

3232
const useStyles = makeStyles<{
3333
isTokenTagPopper: boolean
@@ -58,12 +58,7 @@ const useStyles = makeStyles<{
5858
props.isCollectionProjectPopper ?
5959
{
6060
minHeight: 374,
61-
maxHeight:
62-
props.isCollectionProjectPopper ?
63-
props.currentTab === ContentTab.Price ?
64-
450
65-
: 374
66-
: 'unset',
61+
maxHeight: props.currentTab === ContentTab.Price ? 450 : 374,
6762
overflow: 'hidden',
6863
display: 'flex',
6964
flexDirection: 'column',
@@ -290,7 +285,6 @@ export function TrendingView(props: TrendingViewProps) {
290285
cardHeader: classes.cardHeader,
291286
}}
292287
currentTab={currentTab}
293-
stats={stats}
294288
identity={identity}
295289
setActive={setActive}
296290
setResult={setResult}
@@ -347,7 +341,7 @@ export function TrendingView(props: TrendingViewProps) {
347341
{currentTab === ContentTab.Price ?
348342
<Box className={classes.priceChartWrapper}>
349343
<PriceChart
350-
classes={{ root: classes.priceChartRoot }}
344+
className={classes.priceChartRoot}
351345
coin={coin}
352346
amount={currentPriceChange ?? trending.market?.price_change_percentage_24h_in_currency ?? 0}
353347
currency={trending.currency}

packages/plugins/Trader/src/SiteAdaptor/trending/TrendingViewDeck.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
} from '@mui/material'
4444
import { first } from 'lodash-es'
4545
import { useCallback, useContext, useEffect, useRef, useState } from 'react'
46-
import { ContentTab, type Currency, type Stat } from '../../types/index.js'
46+
import { ContentTab, type Currency } from '../../types/index.js'
4747
import { CoinIcon } from './CoinIcon.js'
4848
import { TrendingCard, type TrendingCardProps } from './TrendingCard.js'
4949
import { TrendingViewDescriptor } from './TrendingViewDescriptor.js'
@@ -156,7 +156,6 @@ const useStyles = makeStyles<{
156156
})
157157

158158
interface TrendingViewDeckProps extends withClasses<'header' | 'body' | 'footer' | 'content' | 'cardHeader'> {
159-
stats: Stat[]
160159
currency: Currency
161160
currentTab: ContentTab
162161
trending: TrendingAPI.Trending
@@ -173,7 +172,6 @@ interface TrendingViewDeckProps extends withClasses<'header' | 'body' | 'footer'
173172
export function TrendingViewDeck(props: TrendingViewDeckProps) {
174173
const {
175174
trending,
176-
stats,
177175
children,
178176
TrendingCardProps,
179177
resultList = EMPTY_LIST,

packages/plugins/Trader/src/locale/en-US.po

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/plugins/Trader/src/locale/ja-JP.po

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/plugins/Trader/src/locale/ko-KR.po

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/plugins/Trader/src/locale/zh-CN.po

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/plugins/Trader/src/locale/zh-TW.po

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)