diff --git a/packages/backend/migrations/20230927223235_make_quotes_generic.js b/packages/backend/migrations/20230927223235_make_quotes_generic.js index 9c91881c2e..59cde52e6b 100644 --- a/packages/backend/migrations/20230927223235_make_quotes_generic.js +++ b/packages/backend/migrations/20230927223235_make_quotes_generic.js @@ -5,7 +5,7 @@ exports.up = function (knex) { return knex.schema.alterTable('quotes', (table) => { table.json('additionalFields').nullable() - table.decimal('estimatedExchangeRate', 20, 10).notNullable() + table.decimal('estimatedExchangeRate', 20, 10).nullable() }) } diff --git a/packages/backend/src/open_payments/quote/model.ts b/packages/backend/src/open_payments/quote/model.ts index a085c4f418..becfd04f47 100644 --- a/packages/backend/src/open_payments/quote/model.ts +++ b/packages/backend/src/open_payments/quote/model.ts @@ -29,7 +29,7 @@ export class Quote extends PaymentPointerSubresource { public asset!: Asset public additionalFields!: Record - public estimatedExchangeRate!: number + public estimatedExchangeRate?: number public feeId?: string public fee?: Fee diff --git a/packages/backend/src/open_payments/quote/service.ts b/packages/backend/src/open_payments/quote/service.ts index 44bbe9ec3b..95e1563f02 100644 --- a/packages/backend/src/open_payments/quote/service.ts +++ b/packages/backend/src/open_payments/quote/service.ts @@ -218,9 +218,10 @@ function calculateQuoteAmountsAfterFees( } else { // FixedSend const fees = quote.fee?.calculate(receiveAmountValue) ?? 0n - const exchangeAdjustedFees = BigInt( - Number(fees) * quote.estimatedExchangeRate.valueOf() - ) + const estimatedExchangeRate = + quote.estimatedExchangeRate || quote.lowEstimatedExchangeRate.valueOf() + + const exchangeAdjustedFees = BigInt(Number(fees) * estimatedExchangeRate) receiveAmountValue = BigInt(receiveAmountValue) - exchangeAdjustedFees if (receiveAmountValue <= exchangeAdjustedFees) {