Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Initial Decimal Display Issue and Improve Gas Payment Formatting in Hyperlane Explorer #138

Merged
merged 6 commits into from
Nov 14, 2024
Merged
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
Loading