@@ -27,6 +27,7 @@ import { useQuery } from 'ts/hooks/use_query';
2727import { useStake } from 'ts/hooks/use_stake' ;
2828import { useStakingWizard , WizardRouterSteps } from 'ts/hooks/use_wizard' ;
2929
30+ import { ErrorModal } from 'ts/pages/governance/error_modal' ;
3031import { asyncDispatcher } from 'ts/redux/async_dispatcher' ;
3132import { Dispatcher } from 'ts/redux/dispatcher' ;
3233import { State } from 'ts/redux/reducer' ;
@@ -51,6 +52,11 @@ export interface StakingWizardProps {
5152 onOpenConnectWalletDialog : ( ) => void ;
5253}
5354
55+ interface RPCError {
56+ code : number ;
57+ message : string ;
58+ }
59+
5460const Container = styled . div `
5561 max-width: 1390px;
5662 margin: 0 auto;
@@ -68,6 +74,7 @@ export const StakingWizard: React.FC<StakingWizardProps> = (props) => {
6874 const networkId = useSelector ( ( state : State ) => state . networkId ) ;
6975 const apiClient = useAPIClient ( networkId ) ;
7076
77+ const [ stakingOrAllowanceError , setStakingOrAllowanceError ] = React . useState < Error | undefined > ( undefined ) ;
7178 const [ stakingPools , setStakingPools ] = useState < PoolWithStats [ ] | undefined > ( undefined ) ;
7279 const [ selectedStakingPools , setSelectedStakingPools ] = React . useState < UserStakingChoice [ ] | undefined > ( undefined ) ;
7380 const [ currentEpochStats , setCurrentEpochStats ] = useState < Epoch | undefined > ( undefined ) ;
@@ -138,6 +145,16 @@ export const StakingWizard: React.FC<StakingWizardProps> = (props) => {
138145 fetchAndSetStakingStats ( ) ;
139146 } , [ networkId , apiClient ] ) ;
140147
148+ useEffect ( ( ) => {
149+ const castedStakeError = ( stake . error as unknown ) as RPCError ;
150+ const castedAllowanceError = ( allowance . error as unknown ) as RPCError ;
151+ if ( castedStakeError && castedStakeError . code === - 32000 ) {
152+ setStakingOrAllowanceError ( stake . error ) ;
153+ } else if ( castedAllowanceError && castedAllowanceError . code === - 32000 ) {
154+ setStakingOrAllowanceError ( allowance . error ) ;
155+ }
156+ } , [ stake . error , allowance . error ] ) ;
157+
141158 const { currentStep, next } = useStakingWizard ( ) ;
142159
143160 const handleClickNextStep = useCallback ( ( ) => {
@@ -230,6 +247,15 @@ export const StakingWizard: React.FC<StakingWizardProps> = (props) => {
230247 }
231248 />
232249 </ Container >
250+ < ErrorModal
251+ isOpen = { Boolean ( stakingOrAllowanceError ) }
252+ text = { 'More ETH is required to complete this transaction. Fund your wallet and try again.' }
253+ heading = { 'Insufficient ETH' }
254+ buttonText = { 'Dismiss' }
255+ onClose = { ( ) => {
256+ setStakingOrAllowanceError ( undefined ) ;
257+ } }
258+ />
233259 </ StakingPageLayout >
234260 ) ;
235261} ;
0 commit comments