aboutsummaryrefslogtreecommitdiffstats
path: root/public
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2015-11-18 17:15:19 -0800
committerAdam Soltys <[email protected]>2015-11-27 22:02:48 -0800
commitc98e4b8f8b4b646ec3f92618f9f74fd35cabbde1 (patch)
treef704836a65436086b2bf9353507639759639a12d /public
parent1292c860716b353dbb9441422b09a60226370d67 (diff)
downloadcoinos-server-c98e4b8f8b4b646ec3f92618f9f74fd35cabbde1.tar.gz
coinos-server-c98e4b8f8b4b646ec3f92618f9f74fd35cabbde1.zip
Currency toggle
Diffstat (limited to 'public')
-rw-r--r--public/js/wallet.coffee30
1 files changed, 26 insertions, 4 deletions
diff --git a/public/js/wallet.coffee b/public/js/wallet.coffee
index c2cc5041..7399973d 100644
--- a/public/js/wallet.coffee
+++ b/public/js/wallet.coffee
@@ -30,8 +30,24 @@ $(->
$('.has-error').effect('shake', 500)
return false
)
+
+ $('#currency_toggle').click(->
+ if $(this).html() is 'BTC'
+ g.amount = $('#amount').val()
+ $('#amount').val((g.amount * g.exchange).toFixed(2))
+ $(this).html(g.user.currency)
+ else
+ amount = $('#amount').val() / g.exchange
+ if Math.abs(g.amount - amount) > 0.00001
+ $('#amount').val(parseFloat(amount).toFixed(8))
+ else
+ $('#amount').val(parseFloat(g.amount).toFixed(8))
+
+ $(this).html('BTC')
+ )
)
+
getToken = ->
$.get("/token", (token) ->
g.token = token
@@ -45,9 +61,14 @@ getUser = ->
$('#address').val(user.address)
$('form').fadeIn()
- createWallet()
+ getExchangeRate()
)
+getExchangeRate = ->
+ $.get("/ticker?currency=#{g.user.currency}&symbol=#{g.user.symbol}&type=bid", (exchange) ->
+ g.exchange = exchange
+ createWallet()
+ )
createWallet = ->
if localStorage.getItem(g.user.username) is null
@@ -102,9 +123,10 @@ getAddresses = ->
calculateBalance = ->
balances = JSON.parse(localStorage.getItem(g.user.username)).balances
balance = balances.reduce (t,s) -> t + s
- val = (balance / 100000000).toFixed(8)
- $('#balance').html(val)
- $('#amount').val(val)
+ g.balance = (balance / 100000000).toFixed(8)
+ $('#balance').html(g.balance)
+ $('#fiat').html("#{(g.balance * g.exchange).toFixed(2)} #{g.user.currency}")
+ $('#amount').val(g.balance)
check_address = (address) ->
try