Skip to content

Commit

Permalink
refactor: Style amounts in USD; Strict typing on Money Format
Browse files Browse the repository at this point in the history
  • Loading branch information
fearandesire committed May 13, 2024
1 parent 11879ab commit b8957ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/commands/betting/doubledown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Command.Options>({
description: 'Double down an existing bet',
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions src/utils/api/common/money-formatting/money-format.ts
Original file line number Diff line number Diff line change
@@ -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')
}
/**
Expand All @@ -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,
Expand Down

0 comments on commit b8957ea

Please sign in to comment.