mirror of https://github.com/BTCPrivate/copay.git
commit
1dc420b215
48
index.html
48
index.html
|
@ -705,10 +705,58 @@
|
|||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="medium-8 medium-centered large-8 large-centered columns">
|
||||
<hr>
|
||||
<h3>Address Book</h3>
|
||||
<p class="text-gray" ng-hide="showAddressBook()">Empry. Create some alias for addresses</p>
|
||||
<table ng-show="showAddressBook()">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Label</td>
|
||||
<th>Address</td>
|
||||
<th>Creator</td>
|
||||
<th>Date</td>
|
||||
<th> </td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="(addr, info) in $root.wallet.addressBook" ng-if="info.copayerId != -1">
|
||||
<td><a ng-click="copyAddress(addr)" title="Copy address">{{info.label}}</a></td>
|
||||
<td>{{addr}}</td>
|
||||
<td>{{$root.wallet.publicKeyRing.nicknameForCopayer(info.copayerId)}}</td>
|
||||
<td><time>{{info.createdTs | amCalendar}}</time></td>
|
||||
<td><a ng-click="deleteAddressBook(addr)"><i class="fi-trash"></i></a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<button class="m10t button tiny secondary radius text-center" ng-click="openAddressBookModal()">Add New Entry</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/ng-template" id="addressBookModal.html">
|
||||
<h3>Add Address Book Entry</h3>
|
||||
<form name="addressBookForm" ng-submit="submitAddressBook(addressBookForm)" novalidate>
|
||||
<label for="newaddress">Address
|
||||
<small ng-hide="!addressBookForm.newaddress.$pristine || newaddress">required</small>
|
||||
<small class="is-valid" ng-show="!addressBookForm.newaddress.$invalid && newaddress">Valid</small>
|
||||
<small class="has-error" ng-show="addressBookForm.newaddress.$invalid && newaddress">
|
||||
Not valid</small>
|
||||
<input type="text" id="newaddress" name="newaddress" ng-disabled="loading"
|
||||
placeholder="Address" ng-model="newaddress" valid-address required>
|
||||
</label>
|
||||
<label for="newlabel">Label
|
||||
<small ng-hide="!addressBookForm.newlabel.$pristine || newlabel">required</small>
|
||||
<input type="text" id="newlabel" name="newlabel" ng-disabled="loading"
|
||||
placeholder="Label" ng-model="newlabel" required>
|
||||
</label>
|
||||
<a class="button small default radius" ng-click="cancel()">Cancel</a>
|
||||
<input type="submit" class="button small secondary radius right" ng-disabled="addressBookForm.$invalid || loading" value="Add Address">
|
||||
</form>
|
||||
<a class="close-reveal-modal" ng-click="cancel()">×</a>
|
||||
</script>
|
||||
|
||||
<!-- BACKUP -->
|
||||
<script type="text/ng-template" id="backup.html">
|
||||
<div class="backup" ng-controller="BackupController">
|
||||
|
|
|
@ -2,13 +2,27 @@
|
|||
var bitcore = require('bitcore');
|
||||
|
||||
angular.module('copayApp.controllers').controller('SendController',
|
||||
function($scope, $rootScope, $window, $location, $timeout) {
|
||||
function($scope, $rootScope, $window, $location, $timeout, $anchorScroll, $modal) {
|
||||
$scope.title = 'Send';
|
||||
$scope.loading = false;
|
||||
var satToUnit = 1 / config.unitToSatoshi;
|
||||
$scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit;
|
||||
$scope.unitToBtc = config.unitToSatoshi / bitcore.util.COIN;
|
||||
|
||||
$scope.showAddressBook = function() {
|
||||
var w = $rootScope.wallet;
|
||||
var flag;
|
||||
if (w) {
|
||||
for (var k in w.addressBook) {
|
||||
if (w.addressBook[k].copayerId != -1) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
};
|
||||
|
||||
// TODO this shouldnt be on a particular controller.
|
||||
// Detect mobile devices
|
||||
var isMobile = {
|
||||
|
@ -187,4 +201,80 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
}
|
||||
}, 500);
|
||||
};
|
||||
|
||||
$scope.deleteAddressBook = function(addressBook) {
|
||||
var w = $rootScope.wallet;
|
||||
$timeout(function() {
|
||||
var errorMsg;
|
||||
try {
|
||||
w.deleteAddressBook(addressBook);
|
||||
} catch (e) {
|
||||
errorMsg = e.message;
|
||||
}
|
||||
|
||||
$rootScope.$flashMessage = {
|
||||
message: errorMsg ? errorMsg : 'Entry removed successful',
|
||||
type: errorMsg ? 'error' : 'success'
|
||||
};
|
||||
$rootScope.$digest();
|
||||
}, 500);
|
||||
};
|
||||
|
||||
$scope.copyAddress = function(address) {
|
||||
$scope.address = address;
|
||||
$anchorScroll();
|
||||
};
|
||||
|
||||
$scope.openAddressBookModal = function() {
|
||||
var modalInstance = $modal.open({
|
||||
templateUrl: 'addressBookModal.html',
|
||||
windowClass: 'tiny',
|
||||
controller: function($scope, $modalInstance) {
|
||||
|
||||
$scope.submitAddressBook = function(form) {
|
||||
if (form.$invalid) {
|
||||
$rootScope.$flashMessage = {
|
||||
message: 'Complete required fields, please',
|
||||
type: 'error'
|
||||
};
|
||||
return;
|
||||
}
|
||||
var entry = {
|
||||
"address": form.newaddress.$modelValue,
|
||||
"label": form.newlabel.$modelValue
|
||||
};
|
||||
form.newaddress.$pristine = form.newlabel.$pristine = true;
|
||||
$modalInstance.close(entry);
|
||||
};
|
||||
|
||||
$scope.cancel = function() {
|
||||
$modalInstance.dismiss('cancel');
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
modalInstance.result.then(function(entry) {
|
||||
var w = $rootScope.wallet;
|
||||
|
||||
$timeout(function() {
|
||||
$scope.loading = false;
|
||||
var errorMsg;
|
||||
try {
|
||||
w.setAddressBook(entry.address, entry.label);
|
||||
} catch (e) {
|
||||
errorMsg = e.message;
|
||||
}
|
||||
|
||||
$rootScope.$flashMessage = {
|
||||
message: errorMsg ? errorMsg : 'New entry has been created',
|
||||
type: errorMsg ? 'error' : 'success'
|
||||
};
|
||||
$rootScope.$digest();
|
||||
}, 500);
|
||||
$anchorScroll();
|
||||
// reset fields
|
||||
$scope.newaddress = $scope.newlabel = null;
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
@ -51,6 +51,7 @@ function Wallet(opts) {
|
|||
this.txProposals.walletId = this.id;
|
||||
this.network.maxPeers = this.totalCopayers;
|
||||
this.registeredPeerIds = [];
|
||||
this.addressBook = opts.addressBook || {};
|
||||
}
|
||||
|
||||
Wallet.parent = EventEmitter;
|
||||
|
@ -133,6 +134,28 @@ Wallet.prototype._handleTxProposal = function(senderId, data) {
|
|||
}
|
||||
};
|
||||
|
||||
Wallet.prototype._handleAddressBook = function(senderId, data, isInbound) {
|
||||
this.log('RECV ADDRESSBOOK:', data);
|
||||
var rcv = data.addressBook;
|
||||
var hasChange;
|
||||
for(var key in rcv) {
|
||||
if (!this.addressBook[key]) {
|
||||
this.addressBook[key] = rcv[key];
|
||||
hasChange = true;
|
||||
}
|
||||
else {
|
||||
if (rcv[key].createdTs > this.addressBook[key].createdTs) {
|
||||
this.addressBook[key] = rcv[key];
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasChange) {
|
||||
this.emit('addressBookUpdated');
|
||||
this.store();
|
||||
}
|
||||
};
|
||||
|
||||
Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
||||
|
||||
// TODO check message signature
|
||||
|
@ -149,6 +172,7 @@ Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
|||
break;
|
||||
case 'walletReady':
|
||||
this.sendPublicKeyRing(senderId);
|
||||
this.sendAddressBook(senderId);
|
||||
this.sendAllTxProposals(senderId); // send old txps
|
||||
break;
|
||||
case 'publicKeyRing':
|
||||
|
@ -160,6 +184,9 @@ Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
|||
case 'indexes':
|
||||
this._handleIndexes(senderId, data, isInbound);
|
||||
break;
|
||||
case 'addressbook':
|
||||
this._handleAddressBook(senderId, data, isInbound);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -325,7 +352,8 @@ Wallet.prototype.toObj = function() {
|
|||
opts: optsObj,
|
||||
publicKeyRing: this.publicKeyRing.toObj(),
|
||||
txProposals: this.txProposals.toObj(),
|
||||
privateKey: this.privateKey ? this.privateKey.toObj() : undefined
|
||||
privateKey: this.privateKey ? this.privateKey.toObj() : undefined,
|
||||
addressBook: this.addressBook
|
||||
};
|
||||
|
||||
return walletObj;
|
||||
|
@ -333,6 +361,7 @@ Wallet.prototype.toObj = function() {
|
|||
|
||||
Wallet.fromObj = function(o, storage, network, blockchain) {
|
||||
var opts = JSON.parse(JSON.stringify(o.opts));
|
||||
opts.addressBook = o.addressBook;
|
||||
opts.publicKeyRing = PublicKeyRing.fromObj(o.publicKeyRing);
|
||||
opts.txProposals = TxProposals.fromObj(o.txProposals);
|
||||
opts.privateKey = PrivateKey.fromObj(o.privateKey);
|
||||
|
@ -412,6 +441,15 @@ Wallet.prototype.sendIndexes = function(recipients) {
|
|||
});
|
||||
};
|
||||
|
||||
Wallet.prototype.sendAddressBook = function(recipients) {
|
||||
this.log('### SENDING addressBook TO:', recipients || 'All', this.addressBook);
|
||||
this.network.send(recipients, {
|
||||
type: 'addressbook',
|
||||
addressBook: this.addressBook,
|
||||
walletId: this.id,
|
||||
});
|
||||
};
|
||||
|
||||
Wallet.prototype.getName = function() {
|
||||
return this.name || this.id;
|
||||
};
|
||||
|
@ -779,4 +817,31 @@ Wallet.prototype.getNetwork = function() {
|
|||
return this.network;
|
||||
};
|
||||
|
||||
Wallet.prototype._checkAddressBook = function(key) {
|
||||
if (this.addressBook[key] && this.addressBook[key].copayerId != -1) {
|
||||
throw new Error('This address already exists in your Address Book: ' + address);
|
||||
}
|
||||
};
|
||||
|
||||
Wallet.prototype.setAddressBook = function(key, label) {
|
||||
this._checkAddressBook(key);
|
||||
var addressbook = {
|
||||
createdTs: Date.now(),
|
||||
copayerId: this.getMyCopayerId(),
|
||||
label: label
|
||||
};
|
||||
this.addressBook[key] = addressbook;
|
||||
this.sendAddressBook();
|
||||
this.store();
|
||||
};
|
||||
|
||||
Wallet.prototype.deleteAddressBook = function(key) {
|
||||
if (key) {
|
||||
this.addressBook[key].copayerId = -1;
|
||||
this.addressBook[key].createdTs = Date.now();
|
||||
this.sendAddressBook();
|
||||
this.store();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = require('soop')(Wallet);
|
||||
|
|
|
@ -96,6 +96,7 @@ WalletFactory.prototype.read = function(walletId) {
|
|||
obj.publicKeyRing = s.get(walletId, 'publicKeyRing');
|
||||
obj.txProposals = s.get(walletId, 'txProposals');
|
||||
obj.privateKey = s.get(walletId, 'privateKey');
|
||||
obj.addressBook = s.get(walletId, 'addressBook');
|
||||
|
||||
var w = this.fromObj(obj);
|
||||
return w;
|
||||
|
|
|
@ -134,6 +134,11 @@ angular.module('copayApp.services')
|
|||
break;
|
||||
}
|
||||
});
|
||||
w.on('addressBookUpdated', function(dontDigest) {
|
||||
if (!dontDigest) {
|
||||
$rootScope.$digest();
|
||||
}
|
||||
});
|
||||
w.on('connectionError', function(msg) {
|
||||
root.onErrorDigest(null, msg);
|
||||
});
|
||||
|
|
|
@ -6,6 +6,13 @@ var FakeWallet = function() {
|
|||
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000
|
||||
};
|
||||
this.name = 'myTESTwullet';
|
||||
this.addressBook = {
|
||||
'2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ' : {
|
||||
label: 'John',
|
||||
copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03',
|
||||
createdTs: 1403102115,
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr) {
|
||||
|
|
|
@ -67,6 +67,19 @@ describe('Wallet model', function() {
|
|||
c.network = new Network(config.network);
|
||||
c.blockchain = new Blockchain(config.blockchain);
|
||||
|
||||
c.addressBook = {
|
||||
'2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ' : {
|
||||
label: 'John',
|
||||
copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03',
|
||||
createdTs: 1403102115,
|
||||
},
|
||||
'2MtP8WyiwG7ZdVWM96CVsk2M1N8zyfiVQsY' : {
|
||||
label: 'Jennifer',
|
||||
copayerId: '032991f836543a492bd6d0bb112552bfc7c5f3b7d5388fcbcbf2fbb893b44770d7',
|
||||
createdTs: 1403103115,
|
||||
}
|
||||
};
|
||||
|
||||
c.networkName = config.networkName;
|
||||
c.verbose = config.verbose;
|
||||
c.version = '0.0.1';
|
||||
|
@ -85,6 +98,7 @@ describe('Wallet model', function() {
|
|||
should.exist(w.privateKey);
|
||||
should.exist(w.txProposals);
|
||||
should.exist(w.netKey);
|
||||
should.exist(w.addressBook);
|
||||
var b = new bitcore.Buffer(w.netKey, 'base64');
|
||||
b.toString('hex').length.should.equal(16);
|
||||
});
|
||||
|
@ -686,4 +700,64 @@ describe('Wallet model', function() {
|
|||
done();
|
||||
});
|
||||
|
||||
var contacts = [
|
||||
{
|
||||
label: 'Charles',
|
||||
address: '2N8pJWpXCAxmNLHKVEhz3TtTcYCtHd43xWU ',
|
||||
},
|
||||
{
|
||||
label: 'Linda',
|
||||
address: '2N4Zq92goYGrf5J4F4SZZq7jnPYbCiyRYT2 ',
|
||||
}
|
||||
];
|
||||
|
||||
it('should create new entry for address book', function() {
|
||||
var w = createW();
|
||||
contacts.forEach(function(c) {
|
||||
w.setAddressBook(c.address, c.label);
|
||||
});
|
||||
Object.keys(w.addressBook).length.should.equal(4);
|
||||
});
|
||||
|
||||
it('should fail if create a duplicate address', function() {
|
||||
var w = createW();
|
||||
w.setAddressBook(contacts[0].address, contacts[0].label);
|
||||
(function() {
|
||||
w.setAddressBook(contacts[0].address, contacts[0].label);
|
||||
}).should.
|
||||
throw();
|
||||
});
|
||||
|
||||
it('should delete an entry for address book', function() {
|
||||
var w = createW();
|
||||
contacts.forEach(function(c) {
|
||||
w.setAddressBook(c.address, c.label);
|
||||
});
|
||||
Object.keys(w.addressBook).length.should.equal(4);
|
||||
var key = contacts[0].address;
|
||||
w.deleteAddressBook(key);
|
||||
w.addressBook[key].copayerId.should.equal(-1);
|
||||
});
|
||||
|
||||
it('handle network addressBook correctly', function() {
|
||||
var w = createW();
|
||||
var data = {
|
||||
walletId: w.id,
|
||||
addressBook: {
|
||||
'msj42CCGruhRsFrGATiUuh25dtxYtnpbTx' : {
|
||||
label: 'Faucet',
|
||||
copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03',
|
||||
createdTs: 1403102115,
|
||||
}
|
||||
},
|
||||
type: 'addressbook'
|
||||
};
|
||||
Object.keys(w.addressBook).length.should.equal(2);
|
||||
w._handleAddressBook('senderID', data, true);
|
||||
Object.keys(w.addressBook).length.should.equal(3);
|
||||
data.addressBook['msj42CCGruhRsFrGATiUuh25dtxYtnpbTx'].createdTs = 1403102215;
|
||||
w._handleAddressBook('senderID', data, true);
|
||||
Object.keys(w.addressBook).length.should.equal(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -80,7 +80,7 @@ describe('WalletFactory model', function() {
|
|||
});
|
||||
|
||||
it('#fromObj #toObj round trip', function() {
|
||||
var o = '{"opts":{"id":"dbfe10c3fae71cea","spendUnconfirmed":1,"requiredCopayers":3,"totalCopayers":5,"netKey":"LppzFYqlgT0=","version":"0.0.5"},"publicKeyRing":{"walletId":"dbfe10c3fae71cea","networkName":"testnet","requiredCopayers":3,"totalCopayers":5,"indexes":{"changeIndex":0,"receiveIndex":0},"copayersExtPubKeys":["tpubD6NzVbkrYhZ4YGK8ZhZ8WVeBXNAAoTYjjpw9twCPiNGrGQYFktP3iVQkKmZNiFnUcAFMJRxJVJF6Nq9MDv2kiRceExJaHFbxUCGUiRhmy97","tpubD6NzVbkrYhZ4YKGDJkzWdQsQV3AcFemaQKiwNhV4RL8FHnBFvinidGdQtP8RKj3h34E65RkdtxjrggZYqsEwJ8RhhN2zz9VrjLnrnwbXYNc","tpubD6NzVbkrYhZ4YkDiewjb32Pp3Sz9WK2jpp37KnL7RCrHAyPpnLfgdfRnTdpn6DTWmPS7niywfgWiT42aJb1J6CjWVNmkgsMCxuw7j9DaGKB","tpubD6NzVbkrYhZ4XEtUAz4UUTWbprewbLTaMhR8NUvSJUEAh4Sidxr6rRPFdqqVRR73btKf13wUjds2i8vVCNo8sbKrAnyoTr3o5Y6QSbboQjk","tpubD6NzVbkrYhZ4Yj9AAt6xUVuGPVd8jXCrEE6V2wp7U3PFh8jYYvVad31b4VUXEYXzSnkco4fktu8r4icBsB2t3pCR3WnhVLedY2hxGcPFLKD"],"nicknameFor":{},"publicKeysCache":{"m/0/1/0":["0314368b8efa07e8c7dad30498d0a7e3aa575db1fef833347c6d381c1a33a17b17","02cfd95f89ab46bd3bd86954dd9f83dbab0cd2e4466dee587e8e4d8d733fc0d748","02568969eb6212fe946450be6c5b3353fc754a40b2cdc4aed501a8976fec371da8","0360f870a088ae0ef1c37035a9b6a462ca8dcdd5da275f4e2dcd19f44b81d3e7e4","0300ad8f1bded838b02e127bb25961fbcee718db2df81f680f889692acdcbdd73d"],"m/0/1/1":["024f97a9adb2fa9306c4e3d9244f5e5355c7e2c6b3dd4122ba804e17dc9729df5d","0214834a5adcbc4ad0f3bbbc1c280b8ac480387fcc9a1fd988c1526ed496d923c4","024e72338bd5e976375d076bd71a9649e9141b4cbfc9e16cb7109b354b3e913a05","0322045ea35c3118aa7ab9f2c9f182b0120956b0aa65cc72b9d093f145327a4b17","030dc2450c72df366c1960739c577a2efd4451070bd78effcb6f71d1bcd7dfc7a8"],"m/0/1/2":["0247de59deb66783b8f9b0c326234a9569d00866c2a73f599e77a4d0cab5cbce8f","0376e49f0ac3647404034aae0dc8dd927c34a634ef24ea36f56a272f75fce9539b","032fbaa2593bd1eea4a46e7ac15f15802cdd1eb65a7d5bc4364ddd9d52f0838234","03a81f2a7e1f7191aa0b0c6e0a4ccefc71edd3564e86014972fe338045f68d5a5a","02eb8a012ea9a709392502cacda6ef5115d6d2319ab470d546d9068ab941621a99"],"m/0/0/0":["036dcbd378b4352120d6b720b6294dd2d0dd02801fcf010bb69dadbec1f3999279","022089eedb85dc45d1efa418e1ea226588deedebc1d85acca15ff72783e33636c0","0388aa5fd432b74c56427396f350d236c3ca8f7b2f62da513ce4c2e6ff04a67e9c","02fc4caa7449db7483d2e1fccdacac6fa2f736278c758af9966402589b5632f13e","02e4a15b885d8b2d586f82fa85d16179644e60a154674bde0ec3004810b1bdab99"],"m/0/0/1":["039afa26b2f341c76c7b3c3d0672438f35ac6ebb67b1ddfefac9cd79b7b24418c1","021acaaf500d431ebc396f50630767b01c91ce98ae48e968775ceaad932b7e3b8e","022a947259c4a9f76d5e95c0849df31d01233df41d0d75d631b89317a48d8cddce","03d38d9f94217da780303d9a8987c86d737ef39683febc0cd6632cddbfa62186fd","0394d2581b307fe2af19721888d922aab58ab198ef88cedf9506177e30d807811e"],"m/0/0/2":["037825ffce15d34f9bd6c02bcda7701826706471a4d6ab5004eb965f98811c2098","023768dd6d3c71b7df5733ccda5b2d8b454d5b4c4179d91a6fda74db8b869a2406","021a79e91f003f308764d43039e9b5d56bc8f33ca2f4d30ec6cc5a37c0d09dc273","02437f1e388b273936319f79a5d22958ef5ebff9c8cd7b6f6f72518445b1e30867","0373b0881cb4fd02baa62589023fdfe9739c6148cf104d907549f2528eb80146f5"]}},"txProposals":{"txps":[],"walletId":"dbfe10c3fae71cea","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPeoHLg3tY75z4xLeEe8MqAXLNcRA6J6UTRvHV8VZTXznt9eoTmSk1fwSrwZtMhY3XkNsceJ14h6sCXHSWinRqMSSbY8tfhHi","networkName":"testnet","privateKeyCache":{}}}';
|
||||
var o = '{"opts":{"id":"dbfe10c3fae71cea","spendUnconfirmed":1,"requiredCopayers":3,"totalCopayers":5,"netKey":"LppzFYqlgT0=","version":"0.0.5"},"publicKeyRing":{"walletId":"dbfe10c3fae71cea","networkName":"testnet","requiredCopayers":3,"totalCopayers":5,"indexes":{"changeIndex":0,"receiveIndex":0},"copayersExtPubKeys":["tpubD6NzVbkrYhZ4YGK8ZhZ8WVeBXNAAoTYjjpw9twCPiNGrGQYFktP3iVQkKmZNiFnUcAFMJRxJVJF6Nq9MDv2kiRceExJaHFbxUCGUiRhmy97","tpubD6NzVbkrYhZ4YKGDJkzWdQsQV3AcFemaQKiwNhV4RL8FHnBFvinidGdQtP8RKj3h34E65RkdtxjrggZYqsEwJ8RhhN2zz9VrjLnrnwbXYNc","tpubD6NzVbkrYhZ4YkDiewjb32Pp3Sz9WK2jpp37KnL7RCrHAyPpnLfgdfRnTdpn6DTWmPS7niywfgWiT42aJb1J6CjWVNmkgsMCxuw7j9DaGKB","tpubD6NzVbkrYhZ4XEtUAz4UUTWbprewbLTaMhR8NUvSJUEAh4Sidxr6rRPFdqqVRR73btKf13wUjds2i8vVCNo8sbKrAnyoTr3o5Y6QSbboQjk","tpubD6NzVbkrYhZ4Yj9AAt6xUVuGPVd8jXCrEE6V2wp7U3PFh8jYYvVad31b4VUXEYXzSnkco4fktu8r4icBsB2t3pCR3WnhVLedY2hxGcPFLKD"],"nicknameFor":{},"publicKeysCache":{"m/0/1/0":["0314368b8efa07e8c7dad30498d0a7e3aa575db1fef833347c6d381c1a33a17b17","02cfd95f89ab46bd3bd86954dd9f83dbab0cd2e4466dee587e8e4d8d733fc0d748","02568969eb6212fe946450be6c5b3353fc754a40b2cdc4aed501a8976fec371da8","0360f870a088ae0ef1c37035a9b6a462ca8dcdd5da275f4e2dcd19f44b81d3e7e4","0300ad8f1bded838b02e127bb25961fbcee718db2df81f680f889692acdcbdd73d"],"m/0/1/1":["024f97a9adb2fa9306c4e3d9244f5e5355c7e2c6b3dd4122ba804e17dc9729df5d","0214834a5adcbc4ad0f3bbbc1c280b8ac480387fcc9a1fd988c1526ed496d923c4","024e72338bd5e976375d076bd71a9649e9141b4cbfc9e16cb7109b354b3e913a05","0322045ea35c3118aa7ab9f2c9f182b0120956b0aa65cc72b9d093f145327a4b17","030dc2450c72df366c1960739c577a2efd4451070bd78effcb6f71d1bcd7dfc7a8"],"m/0/1/2":["0247de59deb66783b8f9b0c326234a9569d00866c2a73f599e77a4d0cab5cbce8f","0376e49f0ac3647404034aae0dc8dd927c34a634ef24ea36f56a272f75fce9539b","032fbaa2593bd1eea4a46e7ac15f15802cdd1eb65a7d5bc4364ddd9d52f0838234","03a81f2a7e1f7191aa0b0c6e0a4ccefc71edd3564e86014972fe338045f68d5a5a","02eb8a012ea9a709392502cacda6ef5115d6d2319ab470d546d9068ab941621a99"],"m/0/0/0":["036dcbd378b4352120d6b720b6294dd2d0dd02801fcf010bb69dadbec1f3999279","022089eedb85dc45d1efa418e1ea226588deedebc1d85acca15ff72783e33636c0","0388aa5fd432b74c56427396f350d236c3ca8f7b2f62da513ce4c2e6ff04a67e9c","02fc4caa7449db7483d2e1fccdacac6fa2f736278c758af9966402589b5632f13e","02e4a15b885d8b2d586f82fa85d16179644e60a154674bde0ec3004810b1bdab99"],"m/0/0/1":["039afa26b2f341c76c7b3c3d0672438f35ac6ebb67b1ddfefac9cd79b7b24418c1","021acaaf500d431ebc396f50630767b01c91ce98ae48e968775ceaad932b7e3b8e","022a947259c4a9f76d5e95c0849df31d01233df41d0d75d631b89317a48d8cddce","03d38d9f94217da780303d9a8987c86d737ef39683febc0cd6632cddbfa62186fd","0394d2581b307fe2af19721888d922aab58ab198ef88cedf9506177e30d807811e"],"m/0/0/2":["037825ffce15d34f9bd6c02bcda7701826706471a4d6ab5004eb965f98811c2098","023768dd6d3c71b7df5733ccda5b2d8b454d5b4c4179d91a6fda74db8b869a2406","021a79e91f003f308764d43039e9b5d56bc8f33ca2f4d30ec6cc5a37c0d09dc273","02437f1e388b273936319f79a5d22958ef5ebff9c8cd7b6f6f72518445b1e30867","0373b0881cb4fd02baa62589023fdfe9739c6148cf104d907549f2528eb80146f5"]}},"txProposals":{"txps":[],"walletId":"dbfe10c3fae71cea","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPeoHLg3tY75z4xLeEe8MqAXLNcRA6J6UTRvHV8VZTXznt9eoTmSk1fwSrwZtMhY3XkNsceJ14h6sCXHSWinRqMSSbY8tfhHi","networkName":"testnet","privateKeyCache":{}},"addressBook":{}}';
|
||||
|
||||
var wf = new WalletFactory(config, '0.0.5');
|
||||
var w = wf.fromObj(JSON.parse(o));
|
||||
|
|
|
@ -21,11 +21,9 @@ describe("Unit: Controllers", function() {
|
|||
totalCopayers: 5,
|
||||
spendUnconfirmed: 1,
|
||||
reconnectDelay: 100,
|
||||
networkName: 'testnet',
|
||||
networkName: 'testnet'
|
||||
};
|
||||
|
||||
|
||||
|
||||
describe('Backup Controller', function() {
|
||||
var ctrl;
|
||||
beforeEach(inject(function($controller, $rootScope) {
|
||||
|
@ -79,7 +77,7 @@ describe("Unit: Controllers", function() {
|
|||
});
|
||||
|
||||
describe('Transactions Controller', function() {
|
||||
var transactionCtrl;
|
||||
var transactionsCtrl;
|
||||
beforeEach(inject(function($controller, $rootScope) {
|
||||
scope = $rootScope.$new();
|
||||
transactionsCtrl = $controller('TransactionsController', {
|
||||
|
@ -97,6 +95,61 @@ describe("Unit: Controllers", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Send Controller', function() {
|
||||
var scope, form;
|
||||
beforeEach(angular.mock.module('copayApp'));
|
||||
beforeEach(angular.mock.inject(function($compile, $rootScope, $controller){
|
||||
scope = $rootScope.$new();
|
||||
$rootScope.wallet = new FakeWallet(config);
|
||||
var element = angular.element(
|
||||
'<form name="form">' +
|
||||
'<input type="text" id="newaddress" name="newaddress" ng-disabled="loading" placeholder="Address" ng-model="newaddress" valid-address required>' +
|
||||
'<input type="text" id="newlabel" name="newlabel" ng-disabled="loading" placeholder="Label" ng-model="newlabel" required>' +
|
||||
'</form>'
|
||||
);
|
||||
scope.model = {
|
||||
newaddress: null,
|
||||
newlabel: null
|
||||
};
|
||||
$compile(element)(scope);
|
||||
$controller('SendController', {$scope: scope});
|
||||
scope.$digest();
|
||||
form = scope.form;
|
||||
}));
|
||||
|
||||
it('should have a SendController controller', function() {
|
||||
expect(scope.loading).equal(false);
|
||||
});
|
||||
|
||||
it('should have a title', function() {
|
||||
expect(scope.title).equal('Send');
|
||||
});
|
||||
|
||||
it('should return true if wallet has addressBook', function() {
|
||||
expect(scope.showAddressBook()).equal(true);
|
||||
});
|
||||
|
||||
it('should validate address', function() {
|
||||
form.newaddress.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
||||
expect(form.newaddress.$invalid).to.equal(false);
|
||||
});
|
||||
|
||||
it('should not validate address', function() {
|
||||
form.newaddress.$setViewValue('thisisaninvalidaddress');
|
||||
expect(form.newaddress.$invalid).to.equal(true);
|
||||
});
|
||||
|
||||
it('should validate label', function() {
|
||||
form.newlabel.$setViewValue('John');
|
||||
expect(form.newlabel.$invalid).to.equal(false);
|
||||
});
|
||||
|
||||
it('should not validate label', function() {
|
||||
expect(form.newlabel.$invalid).to.equal(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("Unit: Header Controller", function() {
|
||||
var scope, $httpBackendOut;
|
||||
var GH = 'https://api.github.com/repos/bitpay/copay/tags';
|
||||
|
|
Loading…
Reference in New Issue