Skip to content

Commit

Permalink
fix: eslint, symbol if value zero.
Browse files Browse the repository at this point in the history
Signed-off-by: Eugene Panteleymonchuk <[email protected]>
  • Loading branch information
panteleymonchuk committed Jan 31, 2024
1 parent 63b7dea commit 8858c69
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions api/src/routes/stardust/transactionhistory/download/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const getTransactionHistoryRecords = (
timestamp: lastOutputTime,
dateFormatted: moment(lastOutputTime * 1000).format("YYYY-MM-DD HH:mm:ss"),
balanceChange,
balanceChangeFormatted: formatAmount(Math.abs(balanceChange), tokenInfo, false),
balanceChangeFormatted: formatAmount(Math.abs(balanceChange), tokenInfo, false, isSpent),
outputs,
});
}
Expand Down Expand Up @@ -192,11 +192,16 @@ export const calculateBalanceChange = (outputs: OutputWithDetails[]) => {
* @param value - The value to format.
* @param tokenInfo - Information about the token, including units and decimals.
* @param formatFull - If true, formats the entire number. Otherwise, uses decimalPlaces.
* @param isSpent
* @param isSpent - boolean indicating if the amount is spent or not. Need to provide right symbol.
* @returns The formatted amount with the token unit.
*/
export function formatAmount(value: number, tokenInfo: INodeInfoBaseToken, formatFull: boolean = false, isSpent: boolean = false): string {
const isSpentSymbol = isSpent ? "-" : "+";
let isSpentSymbol = isSpent ? "-" : "+";

if (!value) {
// 0 is not spent
isSpentSymbol = "";
}

if (formatFull) {
return `${isSpentSymbol}${value} ${tokenInfo.subunit ?? tokenInfo.unit}`;
Expand Down

0 comments on commit 8858c69

Please sign in to comment.