aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2015-11-19 16:45:20 -0800
committerAdam Soltys <[email protected]>2015-11-27 22:02:48 -0800
commitd9373fb974724b2fa5accf42e766cca712d169d2 (patch)
treea090d10873b66e2b10b03777188e8828a73ce9f3
parentb2b8eeaa85c21e5319f903002b73c571d81b54f5 (diff)
downloadcoinos-server-d9373fb974724b2fa5accf42e766cca712d169d2.tar.gz
coinos-server-d9373fb974724b2fa5accf42e766cca712d169d2.zip
Use custom units in wallet
-rw-r--r--public/js/wallet.coffee39
-rw-r--r--views/users/wallet.html4
2 files changed, 29 insertions, 14 deletions
diff --git a/public/js/wallet.coffee b/public/js/wallet.coffee
index 606c1f7d..ec97bace 100644
--- a/public/js/wallet.coffee
+++ b/public/js/wallet.coffee
@@ -32,25 +32,26 @@ $(->
)
$('#currency_toggle').click(->
- if $(this).html() is 'BTC'
- g.amount = $('#amount').val()
- $('#amount').val((g.amount * g.exchange).toFixed(2))
+ if $(this).html() is g.user.unit
+ g.amount = parseFloat($('#amount').val()).toFixed(precision())
+ $('#amount').val((g.amount * g.exchange / multiplier()).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))
+ amount = parseFloat($('#amount').val() * multiplier() / g.exchange).toFixed(precision())
+ if Math.abs(g.amount - amount).toFixed(precision()) > (.000000005 * g.exchange * multiplier()).toFixed(precision())
+ $('#amount').val(amount)
else
- $('#amount').val(parseFloat(g.amount).toFixed(8))
+ $('#amount').val(g.amount)
- $(this).html('BTC')
+ $(this).html(g.user.unit)
)
$('#max').click(->
- if $('#currency_toggle').html() is 'BTC'
+ if $('#currency_toggle').html() is g.user.unit
$('#amount').val(g.balance)
else
- $('#amount').val((g.balance * g.exchange).toFixed(2))
+ g.amount = parseFloat(g.balance).toFixed(precision())
+ $('#amount').val((g.balance / multiplier() * g.exchange).toFixed(2))
)
)
@@ -66,6 +67,8 @@ getUser = ->
g.user = user
$('#pubkey').val(user.pubkey)
$('#address').val(user.address)
+ $('#unit').html(user.unit)
+ $('#currency_toggle').html(user.unit)
$('form').fadeIn()
getExchangeRate()
@@ -130,9 +133,10 @@ getAddresses = ->
calculateBalance = ->
balances = JSON.parse(localStorage.getItem(g.user.username)).balances
balance = balances.reduce (t,s) -> t + s
- g.balance = (balance / 100000000).toFixed(8)
+ g.balance = (balance * multiplier() / 100000000).toFixed(precision())
+ fiat = (g.balance * g.exchange / multiplier()).toFixed(2)
$('#balance').html(g.balance)
- $('#fiat').html("#{(g.balance * g.exchange).toFixed(2)} #{g.user.currency}")
+ $('#fiat').html("#{fiat} #{g.user.currency}")
$('#amount').val(g.balance)
check_address = (address) ->
@@ -148,3 +152,14 @@ isBip32 = (address) ->
return true
catch
return false
+
+multiplier = ->
+ switch g.user.unit
+ when 'BTC' then 1
+ when 'mBTC' then 1000
+ when 'µBTC' then 1000000
+ when 'bits' then 1000000
+ when 'satoshis' then 100000000
+
+precision = ->
+ 9 - multiplier().toString().length
diff --git a/views/users/wallet.html b/views/users/wallet.html
index fac7ac4b..4eb2e633 100644
--- a/views/users/wallet.html
+++ b/views/users/wallet.html
@@ -10,7 +10,7 @@
<div class="form-group">
<label>Available Balance:</label>
- <b id="balance" class="lead">0 BTC</b> /
+ <b id="balance" class="lead">0</b> <b id="unit" class="lead"></b> /
<b id="fiat" class="lead">0</b>
</div>
@@ -27,7 +27,7 @@
<div class="input-group">
<input type="number" id="amount" name="amount" class="form-control" />
<span class="input-group-btn">
- <button id="currency_toggle" type="button" class="btn">BTC</button>
+ <button id="currency_toggle" type="button" class="btn"></button>
</span>
<span class="input-group-btn">
<button id="max" type="button" class="btn">Max</button>