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: feedback for insufficient ETH to cover transaction fees #1683

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/long-jobs-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": patch
---

Fix feedback when user has insufficient ETH to cover fees.
5 changes: 5 additions & 0 deletions .changeset/tender-mails-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": patch
---

Fix large amounts breaking the UI on the homescreen.
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ import {
} from '@fuel-ui/react';
import { type FC, useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
import {
AmountVisibility,
Pages,
formatBalance,
shortAddress,
} from '~/systems/Core';
import { useBalanceVisibility } from '~/systems/Core/hooks/useVisibility';
import { Pages, shortAddress } from '~/systems/Core';

import { AssetRemoveDialog } from '../AssetRemoveDialog';

import type { AssetData, AssetFuelData } from '@fuel-wallet/types';
import type { BNInput } from 'fuels';
import useFuelAsset from '../../hooks/useFuelAsset';
import { AssetItemAmount } from './AssetItemAmount';
import { AssetItemLoader } from './AssetItemLoader';

export type AssetItemProps = {
Expand Down Expand Up @@ -55,7 +50,6 @@ export const AssetItem: AssetItemComponent = ({
shouldShowCopyAssetAddress,
}) => {
const navigate = useNavigate();
const { visibility } = useBalanceVisibility();

const fuelAssetFromInputAsset = useFuelAsset({ asset: inputAsset });
const asset = useMemo(() => {
Expand Down Expand Up @@ -123,25 +117,8 @@ export const AssetItem: AssetItemComponent = ({
}

if (amount) {
const { original, tooltip } = formatBalance(amount, decimals);

return (
<Tooltip
content={original.display}
delayDuration={0}
open={visibility && tooltip ? undefined : false}
>
<Text
css={{ fontSize: '$sm', fontWeight: '$normal', textAlign: 'right' }}
>
<AmountVisibility
value={amount}
units={decimals}
visibility={visibility}
/>{' '}
{symbol}
</Text>
</Tooltip>
<AssetItemAmount amount={amount} decimals={decimals} symbol={symbol} />
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { cssObj } from '@fuel-ui/css';
import { Box, Text, Tooltip } from '@fuel-ui/react';
import type { BNInput } from 'fuels';
import { useEffect, useMemo, useRef, useState } from 'react';
import { AmountVisibility, formatBalance } from '~/systems/Core';
import { useBalanceVisibility } from '~/systems/Core/hooks/useVisibility';

type AssetItemAmountProps = {
amount: BNInput;
decimals: number | undefined;
symbol: string | undefined;
};

export const AssetItemAmount = ({
amount,
decimals,
symbol,
}: AssetItemAmountProps) => {
const { visibility } = useBalanceVisibility();
const { original, tooltip } = formatBalance(amount, decimals);

const amountRef = useRef<HTMLSpanElement>(null);
const [isTruncated, setIsTruncated] = useState(false);

const open = useMemo<boolean | undefined>(() => {
if (visibility && (tooltip || isTruncated)) return undefined;
return false;
}, [tooltip, visibility, isTruncated]);

useEffect(() => {
if (!tooltip && amountRef.current) {
const amountEl = amountRef.current;
setIsTruncated(amountEl.scrollWidth > amountEl.clientWidth);
}
}, [tooltip]);

return (
<Tooltip content={original.display} delayDuration={0} open={open}>
<Box css={styles.root}>
<Text as="span" ref={amountRef} css={styles.amount}>
<AmountVisibility
value={amount}
units={decimals}
visibility={visibility}
/>
</Text>
<Text as="span" css={styles.symbol}>
{symbol}
</Text>
</Box>
</Tooltip>
);
};

const styles = {
root: cssObj({
display: 'inline-flex',
columnGap: '$1',
minWidth: 0,
alignItems: 'center',
flexWrap: 'nowrap',
fontSize: '$sm',
fontWeight: '$normal',
textAlign: 'right',
paddingLeft: '$2',
}),
amount: cssObj({
display: 'inline-block',
overflow: 'hidden',
textOverflow: 'ellipsis',
}),
symbol: cssObj({
flexShrink: 0,
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,18 @@ export class TxService {
if (e instanceof FuelError) {
const error = e.toObject();

// If the gas limit is too low, we cannot move forward
if (error.code === ErrorCode.GAS_LIMIT_TOO_LOW) {
throw e;
}

// If this is the last attempt and we still don't have funds, we cannot move forward
if (
attempts === maxAttempts &&
error.code === ErrorCode.NOT_ENOUGH_FUNDS
) {
throw e;
}
}
}
}
Expand Down
Loading