-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centrifuge App: transfer CFG to EVM address (#1720)
* Add cfg row to table * Rename to holdings and install drawer * Add heading and label value stacks * Add subscan as block explorer for evm on cent chain * Add send cfg form * Add receive cfg component * Fetch wrapped CFG token price * Add CFG Price chart * Get price chart data * Adjust receive tab for substrate connected wallets * Update order of nav bar components * Adapt some colors pre input update * Enable drawer on prime but hide send/receive * Add hook to fetch historical token prices * Use most current price for label * Add filters and price difference in percent * Move chart to be reused and fix decimal errors in input * Correct USDT to USD in holdings table * Fix evm to cent trasnfers and tx toast * Fix currency in toast * Fix x axis ticks on charts * Add tooltip * Clean up address conversion * Show native currency only on native network * Remove addressToHex * Change address fetching * Update styles and copy * Subtract txFee from max send * Update tx fee hook * Remove extended evm address to avoid confusion * Memoize Price chart * Improve x axis on price chart
- Loading branch information
1 parent
adf83db
commit 987848e
Showing
25 changed files
with
594 additions
and
90 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
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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { Box, Select, Shelf, Stack, Text } from '@centrifuge/fabric' | ||
import React from 'react' | ||
import { Area, AreaChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts' | ||
import { useTheme } from 'styled-components' | ||
import { Dec } from '../../utils/Decimal' | ||
import { CustomizedTooltip } from './Tooltip' | ||
|
||
export type FilterOptions = 'YTD' | '30days' | '90days' | ||
|
||
type PriceChartProps = { | ||
data: { day: Date; price: number }[] | ||
currency: string | ||
filter?: FilterOptions | ||
setFilter?: React.Dispatch<React.SetStateAction<FilterOptions>> | ||
} | ||
|
||
export const PriceChart = ({ data, currency, filter, setFilter }: PriceChartProps) => { | ||
const theme = useTheme() | ||
const currentPrice = data.at(-1)?.price | ||
|
||
const priceDifference = React.useMemo(() => { | ||
return Dec(data.at(0)?.price || 1).div(currentPrice || 1) | ||
}, [data, filter]) | ||
|
||
return ( | ||
<Stack gap={0}> | ||
<Shelf gap={1} justifyContent="space-between"> | ||
<Shelf gap={1}> | ||
{currentPrice && ( | ||
<Text variant="body3"> | ||
{currency} - {currentPrice.toFixed(4)} USD | ||
</Text> | ||
)} | ||
<Text variant="body3" color={priceDifference.gte(0) ? 'statusOk' : 'statusError'}> | ||
{' '} | ||
{priceDifference.gte(0) ? '+' : '-'} {priceDifference.mul(100).toFixed(2)}% | ||
</Text> | ||
</Shelf> | ||
{filter && setFilter && ( | ||
<Box alignSelf="flex-end" justifySelf="flex-end"> | ||
<Select | ||
options={[ | ||
{ label: 'YTD', value: 'YTD' }, | ||
{ label: '30 days', value: '30days' }, | ||
{ label: '90 days', value: '90days' }, | ||
]} | ||
onChange={(option) => setFilter(option.target.value as FilterOptions)} | ||
/> | ||
</Box> | ||
)} | ||
</Shelf> | ||
<ResponsiveContainer width="100%" height="100%" minHeight="200px"> | ||
<AreaChart data={data || []} margin={{ top: 18, left: -30 }}> | ||
<defs> | ||
<linearGradient id="colorPrice" x1="0" y1="0" x2="0" y2="1"> | ||
<stop offset="5%" stopColor={'#626262'} stopOpacity={0.4} /> | ||
<stop offset="95%" stopColor={'#908f8f'} stopOpacity={0} /> | ||
</linearGradient> | ||
</defs> | ||
<XAxis | ||
dataKey="day" | ||
type="category" | ||
tickFormatter={(tick: number) => { | ||
if (data.length > 180) { | ||
return new Date(tick).toLocaleString('en-US', { month: 'short' }) | ||
} | ||
return new Date(tick).toLocaleString('en-US', { day: 'numeric', month: 'short' }) | ||
}} | ||
interval={(function interval() { | ||
if (filter === '30days') return 5 | ||
if (filter === '90days') return 14 | ||
if (filter === 'YTD' && data.length < 180) return 30 | ||
return 45 | ||
})()} | ||
style={{ fontSize: '10px', fill: theme.colors.textSecondary, letterSpacing: '-0.5px' }} | ||
tickLine={false} | ||
allowDuplicatedCategory={false} | ||
/> | ||
<YAxis | ||
tickCount={6} | ||
dataKey="price" | ||
tickLine={false} | ||
style={{ fontSize: '10px', fill: theme.colors.textSecondary, letterSpacing: '-0.5px' }} | ||
tickFormatter={(tick: number) => { | ||
return tick.toFixed(2) | ||
}} | ||
interval={'preserveStartEnd'} | ||
/> | ||
<CartesianGrid stroke={theme.colors.borderSecondary} /> | ||
<Tooltip content={<CustomizedTooltip currency={currency} precision={4} />} /> | ||
<Area | ||
type="monotone" | ||
dataKey="price" | ||
strokeWidth={1} | ||
fillOpacity={1} | ||
fill="url(#colorPrice)" | ||
name="Price" | ||
activeDot={{ fill: '#908f8f' }} | ||
stroke="#908f8f" | ||
/> | ||
</AreaChart> | ||
</ResponsiveContainer> | ||
</Stack> | ||
) | ||
} |
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
32 changes: 2 additions & 30 deletions
32
...components/Charts/CustomChartElements.tsx → ...uge-app/src/components/Charts/Tooltip.tsx
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.