remove crypto rate display from cart
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
import { BadRequestException } from '@nestjs/common';
|
import { BadRequestException } from '@nestjs/common';
|
||||||
import { DeliveryMode } from '../../product/types/DeliveryMode';
|
import { DeliveryMode } from '../../product/types/DeliveryMode';
|
||||||
import type { StorefrontProductsService } from '../../storefrontProduct/services/StorefrontProductsService';
|
import type { StorefrontProductsService } from '../../storefrontProduct/services/StorefrontProductsService';
|
||||||
import type { ExchangeRateService } from '../../exchangeRate/services/ExchangeRateService';
|
|
||||||
import { PaymentMethod } from '../../payment/types/PaymentMethod';
|
|
||||||
import type { CookieCartLineExtended } from '../types/CookieCartLineExtended';
|
import type { CookieCartLineExtended } from '../types/CookieCartLineExtended';
|
||||||
import type { StorefrontDiscountService } from './StorefrontDiscountService';
|
import type { StorefrontDiscountService } from './StorefrontDiscountService';
|
||||||
import { StorefrontCartService } from './StorefrontCartService';
|
import { StorefrontCartService } from './StorefrontCartService';
|
||||||
@@ -30,9 +28,6 @@ describe('StorefrontCartService', () => {
|
|||||||
getStorefrontVariantsByIds: jest.Mock;
|
getStorefrontVariantsByIds: jest.Mock;
|
||||||
getStorefrontVariant: jest.Mock;
|
getStorefrontVariant: jest.Mock;
|
||||||
};
|
};
|
||||||
let exchangeRateService: {
|
|
||||||
getLiveFiatPerCrypto: jest.Mock;
|
|
||||||
};
|
|
||||||
let discountService: {
|
let discountService: {
|
||||||
getDiscountStateForCart: jest.Mock;
|
getDiscountStateForCart: jest.Mock;
|
||||||
applyDiscountCode: jest.Mock;
|
applyDiscountCode: jest.Mock;
|
||||||
@@ -44,10 +39,6 @@ describe('StorefrontCartService', () => {
|
|||||||
getStorefrontVariant: jest.fn().mockResolvedValue(buildVariant())
|
getStorefrontVariant: jest.fn().mockResolvedValue(buildVariant())
|
||||||
};
|
};
|
||||||
|
|
||||||
exchangeRateService = {
|
|
||||||
getLiveFiatPerCrypto: jest.fn().mockReturnValue(150)
|
|
||||||
};
|
|
||||||
|
|
||||||
discountService = {
|
discountService = {
|
||||||
getDiscountStateForCart: jest.fn().mockResolvedValue({
|
getDiscountStateForCart: jest.fn().mockResolvedValue({
|
||||||
discounts: [],
|
discounts: [],
|
||||||
@@ -59,7 +50,6 @@ describe('StorefrontCartService', () => {
|
|||||||
|
|
||||||
service = new StorefrontCartService(
|
service = new StorefrontCartService(
|
||||||
productsService as unknown as StorefrontProductsService,
|
productsService as unknown as StorefrontProductsService,
|
||||||
exchangeRateService as unknown as ExchangeRateService,
|
|
||||||
discountService as unknown as StorefrontDiscountService
|
discountService as unknown as StorefrontDiscountService
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -99,8 +89,6 @@ describe('StorefrontCartService', () => {
|
|||||||
discounts: [],
|
discounts: [],
|
||||||
cartDiscountTotal: 0,
|
cartDiscountTotal: 0,
|
||||||
cartTotalPrice: 0,
|
cartTotalPrice: 0,
|
||||||
cartTotalXmr: null,
|
|
||||||
fiatPerXmr: null,
|
|
||||||
hasManualLines: false,
|
hasManualLines: false,
|
||||||
hasAutoLines: false,
|
hasAutoLines: false,
|
||||||
cartTotalIssueMessage: null,
|
cartTotalIssueMessage: null,
|
||||||
@@ -108,23 +96,13 @@ describe('StorefrontCartService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('converts the discounted total to XMR when a live rate is available', async () => {
|
it('returns cart totals and delivery flags', async () => {
|
||||||
const summary = await service.getCartSummary([{ variantId, qty: 1 }], []);
|
const summary = await service.getCartSummary([{ variantId, qty: 1 }], []);
|
||||||
|
|
||||||
expect(summary.cartSubtotal).toBe(10);
|
expect(summary.cartSubtotal).toBe(10);
|
||||||
expect(summary.cartTotalPrice).toBe(10);
|
expect(summary.cartTotalPrice).toBe(10);
|
||||||
expect(summary.fiatPerXmr).toBe(150);
|
|
||||||
expect(summary.cartTotalXmr).toBe('0.06666667');
|
|
||||||
expect(summary.hasAutoLines).toBe(true);
|
expect(summary.hasAutoLines).toBe(true);
|
||||||
});
|
expect(summary.hasIssues).toBe(false);
|
||||||
|
|
||||||
it('leaves cartTotalXmr null when no live rate is available', async () => {
|
|
||||||
exchangeRateService.getLiveFiatPerCrypto.mockReturnValue(null);
|
|
||||||
|
|
||||||
const summary = await service.getCartSummary([{ variantId, qty: 1 }], []);
|
|
||||||
|
|
||||||
expect(summary.cartTotalXmr).toBeNull();
|
|
||||||
expect(summary.fiatPerXmr).toBeNull();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('flags manual and auto delivery lines separately', async () => {
|
it('flags manual and auto delivery lines separately', async () => {
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ import type { CookieCart } from '../../storefrontCore/types/cart/CookieCart';
|
|||||||
import { getQtyByVariantIdFromCart } from '../../../utils/cart/getQtyByVariantIdFromCart';
|
import { getQtyByVariantIdFromCart } from '../../../utils/cart/getQtyByVariantIdFromCart';
|
||||||
import { DeliveryMode } from '../../product/types/DeliveryMode';
|
import { DeliveryMode } from '../../product/types/DeliveryMode';
|
||||||
import { StorefrontProductsService } from '../../storefrontProduct/services/StorefrontProductsService';
|
import { StorefrontProductsService } from '../../storefrontProduct/services/StorefrontProductsService';
|
||||||
import { ExchangeRateService } from '../../exchangeRate/services/ExchangeRateService';
|
|
||||||
import { PaymentMethod } from '../../payment/types/PaymentMethod';
|
|
||||||
import { convertFiatToXmr } from '../../../utils/monero/convertFiatToXmr';
|
|
||||||
import { CookieCartLineDto } from '../dto/CookieCartLineDto';
|
import { CookieCartLineDto } from '../dto/CookieCartLineDto';
|
||||||
import type { CookieCartExtended } from '../types/CookieCartExtended';
|
import type { CookieCartExtended } from '../types/CookieCartExtended';
|
||||||
import type { CookieCartLineExtended } from '../types/CookieCartLineExtended';
|
import type { CookieCartLineExtended } from '../types/CookieCartLineExtended';
|
||||||
@@ -23,7 +20,6 @@ import { StorefrontDiscountService } from './StorefrontDiscountService';
|
|||||||
export class StorefrontCartService {
|
export class StorefrontCartService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly productsService: StorefrontProductsService,
|
private readonly productsService: StorefrontProductsService,
|
||||||
private readonly exchangeRateService: ExchangeRateService,
|
|
||||||
private readonly discountService: StorefrontDiscountService
|
private readonly discountService: StorefrontDiscountService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -67,8 +63,6 @@ export class StorefrontCartService {
|
|||||||
discounts: [],
|
discounts: [],
|
||||||
cartDiscountTotal: 0,
|
cartDiscountTotal: 0,
|
||||||
cartTotalPrice: 0,
|
cartTotalPrice: 0,
|
||||||
cartTotalXmr: null,
|
|
||||||
fiatPerXmr: null,
|
|
||||||
hasManualLines: false,
|
hasManualLines: false,
|
||||||
hasAutoLines: false,
|
hasAutoLines: false,
|
||||||
cartTotalIssueMessage: null,
|
cartTotalIssueMessage: null,
|
||||||
@@ -78,8 +72,6 @@ export class StorefrontCartService {
|
|||||||
|
|
||||||
const cartSubtotal = sumByKey(cartExtended, 'lineSubtotal');
|
const cartSubtotal = sumByKey(cartExtended, 'lineSubtotal');
|
||||||
const discountState = await this.discountService.getDiscountStateForCart(discountCodes, cartExtended);
|
const discountState = await this.discountService.getDiscountStateForCart(discountCodes, cartExtended);
|
||||||
const fiatPerXmr = this.exchangeRateService.getLiveFiatPerCrypto(PaymentMethod.Xmr);
|
|
||||||
const cartTotalXmr = fiatPerXmr !== null ? convertFiatToXmr(discountState.cartTotalPrice, fiatPerXmr) : null;
|
|
||||||
const hasManualLines = cartExtended.some(line => line.deliveryMode === DeliveryMode.Manual);
|
const hasManualLines = cartExtended.some(line => line.deliveryMode === DeliveryMode.Manual);
|
||||||
const hasAutoLines = cartExtended.some(line => line.deliveryMode === DeliveryMode.Auto);
|
const hasAutoLines = cartExtended.some(line => line.deliveryMode === DeliveryMode.Auto);
|
||||||
const cartTotalIssueMessage = getZeroCartTotalIssue(discountState.cartTotalPrice, cartExtended.length > 0);
|
const cartTotalIssueMessage = getZeroCartTotalIssue(discountState.cartTotalPrice, cartExtended.length > 0);
|
||||||
@@ -92,8 +84,6 @@ export class StorefrontCartService {
|
|||||||
cartExtended,
|
cartExtended,
|
||||||
cartSubtotal,
|
cartSubtotal,
|
||||||
...discountState,
|
...discountState,
|
||||||
cartTotalXmr,
|
|
||||||
fiatPerXmr,
|
|
||||||
hasManualLines,
|
hasManualLines,
|
||||||
hasAutoLines,
|
hasAutoLines,
|
||||||
cartTotalIssueMessage,
|
cartTotalIssueMessage,
|
||||||
|
|||||||
@@ -52,13 +52,6 @@
|
|||||||
{{cartTotalPrice}}
|
{{cartTotalPrice}}
|
||||||
{{shopFiatCurrency}}
|
{{shopFiatCurrency}}
|
||||||
</p>
|
</p>
|
||||||
{{#if cartTotalXmr}}
|
|
||||||
<p class='sf-text-muted'>= {{cartTotalXmr}} XMR</p>
|
|
||||||
{{else}}
|
|
||||||
<p class='sf-text-muted'>
|
|
||||||
We couldn't determine the XMR rate right now. Please try again later.
|
|
||||||
</p>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
<form class='sf-form-row' method='post' action='/shop/cart/discount'>
|
<form class='sf-form-row' method='post' action='/shop/cart/discount'>
|
||||||
<label class='sf-field'>
|
<label class='sf-field'>
|
||||||
@@ -73,7 +66,6 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class='sf-stack sf-mt-4'>
|
<div class='sf-stack sf-mt-4'>
|
||||||
{{#if cartTotalXmr}}
|
|
||||||
{{#unless hasIssues}}
|
{{#unless hasIssues}}
|
||||||
<form class='sf-form-col' method='post' action='/shop/checkout/pay'>
|
<form class='sf-form-col' method='post' action='/shop/checkout/pay'>
|
||||||
<div>{{{captchaSvg}}}</div>
|
<div>{{{captchaSvg}}}</div>
|
||||||
@@ -87,8 +79,8 @@
|
|||||||
<button type='button' class='sf-btn sf-btn--primary' disabled title='Resolve cart issues before paying'>Pay with XMR</button>
|
<button type='button' class='sf-btn sf-btn--primary' disabled title='Resolve cart issues before paying'>Pay with XMR</button>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<button type='button' class='sf-btn sf-btn--primary' disabled title='XMR rate unavailable'>Pay with XMR</button>
|
<button type='button' class='sf-btn sf-btn--primary' disabled title='Resolve cart issues before paying'>Continue to payment</button>
|
||||||
{{/if}}
|
{{/unless}}
|
||||||
|
|
||||||
{{> manual-shipping-info}}
|
{{> manual-shipping-info}}
|
||||||
{{> auto-delivery-info}}
|
{{> auto-delivery-info}}
|
||||||
|
|||||||
Reference in New Issue
Block a user