-
Notifications
You must be signed in to change notification settings - Fork 3
feat: refactor graphs and market page #295
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
852fa3e
feat: new graph
antoncoding bf31f7e
refactor: redesign header
antoncoding b479704
misc: fix icons
antoncoding 0091e50
chore: remove unused
antoncoding f61ee63
chore: cleanup
antoncoding a4ce1b6
chore: styling
antoncoding 1791679
chore: fix
antoncoding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,49 @@ | ||
| import Link from 'next/link'; | ||
| import { ExternalLinkIcon } from '@radix-ui/react-icons'; | ||
| import { Avatar } from '@/components/Avatar/Avatar'; | ||
| import { TokenIcon } from '@/components/shared/token-icon'; | ||
| import { getExplorerURL } from '@/utils/external'; | ||
|
|
||
| type AddressIdentityProps = { | ||
| address: string; | ||
| chainId: number; | ||
| label?: string; | ||
| isToken?: boolean; | ||
| tokenSymbol?: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Use to display address, not Account. Better used for contracts | ||
| * @param param0 | ||
| * @returns | ||
| */ | ||
| export function AddressIdentity({ address, chainId, label, isToken, tokenSymbol }: AddressIdentityProps) { | ||
| return ( | ||
| <Link | ||
| href={getExplorerURL(address as `0x${string}`, chainId)} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="inline-flex items-center gap-1.5 rounded-sm bg-hovered px-2 py-1 text-xs text-secondary no-underline hover:bg-gray-300 dark:hover:bg-gray-700" | ||
| > | ||
| {isToken ? ( | ||
| <TokenIcon | ||
| address={address} | ||
| chainId={chainId} | ||
| symbol={tokenSymbol ?? ''} | ||
| width={14} | ||
| height={14} | ||
| /> | ||
| ) : ( | ||
| <Avatar | ||
| address={address as `0x${string}`} | ||
| size={14} | ||
| /> | ||
| )} | ||
| {label && <span>{label}</span>} | ||
| <span className="font-mono text-[11px]"> | ||
| {address.slice(0, 6)}...{address.slice(-4)} | ||
| </span> | ||
| <ExternalLinkIcon className="h-3 w-3" /> | ||
| </Link> | ||
| ); | ||
| } | ||
This file contains hidden or 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 hidden or 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
125 changes: 125 additions & 0 deletions
125
src/features/market-detail/components/charts/chart-utils.tsx
This file contains hidden or 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,125 @@ | ||
| import type { Dispatch, SetStateAction } from 'react'; | ||
| import { CHART_COLORS } from '@/constants/chartColors'; | ||
|
|
||
| export const TIMEFRAME_LABELS: Record<string, string> = { | ||
| '1d': '1D', | ||
| '7d': '7D', | ||
| '30d': '30D', | ||
| }; | ||
|
|
||
| type GradientConfig = { | ||
| id: string; | ||
| color: string; | ||
| }; | ||
|
|
||
| export function ChartGradients({ prefix, gradients }: { prefix: string; gradients: GradientConfig[] }) { | ||
| return ( | ||
| <defs> | ||
| {gradients.map(({ id, color }) => ( | ||
| <linearGradient | ||
| key={id} | ||
| id={`${prefix}-${id}`} | ||
| x1="0" | ||
| y1="0" | ||
| x2="0" | ||
| y2="1" | ||
| > | ||
| <stop | ||
| offset="0%" | ||
| stopColor={color} | ||
| stopOpacity={0.08} | ||
| /> | ||
| <stop | ||
| offset="100%" | ||
| stopColor={color} | ||
| stopOpacity={0} | ||
| /> | ||
| </linearGradient> | ||
| ))} | ||
| </defs> | ||
| ); | ||
| } | ||
|
|
||
| export const RATE_CHART_GRADIENTS: GradientConfig[] = [ | ||
| { id: 'supplyGradient', color: CHART_COLORS.supply.stroke }, | ||
| { id: 'borrowGradient', color: CHART_COLORS.borrow.stroke }, | ||
| { id: 'targetGradient', color: CHART_COLORS.apyAtTarget.stroke }, | ||
| ]; | ||
|
|
||
| export const VOLUME_CHART_GRADIENTS: GradientConfig[] = [ | ||
| { id: 'supplyGradient', color: CHART_COLORS.supply.stroke }, | ||
| { id: 'borrowGradient', color: CHART_COLORS.borrow.stroke }, | ||
| { id: 'liquidityGradient', color: CHART_COLORS.apyAtTarget.stroke }, | ||
| ]; | ||
|
|
||
| type ChartTooltipContentProps = { | ||
| active?: boolean; | ||
| payload?: any[]; | ||
| label?: number; | ||
| formatValue: (value: number) => string; | ||
| }; | ||
|
|
||
| export function ChartTooltipContent({ active, payload, label, formatValue }: ChartTooltipContentProps) { | ||
| if (!active || !payload) return null; | ||
| return ( | ||
| <div className="rounded-lg border border-border bg-background p-3 shadow-lg"> | ||
| <p className="mb-2 text-xs text-secondary">{new Date((label ?? 0) * 1000).toLocaleDateString()}</p> | ||
| <div className="space-y-1"> | ||
| {payload.map((entry: any) => ( | ||
| <div | ||
| key={entry.dataKey} | ||
| className="flex items-center justify-between gap-6 text-sm" | ||
| > | ||
| <div className="flex items-center gap-2"> | ||
| <span | ||
| className="h-2 w-2 rounded-full" | ||
| style={{ backgroundColor: entry.color }} | ||
| /> | ||
| <span className="text-secondary">{entry.name}</span> | ||
| </div> | ||
| <span className="tabular-nums">{formatValue(entry.value)}</span> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| type ChartLegendProps<T extends Record<string, boolean>> = { | ||
| visibleLines: T; | ||
| setVisibleLines: Dispatch<SetStateAction<T>>; | ||
| }; | ||
|
|
||
| export function createLegendClickHandler<T extends Record<string, boolean>>({ visibleLines, setVisibleLines }: ChartLegendProps<T>) { | ||
| return { | ||
| onClick: (e: any) => { | ||
| const dataKey = e.dataKey as keyof T; | ||
| setVisibleLines((prev) => ({ | ||
| ...prev, | ||
| [dataKey]: !prev[dataKey], | ||
| })); | ||
| }, | ||
| formatter: (value: string, entry: any) => ( | ||
| <span | ||
| className="text-xs" | ||
| style={{ | ||
| color: visibleLines[entry.dataKey as keyof T] ? 'var(--color-text-secondary)' : '#666', | ||
| }} | ||
| > | ||
| {value} | ||
| </span> | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
| export const chartTooltipCursor = { | ||
| stroke: 'var(--color-text-secondary)', | ||
| strokeWidth: 1, | ||
| strokeDasharray: '4 4', | ||
| }; | ||
|
|
||
| export const chartLegendStyle = { | ||
| wrapperStyle: { fontSize: '12px', paddingTop: '8px' }, | ||
| iconType: 'circle' as const, | ||
| iconSize: 8, | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.