aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2015-11-13 08:19:22 -0800
committerAdam Soltys <[email protected]>2015-11-13 09:00:52 -0800
commit4b7a8754512a6965570482d330865190a6320e9d (patch)
treee98723e8eff234f10e55d581ed41db51f4f740cd
parent1e7eb384be681e69f33c11e8a0ec9b9751b084c0 (diff)
downloadcoinos-server-4b7a8754512a6965570482d330865190a6320e9d.tar.gz
coinos-server-4b7a8754512a6965570482d330865190a6320e9d.zip
Get wallet balance
-rw-r--r--app.js5
-rw-r--r--public/js/wallet.coffee132
-rw-r--r--src/app.coffee4
-rw-r--r--views/users/wallet.html92
4 files changed, 77 insertions, 156 deletions
diff --git a/app.js b/app.js
index 5f381065..cc79d0cc 100644
--- a/app.js
+++ b/app.js
@@ -113,6 +113,11 @@
app.get('/ticker', cache, calculator.ticker);
+ app.get('/token', cache, function(req, res) {
+ res.write(config.blockcypher_token);
+ return res.end();
+ });
+
app.get('/tips', cache, function(req, res) {
return res.render('tips', {
notice: true,
diff --git a/public/js/wallet.coffee b/public/js/wallet.coffee
index 6bf17031..fcbbd062 100644
--- a/public/js/wallet.coffee
+++ b/public/js/wallet.coffee
@@ -22,111 +22,45 @@ g = exports ? this
g.proceed = false
$(->
- $('#encryption-password').pwstrength(showVerdicts: false)
+ api = 'https://api.blockcypher.com/v1/btc/main'
+ addresses = []
+ balance = 0
+ token = ''
+ $('#balance, #amount').hide()
+ $.get("/token", (data) ->
+ token = data
+ $.get("#{api}/wallets/hd/yummy/addresses?token=#{token}", (data) ->
+ for c in data.chains
+ for a in c.chain_addresses
+ addresses.push(a.address)
- user = $('#username').val()
- $.getJSON("/#{user}.json", (data) ->
- $('#pubkey').val(data.pubkey)
- $('#address').val(data.address)
- $('#setup').fadeIn()
- )
-
- $('#pubkey').blur(->
- if check_address($(this).val())
- $(this).parent().removeClass('has-error')
- else
- $(this).parent().addClass('has-error')
- )
-
- $('#generate').click(->
- key = new Key()
- g.pubkey = key.extended_public_key_string()
- g.privkey = key.extended_private_key_string()
-
- $('#modal').modal()
- $('#pubkey_text').html(g.pubkey)
- $('#privkey_text').html(g.privkey)
- $('#qr').html('')
- new QRCode('qr', text: g.privkey, width: 260, height: 260)
- )
-
- $('#encryption-password').keyup((e) ->
- return if e.keyCode is 9 or e.keyCode is 16
- g.enc_privkey = CryptoJS.AES.encrypt(g.privkey, $(this).val()).toString()
- g.enc_privkey = g.privkey if $(this).val() == ''
- $('#privkey_text').html(g.enc_privkey)
- $('#qr').html('')
- new QRCode('qr', text: g.enc_privkey, width: 260, height: 260)
-
- if $(this).val()
- $('#status').html('(Encrypted)')
- else
- $('#status').html('(Unencrypted)')
- )
-
- $('#confirm').blur(->
- $('#confirm_error').remove()
- if $('#password').val() != $('#confirm').val()
- $('#password, #confirm').parent().addClass('has-error')
- $('#confirm').parent().after('<div id="confirm_error" class="alert alert-danger">Passwords don\'t match</div>')
- else
- $('#password, #confirm').parent().removeClass('has-error')
- )
-
- $('#encryption-password, #encryption-confirm').keyup((e) -> check_passwords(e) unless e.keyCode is 9)
- $('#encryption-password, #encryption-confirm').blur((e) -> check_passwords(e))
-
- check_passwords = (e) ->
- if $('#encryption-password').val() != $('#encryption-confirm').val() or $('#encryption-password').val() is ''
- $('#encryption-password, #encryption-confirm').parent().addClass('has-error')
- $('#modal .alert').removeClass('alert-success').addClass('alert-danger')
- else
- $('#encryption-password, #encryption-confirm').parent().removeClass('has-error')
- $('#modal .alert').removeClass('alert-danger').addClass('alert-success')
-
- if $('.progress-bar-success').length > 0
- $('#encryption-password').parent().removeClass('has-error')
- else
- $('#encryption-password').parent().addClass('has-error')
+ chunks = []
+ for i in [0 .. addresses.length] by 10
+ chunks.push(addresses.slice(i,i+10))
- $('#print').click(->
- $('#key-dialog').printElement(printMode: 'popup')
- )
-
- $('a[data-toggle="tab"]').on('shown.bs.tab', (e) ->
- $('#print').toggle(e.target.attributes.href.value == '#step1')
- )
+ doSetTimeout = (c,i) ->
+ setTimeout(->
+ $.get("#{api}/addrs/#{c.join(';')}/balance?token=#{token}", (addresses) ->
+ for address in addresses
+ balance = parseInt(balance) + parseInt(address.final_balance)
+ val = (balance / 100000000).toFixed(8)
- $('#close').click(->
- $('#modal .form-control').blur()
- if $('#modal .has-error').length > 0
- $('#step1_link').click()
- $('#modal .has-error').effect('shake', 500)
- else
- g.update_key = true
- $('#modal').modal('hide')
- )
- $('#encrypt').submit(-> $('#close').click(); return false)
+ $('#balance').html(val)
+ $('#amount').val(val)
+ $('#balance, #amount').fadeIn()
+ )
+ , i*1500)
- $('#modal').on('show.bs.modal', ->
- $('#encryption-password, #encryption-confirm').val('').keyup().parent().removeClass('has-error')
- $('#modal .alert').removeClass('alert-success').addClass('alert-danger')
+ for c, i in chunks
+ doSetTimeout(c, i)
+ )
)
- $('#modal').on('shown.bs.modal', ->
- g.update_key = false
- $('#encryption-password').focus()
- ).on('hidden.bs.modal', ->
- if g.update_key
- $('#pubkey').val(g.pubkey)
- $('#privkey').val(g.enc_privkey)
- )
-
- $('#setup').submit(->
- $('#setup .form-control').blur()
- if $('#setup .has-error').length > 0
- $('#setup .has-error').effect('shake', 500)
- return false
+ user = $('#username').val()
+ $.getJSON("/#{user}.json", (data) ->
+ $('#pubkey').val(data.pubkey)
+ $('#address').val(data.address)
+ $('#setup').fadeIn()
)
)
diff --git a/src/app.coffee b/src/app.coffee
index 554ef303..caab1bcb 100644
--- a/src/app.coffee
+++ b/src/app.coffee
@@ -67,6 +67,10 @@ app.get('/address', cache, calculator.address)
app.get('/register', cache, users.new)
app.get('/sweep', calculator.sweep)
app.get('/ticker', cache, calculator.ticker)
+app.get('/token', cache, (req, res) ->
+ res.write(config.blockcypher_token)
+ res.end()
+)
app.get('/tips', cache, (req, res) ->
res.render('tips',
notice: true,
diff --git a/views/users/wallet.html b/views/users/wallet.html
index c7c91949..873a12d1 100644
--- a/views/users/wallet.html
+++ b/views/users/wallet.html
@@ -9,70 +9,48 @@
<input type="hidden" id="email" name="email" />
<div class="form-group">
- <label for="pubkey">Bitcoin Receiving Address or HD Wallet Pubkey:</label>
- <div class="input-group">
- <input type="text" id="pubkey" name="pubkey" class="form-control" placeholder="xpub..." />
- <input type="hidden" id="privkey" name="privkey" />
- <span class="input-group-btn">
- <button id="generate" type="button" class="btn">New</button>
- </span>
- </div>
+ <label>Available Balance:</label>
+ <b id="balance" class="lead">0.05154234</b> BTC
</div>
- <input class="btn btn-primary" type="submit" value="Done" />
-</form>
-
-<div class="modal fade" id="modal" tabindex="-1" role="dialog">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
- <h4 class="modal-title">New HD Wallet</h4>
- </div>
-
- <div class="modal-body">
- <ul class="nav nav-tabs" role="tablist">
- <li class="active"><a id="step1_link" href="#step1" role="tab" data-toggle="tab">Wallet Keys</a></li>
- <li><a href="#step2" role="tab" data-toggle="tab">What's this?</a></li>
- </ul>
- <div class="tab-content">
- <div id="step1" class="tab-pane active">
- <form id="encrypt">
- <div class="form-group">
- <label for="encryption-password">Encryption Passphrase <small>(16+ characters)</small>:</label>
- <input type="password" id="encryption-password" name="encryption-password" class="form-control" />
- </div>
-
- <div class="form-group">
- <label for="encryption-confirm">Confirm Passphrase:</label>
- <input type="password" id="encryption-confirm" name="encryption-confirm" class="form-control" />
- </div>
+ <div>
+ <ul class="nav nav-tabs" role="tablist">
+ <li role="presentation" class="active"><a href="#withdraw" aria-controls="withdraw" role="tab" data-toggle="tab">Withdraw</a></li>
+ <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Manage Keys</a></li>
+ </ul>
- <input type="submit" style="position: absolute; left: -9999px" />
- </form>
-
- <div id="key-dialog" class="alert alert-danger">
- Master Public Key
- <pre id="pubkey_text"></pre>
- Master Private Key <span id="status">(Unencrypted)</span>
- <pre id="privkey_text"></pre>
- <div id="qr"></div>
- </div>
+ <div class="tab-content">
+ <div role="tabpanel" class="tab-pane active" id="withdraw">
+ <div class="form-group">
+ <label for="amount">Amount:</label>
+ <div class="input-group">
+ <input type="number" id="amount" name="amount" class="form-control" value="0.05154232" />
+ <span class="input-group-btn">
+ <button type="button" class="btn">BTC</button>
+ </span>
+ <span class="input-group-btn">
+ <button type="button" class="btn">Max</button>
+ </span>
</div>
- <div id="step2" class="tab-pane">
- <p>An <abbr title="Hierarchical Deterministic Wallet">HD Wallet</abbr> is a master key that can be used to derive several Bitcoin addresses. CoinOS will use the master key that's generated here to derive a new address for every payment to your account so that people can't link separate payments together and invade your customers' privacy.</p>
- <p>The master <b>pubkey</b> is what's used to derive the addresses and the master <b>private</b> key is what's needed to authorize payments out from the wallet. CoinOS will get you to encrypt the private key with a strong passphrase before it's stored on our server so that no one but you can access your funds. The password could be a different password from the one you use to login to your account, or it could be the same, but what's important is that you remember it. You'll need to enter the password whenever you make a transaction out of the wallet.</p>
- <p class="text-danger"><b>IMPORTANT: We cannot recover or reset your password. If you lose it or forget it, any funds sent to your account will be lost forever, so make it memorable or write it down.</b></p>
+ </div>
- <img src="/assets/img/forever.gif" width="370px" />
+ <div class="form-group">
+ <label for="amount">Recipient:</label>
+ <div class="input-group">
+ <input type="text" id="recipient" name="recipient" class="form-control" />
+ <span class="input-group-btn">
+ <button type="button" class="btn"><span class="glyphicon glyphicon-camera"></span></button>
+ </span>
</div>
-
- </div>
+ </div>
</div>
- <div class="modal-footer">
- <button type="button" id="print" class="btn btn-primary"><span class="glyphicon glyphicon-print"></span> Print</button>
- <button type="button" id="close" class="btn btn-primary">Got it!</button>
+ <div role="tabpanel" class="tab-pane" id="settings">
+ <div class="form-group">
+ <label for="pubkey">Bitcoin Receiving Address or HD Wallet Pubkey:</label>
+ <input type="text" id="pubkey" name="pubkey" class="form-control" placeholder="xpub..." />
+ <input type="hidden" id="privkey" name="privkey" />
+ </div>
</div>
</div>
</div>
-</div>
+</form>