aboutsummaryrefslogtreecommitdiffstats
path: root/public/js
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 /public/js
parentb2b8eeaa85c21e5319f903002b73c571d81b54f5 (diff)
downloadcoinos-server-d9373fb974724b2fa5accf42e766cca712d169d2.tar.gz
coinos-server-d9373fb974724b2fa5accf42e766cca712d169d2.zip
Use custom units in wallet
Diffstat (limited to 'public/js')
-rw-r--r--public/js/wallet.coffee39
1 files changed, 27 insertions, 12 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