Skip to content

Commit

Permalink
fix: Updated display format for asset currency dif (#12775)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
- This PR updates the format of the change in currency for negative
cases to be `-$123.45` instead of `$-123.45`

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

## **Related issues**

Fixes: #10922 

## **Manual testing steps**

1. Go to Assets
2. Look at the amount changed in dollars
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**
![Simulator Screenshot - iPhone 15 Pro Max - 2024-12-18 at 11 57
50](https://github.com/user-attachments/assets/df7fc031-2152-4f72-878e-4be41d0e0d0c)

![Screenshot_1734563249](https://github.com/user-attachments/assets/d713ddee-cfcf-4e68-b08c-566e448a12a1)

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
brianacnguyen authored Dec 20, 2024
1 parent 442d331 commit ec8804c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/util/number/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ export function addCurrencySymbol(
currencyCode,
extendDecimals = false,
) {
const prefix = parseFloat(amount) < 0 ? '-' : '';
if (extendDecimals) {
if (isNumberScientificNotationWhenString(amount)) {
amount = amount.toFixed(18);
Expand Down Expand Up @@ -512,17 +513,22 @@ export function addCurrencySymbol(
amount = parseFloat(amount).toFixed(2);
}

const amountString = amount.toString();
const absAmountStr = amountString.startsWith('-')
? amountString.slice(1) // Remove the first character if it's a '-'
: amountString;

if (currencySymbols[currencyCode]) {
return `${currencySymbols[currencyCode]}${amount}`;
return `${prefix}${currencySymbols[currencyCode]}${absAmountStr}`;
}

const lowercaseCurrencyCode = currencyCode?.toLowerCase();

if (currencySymbols[lowercaseCurrencyCode]) {
return `${currencySymbols[lowercaseCurrencyCode]}${amount}`;
return `${prefix}${currencySymbols[lowercaseCurrencyCode]}${absAmountStr}`;
}

return `${amount} ${currencyCode}`;
return `${prefix}${absAmountStr} ${currencyCode}`;
}

/**
Expand Down

0 comments on commit ec8804c

Please sign in to comment.