Skip to content

Commit

Permalink
Fix Initial Decimal Display Issue and Improve Gas Payment Formatting …
Browse files Browse the repository at this point in the history
…in Hyperlane Explorer (#138)

Setting the initial display to use the correct native token decimals in
GasDetailsCard. This ensures accurate Total paid values are shown

---------

Co-authored-by: J M Rossy <[email protected]>
  • Loading branch information
butcher73 and jmrossy authored Nov 14, 2024
1 parent d7da83d commit 134d1cb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/features/messages/cards/GasDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ export function GasDetailsCard({ message, blur, igpPayments = {} }: Props) {
const unitOptions = useMemo(() => {
const originMetadata = multiProvider.tryGetChainMetadata(message.originDomainId);
const nativeCurrencyName = originMetadata?.nativeToken?.symbol || 'Eth';
const nativeDecimals = originMetadata?.nativeToken?.decimals || 18;
return [
{ value: 18, display: toTitleCase(nativeCurrencyName) },
{ value: nativeDecimals, display: toTitleCase(nativeCurrencyName) },
{ value: 9, display: 'Gwei' },
{ value: 0, display: 'Wei' },
];
}, [message, multiProvider]);

const [decimals, setDecimals] = useState(unitOptions[0].value);
const [decimals, setDecimals] = useState<number>(unitOptions[1].value);

const { totalGasAmount, paymentFormatted, numPayments, avgPrice, paymentsWithAddr } =
useMemo(() => {
Expand Down Expand Up @@ -179,7 +180,7 @@ function computeAvgGasPrice(
const gasBN = new BigNumber(gasAmount);
const paymentBN = new BigNumber(payment);
if (gasBN.isZero() || paymentBN.isZero()) return null;
const wei = paymentBN.div(gasAmount).toFixed(0);
const wei = paymentBN.div(gasBN).toFixed(0);
const formatted = utils.formatUnits(wei, decimals).toString();
return { wei, formatted };
} catch (error) {
Expand Down

0 comments on commit 134d1cb

Please sign in to comment.