Skip to content

Commit 8b29bb5

Browse files
committed
chore: package Diff component and reuse it for the delegation list
1 parent b93021d commit 8b29bb5

File tree

8 files changed

+29
-44
lines changed

8 files changed

+29
-44
lines changed

src/assets/css/pageStatsPanel.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@
8585
}
8686

8787
.metric-trend {
88-
display: flex;
89-
align-items: center;
90-
gap: 5px;
9188
margin-top: 12px;
9289
font-size: 1.2rem;
9390
}

src/components/pages/diff.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const Diff = ({ diff, unit }) => {
2+
let color = '#50e3c2'
3+
const neg = typeof diff == 'string' && diff.startsWith('-')
4+
if (neg) {
5+
diff = diff.slice(1)
6+
color = '#ff3e55'
7+
}
8+
return <span style={{ color }}>
9+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
10+
<path d={neg ? "M6 9L12 15L18 9" : "M18 15L12 9L6 15"} stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
11+
</svg>
12+
<span style={{ marginLeft: 5 }}>{diff} {unit}</span>
13+
</span>
14+
}

src/components/sections/callToAction.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const CallToAction = () => {
2929
if (walletAddress == null) {
3030
component = <div className="hero-btns">
3131
<a onClick={onConnectWallet} className="theme-btn">
32-
Connect Wallet To See Your Options
32+
Connect Wallet
3333
</a>
3434
</div>
3535
} else if (isLoading) {

src/components/ui/delegationSummary.tsx

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import classNames from "classnames"
21
import { SpinnerCircular } from "spinners-react"
32
import { ApiResponseDto_PageStatsDto } from "~/backendApi"
43
import { Formatter } from "~/utils/misc/formatter"
4+
import { Diff } from "../pages/diff"
55
import { PAGE_COLOR_CODE } from "~/constants"
66

7-
const DOWN_ARROW = "M6 9L12 15L18 9"
8-
const UP_ARROW = "M18 15L12 9L6 15"
7+
98

109
const DelegationSummary = ({ data, isLoading, error }: {
1110
data: ApiResponseDto_PageStatsDto, isLoading: boolean, error: string
@@ -31,20 +30,10 @@ const DelegationSummary = ({ data, isLoading, error }: {
3130
console.log(String(error)) // should not happen
3231
}
3332

34-
const delegatedNeg = typeof delegatedDiff == 'string' && delegatedDiff.startsWith('-')
35-
const delegatorNeg = typeof delegatorDiff == 'string' && delegatorDiff.startsWith('-')
36-
37-
if (delegatedNeg) {
38-
delegatedDiff = delegatedDiff.slice(1)
39-
}
40-
if (delegatorNeg) {
41-
delegatorDiff = delegatorDiff.slice(1)
42-
}
43-
4433
return <div className="page-stats-container">
4534
<div className="dashboard loading">
46-
4735
<div className="metrics-grid">
36+
4837
<div className="metric-card" data-start="0" data-end="7489" data-increment="1" data-speed="10">
4938
<div className="metric-title">
5039
Total Delegated
@@ -53,11 +42,8 @@ const DelegationSummary = ({ data, isLoading, error }: {
5342
<span className="counter-unit">$</span>
5443
<div className="counter" id="counter-1">{delegated}</div>
5544
</div>
56-
<div className={classNames('metric-trend', { 'trend-down': delegatedNeg, 'trend-up': !delegatedNeg })}>
57-
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
58-
<path d={delegatedNeg ? DOWN_ARROW : UP_ARROW} stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
59-
</svg>
60-
<span>{delegatedDiff} in 24h</span>
45+
<div className="metric-trend">
46+
<Diff diff={delegatedDiff} unit={"in 24h"} />
6147
</div>
6248
</div>
6349

@@ -69,11 +55,8 @@ const DelegationSummary = ({ data, isLoading, error }: {
6955
<div className="counter" id="counter-2">{delegators}</div>
7056
<span className="counter-unit">users</span>
7157
</div>
72-
<div className={classNames('metric-trend', { 'trend-down': delegatorNeg, 'trend-up': !delegatorNeg })}>
73-
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
74-
<path d={delegatorNeg ? DOWN_ARROW : UP_ARROW} stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
75-
</svg>
76-
<span>{delegatorDiff} in 24h</span>
58+
<div className="metric-trend">
59+
<Diff diff={delegatorDiff} unit={"in 24h"} />
7760
</div>
7861
</div>
7962

src/components/ui/delegationUpdates.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from "react"
22
import { SpinnerCircular } from "spinners-react"
33
import { ApiResponseDto_PageStatsDto, DelegationDto } from "~/backendApi"
4-
import * as C from "~/constants"
54
import { Formatter } from "~/utils/misc/formatter"
65
import { HashLink } from "../utils/links"
6+
import { Diff } from "../pages/diff"
7+
import * as C from "~/constants"
78
import avalanche from "../../assets/images/tokens/AVAX.svg"
89
import flare from "../../assets/images/tokens/FLR.svg"
910
import songbird from "../../assets/images/tokens/SGB.svg"
@@ -59,16 +60,6 @@ function resolveProtocolName(protocol: DelegationDto.protocol): string {
5960
}
6061
}
6162

62-
const NumberDiff = ({ text, value }: { text: string, value: number }) => {
63-
if (value > 0) {
64-
return <span style={{ color: '#50e3c2' }}>+{text}</span>
65-
} else if (value < 0) {
66-
return <span style={{ color: '#ff3e55' }}>{text}</span>
67-
} else {
68-
return <span style={{ color: 'white' }}>0</span>
69-
}
70-
}
71-
7263
const DelegationUpdates = ({ data, isLoading, error }: {
7364
data: ApiResponseDto_PageStatsDto, isLoading: boolean, error: string
7465
}) => {
@@ -94,12 +85,12 @@ const DelegationUpdates = ({ data, isLoading, error }: {
9485
{delegations.map((delegation, i) => {
9586
const logo = chainToLogoUrl(delegation.chain)
9687
const url = chainToTransactionUrl(delegation.chain, delegation.protocol, delegation.transaction)
97-
const delegated = Formatter.number(delegation.delegated)
88+
const diff = Formatter.number(delegation.delegated)
9889
return <React.Fragment key={i}>
9990
<div><img src={logo} width={25} /></div>
10091
<div>{resolveProtocolName(delegation.protocol)}</div>
10192
<div><HashLink address={delegation.transaction} url={url} length={5} copy={false} /></div>
102-
<div><NumberDiff value={Number(delegation.delegated)} text={delegated} /></div>
93+
<div style={{ textAlign: 'center' }}><Diff diff={diff} unit={chainToSymbol(delegation.chain)} /></div>
10394
<div>{Formatter.relativeDate(delegation.timestamp)}</div>
10495
</React.Fragment>
10596
})}

src/pages/protocols/flare-fsp/components/delegateLocal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const FlareFspLocalDelegateComponent = () => {
5959
if (walletAddress == null) {
6060
component = <div style={{ textAlign: 'center' }}>
6161
<a onClick={connectWallet} className="theme-btn">
62-
Connect Wallet To See Your Position
62+
Connect Wallet
6363
</a>
6464
</div>
6565
} else if (isLoading) {

src/pages/protocols/flare-validator/components/delegateLocal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const FlareValidatorLocalDelegateComponent = () => {
121121
if (walletAddress == null) {
122122
component = <div style={{ textAlign: 'center' }}>
123123
<a onClick={onConnectWallet} className="theme-btn">
124-
Connect Wallet To See Your Position
124+
Connect Wallet
125125
</a>
126126
</div>
127127
} else if (isLoading && resp?.data == null && resp?.status != 404) {

src/pages/protocols/songbird-fsp/components/delegateLocal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const SongbirdFspLocalDelegateComponent = () => {
5959
if (walletAddress == null) {
6060
component = <div style={{ textAlign: 'center' }}>
6161
<a onClick={connectWallet} className="theme-btn">
62-
Connect Wallet To See Your Position
62+
Connect Wallet
6363
</a>
6464
</div>
6565
} else if (isLoading) {

0 commit comments

Comments
 (0)