From c0b7970ff6b52d5a4245242f4811e2da13ad64e4 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Sun, 1 Mar 2015 15:58:17 -0300 Subject: [PATCH] fix bit client: create, join, status --- bit-wallet/bit-create | 1 - bit-wallet/bit-join | 1 - bit-wallet/bit-status | 24 ++++++++++++------------ bit-wallet/cli-utils.js | 18 ++++++++++++++---- lib/client/api.js | 2 +- test/integration/client.js | 1 + 6 files changed, 28 insertions(+), 19 deletions(-) diff --git a/bit-wallet/bit-create b/bit-wallet/bit-create index 75f2b7b..6fb2bdd 100755 --- a/bit-wallet/bit-create +++ b/bit-wallet/bit-create @@ -8,7 +8,6 @@ program = utils.configureCommander(program); program .option('-t, --testnet', 'Create a Testnet Wallet') - .option('-n, --nopasswd [level]', 'Set access for no password usage: none(default), readonly, readwrite, full', 'none') .usage('[options] [copayerName]') .parse(process.argv); diff --git a/bit-wallet/bit-join b/bit-wallet/bit-join index 6834b08..1429b38 100755 --- a/bit-wallet/bit-join +++ b/bit-wallet/bit-join @@ -7,7 +7,6 @@ program = utils.configureCommander(program); program .usage('[options] [copayerName]') - .option('-n, --nopasswd [level]', 'Set access for no password usage: none(default), readonly, readwrite, full', 'none') .parse(process.argv); var args = program.args; diff --git a/bit-wallet/bit-status b/bit-wallet/bit-status index 43faaa5..37bd1e2 100755 --- a/bit-wallet/bit-status +++ b/bit-wallet/bit-status @@ -9,20 +9,20 @@ program .parse(process.argv); var args = program.args; -var client = utils.getClient(program); +utils.getClient(program, function (client) { + client.getStatus(function(err, res) { + utils.die(err); -client.getStatus(function(err, res) { - utils.die(err); + var x = res.wallet; + console.log('* Wallet %s [%s]: %d-%d %s ', x.name, x.network, x.m, x.n, x.status); - var x = res.wallet; - console.log('* Wallet %s [%s]: %d-%d %s ', x.name, x.network, x.m, x.n, x.status); + if (x.status != 'complete') + console.log(' Missing copayers:', x.n - x.copayers.length); + console.log('* Copayers:', _.pluck(x.copayers,'name').join(', ')); - if (x.status != 'complete') - console.log(' Missing copayers:', x.n - x.copayers.length); - console.log('* Copayers:', _.pluck(x.copayers,'name').join(', ')); + var x = res.balance; + console.log('* Balance %s (Locked: %s)', utils.renderAmount(x.totalAmount), utils.renderAmount(x.lockedAmount)); - var x = res.balance; - console.log('* Balance %s (Locked: %s)', utils.renderAmount(x.totalAmount), utils.renderAmount(x.lockedAmount)); - - utils.renderTxProposals(res.pendingTxps); + utils.renderTxProposals(res.pendingTxps); + }); }); diff --git a/bit-wallet/cli-utils.js b/bit-wallet/cli-utils.js index 44e7b02..4613a19 100644 --- a/bit-wallet/cli-utils.js +++ b/bit-wallet/cli-utils.js @@ -2,6 +2,7 @@ var _ = require('lodash'); var Client = require('../lib/client'); var FileStorage = require('./filestorage'); var read = require('read') +var log = require('npmlog'); var Utils = function() {}; @@ -50,10 +51,19 @@ Utils.getClient = function(args, cb) { }); storage.load(function(err, walletData) { if (err && err.code != 'ENOENT') die(err); - if (walletData) { - client.import(walletData); - } - return cb(client); + if (!walletData) return cb(client); + + client.import(walletData); + client.openWallet(function(err, justCompleted) { + if (client.isComplete() && justCompleted) { + Utils.saveClient(args, client, function() { + log.info('Your wallet has just been completed. Please backup your wallet file or use the export command.'); + return cb(client); + }); + } else { + return cb(client); + } + }); }); }; diff --git a/lib/client/api.js b/lib/client/api.js index 97635a3..9b3b03f 100644 --- a/lib/client/api.js +++ b/lib/client/api.js @@ -329,7 +329,7 @@ API.prototype.joinWallet = function(secret, copayerName, cb) { }; API.prototype.getStatus = function(cb) { - $.checkState(this.credentials && this.credentials.isComplete()); + $.checkState(this.credentials); var self = this; self._doGetRequest('/v1/wallets/', function(err, result) { diff --git a/test/integration/client.js b/test/integration/client.js index 1480c06..a2ad67e 100644 --- a/test/integration/client.js +++ b/test/integration/client.js @@ -324,6 +324,7 @@ describe('client API ', function() { }); }); }); + it.skip('should return wallet status even if wallet is not yet complete', function(done) {}); }); describe('Address Creation', function() {