aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--public/js/wallet.coffee30
-rw-r--r--views/users/wallet.html5
2 files changed, 29 insertions, 6 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
diff --git a/views/users/wallet.html b/views/users/wallet.html
index 592aec3b..0ea2d187 100644
--- a/views/users/wallet.html
+++ b/views/users/wallet.html
@@ -10,7 +10,8 @@
<div class="form-group">
<label>Available Balance:</label>
- <b id="balance" class="lead">0</b> BTC
+ <b id="balance" class="lead">0 BTC</b> /
+ <b id="fiat" class="lead">0</b>
</div>
<div>
@@ -26,7 +27,7 @@
<div class="input-group">
<input type="number" id="amount" name="amount" class="form-control" />
<span class="input-group-btn">
- <button type="button" class="btn">BTC</button>
+ <button id="currency_toggle" type="button" class="btn">BTC</button>
</span>
<span class="input-group-btn">
<button type="button" class="btn">Max</button>