diff --git a/README.md b/README.md index e2f6153..8a4fbc3 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,41 @@ [atom-bitcoin](https://atom.io/packages/atom-bitcoin) ============ -Watch the latest selling price for bitcoin while you code! +####Watch the latest selling price for bitcoin while you code! ![](https://dl.dropboxusercontent.com/s/4lvxmytpicoz9o1/screenshot.png?dl=1&token_hash=AAEBoVYT77ey684_qqX5ltFAhUOfRdqmxjMUcnuUNxnFTA) -To install +####To install -`` cd /Users/your_username/.atom/packages `` +`` apm install atom-bitcoin `` or search for ``atom-bitcoin`` in Settings > Packages -`` git clone git@github.com:ahmetabdi/atom-bitcoin.git `` +This uses the [BitcoinAverage API](https://bitcoinaverage.com/api.htm), an open source project designed to provide weighted average bitcoin price calculation. It utilises all exchanges where price and volume data is available. -then restart atom +####Features -Update interval fixed to 5 seconds +- Update interval defaults to 5 seconds but any second-based interval can be entered in the settings -Has colour updates to show increase/decrease in price in USD +- Has colour updates to show increase/decrease/stable in price -This uses the [BitcoinAverage API](https://bitcoinaverage.com/api.htm) +- Currency defaults to USD but any currency from the list below can be entered in the settings -It's an open source project designed to provide weighted average bitcoin price calculation. It utilises all exchanges where price and volume data is available. + - AUD + - BRL + - CAD + - CHF + - CNY + - EUR + - GBP + - HKD + - ILS + - JPY + - NOK + - NZD + - PLN + - RUB + - SEK + - SGD + - TRY + - USD + - ZAR diff --git a/lib/atom-bitcoin-status-bar-view.coffee b/lib/atom-bitcoin-status-bar-view.coffee index 7624b2f..b744411 100644 --- a/lib/atom-bitcoin-status-bar-view.coffee +++ b/lib/atom-bitcoin-status-bar-view.coffee @@ -1,14 +1,16 @@ {View} = require 'atom' jQuery = require 'jquery' +valid_currencies = require './currencies' module.exports = class AtomBitcoinStatusBarView extends View default_interval: 5000 + default_currency: 'USD' load_text: 'Retreiving price...' @content: -> - @div class: 'inline-block', => - @span outlet: "bitcoinInfo", class: 'atom-bitcoin-status', tabindex: '-1', "" + @div class: 'inline-block atom-bitcoin', => + @span outlet: "bitcoinInfo", tabindex: '-1', "" initialize: -> # We wait until all the other packages have been loaded, @@ -27,6 +29,11 @@ class AtomBitcoinStatusBarView extends View interval = atom.config.get('atom-bitcoin.interval') interval = if not isNaN(interval) then (interval.toFixed() * 1000) else @default_interval + # Get user settings for currency + # Insure currency is in the supported list or use default + currency = atom.config.get('atom-bitcoin.currency') + currency = if currency of valid_currencies then currency else @default_currency + # Display loading text @display(null) @@ -34,25 +41,28 @@ class AtomBitcoinStatusBarView extends View last_output = undefined setInterval => jQuery ($) -> - json = $.getJSON "https://api.bitcoinaverage.com/ticker/USD/last", '', (data, resp) -> + json = $.getJSON 'https://api.bitcoinaverage.com/ticker/'+currency+'/last', '', (data, resp) -> if resp = "success" output = parseFloat(data).toFixed(2) - if output > last_output - $(".atom-bitcoin-status").css "color", "green" - else if output < last_output - $(".atom-bitcoin-status").css "color", "red" - else - else #Handle failed response? + # Set color for ticker + @bitcoinInfo.removeClass('status-stable status-rise status-fall') + if output > last_output + @bitcoinInfo.addClass('status-rise') + else if output < last_output + @bitcoinInfo.addClass('status-fall') + else + @bitcoinInfo.addClass('status-stable') + # Update price - @display(output) + @display(output, valid_currencies[currency]) last_output = output , interval # config or default interval - display: (price) -> + display: (price, symbol) -> # Display loading text or current price - @bitcoinInfo.text(if not price then @load_text else "$#{price}") + @bitcoinInfo.text(if not price then @load_text else symbol+price) diff --git a/lib/atom-bitcoin.coffee b/lib/atom-bitcoin.coffee index ccb8c18..4e8a3d9 100644 --- a/lib/atom-bitcoin.coffee +++ b/lib/atom-bitcoin.coffee @@ -5,4 +5,5 @@ module.exports = @atomBitcoinStatusBarView = new AtomBitcoinStatusBarView() configDefaults: + currency: 'USD' interval: 5 diff --git a/lib/currencies.coffee b/lib/currencies.coffee new file mode 100644 index 0000000..838f466 --- /dev/null +++ b/lib/currencies.coffee @@ -0,0 +1,21 @@ +module.exports = { + "AUD": "\u0024", + "BRL": "\u0052\u0024", + "CAD": "\u0024", + "CHF": "\u0043\u0048\u0046", + "CNY": "\u00a5", + "EUR": "\u20ac", + "GBP": "\u00a3", + "HKD": "\u0024", + "ILS": "\u20aa", + "JPY": "\u00a5", + "NOK": "\u006b\u0072", + "NZD": "\u0024", + "PLN": "\u007a\u0142", + "RUB": "\u0440\u0443\u0431", + "SEK": "\u006b\u0072", + "SGD": "\u0024", + "TRY": "\u20ba", + "USD": "\u0024", + "ZAR": "\u0052" +} diff --git a/stylesheets/atom-spotify.less b/stylesheets/atom-bitcoin.less similarity index 57% rename from stylesheets/atom-spotify.less rename to stylesheets/atom-bitcoin.less index 913c526..da7bd32 100644 --- a/stylesheets/atom-spotify.less +++ b/stylesheets/atom-bitcoin.less @@ -4,6 +4,16 @@ // for a full listing of what's available. @import "ui-variables"; -.atom-bitcoin-status { - color: @text-color; +.atom-bitcoin { + .status-stable { + color: @text-color; + } + + .status-rise { + color: @text-color-success; + } + + .status-fall { + color: @text-color-error; + } }