Skip to content

Commit

Permalink
Merge pull request #406 from PayButton/fix/supported-currencies
Browse files Browse the repository at this point in the history
Fix/supported currencies
  • Loading branch information
Klakurka authored May 17, 2024
2 parents 03165ca + c23a548 commit d0fee82
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 20 deletions.
10 changes: 1 addition & 9 deletions react/lib/components/PayButton/PayButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,4 @@ withUSDGoalCurrency.args = {
animation: 'none',
goalAmount: 500000,
currency: 'USD',
};

export const withEURGoalCurrency = Template.bind({});
withEURGoalCurrency.storyName = 'With EUR Goal';
withEURGoalCurrency.args = {
animation: 'none',
goalAmount: 400000,
currency: 'EUR',
};
};
8 changes: 0 additions & 8 deletions react/lib/components/PaymentDialog/PaymentDialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,3 @@ withUSDGoalCurrency.args = {
goalAmount: 500000,
currency: 'USD',
};

export const withEURGoalCurrency = Template.bind({});
withEURGoalCurrency.storyName = 'With EUR Goal';
withEURGoalCurrency.args = {
animation: 'none',
goalAmount: 400000,
currency: 'EUR',
};
79 changes: 79 additions & 0 deletions react/lib/tests/api-client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { fiatCurrencies, isCrypto, isFiat, isValidCurrency } from '../util/api-client';

describe('API Client Util Tests', () => {
describe('isCrypto', () => {
it('recognizes valid crypto currencies', () => {
expect(isCrypto('BCH')).toBeTruthy();
expect(isCrypto('XEC')).toBeTruthy();
});

it('does not recognize invalid crypto currencies', () => {
expect(isCrypto('BTC')).toBeFalsy();
expect(isCrypto('ETH')).toBeFalsy();
});

it('is case-sensitive', () => {
expect(isCrypto('bch')).toBeFalsy();
expect(isCrypto('xec')).toBeFalsy();
});

it('returns false for empty strings', () => {
expect(isCrypto('')).toBeFalsy();
});

it('returns false for whitespace or special characters', () => {
expect(isCrypto(' BCH ')).toBeFalsy();
expect(isCrypto('BCH@')).toBeFalsy();
});
});

describe('isValidCurrency', () => {
beforeEach(() => {
jest.resetAllMocks();
});

it('identifies fiat currencies correctly', () => {
expect(isValidCurrency('USD')).toBeTruthy();
expect(isValidCurrency('EUR')).toBeFalsy();
expect(isValidCurrency('CAD')).toBeTruthy();
expect(isValidCurrency('GBP')).toBeFalsy();
expect(isValidCurrency('AUD')).toBeFalsy();
});

it('identifies crypto currencies correctly', () => {
expect(isValidCurrency('BCH')).toBeTruthy();
expect(isValidCurrency('XEC')).toBeTruthy();
});

it('returns false for unrecognized currencies', () => {
expect(isValidCurrency('XYZ')).toBeFalsy();
expect(isValidCurrency('ABC')).toBeFalsy();
});

it('is case-sensitive', () => {
expect(isValidCurrency('bch')).toBeFalsy();
expect(isValidCurrency('usd')).toBeFalsy();
expect(isValidCurrency('xec')).toBeFalsy();
});

it('returns false for spaces or special characters', () => {
expect(isValidCurrency(' BCH ')).toBeFalsy();
expect(isValidCurrency('USD@')).toBeFalsy();
});
});

describe('isFiat', () => {
test('returns true for valid fiat currencies', () => {
fiatCurrencies.forEach(currency => {
expect(isFiat(currency)).toBe(true);
});
});

test('returns false for invalid fiat currencies', () => {
const invalidCurrencies = ['INR', 'JPY', 'BTC', 'ETH', 'XYZ', 'EUR'];
invalidCurrencies.forEach(currency => {
expect(isFiat(currency)).toBe(false);
});
});
});
});
7 changes: 4 additions & 3 deletions react/lib/util/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ export default {
getAddressBalance,
};

export const fiatCurrencies = ['USD', 'CAD', 'EUR', 'GBP', 'AUD'] as const;
type fiatCurrenciesTuple = typeof fiatCurrencies; // readonly ['USD', 'CAD', 'EUR', 'GBP', 'AUD']
export type fiatCurrency = fiatCurrenciesTuple[number]; // "USD" | "CAD" | "EUR" | "GBP" | "AUD"
export const fiatCurrencies = ['USD', 'CAD'] as const;

type fiatCurrenciesTuple = typeof fiatCurrencies; // readonly ['USD', 'CAD' ]
export type fiatCurrency = fiatCurrenciesTuple[number]; // "USD" | "CAD"

export const cryptoCurrencies = ['BCH', 'XEC'] as const;
type cryptoCurrenciesTuple = typeof cryptoCurrencies; // readonly ['BCH', 'XEC']
Expand Down

0 comments on commit d0fee82

Please sign in to comment.