Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 774b1c1

Browse files
committed
Listen to staking loading states for success page UI
1 parent 5e628b0 commit 774b1c1

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed

ts/components/governance/wizard_flow.tsx

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import CircularProgress from 'material-ui/CircularProgress';
12
import moment from 'moment';
23
import React from 'react';
34
import styled from 'styled-components';
45

56
import { Button } from 'ts/components/button';
67
import { ChangePoolDialog } from 'ts/components/staking/change_pool_dialog';
8+
import { ErrorButton } from 'ts/components/staking/wizard/wizard_flow';
79
import { generateUniqueId, Jazzicon } from 'ts/components/ui/jazzicon';
10+
import { UseStakeHookResult } from 'ts/hooks/use_stake';
811
import { colors } from 'ts/style/colors';
9-
import { PoolWithStats } from 'ts/types';
12+
import { PoolWithStats, TransactionLoadingState } from 'ts/types';
1013
import { DEFAULT_POOL_ID } from 'ts/utils/configs';
1114

1215
interface IVotingPowerInputProps {
@@ -20,6 +23,8 @@ interface IVotingPowerInputProps {
2023

2124
interface IRegistrationSuccess {
2225
nextEpochStart: Date;
26+
stake: UseStakeHookResult;
27+
retryFlowZRXAmount: number;
2328
}
2429

2530
const ConnectWalletButton = styled(Button)``;
@@ -270,23 +275,53 @@ const MessageList = styled.ul`
270275
}
271276
`;
272277

273-
export const RegistrationSuccess: React.FC<IRegistrationSuccess> = ({ nextEpochStart }) => {
278+
const LoaderWrapper = styled.div`
279+
display: flex;
280+
align-items: center;
281+
justify-content: center;
282+
`;
283+
284+
export const RegistrationSuccess: React.FC<IRegistrationSuccess> = ({ nextEpochStart, stake, retryFlowZRXAmount }) => {
274285
const nextEpochMoment = moment(nextEpochStart);
275286
const todayMoment = moment();
276287
const daysToNextEpoch = nextEpochMoment.diff(todayMoment, 'days');
277288
return (
278289
<SuccessContainer>
279-
<Header>Your voting power is now registered</Header>
280-
<MessageList>
281-
<li>
282-
<strong>Your tokens are now locked.</strong>
283-
Unlocking will be available in {daysToNextEpoch} days
284-
</li>
285-
<li>
286-
<strong>Additional tip</strong>
287-
Unlocking will be available in {daysToNextEpoch} days
288-
</li>
289-
</MessageList>
290+
{stake.loadingState === TransactionLoadingState.Success ? (
291+
<>
292+
<Header>Your voting power is now registered</Header>
293+
<MessageList>
294+
<li>
295+
<strong>Your tokens are now locked.</strong>
296+
Unlocking will be available in {daysToNextEpoch} days
297+
</li>
298+
<li>
299+
<strong>Additional tip</strong>
300+
Unlocking will be available in {daysToNextEpoch} days
301+
</li>
302+
</MessageList>
303+
</>
304+
) : stake.loadingState === TransactionLoadingState.Failed ? (
305+
<ErrorButton
306+
message={'Transaction aborted'}
307+
secondaryButtonText={'Retry'}
308+
onClose={() => {
309+
/*noop*/
310+
}}
311+
onSecondaryClick={() =>
312+
stake.depositAndStake([
313+
{
314+
poolId: DEFAULT_POOL_ID,
315+
zrxAmount: retryFlowZRXAmount,
316+
},
317+
])
318+
}
319+
/>
320+
) : (
321+
<LoaderWrapper>
322+
<CircularProgress size={40} thickness={2} color={colors.brandLight} />
323+
</LoaderWrapper>
324+
)}
290325
</SuccessContainer>
291326
);
292327
};

ts/components/staking/wizard/wizard_flow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ const NumberRound = styled.span`
201201
border: 1px solid #f6f6f6;
202202
`;
203203

204-
const ErrorButton: React.FC<ErrorButtonProps> = (props) => {
204+
export const ErrorButton: React.FC<ErrorButtonProps> = (props) => {
205205
const { onSecondaryClick, message, secondaryButtonText } = props;
206206
return (
207207
<ErrorButtonContainer>

ts/pages/governance/register.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const RegisterWizard: React.FC<IRegisterWizardProps> = (props) => {
4646
pool: undefined,
4747
zrxAmount: undefined,
4848
});
49+
const [retryFlowZRXAmount, setRetryFlowZRXAmount] = React.useState<number>();
4950
const [nextEpochStats, setNextEpochStats] = React.useState<Epoch | undefined>(undefined);
5051
const stake = useStake(networkId, providerState);
5152
const [shouldShowDecisionScreen, setShowDecisionScreen] = React.useState<boolean>(true);
@@ -90,6 +91,7 @@ export const RegisterWizard: React.FC<IRegisterWizardProps> = (props) => {
9091
zrxAmount,
9192
},
9293
]);
94+
setRetryFlowZRXAmount(zrxAmount);
9395
next(RegisterRouterSteps.Success);
9496
}
9597
};
@@ -139,7 +141,11 @@ export const RegisterWizard: React.FC<IRegisterWizardProps> = (props) => {
139141
/>
140142
)}
141143
{currentStep === RegisterRouterSteps.Success && (
142-
<RegistrationSuccess nextEpochStart={nextEpochStart} />
144+
<RegistrationSuccess
145+
nextEpochStart={nextEpochStart}
146+
stake={stake}
147+
retryFlowZRXAmount={retryFlowZRXAmount}
148+
/>
143149
)}
144150
</>
145151
}

0 commit comments

Comments
 (0)