Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centrifuge App: transfer CFG to EVM address #1720

Merged
merged 36 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d08e662
Add cfg row to table
sophialittlejohn Nov 28, 2023
9635507
Merge branch 'main' of github.com:centrifuge/apps into cent-app/cfg-e…
sophialittlejohn Nov 29, 2023
06fb038
Rename to holdings and install drawer
sophialittlejohn Nov 29, 2023
57902ab
Add heading and label value stacks
sophialittlejohn Nov 29, 2023
5176859
Add subscan as block explorer for evm on cent chain
sophialittlejohn Nov 29, 2023
d4241c7
Add send cfg form
sophialittlejohn Nov 29, 2023
c9fad76
Add receive cfg component
sophialittlejohn Nov 30, 2023
aef3b0d
Fetch wrapped CFG token price
sophialittlejohn Nov 30, 2023
ec4faa6
Add CFG Price chart
sophialittlejohn Nov 30, 2023
d57a561
Get price chart data
sophialittlejohn Dec 1, 2023
06d7151
Adjust receive tab for substrate connected wallets
sophialittlejohn Dec 1, 2023
89ecfe3
Update order of nav bar components
sophialittlejohn Dec 1, 2023
6e739df
Adapt some colors pre input update
sophialittlejohn Dec 1, 2023
feff672
Enable drawer on prime but hide send/receive
sophialittlejohn Dec 1, 2023
98ca337
Add hook to fetch historical token prices
sophialittlejohn Dec 1, 2023
b41e1ea
Use most current price for label
sophialittlejohn Dec 1, 2023
53189bb
Add filters and price difference in percent
sophialittlejohn Dec 4, 2023
dfda053
Move chart to be reused and fix decimal errors in input
sophialittlejohn Dec 4, 2023
62d570e
Correct USDT to USD in holdings table
sophialittlejohn Dec 4, 2023
4a1c288
Fix evm to cent trasnfers and tx toast
sophialittlejohn Dec 4, 2023
a0ef091
Fix currency in toast
sophialittlejohn Dec 4, 2023
8ebe91f
Fix x axis ticks on charts
sophialittlejohn Dec 4, 2023
a360b14
Merge branch 'main' of github.com:centrifuge/apps into cent-app/cfg-e…
sophialittlejohn Dec 6, 2023
308479a
Add tooltip
sophialittlejohn Dec 6, 2023
0896b56
Clean up address conversion
sophialittlejohn Dec 6, 2023
d1ccaf8
Show native currency only on native network
sophialittlejohn Dec 6, 2023
3fb2e2f
Remove addressToHex
sophialittlejohn Dec 6, 2023
1a0ca26
Change address fetching
sophialittlejohn Dec 6, 2023
10deab7
Update styles and copy
sophialittlejohn Dec 6, 2023
6dc57cf
Subtract txFee from max send
sophialittlejohn Dec 6, 2023
dc2e5c2
Update tx fee hook
sophialittlejohn Dec 6, 2023
12ce118
Remove extended evm address to avoid confusion
sophialittlejohn Dec 7, 2023
9a20a53
Memoize Price chart
sophialittlejohn Dec 7, 2023
6850e4e
Improve x axis on price chart
sophialittlejohn Dec 7, 2023
0004e6c
Merge branch 'main' into cent-app/cfg-evm-transfer-support
sophialittlejohn Dec 7, 2023
14b10c7
Merge branch 'main' into cent-app/cfg-evm-transfer-support
sophialittlejohn Dec 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions centrifuge-app/src/components/Charts/PoolAssetReserveChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { daysBetween } from '../../utils/date'
import { formatBalance, formatBalanceAbbreviated } from '../../utils/formatting'
import { useDailyPoolStates, usePool } from '../../utils/usePools'
import { Tooltips } from '../Tooltips'
import { CustomizedTooltip, CustomizedXAxisTick } from './CustomChartElements'
import { CustomizedTooltip } from './Tooltip'

type ChartData = {
day: Date
Expand Down Expand Up @@ -56,9 +56,15 @@ const PoolAssetReserveChart: React.VFC = () => {
<ComposedChart data={chartData} margin={{ left: -16 }} reverseStackOrder>
<XAxis
dataKey="day"
tick={<CustomizedXAxisTick variant={chartData.length > 30 ? 'months' : 'days'} />}
tickLine={false}
interval={chartData.length < 18 || chartData.length > 30 ? 0 : 1}
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' })
}}
style={{ fontSize: '10px', fill: theme.colors.textSecondary, letterSpacing: '-0.5px' }}
/>
<YAxis
tickLine={false}
Expand Down
105 changes: 105 additions & 0 deletions centrifuge-app/src/components/Charts/PriceChart.tsx
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>
)
}
13 changes: 10 additions & 3 deletions centrifuge-app/src/components/Charts/PriceYieldChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTheme } from 'styled-components'
import { formatBalance } from '../../utils/formatting'
import { useDailyTrancheStates, usePool } from '../../utils/usePools'
import { Spinner } from '../Spinner'
import { CustomizedTooltip, CustomizedXAxisTick } from './CustomChartElements'
import { CustomizedTooltip } from './Tooltip'

type ChartData = {
day: Date
Expand Down Expand Up @@ -48,9 +48,16 @@ const PriceYieldChart: React.FC<{
<ComposedChart data={data} margin={{ left: -30, top: 2 }} reverseStackOrder>
<XAxis
dataKey="day"
tick={<CustomizedXAxisTick variant={data.length > 30 ? 'months' : 'days'} />}
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' })
}}
style={{ fontSize: '10px', fill: theme.colors.textSecondary, letterSpacing: '-0.5px' }}
tickLine={false}
interval={data.length < 18 || data.length > 30 ? 0 : 1}
allowDuplicatedCategory={false}
/>
<YAxis
tickLine={false}
Expand Down
12 changes: 9 additions & 3 deletions centrifuge-app/src/components/Charts/ReserveCashDragChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTheme } from 'styled-components'
import { formatBalance, formatBalanceAbbreviated, formatPercentage } from '../../utils/formatting'
import { useDailyPoolStates, usePool } from '../../utils/usePools'
import { Tooltips } from '../Tooltips'
import { CustomizedTooltip, CustomizedXAxisTick } from './CustomChartElements'
import { CustomizedTooltip } from './Tooltip'

type ChartData = {
day: Date
Expand Down Expand Up @@ -51,9 +51,15 @@ export default function ReserveCashDragChart() {
<ComposedChart data={chartData} margin={{ left: -16 }}>
<XAxis
dataKey="day"
tick={<CustomizedXAxisTick variant={chartData.length > 30 ? 'months' : 'days'} />}
tickLine={false}
interval={chartData.length < 18 || chartData.length > 30 ? 0 : 1}
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' })
}}
style={{ fontSize: '10px', fill: theme.colors.textSecondary, letterSpacing: '-0.5px' }}
/>
<YAxis
yAxisId="left"
Expand Down
12 changes: 9 additions & 3 deletions centrifuge-app/src/components/Charts/StackedBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useTheme } from 'styled-components'
import { PropsOf } from '../../../helpers'
import { formatDate } from '../../utils/date'
import { formatBalance, formatBalanceAbbreviated } from '../../utils/formatting'
import { TooltipContainer, TooltipEntry, TooltipTitle } from './CustomChartElements'
import { TooltipContainer, TooltipEntry, TooltipTitle } from './Tooltip'

export type StackedBarChartProps = {
data: {
Expand Down Expand Up @@ -49,10 +49,16 @@ export function StackedBarChart({ data, names, colors, currency }: StackedBarCha
style={axisStyle}
tickLine={false}
axisLine={false}
interval={0}
tickMargin={10}
angle={45}
tickFormatter={(tick: number) => formatDate(tick, { year: undefined })}
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' })
}}
allowDuplicatedCategory={false}
/>

<YAxis
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
import { Box, Shelf, Stack, Text } from '@centrifuge/fabric'
import * as React from 'react'
import { AreaProps, TooltipProps } from 'recharts'
import { useTheme } from 'styled-components'
import { TooltipProps } from 'recharts'
import { formatDate } from '../../utils/date'
import { formatBalance, formatPercentage } from '../../utils/formatting'

type CustomizedXAxisTickProps = {
payload?: { value: Date }
variant: 'months' | 'days'
} & Pick<AreaProps, 'x'> &
Pick<AreaProps, 'y'>

export const CustomizedXAxisTick: React.VFC<CustomizedXAxisTickProps> = ({ payload, x, y, variant }) => {
const theme = useTheme()
let tick
if (variant === 'months') {
const formatter = new Intl.DateTimeFormat('en', { month: 'short' })
// show month tick only on the first of every month
tick = payload?.value && new Date(payload.value).getDate() === 1 ? formatter.format(payload?.value) : null
} else {
const formatter = new Intl.DateTimeFormat('en', { day: 'numeric', month: 'short' })
tick = formatter.format(payload?.value)
}

return (
<g transform={`translate(${x},${y})`}>
<text x={0} y={0} dy={16} fontSize="10px" fill={theme.colors.textSecondary} textAnchor="center">
{tick}
</text>
</g>
)
}

type CustomizedTooltipProps = TooltipProps<any, any> & { currency: string; precision?: number }

export const CustomizedTooltip: React.VFC<CustomizedTooltipProps> = ({ payload, currency, precision }) => {
export const CustomizedTooltip: React.FC<CustomizedTooltipProps> = ({ payload, currency, precision }) => {
if (payload && payload?.length > 0) {
return (
<TooltipContainer>
Expand Down
25 changes: 13 additions & 12 deletions centrifuge-app/src/components/Menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,19 @@ export function Menu() {
Pools
</PageLink>

{config.network !== 'centrifuge' && (
<PageLink to="/nfts" stacked={!isLarge}>
<IconNft />
NFTs
{showPrime && (
<PageLink to="/prime" stacked={!isLarge}>
<IconGlobe />
Prime
</PageLink>
)}

<GovernanceMenu />

{showPortfolio && address && (
<PageLink to="/portfolio" stacked={!isLarge}>
<IconPieChart />
Portfolio
</PageLink>
)}
{showPrime && (
<PageLink to="/prime" stacked={!isLarge}>
<IconGlobe />
Prime
</PageLink>
)}

{showPortfolio && address && (
<PageLink to="/history" stacked={!isLarge}>
Expand All @@ -70,6 +62,15 @@ export function Menu() {
</PageLink>
)}

{config.network !== 'centrifuge' && (
<PageLink to="/nfts" stacked={!isLarge}>
<IconNft />
NFTs
</PageLink>
)}

<GovernanceMenu />

{(pools.length > 0 || config.poolCreationType === 'immediate') && (
<IssuerMenu defaultOpen={isLarge} stacked={!isLarge}>
{isLarge ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { Cell, Pie, PieChart as RechartsPieChart, Tooltip, TooltipProps } from 'recharts'
import { formatBalanceAbbreviated, formatPercentage } from '../../utils/formatting'
import { TooltipContainer, TooltipEntry, TooltipTitle } from '../Charts/CustomChartElements'
import { TooltipContainer, TooltipEntry, TooltipTitle } from '../Charts/Tooltip'

type PieChartProps = {
data: { name: string; value: number; color?: string }[]
Expand Down
Loading