Skip to content

Commit ea21887

Browse files
authored
Bridge V2 view minor UI improvements (#2539)
* fix(redesing): show ETAs rounded * fix(redesing): show 4 decimals for token account instead of 6
1 parent 53af315 commit ea21887

File tree

5 files changed

+48
-21
lines changed

5 files changed

+48
-21
lines changed

wormhole-connect/src/store/transferInput.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Context } from 'sdklegacy';
33
import config from 'config';
44
import { TokenConfig } from 'config/types';
55
import { getTokenDecimals } from 'utils';
6-
import { toDecimals } from 'utils/balance';
76
import {
87
switchChain,
98
TransferWallet,
@@ -18,7 +17,7 @@ import {
1817
receiveDataWrapper,
1918
} from './helpers';
2019
import { isPorticoRoute } from 'routes/porticoBridge/utils';
21-
import { Chain } from '@wormhole-foundation/sdk';
20+
import { amount, Chain } from '@wormhole-foundation/sdk';
2221

2322
export type Balance = {
2423
lastUpdated: number;
@@ -35,12 +34,19 @@ export type WalletBalances = { [key: WalletAddress]: BalancesCache };
3534
export const formatBalance = (
3635
chain: Chain,
3736
token: TokenConfig,
38-
balance: bigint | null,
39-
) => {
37+
balance: string | bigint | null,
38+
): string | null => {
39+
if (!balance) {
40+
return null;
41+
}
4042
const decimals = getTokenDecimals(chain, token.tokenId);
41-
const formattedBalance =
42-
balance !== null ? toDecimals(balance, decimals, 6) : null;
43-
return formattedBalance;
43+
const balanceNum = amount.whole({
44+
amount: balance.toString(),
45+
decimals,
46+
});
47+
return balanceNum.toLocaleString('en', {
48+
maximumFractionDigits: 4,
49+
});
4450
};
4551

4652
// for use in USDC or other tokens that have versions on many chains

wormhole-connect/src/utils/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,13 @@ export const isFrankensteinToken = (token: TokenConfig, chain: Chain) => {
380380
export const isWrappedToken = (token: TokenConfig, chain: Chain) => {
381381
return token.nativeChain !== chain;
382382
};
383+
384+
export const millisToHumanString = (ts: number): string => {
385+
if (ts > 60000) {
386+
const minutes = Math.ceil(ts / 60000);
387+
return `~${minutes} min`;
388+
} else {
389+
const seconds = Math.ceil(ts / 1000);
390+
return `~${seconds} sec`;
391+
}
392+
};

wormhole-connect/src/views/v2/Bridge/Routes/SingleRoute.tsx

+15-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import { amount, routes } from '@wormhole-foundation/sdk';
1414

1515
import config from 'config';
1616
import TokenIcon from 'icons/TokenIcons';
17-
import { isEmptyObject, calculateUSDPrice } from 'utils';
18-
import { millisToMinutesAndSeconds } from 'utils/transferValidation';
17+
import { isEmptyObject, calculateUSDPrice, millisToHumanString } from 'utils';
1918

2019
import type { RouteData } from 'config/routes';
2120
import type { RootState } from 'store';
21+
import { formatBalance } from 'store/transferInput';
2222

2323
const useStyles = makeStyles()((theme: any) => ({
2424
container: {
@@ -144,7 +144,7 @@ const SingleRoute = (props: Props) => {
144144
<CircularProgress size={14} />
145145
) : (
146146
<Typography fontSize={14}>
147-
{millisToMinutesAndSeconds(quote?.eta ?? 0)}
147+
{quote?.eta ? millisToHumanString(quote.eta) : 'N/A'}
148148
</Typography>
149149
)}
150150
</>
@@ -263,15 +263,25 @@ const SingleRoute = (props: Props) => {
263263
return quote ? amount.whole(quote?.destinationToken.amount) : undefined;
264264
}, [quote]);
265265

266+
const receiveAmountTrunc = useMemo(() => {
267+
return quote && destChain
268+
? formatBalance(
269+
destChain,
270+
destTokenConfig,
271+
quote.destinationToken.amount.amount,
272+
)
273+
: undefined;
274+
}, [quote]);
275+
266276
const routeCardHeader = useMemo(() => {
267277
return typeof receiveAmount === 'undefined' ? (
268278
<CircularProgress size={18} />
269279
) : (
270280
<Typography>
271-
{receiveAmount} {destTokenConfig.symbol}
281+
{receiveAmountTrunc} {destTokenConfig.symbol}
272282
</Typography>
273283
);
274-
}, [destToken, receiveAmount]);
284+
}, [destToken, receiveAmountTrunc]);
275285

276286
const routeCardSubHeader = useMemo(() => {
277287
if (typeof receiveAmount === 'undefined') {

wormhole-connect/src/views/v2/Redeem/TransactionDetails/index.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ import { makeStyles } from 'tss-react/mui';
1414
import config from 'config';
1515
import { RouteContext } from 'contexts/RouteContext';
1616
import TokenIcon from 'icons/TokenIcons';
17-
import { calculateUSDPrice, trimAddress, trimTxHash } from 'utils';
18-
import { millisToMinutesAndSeconds } from 'utils/transferValidation';
17+
import {
18+
calculateUSDPrice,
19+
millisToHumanString,
20+
trimAddress,
21+
trimTxHash,
22+
} from 'utils';
1923
import { getExplorerLink } from 'utils/sdkv2';
2024

2125
import type { RootState } from 'store';
@@ -253,7 +257,7 @@ const TransactionDetails = () => {
253257
let etaDisplay: string | ReactNode = <CircularProgress size={14} />;
254258

255259
if (eta) {
256-
etaDisplay = millisToMinutesAndSeconds(eta);
260+
etaDisplay = millisToHumanString(eta);
257261
}
258262

259263
return (

wormhole-connect/src/views/v2/Redeem/index.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ import PoweredByIcon from 'icons/PoweredBy';
2222
import { SDKv2Signer } from 'routes/sdkv2/signer';
2323
import { setRedeemTx, setTransferComplete } from 'store/redeem';
2424
import { setRoute } from 'store/router';
25-
import { displayAddress } from 'utils';
25+
import { displayAddress, millisToHumanString } from 'utils';
2626
import { interpretTransferError } from 'utils/errors';
2727
import { joinClass } from 'utils/style';
28-
import {
29-
millisToMinutesAndSeconds,
30-
minutesAndSecondsWithPadding,
31-
} from 'utils/transferValidation';
28+
import { minutesAndSecondsWithPadding } from 'utils/transferValidation';
3229
import {
3330
TransferWallet,
3431
registerWalletSigner,
@@ -216,7 +213,7 @@ const Redeem = () => {
216213
let etaElement: string | ReactNode = <CircularProgress size={14} />;
217214

218215
if (eta) {
219-
etaElement = millisToMinutesAndSeconds(eta);
216+
etaElement = millisToHumanString(eta);
220217
}
221218

222219
return (

0 commit comments

Comments
 (0)