Skip to content

Commit

Permalink
Bridge V2 view minor UI improvements (wormhole-foundation#2539)
Browse files Browse the repository at this point in the history
* fix(redesing): show ETAs rounded

* fix(redesing): show 4 decimals for token account instead of 6
  • Loading branch information
nikarm22 authored Sep 6, 2024
1 parent 53af315 commit ea21887
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
20 changes: 13 additions & 7 deletions wormhole-connect/src/store/transferInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Context } from 'sdklegacy';
import config from 'config';
import { TokenConfig } from 'config/types';
import { getTokenDecimals } from 'utils';
import { toDecimals } from 'utils/balance';
import {
switchChain,
TransferWallet,
Expand All @@ -18,7 +17,7 @@ import {
receiveDataWrapper,
} from './helpers';
import { isPorticoRoute } from 'routes/porticoBridge/utils';
import { Chain } from '@wormhole-foundation/sdk';
import { amount, Chain } from '@wormhole-foundation/sdk';

export type Balance = {
lastUpdated: number;
Expand All @@ -35,12 +34,19 @@ export type WalletBalances = { [key: WalletAddress]: BalancesCache };
export const formatBalance = (
chain: Chain,
token: TokenConfig,
balance: bigint | null,
) => {
balance: string | bigint | null,
): string | null => {
if (!balance) {
return null;
}
const decimals = getTokenDecimals(chain, token.tokenId);
const formattedBalance =
balance !== null ? toDecimals(balance, decimals, 6) : null;
return formattedBalance;
const balanceNum = amount.whole({
amount: balance.toString(),
decimals,
});
return balanceNum.toLocaleString('en', {
maximumFractionDigits: 4,
});
};

// for use in USDC or other tokens that have versions on many chains
Expand Down
10 changes: 10 additions & 0 deletions wormhole-connect/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,13 @@ export const isFrankensteinToken = (token: TokenConfig, chain: Chain) => {
export const isWrappedToken = (token: TokenConfig, chain: Chain) => {
return token.nativeChain !== chain;
};

export const millisToHumanString = (ts: number): string => {
if (ts > 60000) {
const minutes = Math.ceil(ts / 60000);
return `~${minutes} min`;
} else {
const seconds = Math.ceil(ts / 1000);
return `~${seconds} sec`;
}
};
20 changes: 15 additions & 5 deletions wormhole-connect/src/views/v2/Bridge/Routes/SingleRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { amount, routes } from '@wormhole-foundation/sdk';

import config from 'config';
import TokenIcon from 'icons/TokenIcons';
import { isEmptyObject, calculateUSDPrice } from 'utils';
import { millisToMinutesAndSeconds } from 'utils/transferValidation';
import { isEmptyObject, calculateUSDPrice, millisToHumanString } from 'utils';

import type { RouteData } from 'config/routes';
import type { RootState } from 'store';
import { formatBalance } from 'store/transferInput';

const useStyles = makeStyles()((theme: any) => ({
container: {
Expand Down Expand Up @@ -144,7 +144,7 @@ const SingleRoute = (props: Props) => {
<CircularProgress size={14} />
) : (
<Typography fontSize={14}>
{millisToMinutesAndSeconds(quote?.eta ?? 0)}
{quote?.eta ? millisToHumanString(quote.eta) : 'N/A'}
</Typography>
)}
</>
Expand Down Expand Up @@ -263,15 +263,25 @@ const SingleRoute = (props: Props) => {
return quote ? amount.whole(quote?.destinationToken.amount) : undefined;
}, [quote]);

const receiveAmountTrunc = useMemo(() => {
return quote && destChain
? formatBalance(
destChain,
destTokenConfig,
quote.destinationToken.amount.amount,
)
: undefined;
}, [quote]);

const routeCardHeader = useMemo(() => {
return typeof receiveAmount === 'undefined' ? (
<CircularProgress size={18} />
) : (
<Typography>
{receiveAmount} {destTokenConfig.symbol}
{receiveAmountTrunc} {destTokenConfig.symbol}
</Typography>
);
}, [destToken, receiveAmount]);
}, [destToken, receiveAmountTrunc]);

const routeCardSubHeader = useMemo(() => {
if (typeof receiveAmount === 'undefined') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ import { makeStyles } from 'tss-react/mui';
import config from 'config';
import { RouteContext } from 'contexts/RouteContext';
import TokenIcon from 'icons/TokenIcons';
import { calculateUSDPrice, trimAddress, trimTxHash } from 'utils';
import { millisToMinutesAndSeconds } from 'utils/transferValidation';
import {
calculateUSDPrice,
millisToHumanString,
trimAddress,
trimTxHash,
} from 'utils';
import { getExplorerLink } from 'utils/sdkv2';

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

if (eta) {
etaDisplay = millisToMinutesAndSeconds(eta);
etaDisplay = millisToHumanString(eta);
}

return (
Expand Down
9 changes: 3 additions & 6 deletions wormhole-connect/src/views/v2/Redeem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ import PoweredByIcon from 'icons/PoweredBy';
import { SDKv2Signer } from 'routes/sdkv2/signer';
import { setRedeemTx, setTransferComplete } from 'store/redeem';
import { setRoute } from 'store/router';
import { displayAddress } from 'utils';
import { displayAddress, millisToHumanString } from 'utils';
import { interpretTransferError } from 'utils/errors';
import { joinClass } from 'utils/style';
import {
millisToMinutesAndSeconds,
minutesAndSecondsWithPadding,
} from 'utils/transferValidation';
import { minutesAndSecondsWithPadding } from 'utils/transferValidation';
import {
TransferWallet,
registerWalletSigner,
Expand Down Expand Up @@ -216,7 +213,7 @@ const Redeem = () => {
let etaElement: string | ReactNode = <CircularProgress size={14} />;

if (eta) {
etaElement = millisToMinutesAndSeconds(eta);
etaElement = millisToHumanString(eta);
}

return (
Expand Down

0 comments on commit ea21887

Please sign in to comment.