@@ -5,14 +5,16 @@ import {
55 CircularProgress ,
66 Chip ,
77 Button ,
8- Link ,
8+ Alert ,
99} from "@mui/material" ;
1010import OpenInNewIcon from "@mui/icons-material/OpenInNew" ;
1111import { AppService } from "../../services/AppService" ;
1212import { NodeRewards } from "../../types/NodeRewards" ;
1313import { toWei } from "../../utils/Utils" ;
1414import { Config } from "../../types/AppConfig" ;
1515import TxsLinksBox from "../Setup/TxsLinksBox" ;
16+ import { CanClaimRewards } from "../../types/CanClaimRewards" ;
17+ import { TxResponse } from "../../types/TxResponse" ;
1618
1719interface RewardsTabProps {
1820 config ?: Config ;
@@ -25,6 +27,8 @@ const RewardsTab: React.FC<RewardsTabProps> = ({
2527 const [ isClaiming , setIsClaiming ] = useState < boolean > ( false ) ;
2628 const [ txs , setTxs ] = useState < string [ ] > ( [ ] ) ;
2729 const [ nodeRewards , setNodeRewards ] = useState < NodeRewards > ( ) ;
30+ const [ nodeCanClaimRewards , setNodeCanClaimRewards ] = useState < CanClaimRewards > ( ) ;
31+ const [ txResponse , setTxResponse ] = useState < TxResponse > ( ) ;
2832
2933 const appService = new AppService ( ) ;
3034
@@ -51,26 +55,32 @@ const RewardsTab: React.FC<RewardsTabProps> = ({
5155 var indexes = rewardsInfo . unclaimedIntervals
5256 . map ( ( reward ) => reward . index )
5357 . join ( "," ) ;
58+ const sumCollateralRplAmount = rewardsInfo . unclaimedIntervals . reduce (
59+ ( accumulator , currentValue ) => accumulator + Number ( currentValue . collateralRplAmount ) ,
60+ 0
61+ ) ;
5462 var canClainRewards = restake
5563 ? await appService . getNodeCanClaimAndRestakeRewards (
5664 indexes ,
57- toWei ( nodeRewards ?. unclaimedRplRewards ?? 0 )
65+ sumCollateralRplAmount ,
5866 )
5967 : await appService . getNodeCanClaimRewards ( indexes ) ;
68+ setNodeCanClaimRewards ( canClainRewards ) ;
6069 if ( canClainRewards . status !== "success" ) {
6170 return ;
6271 }
63- var claimRewards = restake
72+ var tx = restake
6473 ? await appService . nodeClaimAndRestakeRewards (
6574 indexes ,
66- toWei ( nodeRewards ?. unclaimedRplRewards ?? 0 )
75+ sumCollateralRplAmount ,
6776 )
6877 : await appService . nodeClaimRewards ( indexes ) ;
69- setTxs ( [ ...txs , claimRewards . txHash ] ) ;
70- if ( claimRewards . status !== "success" ) {
78+ setTxResponse ( tx ) ;
79+ setTxs ( [ ...txs , tx . txHash ] ) ;
80+ if ( tx . status !== "success" ) {
7181 return ;
7282 }
73- await appService . wait ( claimRewards . txHash ) ;
83+ await appService . wait ( tx . txHash ) ;
7484 fetchData ( ) ;
7585 } finally {
7686 setIsClaiming ( false ) ;
@@ -83,6 +93,31 @@ const RewardsTab: React.FC<RewardsTabProps> = ({
8393 ( nodeRewards ?. unclaimedRplRewards ?? 0 ) === 0
8494 ) ;
8595 }
96+
97+ function ErrorAlertBox ( ) : JSX . Element {
98+ return (
99+ < >
100+ { nodeCanClaimRewards ?. error && (
101+ < Alert
102+ severity = "error"
103+ sx = { { marginTop : 2 , marginBottom : 2 } }
104+ variant = "filled"
105+ >
106+ { nodeCanClaimRewards ?. error }
107+ </ Alert >
108+ ) }
109+ { txResponse ?. error && (
110+ < Alert
111+ severity = "error"
112+ sx = { { marginTop : 2 , marginBottom : 2 } }
113+ variant = "filled"
114+ >
115+ { txResponse ?. error }
116+ </ Alert >
117+ ) }
118+ </ >
119+ ) ;
120+ }
86121
87122 return (
88123 < Box >
@@ -144,6 +179,7 @@ const RewardsTab: React.FC<RewardsTabProps> = ({
144179 </ Button >
145180 </ Box >
146181 < TxsLinksBox txs = { txs } explorerUrl = { config ?. explorerUrl } />
182+ < ErrorAlertBox />
147183 </ >
148184 ) }
149185 </ Box >
0 commit comments