Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/domain/shared/MoneyAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ export class JMDAmount extends MoneyAmount {

static dollars(d: number): JMDAmount | BigIntConversionError {
try {
return new JMDAmount(BigInt(d) * 100n)
// Mirror USDAmount.dollars: use the Money lib for a decimal-safe conversion.
// BigInt(d) throws on any fractional rate (e.g. an NCB rate of 155.5), which
// is what the exchange-rate value virtually always is.
const dollarAmt = new Money(d.toString(), "JMDollars", Round.HALF_TO_EVEN)
const cents = JMDAmount.cents("100")
if (cents instanceof BigIntConversionError) return cents // should never happen
return new JMDAmount(cents.money.multiply(dollarAmt).toFixed(2))
} catch (error) {
return new BigIntConversionError(
error instanceof Error ? error.message : String(error),
Expand Down
5 changes: 5 additions & 0 deletions src/graphql/error-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,11 @@ export const mapError = (error: ApplicationError): CustomApolloError => {
message = "No upgrade request found for this account"
return new NotFoundError({ message, logger: baseLogger })

case "ExchangeRateQueryError":
message =
"Cashout is temporarily unavailable while we refresh the exchange rate. Please try again shortly."
return new UnexpectedClientError({ message, logger: baseLogger })

case "InvalidLnurlError":
return new InvalidLnurlError({ message: error.message, logger: baseLogger })

Expand Down
Loading