* Create the CurrencyCode and use it for the currency `code` instead of the type `string`

Using the CurrencyCode type, the allowed values for the `code` property are restricted
to the ISO 4217 codes and not any string.

* Add and remove some currency codes to match the ones on WooCommerce

The WooCommerce supported list can be found here: https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/wc-core-functions.php#L475

* Use CurrencyCode type on CurrencyInfo and CurrencyResponse instead of string
This commit is contained in:
Alba Rincón 2022-03-23 00:30:56 +01:00 committed by GitHub
parent e7a061d56f
commit 1f9e4675fc
3 changed files with 174 additions and 4 deletions

View File

@ -11,7 +11,7 @@ import { Currency } from '@woocommerce/types';
import FooterItem, { TotalsFooterItemProps } from '..';
const NZD: Currency = {
code: 'nzd',
code: 'NZD',
symbol: '$',
thousandSeparator: ' ',
decimalSeparator: '.',

View File

@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { CurrencyCode } from '@woocommerce/type-defs/currency';
/**
* Internal dependencies
*/
@ -10,7 +15,7 @@ import {
import { ProductResponseItemData } from './product-response';
export interface CurrencyInfo {
currency_code: string;
currency_code: CurrencyCode;
currency_symbol: string;
currency_minor_unit: number;
currency_decimal_separator: string;

View File

@ -2,7 +2,7 @@ export interface Currency {
/**
* ISO 4217 Currency Code
*/
code: string; // @todo create a list of allowed currency codes
code: CurrencyCode;
/**
* String which separates the decimals from the integer
*/
@ -34,7 +34,7 @@ export interface Currency {
}
export interface CurrencyResponse {
currency_code: string;
currency_code: CurrencyCode;
currency_symbol: string;
currency_minor_unit: number;
currency_decimal_separator: string;
@ -44,3 +44,168 @@ export interface CurrencyResponse {
}
export type SymbolPosition = 'left' | 'left_space' | 'right' | 'right_space';
export type CurrencyCode =
| 'AED'
| 'AFN'
| 'ALL'
| 'AMD'
| 'ANG'
| 'AOA'
| 'ARS'
| 'AUD'
| 'AWG'
| 'AZN'
| 'BAM'
| 'BBD'
| 'BDT'
| 'BGN'
| 'BHD'
| 'BIF'
| 'BMD'
| 'BND'
| 'BOB'
| 'BRL'
| 'BSD'
| 'B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