CoinTools v0.0.4: Conversion Between Two Fiat or Fiat-Coin + 24 Hour Cap Chart
Introduction
CoinTools is a handy gadget to Chrome browser that you can launch easily to view the information of cryptocurrency.
Previous Contributions
- CoinTools v0.0.3: Adding Total Market Cap USD Chart, Localization and Stock Price Emoji
- v0.0.2 Cryptocurrency Conversion + UI Localization
- v0.0.1 Introduction to CoinTools! A Cryptocurrency Chrome Extension
Technology Stacks
Javascript that runs in Chrome.
Github
https://github.com/DoctorLai/CoinTools
Chrome Webstore
It is available online at Chrome Webstore:
https://chrome.google.com/webstore/detail/coin-tools/fmglcggbdcbkpkfapngjobfeakehpcgj
v0.0.4 Feature
Along with bug fixes, minor tweaks and code refactoring, this version has the following features:
- Total market cap USD in 24 hours
- Conversion between two FIAT currencies
- Conversion between FIAT and cryptocurrency
- Ranking table changed from 100 to 200.
Commits
Roadmap of CoinTools
- real-time graphs
- search cryptocurrency
- historical data
Screenshots
24 Hour Total Market Cap USD Pie Chart:
You can now specify the FIAT currency
Javascript
To convert between two FIAT is done via 1 BTC.
// ajax calling API to return the price of USD for coin
const getPriceOfUSD = (coin) => {
return new Promise((resolve, reject) => {
let api = "https://api.coinmarketcap.com/v1/ticker/" + coin + '/';
fetch(api, {mode: 'cors'}).then(validateResponse).then(readResponseAsJSON).then(function(result) {
resolve(result[0].price_usd);
}).catch(function(error) {
logit('Request failed: ' + api + ": " + error);
reject(error);
});
});
}
// ajax calling API to return the price of currency for 1 BTC
const getPriceOf1BTC = (currency) => {
return new Promise((resolve, reject) => {
let api = "https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=" + currency.toUpperCase();
fetch(api, {mode: 'cors'}).then(validateResponse).then(readResponseAsJSON).then(function(result) {
resolve(result[0]['price_' + currency.toLowerCase()]);
}).catch(function(error) {
logit('Request failed: ' + api + ": " + error);
reject(error);
});
});
}
// ajax calling API to return the price of USD for coin
const getPriceOf = (coin, fiat) => {
return new Promise((resolve, reject) => {
let api = "https://api.coinmarketcap.com/v1/ticker/" + coin + '/?convert=' + fiat.toUpperCase();
fetch(api, {mode: 'cors'}).then(validateResponse).then(readResponseAsJSON).then(function(result) {
resolve(result[0]['price_' + fiat.toLowerCase()]);
}).catch(function(error) {
logit('Request failed: ' + api + ": " + error);
reject(error);
});
});
}
// ajax get conversion
const getConversion = async(coin1, coin2) => {
// determine if input is coin or currency
let is_coin1 = !currency_array.includes(coin1.toUpperCase());
let is_coin2 = !currency_array.includes(coin2.toUpperCase());
// both are coins
if ((is_coin1) && (is_coin2)) {
let api1 = getPriceOfUSD(coin1);
let api2 = getPriceOfUSD(coin2);
return await api1 / await api2;
}
// both are currencies e.g. USD to CNY
if ((!is_coin1) && (!is_coin2)) {
let api1 = getPriceOf1BTC(coin1);
let api2 = getPriceOf1BTC(coin2);
return await api2 / await api1;
}
// converting coin1 to fiat coin2
if (is_coin1) {
return await getPriceOf(coin1, coin2);
} else { // convert coin2 to fiat coin1
return 1.0/await getPriceOf(coin2, coin1);
}
}
License
Contribution Welcome
Github: https://github.com/DoctorLai/CoinTools/
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request.
Chrome Webstore
Install the CoinTools Now!
Posted on Utopian.io - Rewarding Open Source Contributors
Great post
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
great contribution thank you justyy for the wonderful article
Hey @justyy I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x