Skip to content

Commit

Permalink
used currency-codes package
Browse files Browse the repository at this point in the history
  • Loading branch information
lendihop committed Oct 2, 2023
1 parent acca9ae commit d305ab3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/app/hooks/AliceBob/use-output-currencies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useState } from 'react';

import { knownAliceBobFiatCurrencies, knownAliceBobFiatCurrenciesNames } from 'app/store/buy-with-credit-card/utils';
import { getCurrencyNameByCode, knownAliceBobFiatCurrencies } from 'app/store/buy-with-credit-card/utils';
import { getAliceBobPairsInfo } from 'lib/apis/temple';
import { FIAT_ICONS_SRC } from 'lib/icons';

Expand All @@ -13,7 +13,7 @@ export interface AliceBobWithdrawCurrency {
}

export const DEFAULT_OUTPUT_CURRENCY = {
name: knownAliceBobFiatCurrenciesNames['UAH'],
name: getCurrencyNameByCode('UAH'),
code: 'UAH',
icon: FIAT_ICONS_SRC.UAH
};
Expand Down Expand Up @@ -46,7 +46,7 @@ export const useOutputCurrencies = (
}

return {
name: knownAliceBobFiatCurrenciesNames[code] ?? '',
name: getCurrencyNameByCode(code),
code,
icon: `https://static.moonpay.com/widget/currencies/${code.toLowerCase()}.svg`,
minAmount,
Expand Down
38 changes: 21 additions & 17 deletions src/app/store/buy-with-credit-card/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isDefined } from '@rnw-community/shared';
import { AxiosResponse } from 'axios';
import FiatCurrencyInfo from 'currency-codes';

import {
Currency,
Expand All @@ -22,33 +23,36 @@ interface AliceBobFiatCurrency {
const UTORG_FIAT_ICONS_BASE_URL = 'https://utorg.pro/img/flags2/icon-';
const UTORG_CRYPTO_ICONS_BASE_URL = 'https://utorg.pro/img/cryptoIcons';

const knownUtorgFiatCurrenciesNames: Record<string, string> = {
PHP: 'Philippine Peso',
INR: 'Indian Rupee'
};
export const getCurrencyNameByCode = (code: string) => {
const customCurrencyNames: Record<string, string> = {
UAH: 'Ukrainian Hryvnia',
KZT: 'Kazakhstani Tenge'
};

if (isDefined(customCurrencyNames[code])) {
return customCurrencyNames[code];
}

export const knownAliceBobFiatCurrenciesNames: Record<string, string> = {
...knownUtorgFiatCurrenciesNames,
UAH: 'Ukrainian Hryvnia',
MYR: 'Malaysian Ringgit',
KZT: 'Kazakhstan tenge'
const currencyInfo = FiatCurrencyInfo.code(code);

return isDefined(currencyInfo) ? currencyInfo.currency : '???';
};

export const knownAliceBobFiatCurrencies: Record<string, AliceBobFiatCurrency> = {
UAH: {
name: knownAliceBobFiatCurrenciesNames['UAH'],
name: getCurrencyNameByCode('UAH'),
code: 'UAH',
icon: FIAT_ICONS_SRC.UAH,
precision: 2
},
MYR: {
name: knownAliceBobFiatCurrenciesNames['MYR'],
name: getCurrencyNameByCode('MYR'),
code: 'MYR',
icon: `${UTORG_FIAT_ICONS_BASE_URL}MY.svg`,
precision: 2
},
KZT: {
name: knownAliceBobFiatCurrenciesNames['KZT'],
name: getCurrencyNameByCode('KZT'),
code: 'KZT',
icon: FIAT_ICONS_SRC.KZT,
precision: 2
Expand Down Expand Up @@ -97,11 +101,11 @@ export const mapMoonPayProviderCurrencies = (currencies: Currency[]) => ({
export const mapUtorgProviderCurrencies = (currencies: UtorgCurrencyInfo[]) => ({
fiat: currencies
.filter(({ type, depositMax }) => type === UtorgCurrencyInfoType.FIAT && depositMax > 0)
.map(({ display, symbol, depositMin, depositMax, precision }) => ({
name: knownUtorgFiatCurrenciesNames[symbol] ?? '',
code: symbol,
.map(({ display, symbol: code, depositMin, depositMax, precision }) => ({
name: getCurrencyNameByCode(code),
code,
codeToDisplay: display,
icon: `${UTORG_FIAT_ICONS_BASE_URL}${symbol.slice(0, -1)}.svg`,
icon: `${UTORG_FIAT_ICONS_BASE_URL}${code.slice(0, -1)}.svg`,
precision,
minAmount: depositMin,
maxAmount: depositMax
Expand Down Expand Up @@ -135,7 +139,7 @@ export const mapAliceBobProviderCurrencies = (response: AxiosResponse<{ pairsInf
}

return {
name: knownAliceBobFiatCurrenciesNames[code] ?? '',
name: getCurrencyNameByCode(code),
code,
icon: `https://static.moonpay.com/widget/currencies/${code.toLowerCase()}.svg`,
precision: 2,
Expand Down

0 comments on commit d305ab3

Please sign in to comment.