-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- use existing components on the AccountTokens table
- updated the FormatUSD component with props similar to Denominate ( FormatAmount )
- Loading branch information
Showing
5 changed files
with
126 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
import BigNumber from 'bignumber.js'; | ||
import { amountWithoutRounding } from 'helpers'; | ||
|
||
export const formatUSD = ({ | ||
amount, | ||
usd, | ||
digits, | ||
showPrefix = true | ||
}: { | ||
export interface FormatUSDType { | ||
amount: string | number; | ||
usd?: string | number; | ||
digits?: number; | ||
maxDigits?: number; | ||
showPrefix?: boolean; | ||
}) => { | ||
showLastNonZeroDecimal?: boolean; | ||
} | ||
|
||
export const formatUSD = ({ | ||
amount, | ||
usd, | ||
digits, | ||
showPrefix = true, | ||
maxDigits, | ||
showLastNonZeroDecimal | ||
}: FormatUSDType) => { | ||
const value = new BigNumber(amount).times(usd ? new BigNumber(usd) : 1); | ||
|
||
const displayValue = showLastNonZeroDecimal | ||
? amountWithoutRounding(value, digits, maxDigits) | ||
: value.toFormat(digits); | ||
|
||
return `${ | ||
showPrefix ? (value.isGreaterThan(0) ? '~' : '=') : '' | ||
}$${value.toFormat(digits)}`; | ||
}$${displayValue}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters