refactor xmr rate module to exchange rate module for multi crypto support

This commit is contained in:
2026-09-02 14:53:50 +02:00
parent 6818f08dbe
commit 0510695598
29 changed files with 630 additions and 388 deletions
@@ -2,7 +2,7 @@ import { Logger, ServiceUnavailableException } from '@nestjs/common';
import type { ConfigService } from '@nestjs/config';
import type { Repository } from 'typeorm';
import type { MoneroWalletRpcClient } from '../../moneroWallet/services/MoneroWalletRpcClient';
import type { XmrRateService } from '../../xmrRate/services/XmrRateService';
import type { ExchangeRateService } from '../../exchangeRate/services/ExchangeRateService';
import { Invoice } from '../entities/Invoice';
import { InvoiceReason } from '../types/InvoiceReason';
import { PaymentMethod } from '../types/PaymentMethod';
@@ -22,8 +22,8 @@ describe('InvoiceService', () => {
let walletRpcClient: {
createAddress: jest.Mock;
};
let xmrRateService: {
getLiveFiatPerXmr: jest.Mock;
let exchangeRateService: {
getLiveFiatPerCrypto: jest.Mock;
};
let errorLogSpy: jest.SpiedFunction<typeof Logger.prototype.error>;
@@ -60,15 +60,15 @@ describe('InvoiceService', () => {
})
};
xmrRateService = {
getLiveFiatPerXmr: jest.fn().mockReturnValue(150)
exchangeRateService = {
getLiveFiatPerCrypto: jest.fn().mockReturnValue(150)
};
service = new InvoiceService(
invoiceRepo as unknown as Repository<Invoice>,
configService as unknown as ConfigService,
walletRpcClient as unknown as MoneroWalletRpcClient,
xmrRateService as unknown as XmrRateService
exchangeRateService as unknown as ExchangeRateService
);
});
@@ -85,7 +85,7 @@ describe('InvoiceService', () => {
});
it('throws when the live XMR rate is unavailable for checkout invoices', async () => {
xmrRateService.getLiveFiatPerXmr.mockReturnValue(null);
exchangeRateService.getLiveFiatPerCrypto.mockReturnValue(null);
await expect(issueCheckoutInvoice()).rejects.toThrow(
new ServiceUnavailableException("We can't show a price right now. Please try again in a few minutes.")
@@ -169,7 +169,7 @@ describe('InvoiceService', () => {
});
it('uses shipping-specific messages and address labels for shipping invoices', async () => {
xmrRateService.getLiveFiatPerXmr.mockReturnValue(null);
exchangeRateService.getLiveFiatPerCrypto.mockReturnValue(null);
await expect(
service.issueInvoice({
@@ -184,7 +184,7 @@ describe('InvoiceService', () => {
)
);
xmrRateService.getLiveFiatPerXmr.mockReturnValue(150);
exchangeRateService.getLiveFiatPerCrypto.mockReturnValue(150);
walletRpcClient.createAddress.mockRejectedValue(new Error('rpc down'));
await expect(