Skip to content

Commit

Permalink
Fix: if country is not found in function, default to USD
Browse files Browse the repository at this point in the history
I forgot that there was this continent called EUROPE and that they had the same currency, so I have to change my logic soon. tbd
  • Loading branch information
nima9 committed Mar 13, 2024
1 parent 554808d commit c3dac68
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/functions/countryToCurrency.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import currencyData from '../api/currencies.json'

export function countryToCurrency(countryCode) {
let printedCurr = ''
let matchedCurrency = Object.values(currencyData).find((c) => c.code.slice(0, 2) === countryCode)
let printedCurr = `${matchedCurrency.symbol_native} ${matchedCurrency.code}`
if (!matchedCurrency) {
printedCurr = '$ USD'
} else {
printedCurr = `${matchedCurrency.symbol_native} ${matchedCurrency.code}`
}

return printedCurr
}

0 comments on commit c3dac68

Please sign in to comment.