@@ -3,81 +3,43 @@ import { SpinnerCircular } from "spinners-react"
33import { ApiResponseDto_PageStatsDto , RewardClaimDto } from "~/backendApi"
44import { Formatter } from "~/utils/misc/formatter"
55import { HashLink } from "../utils/links"
6+ import { Chain , Protocol } from "~/enums"
67import * as C from "~/constants"
78import avalanche from "../../assets/images/tokens/AVAX.svg"
89import flare from "../../assets/images/tokens/FLR.svg"
910import songbird from "../../assets/images/tokens/SGB.svg"
1011
11-
12- function chainToLogoUrl ( chain : RewardClaimDto . chain ) : string {
13- if ( chain == RewardClaimDto . chain . _0 ) {
14- return flare
15- } else if ( chain == RewardClaimDto . chain . _1 ) {
16- return songbird
17- } else {
18- return avalanche
19- }
20- }
21-
22- function chainToSymbol ( chain : RewardClaimDto . chain ) : string {
23- if ( chain == RewardClaimDto . chain . _0 ) {
24- return 'FLR'
25- } else if ( chain == RewardClaimDto . chain . _1 ) {
26- return 'SGB'
27- } else {
28- return 'AVAX'
29- }
12+ const CHAIN_LOGO : Record < number , string > = {
13+ [ Chain . FLARE ] : flare ,
14+ [ Chain . SONGBIRD ] : songbird ,
15+ [ Chain . AVALANCHE ] : avalanche ,
3016}
3117
32- function chainToTransactionUrl (
33- chain : RewardClaimDto . chain ,
34- protocol : RewardClaimDto . protocol ,
35- hash : string
36- ) : string {
37- if ( chain == RewardClaimDto . chain . _0 ) {
38- if ( protocol == RewardClaimDto . protocol . _0 ) {
18+ function chainToTransactionUrl ( chain : number , protocol : number , hash : string ) : string {
19+ if ( chain == Chain . FLARE ) {
20+ if ( protocol == Protocol . FSP ) {
3921 return C . flareEvmTransactionUrl ( hash )
40- } else if ( protocol == RewardClaimDto . protocol . _1 ) {
41- return C . flarePChainTransactionUrl ( hash )
4222 } else {
43- throw Error ( `Invalid protocol ${ chain } : ${ protocol } ` )
23+ return C . flarePChainTransactionUrl ( hash )
4424 }
45- } else if ( chain == RewardClaimDto . chain . _1 ) {
25+ } else if ( chain == Chain . SONGBIRD ) {
4626 return C . songbirdEvmTransactionUrl ( hash )
47- } else if ( chain == RewardClaimDto . chain . _2 ) {
27+ } else if ( chain == Chain . AVALANCHE ) {
4828 return C . avalanchePChainTransactionUrl ( hash )
49- } else {
50- throw Error ( `Invalid protocol ${ chain } :${ protocol } ` )
5129 }
5230}
5331
54- function chainToAddressUrl (
55- chain : RewardClaimDto . chain ,
56- protocol : RewardClaimDto . protocol ,
57- address : string
58- ) : string {
59- if ( chain == RewardClaimDto . chain . _0 ) {
60- if ( protocol == RewardClaimDto . protocol . _0 ) {
32+ function chainToAddressUrl ( chain : number , protocol : number , address : string ) : string {
33+ if ( chain == Chain . FLARE ) {
34+ if ( protocol == Protocol . FSP ) {
6135 return C . flareEvmAddressUrl ( address )
62- } else if ( protocol == RewardClaimDto . protocol . _1 ) {
63- return C . flarePChainAddressUrl ( address )
6436 } else {
65- throw Error ( `Invalid protocol ${ chain } : ${ protocol } ` )
37+ return C . flarePChainAddressUrl ( address )
6638 }
67- } else if ( chain == RewardClaimDto . chain . _1 ) {
39+ } else if ( chain == Chain . SONGBIRD ) {
6840 return C . songbirdEvmAddressUrl ( address )
69- } else if ( chain == RewardClaimDto . chain . _2 ) {
41+ } else if ( chain == Chain . AVALANCHE ) {
7042 return C . avalanchePChainAddressUrl ( address )
71- } else {
72- throw Error ( `Invalid protocol ${ chain } :${ protocol } ` )
73- }
74- }
75-
76- function resolveProtocolName ( protocol : RewardClaimDto . protocol ) : string {
77- if ( protocol == RewardClaimDto . protocol . _0 ) {
78- return 'FSP'
79- } else if ( protocol == RewardClaimDto . protocol . _1 ) {
80- return 'Validator'
8143 }
8244}
8345
@@ -113,26 +75,26 @@ const RewardClaims = ({ data, isLoading, error }: {
11375 </ div >
11476 < div className = "reward-claims-carousel" ref = { scrollRef } >
11577 { rewards . map ( ( reward , i ) => {
116- const logo = chainToLogoUrl ( reward . chain )
117- const symbol = chainToSymbol ( reward . chain )
78+ const logo = CHAIN_LOGO [ reward . chain ]
79+ const symbol = C . CHAIN_SYMBOL [ reward . chain ]
11880 const txUrl = chainToTransactionUrl ( reward . chain , reward . protocol , reward . transaction )
11981 const addrUrl = chainToAddressUrl ( reward . chain , reward . protocol , reward . recipient )
12082 return < div className = "reward-claim-card" key = { i } >
12183 < div className = "reward-claim-card-top" >
12284 < img src = { logo } width = { 28 } alt = { symbol } />
123- < span className = "reward-claim-protocol" > { resolveProtocolName ( reward . protocol ) } </ span >
85+ < span className = "reward-claim-protocol" > { C . PROTOCOL_NAME [ reward . protocol ] } </ span >
12486 </ div >
12587 < div className = "reward-claim-amount" >
12688 +{ Formatter . number ( reward . reward ) } < span className = "reward-claim-symbol" > { symbol } </ span >
12789 </ div >
12890 < div className = "reward-claim-details" >
12991 < div className = "reward-claim-row" >
13092 < span className = "reward-claim-label" > Tx</ span >
131- < HashLink address = { reward . transaction } url = { txUrl } length = { 6 } copy = { true } />
93+ < HashLink address = { reward . transaction } url = { txUrl } length = { 6 } copy = { false } />
13294 </ div >
13395 < div className = "reward-claim-row" >
13496 < span className = "reward-claim-label" > To</ span >
135- < HashLink address = { reward . recipient } url = { addrUrl } length = { 6 } copy = { true } />
97+ < HashLink address = { reward . recipient } url = { addrUrl } length = { 6 } copy = { false } />
13698 </ div >
13799 </ div >
138100 < div className = "reward-claim-time" > { Formatter . relativeDate ( reward . timestamp ) } </ div >
0 commit comments