From b8957eae3b64a9566f2916329883592f0c83266d Mon Sep 17 00:00:00 2001 From: fearandesire <63979371+fearandesire@users.noreply.github.com> Date: Mon, 13 May 2024 13:10:55 -0400 Subject: [PATCH] refactor: Style amounts in USD; Strict typing on Money Format --- src/commands/betting/doubledown.ts | 8 +++++++- src/utils/api/common/money-formatting/money-format.ts | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/commands/betting/doubledown.ts b/src/commands/betting/doubledown.ts index b3d983d5..2d906727 100644 --- a/src/commands/betting/doubledown.ts +++ b/src/commands/betting/doubledown.ts @@ -10,6 +10,7 @@ import { EmbedBuilder } from 'discord.js' import embedColors from '../../lib/colorsConfig.js' import PatreonFacade from '../../utils/api/patreon/Patreon-Facade.js' import { ErrorEmbeds } from '../../utils/common/errors/global.js' +import MoneyFormatter from '../../utils/api/common/money-formatting/money-format.js' @ApplyOptions({ description: 'Double down an existing bet', @@ -53,9 +54,14 @@ export class UserCommand extends Command { ) const { newBetAmount, newProfit, newPayout, newBalance } = newBetDetails.betslip + // Format the money + const formattedAmount = MoneyFormatter.toUSD(newBetAmount) + const formattedPayout = MoneyFormatter.toUSD(newPayout) + const formattedProfit = MoneyFormatter.toUSD(newProfit) + const formattedBalance = MoneyFormatter.toUSD(newBalance) const modifiedBetEmbed = new EmbedBuilder() .setDescription( - `## Double Down\n\n**Bet:** ${newBetAmount} | **Payout:** ${newPayout}\n**Profit:** ${newProfit}\n**Balance:** ${newBalance}`, + `## Double Down\n\n**Bet:** ${formattedAmount} | **Payout:** ${formattedPayout}\n**Profit:** ${formattedProfit}\n**Balance:** ${formattedBalance}`, ) .setColor(embedColors.success) .setThumbnail(interaction.user.displayAvatarURL()) diff --git a/src/utils/api/common/money-formatting/money-format.ts b/src/utils/api/common/money-formatting/money-format.ts index 3eb55473..707856d4 100644 --- a/src/utils/api/common/money-formatting/money-format.ts +++ b/src/utils/api/common/money-formatting/money-format.ts @@ -1,7 +1,7 @@ import numeral from 'numeral' export default class MoneyFormatter { - static toUSD(amount: number | string) { + static toUSD(amount: number) { return numeral(amount).format('$0,0.00') } /** @@ -12,9 +12,9 @@ export default class MoneyFormatter { static async formatAmounts(bettingNumbers: { [key: string]: number | string }) { - const betAmount = MoneyFormatter.toUSD(bettingNumbers.amount) - const payout = MoneyFormatter.toUSD(bettingNumbers.payout) - const profit = MoneyFormatter.toUSD(bettingNumbers.profit) + const betAmount = MoneyFormatter.toUSD(Number(bettingNumbers.amount)) + const payout = MoneyFormatter.toUSD(Number(bettingNumbers.payout)) + const profit = MoneyFormatter.toUSD(Number(bettingNumbers.profit)) return { betAmount,