CoinTools v0.0.4: Conversion Between Two Fiat or Fiat-Coin + 24 Hour Cap Chart

in #utopian-io6 years ago (edited)

Introduction

CoinTools is a handy gadget to Chrome browser that you can launch easily to view the information of cryptocurrency.

Previous Contributions

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:

  1. Total market cap USD in 24 hours
  2. Conversion between two FIAT currencies
  3. Conversion between FIAT and cryptocurrency
  4. Ranking table changed from 100 to 200.

Commits

Here

Roadmap of CoinTools

  1. real-time graphs
  2. search cryptocurrency
  3. historical data

Screenshots

24 Hour Total Market Cap USD Pie Chart:
image.png

You can now specify the FIAT currency
image.png

image.png

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

MIT

Contribution Welcome

Github: https://github.com/DoctorLai/CoinTools/

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request.

Chrome Webstore

Install the CoinTools Now!



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

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

  • WOW WOW WOW People loved what you did here. GREAT JOB!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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

Coin Marketplace

STEEM 0.26
TRX 0.11
JST 0.033
BTC 64266.94
ETH 3077.24
USDT 1.00
SBD 3.87