Add payment method icons to storefront navbar and cart.

Show BTC/XMR icons beside exchange rates and pay buttons.
This commit is contained in:
2026-09-07 12:28:14 +02:00
parent dd234421a4
commit 68503ea01d
10 changed files with 57 additions and 8 deletions
@@ -0,0 +1,6 @@
import { PaymentMethod } from '../modules/payment/types/PaymentMethod';
export const paymentMethodIconUrl: Record<PaymentMethod, string> = {
[PaymentMethod.Xmr]: '/shop/assets/img/xmr.png',
[PaymentMethod.Btc]: '/shop/assets/img/btc.png'
};
@@ -4,6 +4,7 @@ import { Throttle } from '@nestjs/throttler';
import type { Request, Response } from 'express'; import type { Request, Response } from 'express';
import { throttleProfiles } from '../../../config/throttleProfiles'; import { throttleProfiles } from '../../../config/throttleProfiles';
import type { Config } from '../../../types/Config'; import type { Config } from '../../../types/Config';
import { paymentMethodIconUrl } from '../../../consts/paymentMethodIconUrl';
import { paymentMethodLabel } from '../../../consts/paymentMethodLabel'; import { paymentMethodLabel } from '../../../consts/paymentMethodLabel';
import { StorefrontExceptionFilter } from '../../storefrontCore/filters/StorefrontExceptionFilter'; import { StorefrontExceptionFilter } from '../../storefrontCore/filters/StorefrontExceptionFilter';
import { StorefrontCartCookieService } from '../../storefrontCore/services/StorefrontCartCookieService'; import { StorefrontCartCookieService } from '../../storefrontCore/services/StorefrontCartCookieService';
@@ -70,7 +71,8 @@ export class StorefrontCartController {
const paymentMethods = enabledPaymentMethods.map(paymentMethod => ({ const paymentMethods = enabledPaymentMethods.map(paymentMethod => ({
paymentMethod, paymentMethod,
paymentMethodLabel: paymentMethodLabel[paymentMethod] paymentMethodLabel: paymentMethodLabel[paymentMethod],
iconUrl: paymentMethodIconUrl[paymentMethod]
})); }));
return res.render('cart-summary', { return res.render('cart-summary', {
@@ -355,9 +355,31 @@ a:hover {
gap: var(--sf-space-1); gap: var(--sf-space-1);
} }
.sf-rates {
display: flex;
flex-wrap: wrap;
gap: var(--sf-space-3);
align-items: center;
}
.sf-rate { .sf-rate {
display: inline-flex;
align-items: center;
gap: var(--sf-space-1);
font-size: 0.95rem; font-size: 0.95rem;
color: var(--sf-text-muted); color: var(--sf-text-muted);
white-space: nowrap;
}
.sf-crypto-icon {
width: 1.25rem;
height: 1.25rem;
object-fit: contain;
flex-shrink: 0;
}
.sf-btn--pay {
gap: var(--sf-space-2);
} }
.sf-category-nav { .sf-category-nav {
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

@@ -145,8 +145,8 @@ describe('StorefrontShopViewService', () => {
feedback: { type: 'success', text: 'Added to cart' }, feedback: { type: 'success', text: 'Added to cart' },
shopFiatCurrency: 'USD', shopFiatCurrency: 'USD',
cryptoRates: [ cryptoRates: [
{ cryptoCurrency: 'XMR', fiatPerCrypto: 200 }, { paymentLabel: 'XMR', fiatPerCrypto: 200, iconUrl: '/shop/assets/img/xmr.png' },
{ cryptoCurrency: 'BTC', fiatPerCrypto: 80_000 } { paymentLabel: 'BTC', fiatPerCrypto: 80_000, iconUrl: '/shop/assets/img/btc.png' }
], ],
logoUrl: '/uploads/logo.png', logoUrl: '/uploads/logo.png',
faviconUrl: '/uploads/favicon.ico', faviconUrl: '/uploads/favicon.ico',
@@ -8,6 +8,7 @@ import { formatShortOrderId } from '../../../utils/order/formatShortOrderId';
import { toAbsoluteUrl } from '../../../utils/toAbsoluteUrl'; import { toAbsoluteUrl } from '../../../utils/toAbsoluteUrl';
import { ShopSettingsService } from '../../shopSettings/services/ShopSettingsService'; import { ShopSettingsService } from '../../shopSettings/services/ShopSettingsService';
import { ExchangeRateService } from '../../exchangeRate/services/ExchangeRateService'; import { ExchangeRateService } from '../../exchangeRate/services/ExchangeRateService';
import { paymentMethodIconUrl } from '../../../consts/paymentMethodIconUrl';
import { paymentMethodLabel } from '../../../consts/paymentMethodLabel'; import { paymentMethodLabel } from '../../../consts/paymentMethodLabel';
import { PaymentMethod } from '../../payment/types/PaymentMethod'; import { PaymentMethod } from '../../payment/types/PaymentMethod';
import type { AuthorizedOrderNavItem } from '../types/AuthorizedOrderNavItem'; import type { AuthorizedOrderNavItem } from '../types/AuthorizedOrderNavItem';
@@ -145,8 +146,9 @@ export class StorefrontShopViewService {
return [ return [
{ {
cryptoCurrency: paymentMethodLabel[paymentMethod], paymentLabel: paymentMethodLabel[paymentMethod],
fiatPerCrypto fiatPerCrypto,
iconUrl: paymentMethodIconUrl[paymentMethod]
} }
]; ];
}); });
@@ -1,4 +1,5 @@
export type StorefrontCryptoRate = { export type StorefrontCryptoRate = {
cryptoCurrency: string; paymentLabel: string;
fiatPerCrypto: number; fiatPerCrypto: number;
iconUrl: string;
}; };
@@ -80,9 +80,16 @@
type='submit' type='submit'
name='paymentMethod' name='paymentMethod'
value='{{paymentMethod}}' value='{{paymentMethod}}'
class='sf-btn sf-btn--primary' class='sf-btn sf-btn--primary sf-btn--pay'
> >
Pay with {{paymentMethodLabel}} Pay with {{paymentMethodLabel}}
{{> storefront-image
class='sf-crypto-icon'
src=iconUrl
alt=''
width='20'
height='20'
}}
</button> </button>
{{/each}} {{/each}}
</div> </div>
@@ -32,7 +32,16 @@
{{#if cryptoRates.length}} {{#if cryptoRates.length}}
<div class='sf-rates'> <div class='sf-rates'>
{{#each cryptoRates}} {{#each cryptoRates}}
<div class='sf-rate'>1 {{cryptoCurrency}} = {{fiatPerCrypto}} {{../shopFiatCurrency}}</div> <span class='sf-rate'>
{{> storefront-image
class='sf-crypto-icon'
src=iconUrl
alt=paymentLabel
width='20'
height='20'
}}
<span>{{fiatPerCrypto}} {{../shopFiatCurrency}}</span>
</span>
{{/each}} {{/each}}
</div> </div>
{{/if}} {{/if}}