Skip to content

Commit

Permalink
removed class and added some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
BeycanDeveloper committed Jun 20, 2023
1 parent 8414947 commit 8e5db1c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 163 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 MultipleChain
Copyright (c) 2023 BeycanPress

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
157 changes: 0 additions & 157 deletions currency-converter.class.js

This file was deleted.

17 changes: 17 additions & 0 deletions currency-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ let setApi = (api, apiKey = null) => {
* @throws {Error}
*/
let convert = (from, to, amount) => {
console.log(isSameCurrency(from, to));
if (state.api == 'CoinMarketCap') {
return convertWithCoinMarketCap(from, to, amount);
} else if (state.api == 'CryptoCompare') {
Expand Down Expand Up @@ -131,12 +132,28 @@ let addStableCoins = (symbols) => {
stableCoins = stableCoins.concat(symbols);
}

let isStableCoin = (from, to) => {
if (from.toUpperCase() == 'USD' || $to.toUpperCase() == 'USD') {
if (stableCoins.includes(from.toUpperCase()) || stableCoins.includes(to.toUpperCase())) {
return true;
}
}

return false;
}

let isSameCurrency = (from, to) => {
return from.toUpperCase() == to.toUpperCase();
}


module.exports = {
state,
setApi,
convert,
isStableCoin,
addStableCoins,
isSameCurrency,
convertWithCoinMarketCap,
convertWithCryptoCompare
};
2 changes: 1 addition & 1 deletion currency-converter.js.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module 'currency-converter';
declare module '@beycanpress/currency-converter';
2 changes: 1 addition & 1 deletion dist/currency-converter.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"namespace": "beycanpress",
"name": "@beycanpress/currency-converter",
"version": "0.1.0",
"version": "0.1.1",
"description": "It takes on the task of converting between fiat and cryptocurrencies.",
"license": "MIT",
"browser": "currency-converter.js",
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import CurrencyConverter from '@beycanpress/currency-converter';
const CurrencyConverter = require('@beycanpress/currency-converter');


// 'coinmarketcap' can only use in backend. And it needs an API key.
let converter = new CurrencyConverter('cryptocompare | coinmarketcap', 'api key for coinmarketcap');
// 'CoinMarketCap' can only use in backend. And it needs an API key.
let converter = new CurrencyConverter('CryptoCompare | CoinMarketCap', 'api key for coinmarketcap');
paymentPrice = await converter.convert('USD', 'BTC', 15 /* USD Price */);

paymentPrice // BTC Price
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path');

module.exports = {
target: 'web',
mode: 'production',
entry: {
index: './currency-converter.js',
},
Expand Down

0 comments on commit 8e5db1c

Please sign in to comment.