Skip to content

Commit

Permalink
[Redesign] Adding back button to redeem view and addressing other fee…
Browse files Browse the repository at this point in the history
…dback

Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz>
  • Loading branch information
emreboga committed Oct 18, 2024
1 parent a96a592 commit f799808
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
13 changes: 12 additions & 1 deletion wormhole-connect/src/hooks/useTrackTransferInProgress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { isCompleted, routes } from '@wormhole-foundation/sdk';
import { isCompleted, routes, TransferState } from '@wormhole-foundation/sdk';

import config, { getWormholeContextV2 } from 'config';
import { sleep } from 'utils';
Expand All @@ -18,10 +18,12 @@ type Props = {

type ReturnProps = {
isCompleted: boolean;
isReadyToClaim: boolean;
};

const useTrackTransferV2 = (props: Props): ReturnProps => {
const [completed, setCompleted] = useState(false);
const [readyToClaim, setReadyToClaim] = useState(false);
const [receipt, setReceipt] = useState<routes.Receipt<AttestationReceipt>>();

const { eta, route: routeName } = props;
Expand Down Expand Up @@ -83,6 +85,14 @@ const useTrackTransferV2 = (props: Props): ReturnProps => {
stateChanged = true;
break;
}

// Check whether this is a manual transaction ready to claim
if (
!route.AUTOMATIC_DEPOSIT &&
currentReceipt.state >= TransferState.Attested
) {
setReadyToClaim(true);
}
}
}
} catch (e) {
Expand All @@ -105,6 +115,7 @@ const useTrackTransferV2 = (props: Props): ReturnProps => {

return {
isCompleted: completed,
isReadyToClaim: readyToClaim,
};
};

Expand Down
53 changes: 38 additions & 15 deletions wormhole-connect/src/views/v2/Redeem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useTimer } from 'react-timer-hook';
import { useTheme } from '@mui/material';
import Box from '@mui/material/Box';
import CircularProgress from '@mui/material/CircularProgress';
import ChevronLeft from '@mui/icons-material/ChevronLeft';
import IconButton from '@mui/material/IconButton';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import {
Expand All @@ -29,6 +31,7 @@ import { SDKv2Signer } from 'routes/sdkv2/signer';
import { setRoute } from 'store/router';
import { useUSDamountGetter } from 'hooks/useUSDamountGetter';
import { interpretTransferError } from 'utils/errors';
import { removeTxFromLocalStorage } from 'utils/inProgressTxCache';
import { joinClass } from 'utils/style';
import {
millisToMinutesAndSeconds,
Expand Down Expand Up @@ -81,6 +84,11 @@ const useStyles = makeStyles<StyleProps>()((theme, { transitionDuration }) => ({
maxWidth: '420px',
width: '100%',
},
backButton: {
alignItems: 'start',
maxWidth: '420px',
width: '100%',
},
claimButton: {
backgroundColor: theme.palette.warning.light,
color:
Expand Down Expand Up @@ -169,22 +177,29 @@ const Redeem = () => {

useEffect(() => {
// When we see the transfer was complete for the first time,
// fire a transfer.success telemetry event.
if (isTxComplete && !transferSuccessEventFired) {
setTransferSuccessEventFired(true);
// fire a transfer.success telemetry event
if (isTxComplete) {
if (!transferSuccessEventFired) {
setTransferSuccessEventFired(true);

config.triggerEvent({
type: 'transfer.success',
details: getTransferDetails(
routeName!,
tokenKey,
receivedTokenKey,
fromChain,
toChain,
amount,
getUSDAmount,
),
});
}

config.triggerEvent({
type: 'transfer.success',
details: getTransferDetails(
routeName!,
tokenKey,
receivedTokenKey,
fromChain,
toChain,
amount,
getUSDAmount,
),
});
// Remove the in-progress tx from local storage
if (txData?.sendTx) {
removeTxFromLocalStorage(txData?.sendTx);
}
}
}, [isTxComplete]);

Expand Down Expand Up @@ -724,6 +739,14 @@ const Redeem = () => {
return (
<div className={joinClass([classes.container, classes.spacer])}>
{header}
<Stack className={classes.backButton}>
<IconButton
sx={{ padding: 0 }}
onClick={() => dispatch(setRoute('bridge'))}
>
<ChevronLeft sx={{ fontSize: '32px' }} />
</IconButton>
</Stack>
{statusHeader}
<Box
sx={{
Expand Down
8 changes: 6 additions & 2 deletions wormhole-connect/src/views/v2/TxHistory/Widget/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const WidgetItem = (props: Props) => {
onExpire: () => setEtaExpired(true),
});

const { isCompleted } = useTrackTransferInProgress({
const { isCompleted, isReadyToClaim } = useTrackTransferInProgress({
eta,
receipt,
route,
Expand Down Expand Up @@ -112,6 +112,10 @@ const WidgetItem = (props: Props) => {

// Displays the countdown
const etaCountdown = useMemo(() => {
if (isReadyToClaim) {
return 'Ready to claim...';
}

if (etaExpired || etaRemaining === 0) {
return 'Wrapping up...';
}
Expand All @@ -121,7 +125,7 @@ const WidgetItem = (props: Props) => {
}

return <CircularProgress size={16} />;
}, [etaExpired, etaRemaining, isRunning, minutes, seconds]);
}, [etaExpired, etaRemaining, isReadyToClaim, isRunning, minutes, seconds]);

// A number value between 0-100
const progressBarValue = useMemo(() => {
Expand Down

0 comments on commit f799808

Please sign in to comment.