diff options
| author | Adam Soltys <[email protected]> | 2015-12-10 18:22:00 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2015-12-11 11:29:30 -0800 |
| commit | 208311023aa6eb433d5e1201eafcd53fab0e6dbd (patch) | |
| tree | d08809266bfa80ae44d9fcd03c5ca80464c84839 /public/js/wallet.coffee | |
| parent | 98260c1821fddcca9417b694e6c16ecfbd2be0db (diff) | |
| download | coinos-server-208311023aa6eb433d5e1201eafcd53fab0e6dbd.tar.gz coinos-server-208311023aa6eb433d5e1201eafcd53fab0e6dbd.zip | |
Form validation with bootstrap-validator
Diffstat (limited to 'public/js/wallet.coffee')
| -rw-r--r-- | public/js/wallet.coffee | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/public/js/wallet.coffee b/public/js/wallet.coffee index b34aaae1..ebe6826a 100644 --- a/public/js/wallet.coffee +++ b/public/js/wallet.coffee @@ -2,8 +2,29 @@ g = exports ? this g.proceed = false g.api = 'https://api.blockcypher.com/v1/btc/main' +validators = + address: (e) -> + try + bitcoin.address.fromBase58Check(e.val()) + catch + return false + + password: (e) -> + g.master = null + try + g.master = bitcoin.HDNode.fromBase58(CryptoJS.AES.decrypt($('#privkey').val(), e.val()).toString(CryptoJS.enc.Utf8)) + $('#invalid_keys').fadeOut() + catch + return false + + +errors = + address: 'Invalid address' + password: 'Wrong password' + $(-> getToken() + $('form').validator(custom: validators, errors: errors) $('button[data-toggle=tooltip]').tooltip(trigger: 'hover') @@ -26,7 +47,7 @@ $(-> name: g.user.username extended_public_key: $('#pubkey').val() subchain_indexes: [0,1] - + $.post("#{g.api}/wallets/hd?token=#{g.token}", JSON.stringify(data)).always(-> $.post("#{g.api}/wallets/hd/#{g.user.username}/addresses/derive?token=#{g.token}").always(-> getBalance() @@ -76,13 +97,6 @@ $(-> ) $('#password').keyup(-> - g.master = null - try - g.master = bitcoin.HDNode.fromBase58(CryptoJS.AES.decrypt($('#privkey').val(), $(this).val()).toString(CryptoJS.enc.Utf8)) - $(this).parent().removeClass('has-error').addClass('has-success') - $('#invalid_keys').fadeOut() - catch - $(this).parent().addClass('has-error').removeClass('has-success') ) $('#new_password').keyup(-> @@ -90,14 +104,14 @@ $(-> try bitcoin.HDNode.fromBase58(CryptoJS.AES.decrypt(g.user.privkey, $(this).val()).toString(CryptoJS.enc.Utf8)) - $(this).parent().removeClass('has-error').addClass('has-success') catch - $(this).parent().addClass('has-error').removeClass('has-success') ) $('#manage').click(-> - $('#keys, #withdrawal').toggle() - $('#withdraw, #manage').toggle() + $('#withdrawal').hide() + $('#keys').show() + $('#withdraw').toggle(g.balance > 0) + $('#manage').hide() $('#privkey').val(g.user.privkey) ) @@ -180,8 +194,13 @@ getBalance = -> $('#balance').html(g.balance) $('#fiat').html("#{fiat} #{g.user.currency}") $('#amount').attr('max', g.balance) - $('#amount').focus() $('.wallet').fadeIn() + + if g.balance > 0 + $('#withdrawal').show() + $('#amount').focus() + else + $('#manage').click() ) sendTransaction = -> |
