Skip to content

Commit

Permalink
feat(new tool): Currency Converter
Browse files Browse the repository at this point in the history
Fix part of CorentinTh#571
  • Loading branch information
sharevb committed Sep 28, 2024
1 parent 318fb6e commit efcfd99
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
113 changes: 113 additions & 0 deletions src/tools/currency-converter/currency-converter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<script setup lang="ts">
import { code, countries, country } from 'currency-codes-ts';
import converter from 'currency-exchanger-js';
import moneysData from './moneys.json';
import { useQueryParamOrStorage } from '@/composable/queryParams';
const allCurrencies = Object.entries(moneysData).map(([k, v]) => ({ value: k, label: v || k }));
const otherCurrencies = useQueryParamOrStorage<{ name: string }[]>({ name: 'to', storageName: 'currency-conv:others', defaultValue: [{ name: 'usd' }] });
const currentCurrency = useQueryParamOrStorage<string>({ name: 'from', storageName: 'currency-conv:cur', defaultValue: 'eur' });
const amount = ref(1);
const currentDatetime = ref(Date.now());
async function convertToCurrency(targetCurrency: string) {
const currentCurrencyValue = currentCurrency.value;
const currentDatetimeValue = currentDatetime.value;
const amountValue = amount.value;
return await converter.convertOnDate(amountValue, currentCurrencyValue, targetCurrency, new Date(currentDatetimeValue));
}
const countryToCurrenciesInput = ref('france');
const allCountries = countries();
const countryToCurrenciesOutput = computed(() => country(countryToCurrenciesInput.value));
const currencyToCountriesInput = ref('eur');
const currencyToCountriesOutput = computed(() => code(currencyToCountriesInput.value));
</script>

<template>
<div>
<c-card title="Currency Converter" mb-2>
<c-select
v-model:value="currentCurrency"
label="From"
label-position="left"
searchable
:options="allCurrencies"
mb-2
/>
<n-form-item label="Amount:" label-placement="left" mb-2>
<n-input-number :value="amount" :min="0" />
</n-form-item>

<n-form-item label="For Date:" label-placement="left" mb-2>
<n-date-picker
v-model:value="currentDatetime"
type="date"
/>
</n-form-item>

<c-card title="Converted currencies">
<n-dynamic-input
v-model:value="otherCurrencies"
show-sort-button
:on-create="() => ({ name: 'eur' })"
>
<template #default="{ value }">
<div flex flex-wrap items-center gap-1>
<n-select
v-model:value="value.name"
filterable
placeholder="Please select a currency"
:options="allCurrencies"
w-full
/>
<input-copyable :value="convertToCurrency(value.name)" />
</div>
</template>
</n-dynamic-input>
</c-card>
</c-card>

<c-card title="Country to Currencies" mb-2>
<c-select
v-model:value="countryToCurrenciesInput"
label="Country"
label-position="left"
searchable
:options="allCountries"
/>

<n-divider />

<ul>
<li v-for="(currency, ix) in countryToCurrenciesOutput" :key="ix">
{{ currency.currency }} [{{ currency.code }}/{{ currency.number }} - {{ currency.digits }}digits] (also in: {{ currency.countries?.join(', ') }})
</li>
</ul>
</c-card>

<c-card title="Currencies to Countries" mb-2>
<c-select
v-model:value="currencyToCountriesInput"
label="Currency"
label-position="left"
searchable
:options="allCurrencies"
/>

<n-divider />

<n-p v-if="currencyToCountriesOutput">
{{ currencyToCountriesOutput.currency }} [{{ currencyToCountriesOutput.code }}/{{ currencyToCountriesOutput.number }} - {{ currencyToCountriesOutput.digits }}digits]
</n-p>

<ul v-if="currencyToCountriesOutput">
<li v-for="(countryName, ix) in currencyToCountriesOutput.countries" :key="ix">
{{ countryName }}
</li>
</ul>
</c-card>
</div>
</template>
4 changes: 4 additions & 0 deletions src/tools/currency-converter/currency-exchanger-js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'currency-exchanger-js'{
export function convertOnDate(value: number,fromCurrency: string,toCurrency: string,inputDate: Date): number;
export function convert(value: number,fromCurrency: string,toCurrency: string): number;
}
12 changes: 12 additions & 0 deletions src/tools/currency-converter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Currency } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'Currency Converter',
path: '/currency-converter',
description: 'Convert currency values using ExchangeRate-API',
keywords: ['currency', 'converter'],
component: () => import('./currency-converter.vue'),
icon: Currency,
createdAt: new Date('2024-08-15'),
});
1 change: 1 addition & 0 deletions src/tools/currency-converter/moneys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "1000sats": "", "1inch": "1inch", "aave": "Aave", "ada": "Cardano", "aed": "Emirati Dirham", "afn": "Afghan Afghani", "agix": "SingularityNET", "akt": "Akash Network", "algo": "Algorand", "all": "Albanian Lek", "amd": "Armenian Dram", "amp": "Amp", "ang": "Dutch Guilder", "aoa": "Angolan Kwanza", "ape": "ApeCoin", "apt": "Aptos", "ar": "Arweave", "arb": "Arbitrum", "ars": "Argentine Peso", "atom": "Cosmos", "ats": "Austrian Schilling", "aud": "Australian Dollar", "avax": "Avalanche", "awg": "Aruban or Dutch Guilder", "axs": "Axie Infinity", "azm": "Azerbaijani Manat", "azn": "Azerbaijan Manat", "bake": "BakeryToken", "bam": "Bosnian Convertible Mark", "bat": "Basic Attention Token", "bbd": "Barbadian or Bajan Dollar", "bch": "Bitcoin Cash", "bdt": "Bangladeshi Taka", "bef": "Belgian Franc", "bgn": "Bulgarian Lev", "bhd": "Bahraini Dinar", "bif": "Burundian Franc", "bmd": "Bermudian Dollar", "bnb": "Binance Coin", "bnd": "Bruneian Dollar", "bob": "Bolivian Bolíviano", "brl": "Brazilian Real", "bsd": "Bahamian Dollar", "bsv": "Bitcoin SV", "bsw": "Biswap", "btc": "Bitcoin", "btcb": "Bitcoin BEP2", "btg": "Bitcoin Gold", "btn": "Bhutanese Ngultrum", "btt": "BitTorrent", "busd": "Binance USD", "bwp": "Botswana Pula", "byn": "Belarusian Ruble", "byr": "Belarusian Ruble", "bzd": "Belizean Dollar", "cad": "Canadian Dollar", "cake": "PancakeSwap", "cdf": "Congolese Franc", "celo": "Celo", "cfx": "Conflux", "chf": "Swiss Franc", "chz": "Chiliz", "clp": "Chilean Peso", "cnh": "Chinese Yuan Renminbi Offshore", "cny": "Chinese Yuan Renminbi", "comp": "Compound", "cop": "Colombian Peso", "crc": "Costa Rican Colon", "cro": "Crypto.com Chain", "crv": "Curve DAO Token", "cspr": "Casper", "cuc": "Cuban Convertible Peso", "cup": "Cuban Peso", "cve": "Cape Verdean Escudo", "cvx": "Convex Finance", "cyp": "Cypriot Pound", "czk": "Czech Koruna", "dai": "DAI", "dash": "Digital Cash", "dcr": "Decred", "dem": "German Deutsche Mark", "dfi": "DfiStarter", "djf": "Djiboutian Franc", "dkk": "Danish Krone", "doge": "Dogecoin", "dop": "Dominican Peso", "dot": "Polkadot", "dydx": "dYdX", "dzd": "Algerian Dinar", "eek": "Estonian Kroon", "egld": "Elrond", "egp": "Egyptian Pound", "enj": "Enjin Coin", "eos": "EOS", "ern": "Eritrean Nakfa", "esp": "Spanish Peseta", "etb": "Ethiopian Birr", "etc": "Ethereum Classic", "eth": "Ethereum", "eur": "Euro", "fei": "Fei USD", "fil": "Filecoin", "fim": "Finnish Markka", "fjd": "Fijian Dollar", "fkp": "Falkland Island Pound", "flow": "Flow", "flr": "FLARE", "frax": "Frax", "frf": "French Franc", "ftm": "Fantom", "ftt": "FarmaTrust", "fxs": "Frax Share", "gala": "Gala", "gbp": "British Pound", "gel": "Georgian Lari", "ggp": "Guernsey Pound", "ghc": "Ghanaian Cedi", "ghs": "Ghanaian Cedi", "gip": "Gibraltar Pound", "gmd": "Gambian Dalasi", "gmx": "Goldmaxcoin", "gnf": "Guinean Franc", "gno": "Gnosis", "grd": "Greek Drachma", "grt": "The Graph", "gt": "GateToken", "gtq": "Guatemalan Quetzal", "gusd": "Gemini US Dollar", "gyd": "Guyanese Dollar", "hbar": "Hedera", "hkd": "Hong Kong Dollar", "hnl": "Honduran Lempira", "hnt": "Helium", "hot": "Hydro Protocol", "hrk": "Croatian Kuna", "ht": "Huobi Token", "htg": "Haitian Gourde", "huf": "Hungarian Forint", "icp": "Internet Computer", "idr": "Indonesian Rupiah", "iep": "Irish Pound", "ils": "Israeli Shekel", "imp": "Isle of Man Pound", "imx": "Immutable X", "inj": "Injective", "inr": "Indian Rupee", "iqd": "Iraqi Dinar", "irr": "Iranian Rial", "isk": "Icelandic Krona", "itl": "Italian Lira", "jep": "Jersey Pound", "jmd": "Jamaican Dollar", "jod": "Jordanian Dinar", "jpy": "Japanese Yen", "kas": "", "kava": "Kava", "kcs": "Kucoin", "kda": "Kadena", "kes": "Kenyan Shilling", "kgs": "Kyrgyzstani Som", "khr": "Cambodian Riel", "klay": "Klaytn", "kmf": "Comorian Franc", "knc": "Kyber Network Crystals", "kpw": "North Korean Won", "krw": "South Korean Won", "ksm": "Kusama", "kwd": "Kuwaiti Dinar", "kyd": "Caymanian Dollar", "kzt": "Kazakhstani Tenge", "lak": "Lao Kip", "lbp": "Lebanese Pound", "ldo": "Lido DAO Token", "leo": "LEOcoin", "link": "Chainlink", "lkr": "Sri Lankan Rupee", "lrc": "Loopring", "lrd": "Liberian Dollar", "lsl": "Basotho Loti", "ltc": "Litecoin", "ltl": "Lithuanian Litas", "luf": "Luxembourg Franc", "luna": "Terra", "lunc": "", "lvl": "Latvian Lat", "lyd": "Libyan Dinar", "mad": "Moroccan Dirham", "mana": "Mana Coin Decentraland", "matic": "Polygon", "mbx": "MobieCoin", "mdl": "Moldovan Leu", "mga": "Malagasy Ariary", "mgf": "Malagasy Franc", "mina": "Mina", "mkd": "Macedonian Denar", "mkr": "Maker", "mmk": "Burmese Kyat", "mnt": "Mongolian Tughrik", "mop": "Macau Pataca", "mro": "Mauritanian Ouguiya", "mru": "Mauritanian Ouguiya", "mtl": "Maltese Lira", "mur": "Mauritian Rupee", "mvr": "Maldivian Rufiyaa", "mwk": "Malawian Kwacha", "mxn": "Mexican Peso", "mxv": "", "myr": "Malaysian Ringgit", "mzm": "Mozambican Metical", "mzn": "Mozambican Metical", "nad": "Namibian Dollar", "near": "NEAR Protocol", "neo": "NEO", "nexo": "NEXO", "nft": "NFT", "ngn": "Nigerian Naira", "nio": "Nicaraguan Cordoba", "nlg": "Dutch Guilder", "nok": "Norwegian Krone", "npr": "Nepalese Rupee", "nzd": "New Zealand Dollar", "okb": "Okex", "omr": "Omani Rial", "one": "Menlo One", "op": "Optimism", "ordi": "", "pab": "Panamanian Balboa", "paxg": "PAX Gold", "pen": "Peruvian Sol", "pepe": "", "pgk": "Papua New Guinean Kina", "php": "Philippine Peso", "pkr": "Pakistani Rupee", "pln": "Polish Zloty", "pte": "Portuguese Escudo", "pyg": "Paraguayan Guarani", "qar": "Qatari Riyal", "qnt": "Quant", "qtum": "QTUM", "rol": "Romanian Leu", "ron": "Romanian Leu", "rpl": "Rocket Pool", "rsd": "Serbian Dinar", "rub": "Russian Ruble", "rune": "THORChain (ERC20)", "rvn": "Ravencoin", "rwf": "Rwandan Franc", "sand": "The Sandbox", "sar": "Saudi Arabian Riyal", "sbd": "Solomon Islander Dollar", "scr": "Seychellois Rupee", "sdd": "Sudanese Dinar", "sdg": "Sudanese Pound", "sek": "Swedish Krona", "sgd": "Singapore Dollar", "shib": "Shiba Inu", "shp": "Saint Helenian Pound", "sit": "Slovenian Tolar", "skk": "Slovak Koruna", "sle": "Sierra Leonean Leone", "sll": "Sierra Leonean Leone", "snx": "Synthetix Network", "sol": "Solana", "sos": "Somali Shilling", "spl": "Seborgan Luigino", "srd": "Surinamese Dollar", "srg": "Surinamese Guilder", "std": "Sao Tomean Dobra", "stn": "Sao Tomean Dobra", "stx": "Stacks", "sui": "Sui", "svc": "Salvadoran Colon", "syp": "Syrian Pound", "szl": "Swazi Lilangeni", "thb": "Thai Baht", "theta": "Theta", "tjs": "Tajikistani Somoni", "tmm": "Turkmenistani Manat", "tmt": "Turkmenistani Manat", "tnd": "Tunisian Dinar", "ton": "Tokamak Network", "top": "Tongan Pa'anga", "trl": "Turkish Lira", "trx": "TRON", "try": "Turkish Lira", "ttd": "Trinidadian Dollar", "tusd": "True USD", "tvd": "Tuvaluan Dollar", "twd": "Taiwan New Dollar", "twt": "Trust Wallet Token", "tzs": "Tanzanian Shilling", "uah": "Ukrainian Hryvnia", "ugx": "Ugandan Shilling", "uni": "Uniswap", "usd": "US Dollar", "usdc": "USDC", "usdd": "", "usdp": "USDP Stablecoin", "usdt": "Tether", "uyu": "Uruguayan Peso", "uzs": "Uzbekistani Som", "val": "Vatican City Lira", "veb": "Venezuelan Bolívar", "ved": "", "vef": "Venezuelan Bolívar", "ves": "Venezuelan Bolívar", "vet": "Vechain", "vnd": "Vietnamese Dong", "vuv": "Ni-Vanuatu Vatu", "waves": "Waves", "wemix": "WEMIX", "woo": "WOO Network", "wst": "Samoan Tala", "xaf": "Central African CFA Franc BEAC", "xag": "Silver Ounce", "xau": "Gold Ounce", "xaut": "Tether Gold", "xbt": "", "xcd": "East Caribbean Dollar", "xch": "Chia", "xdc": "XDC Network", "xdr": "IMF Special Drawing Rights", "xec": "Eternal Coin", "xem": "NEM", "xlm": "Stellar Lumen", "xmr": "Monero", "xof": "CFA Franc", "xpd": "Palladium Ounce", "xpf": "CFP Franc", "xpt": "Platinum Ounce", "xrp": "Ripple", "xtz": "Tezos", "yer": "Yemeni Rial", "zar": "South African Rand", "zec": "ZCash", "zil": "Zilliqa", "zmk": "Zambian Kwacha", "zmw": "Zambian Kwacha", "zwd": "Zimbabwean Dollar", "zwg": "", "zwl": "Zimbabwean Dollar" }
2 changes: 2 additions & 0 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as emailNormalizer } from './email-normalizer';
import { tool as currencyConverter } from './currency-converter';

import { tool as asciiTextDrawer } from './ascii-text-drawer';

Expand Down Expand Up @@ -112,6 +113,7 @@ export const toolsByCategory: ToolCategory[] = [
tomlToYaml,
xmlToJson,
jsonToXml,
currencyConverter,
],
},
{
Expand Down

0 comments on commit efcfd99

Please sign in to comment.