mars-v2-frontend/src/components/Trade/TradeChart/index.tsx
Linkie Link 0960f84b58
Pyth price fetching (#723)
* env: remove testing library

* fix: use pyth over oracle

* fix: fix the endpoints

* fix: fix build

* tidy: refactor

* fix: fixed account fetching

* fix: made all queries chain agnostic

* fix: fixed the chart position
2024-01-11 12:16:47 +01:00

60 lines
1.7 KiB
TypeScript

import dynamic from 'next/dynamic'
import Script from 'next/script'
import { useState } from 'react'
import Card from 'components/Card'
import { CircularProgress } from 'components/CircularProgress'
import Loading from 'components/Loading'
import Text from 'components/Text'
import PoweredByPyth from 'components/Trade/TradeChart/PoweredByPyth'
const TVChartContainer = dynamic(
() => import('components/Trade/TradeChart/TVChartContainer').then((mod) => mod.TVChartContainer),
{ ssr: false },
)
interface Props {
buyAsset: Asset
sellAsset: Asset
}
export default function TradeChart(props: Props) {
const [isScriptReady, setIsScriptReady] = useState(false)
return (
<>
<Script
src='/datafeeds/udf/dist/bundle.js'
strategy='lazyOnload'
onReady={() => {
setIsScriptReady(true)
}}
onLoad={() => {
setIsScriptReady(true)
}}
/>
{isScriptReady ? (
<TVChartContainer buyAsset={props.buyAsset} sellAsset={props.sellAsset} />
) : (
<Card
title={
<div className='flex items-center w-full bg-white/10'>
<Text size='lg' className='flex items-center flex-1 p-4 font-semibold'>
Trading Chart
</Text>
<Loading className='h-4 mr-4 w-60' />
</div>
}
contentClassName='px-0.5 pb-0.5 h-full bg-chart w-[calc(100%-2px)] ml-[1px]'
className='h-[70dvh] max-h-[980px] min-h-[560px]'
>
<div className='flex items-center justify-center w-full h-[calc(100%-32px)] rounded-b-base bg-chart'>
<CircularProgress size={60} className='opacity-50' />
</div>
<PoweredByPyth />
</Card>
)}
</>
)
}