Skip to content

Commit

Permalink
[FRE-1247, FRE-1293] fix: improve balance loading state handling and …
Browse files Browse the repository at this point in the history
…display (#534)
  • Loading branch information
ericHgorski authored Dec 3, 2024
1 parent bf6c1f7 commit ba6a4dc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-bats-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@skip-go/widget': patch
---

improve balance display
4 changes: 2 additions & 2 deletions packages/widget/src/pages/ErrorPage/ErrorPageTradeWarning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ export const ErrorPageTradeWarning = ({
description={
<>
<SmallText color={theme.error.text} textAlign="center" textWrap="balance">
You will lose ~{swapDifferencePercentage} of your input value with
You will lose {swapDifferencePercentage} of your input value with
this trade
<br />
Input: {sourceDetails?.amount} {sourceDetails?.symbol} ({usdAmountIn})
<br />
Estimated output: ~{destinationDetails?.amount}{" "}
Estimated output: {destinationDetails?.amount}{" "}
{destinationDetails?.symbol} ({usdAmountOut})
</SmallText>
<SmallTextButton
Expand Down
11 changes: 3 additions & 8 deletions packages/widget/src/pages/SwapPage/ConnectedWalletContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,14 @@ export const ConnectedWalletContent = () => {
if (sourceBalance?.error?.message) return "--";
if (sourceBalance === undefined) return;

const amount = sourceBalance?.amount;
let formattedBalanceAmount = sourceBalance?.formattedAmount;

if (amount === "0") {
formattedBalanceAmount = amount;
}
formattedBalanceAmount = limitDecimalsDisplayed(
removeTrailingZeros(formattedBalanceAmount)
const formattedBalanceAmount = limitDecimalsDisplayed(
removeTrailingZeros(sourceBalance?.formattedAmount)
);

return formattedBalanceAmount + symbol;
}, [sourceBalance, sourceDetails?.symbol]);
if (!sourceAccount) return null;

return (
<Row
gap={6}
Expand Down
6 changes: 4 additions & 2 deletions packages/widget/src/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export function formatNumberWithoutCommas(str: string | number) {
return str.toString().replace(/,/g, "");
}

export const removeTrailingZeros = (input: string | undefined) =>
input?.replace(/0+$/, "").replace(/\.$/, "");
export const removeTrailingZeros = (input: string | undefined) => {
if (input === "0") return input;
return input?.replace(/0+$/, "").replace(/\.$/, "");
}

export function limitDecimalsDisplayed(input: string | number | undefined, decimalPlaces = DEFAULT_DECIMAL_PLACES) {
if (input === undefined) return "";
Expand Down

0 comments on commit ba6a4dc

Please sign in to comment.