components APIs
- Header
- Button
- Layout
- Footer
- Text
- Box
- Card
- Table
- Loading
- Select
- Loader
- Toolbar
- Icon
- CodeInput
- BottomSheet
- InfoBlock
- LanguageToggle
- ProgressCircles
- Ripple
- Toggle
- Tag
- Input
- Paginator
- Filter
- AsyncSelect
- CatalogBigButton
- ReadMore
- ConditionalWrapper
- LastCheckedDisplay
- PriceLabel
- PageTitle
- CartTable
- CartFinalPriceTable
- LoadingSpin
- InfoModal
- ProductCard
- RecommendCoupon
- PriceVales
- NomalLayout
- Web3ReactManager
- Popups
- CurrencyInput
- TransactionErrorContent
- TransactionConfirmationModal
- ConfirmationModalContent
- DoubleCurrencyLogo
- CustomModal
- CurrencySearchModal
- CurrencyLogo
- NumericalInput
- Logo
- QuestionHelper
- ListLogo
- DataTable
- WalletModal
- CustomTable
- MinimalPositionCard
- RemoveLiquidityModal
- CustomTooltip
- ColoredSlider
- ToggleSwitch
- FormattedPriceImpact
- SettingsModal
- ConfirmSwapModal
- AdvancedSwapDetails
- AddressInput
- LineChart
- StakeSyrupModal
- AccountDetails
- BetaWarningBanner
- AreaChart
- ChartType
- TokensTable
- PairTable
- TopMovers
- BarChart
- TransactionsTable
- StakeQuickModal
- UnstakeQuickModal
- SyrupCard
- CustomMenu
- SearchInput
- CustomSwitch
- FarmCard
- BuyFiatModal
- MoonpayModal
- RewardSlider
- Swap
- AddLiquidity
- PoolFinderModal
- PoolPositionCard
- SwapTokenDetails
- SuperHeader
- GlobalStyles
- PrimaryButton
- SectionTitle
- Section
- AccentSection
- ChainSelection
- CoinSelection
- AddressSelection
- SendAction
- Buttons
- Content
- Particles
- IconButton
- NotSupported
- InputSearch
- RouteGuard
- SearchBar
- FileInput
- GovBanner
- AuthForm
- DomainDetails
- Subnav
- ColumnFilter
- ImportExport
- selectFilter
- TaggedArrayInput
- FacetFilter
- ButtonSingleLine
- TextMultiline
- ButtonSelect
- BottomSheetBehavior
- InfoButton
- BulletPointX
- BulletPointCheck
- Title
- LoadingIcon
- SelectFilterControls
- CORInputForm
- SdnInputForm
- Navbar
- HomeRoute
- AuthRoute
- DocumentDetails
- DocumentStepper
- AddGame
- Auth
- Effectiveness
- Export
- PokemonType
- Moves
- Member
- MoveSelector
- Type
- Natures
- Move
- PokeInfo
- Share
- Badges
- Status
- UpdateSW
- About
- Builder
- Calculator
- Changelog
- Import
- Pokestats
- Report
- Rules
- Settings
- Tracker
- DarkThemeProvider
- NotificationHandler
- Background
- Indicator
- StyledButton
- StyledText
- Illustration
- OnboardingSlider
- FlexList
- AppLayout
- ScrollableList
- Visualization
- DataSearch
- Region
- App
- CompareApiLegend
- CompareApiBreadcrumbs
- CompareApiLink
- CompareApiCard
- ExploreApiBreadcrumbs
- ExploreApiLink
- ExploreApiSearch
- ExploreApiConst
- ApiLoader
- RefreshButton
- Listing
- PriceModal
- ConfirmationModal
- Transition
- AutoComplete
- useInput
- Avatar
- Badge
- Breadcrumbs
- ButtonDropdown
- ButtonGroup
- Capacity
- Checkbox
- Code
- Collapse
- CssBaseline
- GeistProvider
- Description
- Display
- Divider
- Dot
- Drawer
- useModal
- Fieldset
- Grid
- Image
- Keyboard
- Link
- Modal
- Note
- Page
- Pagination
- Popover
- Progress
- Radio
- Rating
- Slider
- Snippet
- Spacer
- Spinner
- Tabs
- Textarea
- Tooltip
- Tree
- useBodyScroll
- useClasses
- useClickAway
- useClipboard
- useCurrentState
- useKeyboard
- KeyMod
- KeyCode
- useMediaQuery
- useTabs
- useToasts
- User
- useTheme
- Themes
- GeistUIThemes
- useAllThemes
- CollapsableDialog
- Map
- IPForm
- IPMenu
- Container
- Parallax
- Nav
- SEO
- BlogNav
- ExtensionCard
- MenuComp
Other Related APIs
- react#useState
- react#useEffect
- react#useMemo
- @material-ui/core#Typography
- @material-ui/core#Box
- @material-ui/core#Grid
- @material-ui/core/styles#makeStyles
- @material-ui/core/styles#useTheme
- @material-ui/icons#ArrowDropDown
- @material-ui/icons#ArrowDropUp
- utils#shortenAddress
- utils#formatCompact
- utils#formatNumber
- utils#getTokenInfo
- utils#getEthPrice
- utils#getIntervalTokenData
- components#CurrencyLogo
- utils/wrappedCurrency#unwrappedToken
components#LineChart TypeScript Examples
The following examples show how to use
components#LineChart.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwapTokenDetails.tsx From interface-v2 with GNU General Public License v3.0 | 4 votes |
SwapTokenDetails: React.FC<{
token: Token;
}> = ({ token }) => {
const classes = useStyles();
const currency = unwrappedToken(token);
const tokenAddress = token.address;
const { palette } = useTheme();
const latestBlock = useBlockNumber();
const { tokenDetails, updateTokenDetails } = useTokenDetails();
const [tokenData, setTokenData] = useState<any>(null);
const [priceData, setPriceData] = useState<any>(null);
const priceUp = Number(tokenData?.priceChangeUSD) > 0;
const priceUpPercent = Number(tokenData?.priceChangeUSD).toFixed(2);
const [isCopied, setCopied] = useCopyClipboard();
const prices = priceData ? priceData.map((price: any) => price.close) : [];
useEffect(() => {
async function fetchTokenData() {
const tokenDetail = tokenDetails.find(
(item) => item.address === tokenAddress,
);
setTokenData(tokenDetail?.tokenData);
setPriceData(tokenDetail?.priceData);
const currentTime = dayjs.utc();
const startTime = currentTime
.subtract(1, 'day')
.startOf('hour')
.unix();
const tokenPriceData = await getIntervalTokenData(
tokenAddress,
startTime,
3600,
latestBlock,
);
setPriceData(tokenPriceData);
const [newPrice, oneDayPrice] = await getEthPrice();
const tokenInfo = await getTokenInfo(newPrice, oneDayPrice, tokenAddress);
if (tokenInfo) {
const token0 = tokenInfo[0];
setTokenData(token0);
const tokenDetailToUpdate = {
address: tokenAddress,
tokenData: token0,
priceData: tokenPriceData,
};
updateTokenDetails(tokenDetailToUpdate);
}
}
fetchTokenData();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tokenAddress]);
return (
<Box>
<Box
display='flex'
alignItems='center'
justifyContent='space-between'
px={2}
py={1.5}
>
<Box display='flex' alignItems='center'>
<CurrencyLogo currency={currency} size='28px' />
<Box ml={1}>
<Typography variant='body2'>{currency.symbol}</Typography>
{tokenData ? (
<Box display='flex' alignItems='center'>
<Typography variant='body2'>
${formatNumber(tokenData.priceUSD)}
</Typography>
<Box
ml={0.5}
display='flex'
alignItems='center'
className={priceUp ? classes.success : classes.danger}
>
{priceUp ? <ArrowDropUp /> : <ArrowDropDown />}
<Typography variant='body2'>{priceUpPercent}%</Typography>
</Box>
</Box>
) : (
<Skeleton variant='rect' width={100} height={20} />
)}
</Box>
</Box>
{tokenData && priceData ? (
<Box width={88} height={47} position='relative'>
<Box position='absolute' top={-30} width={1}>
{prices.length > 0 && (
<LineChart
data={prices}
width='100%'
height={120}
color={priceUp ? palette.success.main : palette.error.main}
/>
)}
</Box>
</Box>
) : (
<Skeleton variant='rect' width={88} height={47} />
)}
</Box>
<Box
borderTop={`1px solid ${palette.secondary.light}`}
borderBottom={`1px solid ${palette.secondary.light}`}
px={2}
>
<Grid container>
<Grid item xs={6}>
<Box borderRight={`1px solid ${palette.secondary.light}`} py={1}>
{tokenData ? (
<Typography
variant='body2'
style={{ color: palette.text.secondary }}
>
TVL: {formatCompact(tokenData?.totalLiquidityUSD)}
</Typography>
) : (
<Skeleton variant='rect' width={100} height={16} />
)}
</Box>
</Grid>
<Grid item xs={6}>
<Box py={1} pl={2}>
{tokenData ? (
<Typography
variant='body2'
style={{ color: palette.text.secondary }}
>
24h VOL: {formatCompact(tokenData?.oneDayVolumeUSD)}
</Typography>
) : (
<Skeleton variant='rect' width={100} height={16} />
)}
</Box>
</Grid>
</Grid>
</Box>
<Box
display='flex'
justifyContent='space-between'
alignItems='center'
py={1}
px={2}
>
<a
href={`https://polygonscan.com/token/${tokenAddress}`}
target='_blank'
rel='noopener noreferrer'
style={{ textDecoration: 'none' }}
>
<Typography variant='body2' style={{ color: palette.primary.main }}>
{shortenAddress(tokenAddress)}
</Typography>
</a>
<Box
display='flex'
style={{ cursor: 'pointer', opacity: isCopied ? 0.5 : 1 }}
onClick={() => {
setCopied(tokenAddress);
}}
>
<CopyIcon />
</Box>
</Box>
</Box>
);
}