add bitcoin shop config and payment method enablement

This commit is contained in:
2026-09-03 01:00:07 +02:00
parent a7282a1888
commit 11c94c7834
16 changed files with 170 additions and 4 deletions
@@ -0,0 +1,6 @@
import type { PaymentMethod } from '../../modules/payment/types/PaymentMethod';
export const isPaymentMethodEnabled = (
method: PaymentMethod,
enabledMethods: readonly PaymentMethod[]
): boolean => enabledMethods.includes(method);
@@ -0,0 +1,5 @@
import { PaymentMethod } from '../../modules/payment/types/PaymentMethod';
const PAYMENT_METHOD_VALUES = new Set<string>(Object.values(PaymentMethod));
export const isPaymentMethodValue = (value: string): value is PaymentMethod => PAYMENT_METHOD_VALUES.has(value);
@@ -0,0 +1,25 @@
import { PaymentMethod } from '../../modules/payment/types/PaymentMethod';
import { parseEnabledPaymentMethods } from './parseEnabledPaymentMethods';
describe('parseEnabledPaymentMethods', () => {
it('parses a single enabled method', () => {
expect(parseEnabledPaymentMethods('xmr')).toEqual([PaymentMethod.Xmr]);
});
it('parses multiple enabled methods', () => {
expect(parseEnabledPaymentMethods('xmr, btc')).toEqual([PaymentMethod.Xmr, PaymentMethod.Btc]);
});
it('returns an empty array for empty input', () => {
expect(parseEnabledPaymentMethods('')).toEqual([]);
});
it('filters out unsupported methods', () => {
expect(parseEnabledPaymentMethods('eth')).toEqual([]);
expect(parseEnabledPaymentMethods('xmr,eth')).toEqual([PaymentMethod.Xmr]);
});
it('filters out duplicate methods', () => {
expect(parseEnabledPaymentMethods('xmr,xmr')).toEqual([PaymentMethod.Xmr]);
});
});
@@ -0,0 +1,12 @@
import type { PaymentMethod } from '../../modules/payment/types/PaymentMethod';
import { isPaymentMethodValue } from './isPaymentMethodValue';
export const parseEnabledPaymentMethods = (raw: string): PaymentMethod[] => {
const methods = raw
.split(',')
.map(value => value.trim())
.filter(Boolean)
.filter(isPaymentMethodValue);
return [...new Set(methods)];
};