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 Extension.
Github of CoinTools
https://github.com/DoctorLai/CoinTools
Chrome Webstore
It is available online at Chrome Webstore.
v0.0.4 Feature of CoinTools
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 of CoinTools
How to Convert Between Fiat Currency and Crypto-currency in Javascript?
To convert between two FIAT is done via 1 BTC.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | // 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); } } |
// 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/SteemTools/
- 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!
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
785 wordsloading...
Last Post: SteemTools v0.0.6 - Check Who Downvoted You + API Server Ping
Next Post: SteemTools v0.0.7: Query Powerdown Status, Add SBDS API Server (Backend), Fix Voting Power