forked from vegaprotocol/frontend-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(trading): use candles service for sparklines (#82)
* feat: use candles service for markets page sparklines * feat: use candles service market selector sparkline * chore: mock candles data from service hok * fix: sparkline candle direction
- Loading branch information
Showing
11 changed files
with
168 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,56 @@ | ||
import { Emblem } from '@vegaprotocol/emblem'; | ||
import type { MarketMaybeWithCandles } from '@vegaprotocol/markets'; | ||
import { Link } from 'react-router-dom'; | ||
import { | ||
priceValueFormatter, | ||
priceChangeRenderer, | ||
priceChangeSparklineRenderer, | ||
} from './use-column-defs'; | ||
import { priceValueFormatter } from './use-column-defs'; | ||
import { Links } from '../../lib/links'; | ||
import { Tooltip } from '@vegaprotocol/ui-toolkit'; | ||
import { cn, Sparkline, Tooltip } from '@vegaprotocol/ui-toolkit'; | ||
import { useCandleData } from '@vegaprotocol/rest'; | ||
import { formatNumber } from '@vegaprotocol/utils'; | ||
import { signedNumberCssClass } from '@vegaprotocol/datagrid'; | ||
|
||
export const TopMarketList = ({ | ||
markets, | ||
}: { | ||
markets?: MarketMaybeWithCandles[]; | ||
}) => { | ||
return ( | ||
<div className="flex flex-col justify-between gap-5"> | ||
<ul className="flex flex-col justify-between gap-3"> | ||
{markets?.map((market) => { | ||
return ( | ||
<div | ||
className="grid auto-rows-min grid-cols-8 gap-3 text-sm" | ||
key={market.id} | ||
> | ||
<span className="col-span-3 overflow-hidden"> | ||
<Tooltip description={market.tradableInstrument.instrument.name}> | ||
<Link to={Links.MARKET(market.id)}> | ||
<span className="flex items-center gap-2"> | ||
<Emblem market={market.id} size={26} /> | ||
<span className="text-sm overflow-hidden text-ellipsis"> | ||
{market.tradableInstrument.instrument.code} | ||
</span> | ||
</span> | ||
</Link> | ||
</Tooltip> | ||
</span> | ||
<span className="col-span-2 text-right font-mono"> | ||
{priceValueFormatter(market, 2)} | ||
</span> | ||
<span className="col-span-3 flex justify-end gap-1 text-xs"> | ||
{priceChangeRenderer(market, false)} | ||
{priceChangeSparklineRenderer(market)} | ||
</span> | ||
</div> | ||
); | ||
return <TopMarket key={market.id} market={market} />; | ||
})} | ||
</div> | ||
</ul> | ||
); | ||
}; | ||
|
||
const TopMarket = (props: { market: MarketMaybeWithCandles }) => { | ||
const { sparkline, pctChange } = useCandleData(props.market.id); | ||
return ( | ||
<li className="grid auto-rows-min grid-cols-3 gap-3"> | ||
<span className="overflow-hidden"> | ||
<Tooltip description={props.market.tradableInstrument.instrument.name}> | ||
<Link to={Links.MARKET(props.market.id)}> | ||
<span className="flex items-center gap-2"> | ||
<Emblem market={props.market.id} size={26} /> | ||
<span className="overflow-hidden text-ellipsis"> | ||
{props.market.tradableInstrument.instrument.code} | ||
</span> | ||
</span> | ||
</Link> | ||
</Tooltip> | ||
</span> | ||
<span className="text-right font-mono"> | ||
{priceValueFormatter(props.market, 2)} | ||
</span> | ||
<span className="flex justify-end gap-2 text-xs"> | ||
{pctChange && ( | ||
<span | ||
className={cn('font-mono text-sm', signedNumberCssClass(pctChange))} | ||
> | ||
{formatNumber(pctChange, 2)}% | ||
</span> | ||
)} | ||
{sparkline && <Sparkline data={sparkline} />} | ||
</span> | ||
</li> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,43 @@ | ||
import { useCandleData, type Market } from '@vegaprotocol/rest'; | ||
|
||
import { LoaderCircleIcon } from 'lucide-react'; | ||
import { Currency } from '../currency'; | ||
import { CompactNumber } from '@vegaprotocol/react-helpers'; | ||
import BigNumber from 'bignumber.js'; | ||
import type { Market } from '@vegaprotocol/rest'; | ||
|
||
export const Volume24 = ({ market }: { market: Market }) => { | ||
const { notional, status } = useCandleData(market.id); | ||
throw new Error('candles service does not contain notional value'); | ||
// const { notional, status } = useCandleData(market.id); | ||
|
||
if (status === 'pending') { | ||
return ( | ||
<div className="h-4 py-1"> | ||
<LoaderCircleIcon size={16} className="animate-spin" /> | ||
</div> | ||
); | ||
} | ||
// if (status === 'pending') { | ||
// return ( | ||
// <div className="h-4 py-1"> | ||
// <LoaderCircleIcon size={16} className="animate-spin" /> | ||
// </div> | ||
// ); | ||
// } | ||
|
||
return ( | ||
<Currency | ||
value={notional} | ||
symbol={market.quoteSymbol} | ||
formatDecimals={market.positionDecimalPlaces} | ||
/> | ||
); | ||
// return ( | ||
// <Currency | ||
// value={notional} | ||
// symbol={market.quoteSymbol} | ||
// formatDecimals={market.positionDecimalPlaces} | ||
// /> | ||
// ); | ||
}; | ||
|
||
export const CompactVolume24 = ({ market }: { market: Market }) => { | ||
const { notional, status } = useCandleData(market.id); | ||
throw new Error('candles service does not contain notional value'); | ||
// const { notional, status } = useCandleData(market.id); | ||
|
||
if (status === 'pending') { | ||
return ( | ||
<div className="h-4 py-1"> | ||
<LoaderCircleIcon size={14} className="animate-spin" /> | ||
</div> | ||
); | ||
} | ||
// if (status === 'pending') { | ||
// return ( | ||
// <div className="h-4 py-1"> | ||
// <LoaderCircleIcon size={14} className="animate-spin" /> | ||
// </div> | ||
// ); | ||
// } | ||
|
||
return ( | ||
<CompactNumber | ||
number={notional || BigNumber(0)} | ||
decimals={2} | ||
compactAbove={1000} | ||
/> | ||
); | ||
// return ( | ||
// <CompactNumber | ||
// number={notional || BigNumber(0)} | ||
// decimals={2} | ||
// compactAbove={1000} | ||
// /> | ||
// ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.