commit
7406623ed5
25 changed files with 616 additions and 336 deletions
|
|
@ -1,8 +1,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
var defaultConfig = {
|
var defaultConfig = {
|
||||||
// livenet or testnet
|
// DEFAULT network (livenet or testnet)
|
||||||
networkName: 'testnet',
|
networkName: 'testnet',
|
||||||
|
|
||||||
|
// DEFAULT unit: Bit
|
||||||
|
unitName: 'bits',
|
||||||
|
unitToSatoshi: 100,
|
||||||
|
|
||||||
// wallet limits
|
// wallet limits
|
||||||
limits: {
|
limits: {
|
||||||
totalCopayers: 12,
|
totalCopayers: 12,
|
||||||
|
|
|
||||||
15
css/main.css
15
css/main.css
|
|
@ -219,6 +219,21 @@ small.has-error {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.totalAmount {
|
||||||
|
line-height: 120%;
|
||||||
|
margin-top:2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Turn Off Number Input Spinners */
|
||||||
|
input[type=number]::-webkit-inner-spin-button,
|
||||||
|
input[type=number]::-webkit-outer-spin-button {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.small {
|
.small {
|
||||||
font-size: 60%;
|
font-size: 60%;
|
||||||
line-height: inherit;
|
line-height: inherit;
|
||||||
|
|
|
||||||
82
index.html
82
index.html
|
|
@ -21,7 +21,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="large-9 medium-9 small-9 columns text-center p10t" ng-show="$root.wallet">
|
<div class="large-9 medium-9 small-9 columns text-center p10t" ng-show="$root.wallet">
|
||||||
<div class="large-4 medium-4 columns line-dashed-v">
|
<div class="large-4 medium-4 columns line-dashed-v">
|
||||||
<a href="#/addresses" class="has-tip" tooltip-placement="bottom" tooltip="{{$root.wallet.id}}">
|
<a href="#/addresses" class="has-tip" tooltip-placement="bottom" tooltip="ID: {{$root.wallet.id}}">
|
||||||
<strong><span>{{$root.wallet.getName()}}</span></strong>
|
<strong><span>{{$root.wallet.getName()}}</span></strong>
|
||||||
</a>
|
</a>
|
||||||
<a class="button radius small-icon" title="Manual Refresh"
|
<a class="button radius small-icon" title="Manual Refresh"
|
||||||
|
|
@ -31,21 +31,19 @@
|
||||||
ng-click="signout()"><i class="fi-power"></i></a>
|
ng-click="signout()"><i class="fi-power"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="large-4 medium-4 columns line-dashed-v">
|
<div class="large-4 medium-4 columns line-dashed-v">
|
||||||
Balance:
|
Balance<br>
|
||||||
<span ng-if="$root.updatingBalance">
|
<span ng-if="$root.updatingBalance">
|
||||||
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="!$root.updatingBalance">{{totalBalance || 0}}
|
<span ng-if="!$root.updatingBalance" tooltip="{{totalBalanceBTC}} BTC" tooltip-trigger="mouseenter" tooltip-placement="bottom">{{totalBalance || 0 |number}} {{$root.unitName}}
|
||||||
<i class="fi-bitcoin"></i>
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="large-4 medium-4 columns">
|
<div class="large-4 medium-4 columns">
|
||||||
Available to Spend:
|
Available to Spend<br>
|
||||||
<span ng-if="$root.updatingBalance">
|
<span ng-if="$root.updatingBalance">
|
||||||
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="!$root.updatingBalance">{{availableBalance || 0}}
|
<span ng-show="!$root.updatingBalance" tooltip="{{availableBalanceBTC}} BTC" tooltip-trigger="mouseenter" tooltip-placement="bottom">{{availableBalance || 0|number}} {{$root.unitName}}
|
||||||
<i class="fi-bitcoin"></i>
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -383,13 +381,11 @@
|
||||||
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="!$root.updatingBalance">
|
<span ng-if="!$root.updatingBalance">
|
||||||
{{$root.balanceByAddr[addr.address] || 0}}
|
{{$root.balanceByAddr[addr.address] || 0|number}} {{$root.unitName}}
|
||||||
<i class="fi-bitcoin"></i>
|
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="addrWithFund != addr.address">
|
<span ng-if="addrWithFund != addr.address">
|
||||||
{{addr.balance || 0}}
|
{{addr.balance || 0|number}} {{$root.unitName}}
|
||||||
<i class="fi-bitcoin"></i>
|
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
@ -407,14 +403,12 @@
|
||||||
<span ng-if="$root.updatingBalance">
|
<span ng-if="$root.updatingBalance">
|
||||||
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="!$root.updatingBalance">{{balanceByAddr[selectedAddr.address] || 0}}
|
<span ng-if="!$root.updatingBalance">{{balanceByAddr[selectedAddr.address] || 0 | number}}
|
||||||
<i class="fi-bitcoin"></i>
|
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="addrWithFund != selectedAddr.address" style="word-wrap: break-word;">
|
<span ng-if="addrWithFund != selectedAddr.address" style="word-wrap: break-word;">
|
||||||
{{selectedAddr.address}}<br/>
|
{{selectedAddr.address}}<br/>
|
||||||
{{selectedAddr.balance || 0}}
|
{{selectedAddr.balance || 0|number}} {{$root.unitName}}
|
||||||
<i class="fi-bitcoin"></i>
|
|
||||||
</span>
|
</span>
|
||||||
</strong>
|
</strong>
|
||||||
</p>
|
</p>
|
||||||
|
|
@ -445,7 +439,7 @@
|
||||||
<div class="txheader row m10">
|
<div class="txheader row m10">
|
||||||
<div class="large-8 medium-8 small-12 columns">
|
<div class="large-8 medium-8 small-12 columns">
|
||||||
<div class="row" ng-repeat="out in tx.outs">
|
<div class="row" ng-repeat="out in tx.outs">
|
||||||
<div class="large-3 medium-3 small-3 columns ellipsis"> {{out.value}} <i class="fi-bitcoin size-18"></i></div>
|
<div class="large-3 medium-3 small-3 columns ellipsis"> {{out.value | number}} {{$root.unitName}}</div>
|
||||||
<div class="large-1 medium-1 small-2 columns fi-arrow-right size-24"> </div>
|
<div class="large-1 medium-1 small-2 columns fi-arrow-right size-24"> </div>
|
||||||
<div class="large-8 medium-8 small-7 columns ellipsis"> {{out.address}} </div>
|
<div class="large-8 medium-8 small-7 columns ellipsis"> {{out.address}} </div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -527,7 +521,7 @@
|
||||||
<p class="text-gray m5b" ng-show="!tx.finallyRejected && tx.missingSignatures>1">
|
<p class="text-gray m5b" ng-show="!tx.finallyRejected && tx.missingSignatures>1">
|
||||||
{{tx.missingSignatures}} signatures missing</p>
|
{{tx.missingSignatures}} signatures missing</p>
|
||||||
<div class="ellipsis small text-gray">
|
<div class="ellipsis small text-gray">
|
||||||
<strong>Fee:</strong> <i class="fi-bitcoin"></i> {{tx.fee}}
|
<strong>Fee:</strong> {{tx.fee|number}} {{$root.unitName}}
|
||||||
<strong>Proposal ID:</strong> {{tx.ntxid}}
|
<strong>Proposal ID:</strong> {{tx.ntxid}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -571,7 +565,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-5 medium-5 small-5 columns">
|
<div class="large-5 medium-5 small-5 columns">
|
||||||
<div ng-repeat="vin in btx.vinSimple">
|
<div ng-repeat="vin in btx.vinSimple">
|
||||||
<small class="right m5t">{{vin.value}}</small>
|
<small class="right m5t">{{vin.value| number}} {{$root.unitName}}</small>
|
||||||
<p class="ellipsis text-gray size-12"> {{vin.addr}} </p>
|
<p class="ellipsis text-gray size-12"> {{vin.addr}} </p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -580,7 +574,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="large-6 medium-6 small-6 columns">
|
<div class="large-6 medium-6 small-6 columns">
|
||||||
<div ng-repeat="vout in btx.voutSimple">
|
<div ng-repeat="vout in btx.voutSimple">
|
||||||
<small class="right m5t">{{vout.value}}</small>
|
<small class="right m5t">{{vout.value| number}} {{$root.unitName}}</small>
|
||||||
<p class="ellipsis text-gray size-12"> {{vout.addr}} </p>
|
<p class="ellipsis text-gray size-12"> {{vout.addr}} </p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -588,9 +582,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="m10 size-12 text-gray">
|
<div class="m10 size-12 text-gray">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-4 medium-4 small-4 columns">Fees: {{btx.fees}}</div>
|
<div class="large-4 medium-4 small-4 columns">Fees: {{btx.fees | number}} {{$root.unitName}}</div>
|
||||||
<div class="large-4 medium-4 small-4 columns text-center">Confirmations: {{btx.confirmations || 0}}</div>
|
<div class="large-4 medium-4 small-4 columns text-center">Confirmations: {{btx.confirmations || 0}}</div>
|
||||||
<div class="large-4 medium-4 small-4 columns text-right">Total: {{btx.valueOut}}</div>
|
<div class="large-4 medium-4 small-4 columns text-right">Total: {{btx.valueOut| number}} {{$root.unitName}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -652,22 +646,38 @@
|
||||||
<div class="row collapse">
|
<div class="row collapse">
|
||||||
<label for="amount">Amount
|
<label for="amount">Amount
|
||||||
<small ng-hide="!sendForm.amount.$pristine">required</small>
|
<small ng-hide="!sendForm.amount.$pristine">required</small>
|
||||||
<small class="is-valid" ng-show="!sendForm.amount.$invalid && !sendForm.amount.$pristine">valid!</small>
|
<small class="is-valid" ng-show="!sendForm.amount.$invalid && !sendForm.amount.$pristine">Valid</small>
|
||||||
<small class="has-error" ng-show="sendForm.amount.$invalid && !sendForm.amount.$pristine && !notEnoughAmount">
|
<small class="has-error" ng-show="sendForm.amount.$invalid && !sendForm.amount.$pristine && !notEnoughAmount">
|
||||||
not valid
|
Not valid
|
||||||
</small>
|
</small>
|
||||||
<small ng-show="notEnoughAmount">Insufficient funds!</small>
|
<small ng-show="notEnoughAmount" class="has-error">Insufficient funds</small>
|
||||||
</label>
|
</label>
|
||||||
<div class="small-9 columns">
|
<div class="small-9 columns">
|
||||||
<input type="number" id="amount" ng-disabled="loading"
|
<input type="number" id="amount" ng-disabled="loading"
|
||||||
name="amount" placeholder="Amount" ng-model="amount"
|
name="amount" placeholder="Amount" ng-model="amount"
|
||||||
min="0.0001" max="10000000" enough-amount required>
|
min="1" max="10000000000" enough-amount required
|
||||||
|
autocomplete="off"
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-3 columns">
|
<div class="small-3 columns">
|
||||||
<span class="postfix">BTC</span>
|
<span class="postfix">{{$root.unitName}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="large-6 medium-6 columns m10t" ng-show="amount>0">
|
||||||
|
<small>
|
||||||
|
Total amount for this transaction:
|
||||||
|
</small>
|
||||||
|
<div class="totalAmount">
|
||||||
|
<b>{{amount + defaultFee |number}}</b> {{$root.unitName}}
|
||||||
|
<small>
|
||||||
|
{{ ((amount + defaultFee) * unitToBtc) |number}} BTC
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
<small>
|
||||||
|
Including fee of {{defaultFee|number}} {{$root.unitName}}
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -680,7 +690,7 @@
|
||||||
</label>
|
</label>
|
||||||
<div class="small-12 columns">
|
<div class="small-12 columns">
|
||||||
<textarea id="comment" ng-disabled="loading"
|
<textarea id="comment" ng-disabled="loading"
|
||||||
name="comment" placeholder="Leave a private message to your copayers" ng-model="comment" ng-maxlength="100"></textarea>
|
name="comment" placeholder="Leave a private message to your copayers" ng-model="commentText" ng-maxlength="100"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -740,6 +750,17 @@
|
||||||
<input id="network-name" type="checkbox" ng-model="networkName" ng-true-value="livenet" ng-false-value="testnet" class="form-control">
|
<input id="network-name" type="checkbox" ng-model="networkName" ng-true-value="livenet" ng-false-value="testnet" class="form-control">
|
||||||
<label for="network-name">Livenet</label>
|
<label for="network-name">Livenet</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Wallet Unit</legend>
|
||||||
|
<select class="form-control" ng-model="selectedUnit" ng-options="o.name for o in unitOpts" required>
|
||||||
|
</select>
|
||||||
|
<label for="settingsUnit">Prefered Unit for Wallet</label>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Videoconferencing</legend>
|
||||||
|
<input id="disableVideo-opt" type="checkbox" ng-model="disableVideo" class="form-control">
|
||||||
|
<label for="disableVideo-opt">Enable videoconferencing (only for fast Networks)</label>
|
||||||
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Insight API server</legend>
|
<legend>Insight API server</legend>
|
||||||
<label for="insight-host">Host</label>
|
<label for="insight-host">Host</label>
|
||||||
|
|
@ -758,13 +779,6 @@
|
||||||
<input id="peerjs-secure" type="checkbox" ng-model="networkSecure" class="form-control" disabled="disabled">
|
<input id="peerjs-secure" type="checkbox" ng-model="networkSecure" class="form-control" disabled="disabled">
|
||||||
<label for="peerjs-secure">Use SSL (disabled)</label>
|
<label for="peerjs-secure">Use SSL (disabled)</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
|
||||||
<legend>Videoconferencing</legend>
|
|
||||||
<input id="disableVideo-opt" type="checkbox" ng-model="disableVideo" class="form-control">
|
|
||||||
<label for="disableVideo-opt">Enable videoconferencing (only for fast Networks)</label>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-12 columns line-dashed">
|
<div class="large-12 columns line-dashed">
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ angular.module('copayApp.controllers').controller('HeaderController',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$rootScope.unitName = config.unitName;
|
||||||
|
|
||||||
// Initialize alert notification (not show when init wallet)
|
// Initialize alert notification (not show when init wallet)
|
||||||
$rootScope.txAlertCount = 0;
|
$rootScope.txAlertCount = 0;
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,7 @@ angular.module('copayApp.controllers').controller('ImportController',
|
||||||
}
|
}
|
||||||
$rootScope.wallet = w;
|
$rootScope.wallet = w;
|
||||||
|
|
||||||
controllerUtils.startNetwork($rootScope.wallet);
|
controllerUtils.startNetwork($rootScope.wallet, $scope);
|
||||||
$rootScope.wallet.on('connectionError', function() {
|
|
||||||
var message = "Looks like you are already connected to this wallet, please logout from it and try importing it again.";
|
|
||||||
$rootScope.$flashMessage = { message: message, type: 'error'};
|
|
||||||
});
|
|
||||||
$rootScope.wallet.on('serverError', function() {
|
|
||||||
$rootScope.$flashMessage = { message: 'The PeerJS server is not responding, please try again', type: 'error'};
|
|
||||||
controllerUtils.onErrorDigest();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,34 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
var bitcore = require('bitcore');
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('SendController',
|
angular.module('copayApp.controllers').controller('SendController',
|
||||||
function($scope, $rootScope, $window, $location, $timeout) {
|
function($scope, $rootScope, $window, $location, $timeout) {
|
||||||
$scope.title = 'Send';
|
$scope.title = 'Send';
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
|
var satToUnit = 1 / config.unitToSatoshi;
|
||||||
|
$scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit;
|
||||||
|
$scope.unitToBtc = config.unitToSatoshi / bitcore.util.COIN;
|
||||||
|
|
||||||
|
// TODO this shouldnt be on a particular controller.
|
||||||
// Detect mobile devices
|
// Detect mobile devices
|
||||||
var isMobile = {
|
var isMobile = {
|
||||||
Android: function() {
|
Android: function() {
|
||||||
return navigator.userAgent.match(/Android/i);
|
return navigator.userAgent.match(/Android/i);
|
||||||
},
|
},
|
||||||
BlackBerry: function() {
|
BlackBerry: function() {
|
||||||
return navigator.userAgent.match(/BlackBerry/i);
|
return navigator.userAgent.match(/BlackBerry/i);
|
||||||
},
|
},
|
||||||
iOS: function() {
|
iOS: function() {
|
||||||
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
|
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
|
||||||
},
|
},
|
||||||
Opera: function() {
|
Opera: function() {
|
||||||
return navigator.userAgent.match(/Opera Mini/i);
|
return navigator.userAgent.match(/Opera Mini/i);
|
||||||
},
|
},
|
||||||
Windows: function() {
|
Windows: function() {
|
||||||
return navigator.userAgent.match(/IEMobile/i);
|
return navigator.userAgent.match(/IEMobile/i);
|
||||||
},
|
},
|
||||||
any: function() {
|
any: function() {
|
||||||
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
|
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -32,27 +37,31 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
|
|
||||||
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
|
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
|
||||||
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
||||||
|
|
||||||
$scope.isMobile = isMobile.any();
|
$scope.isMobile = isMobile.any();
|
||||||
$scope.unitIds = ['BTC','mBTC'];
|
|
||||||
$scope.selectedUnit = $scope.unitIds[0];
|
|
||||||
|
|
||||||
$scope.submitForm = function(form) {
|
$scope.submitForm = function(form) {
|
||||||
if (form.$invalid) {
|
if (form.$invalid) {
|
||||||
$rootScope.$flashMessage = { message: 'You can not send a proposal transaction. Please, try again', type: 'error'};
|
$rootScope.$flashMessage = {
|
||||||
|
message: 'You can not send a proposal transaction. Please, try again',
|
||||||
|
type: 'error'
|
||||||
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
|
|
||||||
var address = form.address.$modelValue;
|
var address = form.address.$modelValue;
|
||||||
var amount = (form.amount.$modelValue * 100000000).toFixed(); // satoshi to string
|
var amount = (form.amount.$modelValue * config.unitToSatoshi) | 0;
|
||||||
var comment = form.comment.$modelValue;
|
var commentText = form.comment.$modelValue;
|
||||||
|
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
w.createTx(address, amount, comment, function() {
|
|
||||||
|
w.createTx(address, amount, commentText, function() {
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
$rootScope.$flashMessage = { message: 'The transaction proposal has been created', type: 'success'};
|
$rootScope.$flashMessage = {
|
||||||
|
message: 'The transaction proposal has been created',
|
||||||
|
type: 'success'
|
||||||
|
};
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -81,7 +90,11 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
reader.onload = (function(theFile) {
|
reader.onload = (function(theFile) {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
var mpImg = new MegaPixImage(file);
|
var mpImg = new MegaPixImage(file);
|
||||||
mpImg.render(canvas, { maxWidth: 200, maxHeight: 200, orientation: 6 });
|
mpImg.render(canvas, {
|
||||||
|
maxWidth: 200,
|
||||||
|
maxHeight: 200,
|
||||||
|
orientation: 6
|
||||||
|
});
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
qrcode.width = canvas.width;
|
qrcode.width = canvas.width;
|
||||||
|
|
@ -107,7 +120,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
|
|
||||||
try {
|
try {
|
||||||
qrcode.decode();
|
qrcode.decode();
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
//qrcodeError(e);
|
//qrcodeError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -168,7 +181,9 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
canvas.height = 225;
|
canvas.height = 225;
|
||||||
context.clearRect(0, 0, 300, 225);
|
context.clearRect(0, 0, 300, 225);
|
||||||
|
|
||||||
navigator.getUserMedia({video: true}, _successCallback, _videoError);
|
navigator.getUserMedia({
|
||||||
|
video: true
|
||||||
|
}, _successCallback, _videoError);
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,32 @@ angular.module('copayApp.controllers').controller('SettingsController',
|
||||||
$scope.networkHost = config.network.host;
|
$scope.networkHost = config.network.host;
|
||||||
$scope.networkPort = config.network.port;
|
$scope.networkPort = config.network.port;
|
||||||
$scope.networkSecure = config.network.secure || false;
|
$scope.networkSecure = config.network.secure || false;
|
||||||
$scope.disableVideo = config.disableVideo || true;
|
$scope.disableVideo = config.disableVideo || true;
|
||||||
|
|
||||||
|
$scope.unitOpts = [{
|
||||||
|
name: 'Satoshis (100,000,000 bits = 1BTC)',
|
||||||
|
shortName: 'SAT',
|
||||||
|
value: 1
|
||||||
|
}, {
|
||||||
|
name: 'bits (1,000,000 bits = 1BTC)',
|
||||||
|
shortName: 'bits',
|
||||||
|
value: 100
|
||||||
|
}, {
|
||||||
|
name: 'mBTC (1,000 mBTC = 1BTC)',
|
||||||
|
shortName: 'mBTC',
|
||||||
|
value: 100000
|
||||||
|
}, {
|
||||||
|
name: 'BTC',
|
||||||
|
shortName: 'BTC',
|
||||||
|
value: 100000000
|
||||||
|
}];
|
||||||
|
|
||||||
|
for (var ii in $scope.unitOpts) {
|
||||||
|
if (config.unitName === $scope.unitOpts[ii].shortName) {
|
||||||
|
$scope.selectedUnit = $scope.unitOpts[ii];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$scope.$watch('networkName', function(net) {
|
$scope.$watch('networkName', function(net) {
|
||||||
$scope.insightHost = net === 'testnet' ? 'test.insight.is' : 'live.insight.is';
|
$scope.insightHost = net === 'testnet' ? 'test.insight.is' : 'live.insight.is';
|
||||||
|
|
@ -25,20 +50,21 @@ angular.module('copayApp.controllers').controller('SettingsController',
|
||||||
network.secure = $scope.networkSecure;
|
network.secure = $scope.networkSecure;
|
||||||
|
|
||||||
localStorage.setItem('config', JSON.stringify({
|
localStorage.setItem('config', JSON.stringify({
|
||||||
networkName: $scope.networkName,
|
networkName: $scope.networkName,
|
||||||
blockchain: {
|
blockchain: {
|
||||||
host: $scope.insightHost,
|
host: $scope.insightHost,
|
||||||
port: $scope.insightPort
|
port: $scope.insightPort
|
||||||
},
|
},
|
||||||
socket: {
|
socket: {
|
||||||
host: $scope.insightHost,
|
host: $scope.insightHost,
|
||||||
port: $scope.insightPort
|
port: $scope.insightPort
|
||||||
},
|
},
|
||||||
network: network,
|
network: network,
|
||||||
disableVideo: $scope.disableVideo,
|
disableVideo: $scope.disableVideo,
|
||||||
})
|
unitName: $scope.selectedUnit.shortName,
|
||||||
);
|
unitToSatoshi: $scope.selectedUnit.value,
|
||||||
|
}));
|
||||||
|
|
||||||
$window.location.href= $window.location.origin + $window.location.pathname;
|
$window.location.href = $window.location.origin + $window.location.pathname;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ angular.module('copayApp.controllers').controller('SetupController',
|
||||||
passphrase: passphrase,
|
passphrase: passphrase,
|
||||||
};
|
};
|
||||||
var w = walletFactory.create(opts);
|
var w = walletFactory.create(opts);
|
||||||
controllerUtils.startNetwork(w);
|
controllerUtils.startNetwork(w, $scope);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,7 @@ angular.module('copayApp.controllers').controller('SigninController',
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
installStartupHandlers(w);
|
controllerUtils.startNetwork(w, $scope);
|
||||||
controllerUtils.startNetwork(w);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -65,25 +64,9 @@ angular.module('copayApp.controllers').controller('SigninController',
|
||||||
$rootScope.$flashMessage = { message: 'Unknown error', type: 'error'};
|
$rootScope.$flashMessage = { message: 'Unknown error', type: 'error'};
|
||||||
controllerUtils.onErrorDigest();
|
controllerUtils.onErrorDigest();
|
||||||
} else {
|
} else {
|
||||||
controllerUtils.startNetwork(w);
|
controllerUtils.startNetwork(w, $scope);
|
||||||
installStartupHandlers(w);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
function installStartupHandlers(wallet) {
|
|
||||||
wallet.on('serverError', function(msg) {
|
|
||||||
$rootScope.$flashMessage = {
|
|
||||||
message: 'There was an error connecting to the PeerJS server.'
|
|
||||||
+(msg||'Check you settings and Internet connection.'),
|
|
||||||
type: 'error',
|
|
||||||
};
|
|
||||||
controllerUtils.onErrorDigest($scope);
|
|
||||||
});
|
|
||||||
wallet.on('ready', function() {
|
|
||||||
$scope.loading = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
var bitcore = require('bitcore');
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('TransactionsController',
|
angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
function($scope, $rootScope, $timeout, controllerUtils) {
|
function($scope, $rootScope, $timeout, controllerUtils) {
|
||||||
|
|
@ -10,13 +11,13 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
|
|
||||||
$scope.txpCurrentPage = 1;
|
$scope.txpCurrentPage = 1;
|
||||||
$scope.txpItemsPerPage = 4;
|
$scope.txpItemsPerPage = 4;
|
||||||
|
|
||||||
var COIN = 100000000;
|
|
||||||
$scope.blockchain_txs = [];
|
$scope.blockchain_txs = [];
|
||||||
|
|
||||||
$scope.update = function () {
|
var satToUnit = 1 / config.unitToSatoshi;
|
||||||
|
|
||||||
|
$scope.update = function() {
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
var from = ($scope.txpCurrentPage-1) * $scope.txpItemsPerPage;
|
var from = ($scope.txpCurrentPage - 1) * $scope.txpItemsPerPage;
|
||||||
var opts = {
|
var opts = {
|
||||||
onlyPending: $scope.onlyPending,
|
onlyPending: $scope.onlyPending,
|
||||||
skip: !$scope.onlyPending ? [from, from + $scope.txpItemsPerPage] : null
|
skip: !$scope.onlyPending ? [from, from + $scope.txpItemsPerPage] : null
|
||||||
|
|
@ -25,10 +26,10 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.show = function (onlyPending) {
|
$scope.show = function(onlyPending) {
|
||||||
$scope.loading=true;
|
$scope.loading = true;
|
||||||
$scope.onlyPending = onlyPending;
|
$scope.onlyPending = onlyPending;
|
||||||
setTimeout(function(){
|
setTimeout(function() {
|
||||||
$scope.update();
|
$scope.update();
|
||||||
}, 10);
|
}, 10);
|
||||||
};
|
};
|
||||||
|
|
@ -42,19 +43,19 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
var tmp = {};
|
var tmp = {};
|
||||||
var u = 0;
|
var u = 0;
|
||||||
|
|
||||||
for(var i=0; i < l; i++) {
|
for (var i = 0; i < l; i++) {
|
||||||
|
|
||||||
var notAddr = false;
|
var notAddr = false;
|
||||||
// non standard input
|
// non standard input
|
||||||
if (items[i].scriptSig && !items[i].addr) {
|
if (items[i].scriptSig && !items[i].addr) {
|
||||||
items[i].addr = 'Unparsed address [' + u++ + ']';
|
items[i].addr = 'Unparsed address [' + u+++']';
|
||||||
items[i].notAddr = true;
|
items[i].notAddr = true;
|
||||||
notAddr = true;
|
notAddr = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// non standard output
|
// non standard output
|
||||||
if (items[i].scriptPubKey && !items[i].scriptPubKey.addresses) {
|
if (items[i].scriptPubKey && !items[i].scriptPubKey.addresses) {
|
||||||
items[i].scriptPubKey.addresses = ['Unparsed address [' + u++ + ']'];
|
items[i].scriptPubKey.addresses = ['Unparsed address [' + u+++']'];
|
||||||
items[i].notAddr = true;
|
items[i].notAddr = true;
|
||||||
notAddr = true;
|
notAddr = true;
|
||||||
}
|
}
|
||||||
|
|
@ -77,62 +78,64 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
}
|
}
|
||||||
tmp[addr].isSpent = items[i].spentTxId;
|
tmp[addr].isSpent = items[i].spentTxId;
|
||||||
|
|
||||||
tmp[addr].doubleSpentTxID = tmp[addr].doubleSpentTxID || items[i].doubleSpentTxID;
|
tmp[addr].doubleSpentTxID = tmp[addr].doubleSpentTxID || items[i].doubleSpentTxID;
|
||||||
tmp[addr].doubleSpentIndex = tmp[addr].doubleSpentIndex || items[i].doubleSpentIndex;
|
tmp[addr].doubleSpentIndex = tmp[addr].doubleSpentIndex || items[i].doubleSpentIndex;
|
||||||
tmp[addr].unconfirmedInput += items[i].unconfirmedInput;
|
tmp[addr].unconfirmedInput += items[i].unconfirmedInput;
|
||||||
tmp[addr].dbError = tmp[addr].dbError || items[i].dbError;
|
tmp[addr].dbError = tmp[addr].dbError || items[i].dbError;
|
||||||
tmp[addr].valueSat += Math.round(items[i].value * COIN);
|
tmp[addr].valueSat += parseInt((items[i].value * bitcore.util.COIN).toFixed(0));
|
||||||
tmp[addr].items.push(items[i]);
|
tmp[addr].items.push(items[i]);
|
||||||
tmp[addr].notAddr = notAddr;
|
tmp[addr].notAddr = notAddr;
|
||||||
tmp[addr].count++;
|
tmp[addr].count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
angular.forEach(tmp, function(v) {
|
angular.forEach(tmp, function(v) {
|
||||||
v.value = v.value || parseInt(v.valueSat) / COIN;
|
v.value = (parseInt(v.valueSat || 0).toFixed(0)) * satToUnit;
|
||||||
ret.push(v);
|
ret.push(v);
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.toogleLast = function () {
|
$scope.toogleLast = function() {
|
||||||
$scope.lastShowed = !$scope.lastShowed;
|
$scope.lastShowed = !$scope.lastShowed;
|
||||||
if ($scope.lastShowed) {
|
if ($scope.lastShowed) {
|
||||||
$scope.getTransactions();
|
$scope.getTransactions();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.send = function (ntxid,cb) {
|
$scope.send = function(ntxid, cb) {
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
$rootScope.txAlertCount = 0;
|
$rootScope.txAlertCount = 0;
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
w.sendTx(ntxid, function(txid) {
|
w.sendTx(ntxid, function(txid) {
|
||||||
$rootScope.$flashMessage = txid
|
$rootScope.$flashMessage = txid ? {
|
||||||
? {type:'success', message: 'Transaction broadcasted. txid: ' + txid}
|
type: 'success',
|
||||||
: {type:'error', message: 'There was an error sending the Transaction'}
|
message: 'Transaction broadcasted. txid: ' + txid
|
||||||
;
|
} : {
|
||||||
if (cb) return cb();
|
type: 'error',
|
||||||
else $scope.update();
|
message: 'There was an error sending the Transaction'
|
||||||
|
};
|
||||||
|
if (cb) return cb();
|
||||||
|
else $scope.update();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.sign = function (ntxid) {
|
$scope.sign = function(ntxid) {
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
w.sign(ntxid, function(ret){
|
w.sign(ntxid, function(ret) {
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
$rootScope.$flashMessage = {
|
$rootScope.$flashMessage = {
|
||||||
type:'error',
|
type: 'error',
|
||||||
message: 'There was an error signing the Transaction',
|
message: 'There was an error signing the Transaction',
|
||||||
};
|
};
|
||||||
$scope.update();
|
$scope.update();
|
||||||
} else {
|
} else {
|
||||||
var p = w.txProposals.getTxProposal(ntxid);
|
var p = w.txProposals.getTxProposal(ntxid);
|
||||||
if (p.builder.isFullySigned()) {
|
if (p.builder.isFullySigned()) {
|
||||||
$scope.send(ntxid, function() {
|
$scope.send(ntxid, function() {
|
||||||
$scope.update();
|
$scope.update();
|
||||||
});
|
});
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
$scope.update();
|
$scope.update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -147,16 +150,17 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
$scope.blockchain_txs = [];
|
$scope.blockchain_txs = [];
|
||||||
w.blockchain.getTransactions(addresses, function(txs) {
|
w.blockchain.getTransactions(addresses, function(txs) {
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
for (var i=0; i<txs.length;i++) {
|
for (var i = 0; i < txs.length; i++) {
|
||||||
txs[i].vinSimple = _aggregateItems(txs[i].vin);
|
txs[i].vinSimple = _aggregateItems(txs[i].vin);
|
||||||
txs[i].voutSimple = _aggregateItems(txs[i].vout);
|
txs[i].voutSimple = _aggregateItems(txs[i].vout);
|
||||||
|
txs[i].valueOut = ((txs[i].valueOut * bitcore.util.COIN).toFixed(0)) * satToUnit;
|
||||||
|
txs[i].fees = ((txs[i].fees * bitcore.util.COIN).toFixed(0)) * satToUnit;
|
||||||
$scope.blockchain_txs.push(txs[i]);
|
$scope.blockchain_txs.push(txs[i]);
|
||||||
}
|
}
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
}, 10);
|
}, 10);
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
$scope.lastShowed = false;
|
$scope.lastShowed = false;
|
||||||
|
|
@ -166,15 +170,18 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getShortNetworkName = function() {
|
$scope.getShortNetworkName = function() {
|
||||||
return config.networkName.substring(0,4);
|
return config.networkName.substring(0, 4);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.reject = function (ntxid) {
|
$scope.reject = function(ntxid) {
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
$rootScope.txAlertCount = 0;
|
$rootScope.txAlertCount = 0;
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
w.reject(ntxid);
|
w.reject(ntxid);
|
||||||
$rootScope.$flashMessage = {type:'warning', message: 'Transaction rejected by you'};
|
$rootScope.$flashMessage = {
|
||||||
|
type: 'warning',
|
||||||
|
message: 'Transaction rejected by you'
|
||||||
|
};
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@ angular.module('copayApp.directives')
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, element, attrs, ctrl) {
|
link: function(scope, element, attrs, ctrl) {
|
||||||
var val = function(value) {
|
var val = function(value) {
|
||||||
var availableBalanceNum = ($rootScope.availableBalance * bitcore.util.COIN).toFixed(0);
|
var availableBalanceNum = ($rootScope.availableBalance * config.unitToSatoshi).toFixed(0);
|
||||||
var vNum = Number((value * bitcore.util.COIN).toFixed(0)) + feeSat;
|
var vNum = Number((value * config.unitToSatoshi).toFixed(0)) + feeSat;
|
||||||
if (typeof vNum == "number" && vNum > 0) {
|
if (typeof vNum == "number" && vNum > 0) {
|
||||||
if (availableBalanceNum < vNum) {
|
if (availableBalanceNum < vNum) {
|
||||||
ctrl.$setValidity('enoughAmount', false);
|
ctrl.$setValidity('enoughAmount', false);
|
||||||
|
|
@ -72,7 +72,7 @@ angular.module('copayApp.directives')
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elem, attrs, ctrl) {
|
link: function(scope, elem, attrs, ctrl) {
|
||||||
var validator = function(value) {
|
var validator = function(value) {
|
||||||
ctrl.$setValidity('walletSecret', Boolean(walletFactory.decodeSecret(value)));
|
ctrl.$setValidity('walletSecret', Boolean(walletFactory.decodeSecret(value)));
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ angular.module('copayApp.directives')
|
||||||
var a = element.html();
|
var a = element.html();
|
||||||
var text = attr.loading;
|
var text = attr.loading;
|
||||||
element.on('click', function() {
|
element.on('click', function() {
|
||||||
element.html('<i class="size-21 fi-bitcoin-circle icon-rotate spinner"></i> ' + text + '...');
|
element.html('<i class="size-21 fi-bitcoin-circle icon-rotate spinner"></i> ' + text + '...');
|
||||||
});
|
});
|
||||||
$scope.$watch('loading', function(val) {
|
$scope.$watch('loading', function(val) {
|
||||||
if (!val) {
|
if (!val) {
|
||||||
|
|
@ -126,9 +126,11 @@ angular.module('copayApp.directives')
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
link: function(scope, element, attrs) {
|
link: function(scope, element, attrs) {
|
||||||
scope.$watch(attrs.highlightOnChange, function (newValue, oldValue) {
|
scope.$watch(attrs.highlightOnChange, function(newValue, oldValue) {
|
||||||
element.addClass('highlight');
|
element.addClass('highlight');
|
||||||
setTimeout(function() { element.removeClass('highlight'); }, 500);
|
setTimeout(function() {
|
||||||
|
element.removeClass('highlight');
|
||||||
|
}, 500);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +144,7 @@ angular.module('copayApp.directives')
|
||||||
var strength = {
|
var strength = {
|
||||||
messages: ['very weak', 'weak', 'weak', 'medium', 'strong'],
|
messages: ['very weak', 'weak', 'weak', 'medium', 'strong'],
|
||||||
colors: ['#c0392b', '#e74c3c', '#d35400', '#f39c12', '#27ae60'],
|
colors: ['#c0392b', '#e74c3c', '#d35400', '#f39c12', '#27ae60'],
|
||||||
mesureStrength: function (p) {
|
mesureStrength: function(p) {
|
||||||
var force = 0;
|
var force = 0;
|
||||||
var regex = /[$-/:-?{-~!"^_`\[\]]/g;
|
var regex = /[$-/:-?{-~!"^_`\[\]]/g;
|
||||||
var lowerLetters = /[a-z]+/.test(p);
|
var lowerLetters = /[a-z]+/.test(p);
|
||||||
|
|
@ -150,7 +152,9 @@ angular.module('copayApp.directives')
|
||||||
var numbers = /[0-9]+/.test(p);
|
var numbers = /[0-9]+/.test(p);
|
||||||
var symbols = regex.test(p);
|
var symbols = regex.test(p);
|
||||||
var flags = [lowerLetters, upperLetters, numbers, symbols];
|
var flags = [lowerLetters, upperLetters, numbers, symbols];
|
||||||
var passedMatches = flags.filter(function (el) { return !!el; }).length;
|
var passedMatches = flags.filter(function(el) {
|
||||||
|
return !!el;
|
||||||
|
}).length;
|
||||||
|
|
||||||
force = 2 * p.length + (p.length >= 10 ? 1 : 0);
|
force = 2 * p.length + (p.length >= 10 ? 1 : 0);
|
||||||
force += passedMatches * 10;
|
force += passedMatches * 10;
|
||||||
|
|
@ -164,23 +168,35 @@ angular.module('copayApp.directives')
|
||||||
force = (passedMatches == 3) ? Math.min(force, 40) : force;
|
force = (passedMatches == 3) ? Math.min(force, 40) : force;
|
||||||
return force;
|
return force;
|
||||||
},
|
},
|
||||||
getColor: function (s) {
|
getColor: function(s) {
|
||||||
var idx = 0;
|
var idx = 0;
|
||||||
|
|
||||||
if (s <= 10) { idx = 0; }
|
if (s <= 10) {
|
||||||
else if (s <= 20) { idx = 1; }
|
idx = 0;
|
||||||
else if (s <= 30) { idx = 2; }
|
} else if (s <= 20) {
|
||||||
else if (s <= 40) { idx = 3; }
|
idx = 1;
|
||||||
else { idx = 4; }
|
} else if (s <= 30) {
|
||||||
|
idx = 2;
|
||||||
|
} else if (s <= 40) {
|
||||||
|
idx = 3;
|
||||||
|
} else {
|
||||||
|
idx = 4;
|
||||||
|
}
|
||||||
|
|
||||||
return { idx: idx + 1, col: this.colors[idx], message: this.messages[idx] };
|
return {
|
||||||
|
idx: idx + 1,
|
||||||
|
col: this.colors[idx],
|
||||||
|
message: this.messages[idx]
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
scope.$watch(attrs.ngModel, function (newValue, oldValue) {
|
scope.$watch(attrs.ngModel, function(newValue, oldValue) {
|
||||||
if (newValue && newValue !== '') {
|
if (newValue && newValue !== '') {
|
||||||
var c = strength.getColor(strength.mesureStrength(newValue));
|
var c = strength.getColor(strength.mesureStrength(newValue));
|
||||||
element.css({ 'border-color': c.col });
|
element.css({
|
||||||
|
'border-color': c.col
|
||||||
|
});
|
||||||
scope[attrs.checkStrength] = c.message;
|
scope[attrs.checkStrength] = c.message;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -183,34 +183,35 @@ Insight.prototype._request = function(options, callback) {
|
||||||
request.timeout = 5000;
|
request.timeout = 5000;
|
||||||
request.ontimeout = function() {
|
request.ontimeout = function() {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
return self._request(options,callback);
|
return self._request(options, callback);
|
||||||
}, self.retryDelay);
|
}, self.retryDelay);
|
||||||
return callback(new Error('Insight request timeout'));
|
return callback(new Error('Insight request timeout'));
|
||||||
};
|
};
|
||||||
|
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
if (request.readyState === 4) {
|
if (request.readyState !== 4) return;
|
||||||
if (request.status === 200 || request.status === 304) {
|
var ret, errTxt, e;
|
||||||
try {
|
|
||||||
var ret = JSON.parse(request.responseText);
|
if (request.status === 200 || request.status === 304) {
|
||||||
return callback(null, ret);
|
try {
|
||||||
} catch (e) {
|
ret = JSON.parse(request.responseText);
|
||||||
return callback(new Error('CRITICAL: Wrong response from insight'));
|
} catch (e2) {
|
||||||
}
|
errTxt = 'CRITICAL: Wrong response from insight' + e2;
|
||||||
}
|
|
||||||
// User error
|
|
||||||
else if (request.status >= 400 && request.status < 499) {
|
|
||||||
return callback(new Error('CRITICAL: Bad request to insight. Probably wrong transaction to broadcast?.'));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var err= 'Error code: ' + request.status + ' - Status: ' + request.statusText
|
|
||||||
+ ' - Description: ' + request.responseText;
|
|
||||||
setTimeout(function() {
|
|
||||||
return self._request(options,callback);
|
|
||||||
}, self.retryDelay);
|
|
||||||
return callback(new Error(err));
|
|
||||||
}
|
}
|
||||||
|
} else if (request.status >= 400 && request.status < 499) {
|
||||||
|
errTxt = 'CRITICAL: Bad request to insight. Probably wrong transaction to broadcast?.';
|
||||||
|
} else {
|
||||||
|
errTxt = 'Error code: ' + request.status + ' - Status: ' + request.statusText + ' - Description: ' + request.responseText;
|
||||||
|
setTimeout(function() {
|
||||||
|
console.log('### Retrying Insight Request....');
|
||||||
|
return self._request(options, callback);
|
||||||
|
}, self.retryDelay);
|
||||||
}
|
}
|
||||||
|
if (errTxt) {
|
||||||
|
console.log("INSIGHT ERROR:", e);
|
||||||
|
e = new Error(errTxt);
|
||||||
|
}
|
||||||
|
return callback(e, ret);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.method === 'POST') {
|
if (options.method === 'POST') {
|
||||||
|
|
@ -218,9 +219,7 @@ Insight.prototype._request = function(options, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
request.send(options.data || null);
|
request.send(options.data || null);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
else {
|
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
var req = http.request(options, function(response) {
|
var req = http.request(options, function(response) {
|
||||||
var ret;
|
var ret;
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,21 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var imports = require('soop').imports();
|
var imports = require('soop').imports();
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
var util = bitcore.util;
|
var util = bitcore.util;
|
||||||
var Transaction = bitcore.Transaction;
|
var Transaction = bitcore.Transaction;
|
||||||
var Builder = bitcore.TransactionBuilder;
|
var Builder = bitcore.TransactionBuilder;
|
||||||
var Script = bitcore.Script;
|
var Script = bitcore.Script;
|
||||||
var buffertools = bitcore.buffertools;
|
var buffertools = bitcore.buffertools;
|
||||||
|
|
||||||
function TxProposal(opts) {
|
function TxProposal(opts) {
|
||||||
this.creator = opts.creator;
|
this.creator = opts.creator;
|
||||||
this.createdTs = opts.createdTs;
|
this.createdTs = opts.createdTs;
|
||||||
this.seenBy = opts.seenBy || {};
|
this.seenBy = opts.seenBy || {};
|
||||||
this.signedBy = opts.signedBy || {};
|
this.signedBy = opts.signedBy || {};
|
||||||
this.rejectedBy = opts.rejectedBy || {};
|
this.rejectedBy = opts.rejectedBy || {};
|
||||||
this.builder = opts.builder;
|
this.builder = opts.builder;
|
||||||
this.sentTs = opts.sentTs || null;
|
this.sentTs = opts.sentTs || null;
|
||||||
this.sentTxid = opts.sentTxid || null;
|
this.sentTxid = opts.sentTxid || null;
|
||||||
this.inputChainPaths = opts.inputChainPaths || [];
|
this.inputChainPaths = opts.inputChainPaths || [];
|
||||||
|
|
@ -54,7 +53,7 @@ function TxProposals(opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
this.walletId = opts.walletId;
|
this.walletId = opts.walletId;
|
||||||
this.network = opts.networkName === 'livenet' ?
|
this.network = opts.networkName === 'livenet' ?
|
||||||
bitcore.networks.livenet : bitcore.networks.testnet;
|
bitcore.networks.livenet : bitcore.networks.testnet;
|
||||||
this.txps = {};
|
this.txps = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +76,7 @@ TxProposals.prototype.getNtxids = function() {
|
||||||
|
|
||||||
TxProposals.prototype.toObj = function(onlyThisNtxid) {
|
TxProposals.prototype.toObj = function(onlyThisNtxid) {
|
||||||
var ret = [];
|
var ret = [];
|
||||||
for(var id in this.txps){
|
for (var id in this.txps) {
|
||||||
|
|
||||||
if (onlyThisNtxid && id != onlyThisNtxid)
|
if (onlyThisNtxid && id != onlyThisNtxid)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -94,23 +93,25 @@ TxProposals.prototype.toObj = function(onlyThisNtxid) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposals.prototype._startMerge = function(myTxps, theirTxps) {
|
TxProposals.prototype._startMerge = function(myTxps, theirTxps) {
|
||||||
var fromUs=0, fromTheirs=0, merged =0;
|
var fromUs = 0,
|
||||||
var toMerge = {}, ready={};
|
fromTheirs = 0,
|
||||||
|
merged = 0;
|
||||||
|
var toMerge = {},
|
||||||
|
ready = {};
|
||||||
|
|
||||||
for(var hash in theirTxps){
|
for (var hash in theirTxps) {
|
||||||
if (!myTxps[hash]) {
|
if (!myTxps[hash]) {
|
||||||
ready[hash]=theirTxps[hash]; // only in theirs;
|
ready[hash] = theirTxps[hash]; // only in theirs;
|
||||||
fromTheirs++;
|
fromTheirs++;
|
||||||
}
|
} else {
|
||||||
else {
|
toMerge[hash] = theirTxps[hash]; // need Merging
|
||||||
toMerge[hash]=theirTxps[hash]; // need Merging
|
|
||||||
merged++;
|
merged++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var hash in myTxps){
|
for (var hash in myTxps) {
|
||||||
if(!toMerge[hash]) {
|
if (!toMerge[hash]) {
|
||||||
ready[hash]=myTxps[hash]; // only in myTxps;
|
ready[hash] = myTxps[hash]; // only in myTxps;
|
||||||
fromUs++;
|
fromUs++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -130,7 +131,7 @@ TxProposals.prototype._startMerge = function(myTxps, theirTxps) {
|
||||||
TxProposals.prototype._mergeMetadata = function(myTxps, theirTxps, mergeInfo) {
|
TxProposals.prototype._mergeMetadata = function(myTxps, theirTxps, mergeInfo) {
|
||||||
|
|
||||||
var toMerge = mergeInfo.toMerge;
|
var toMerge = mergeInfo.toMerge;
|
||||||
var hasChanged =0;
|
var hasChanged = 0;
|
||||||
|
|
||||||
Object.keys(toMerge).forEach(function(hash) {
|
Object.keys(toMerge).forEach(function(hash) {
|
||||||
var v0 = myTxps[hash];
|
var v0 = myTxps[hash];
|
||||||
|
|
@ -158,7 +159,7 @@ TxProposals.prototype._mergeMetadata = function(myTxps, theirTxps, mergeInfo) {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!v0.sentTxid && v1.sentTxid) {
|
if (!v0.sentTxid && v1.sentTxid) {
|
||||||
v0.sentTs = v1.sentTs;
|
v0.sentTs = v1.sentTs;
|
||||||
v0.sentTxid = v1.sentTxid;
|
v0.sentTxid = v1.sentTxid;
|
||||||
hasChanged++;
|
hasChanged++;
|
||||||
}
|
}
|
||||||
|
|
@ -170,9 +171,9 @@ TxProposals.prototype._mergeMetadata = function(myTxps, theirTxps, mergeInfo) {
|
||||||
|
|
||||||
TxProposals.prototype._mergeBuilder = function(myTxps, theirTxps, mergeInfo) {
|
TxProposals.prototype._mergeBuilder = function(myTxps, theirTxps, mergeInfo) {
|
||||||
var toMerge = mergeInfo.toMerge;
|
var toMerge = mergeInfo.toMerge;
|
||||||
var hasChanged=0;
|
var hasChanged = 0;
|
||||||
|
|
||||||
for(var hash in toMerge){
|
for (var hash in toMerge) {
|
||||||
var v0 = myTxps[hash].builder;
|
var v0 = myTxps[hash].builder;
|
||||||
var v1 = toMerge[hash].builder;
|
var v1 = toMerge[hash].builder;
|
||||||
|
|
||||||
|
|
@ -180,7 +181,7 @@ TxProposals.prototype._mergeBuilder = function(myTxps, theirTxps, mergeInfo) {
|
||||||
var before = JSON.stringify(v0.toObj());
|
var before = JSON.stringify(v0.toObj());
|
||||||
v0.merge(v1);
|
v0.merge(v1);
|
||||||
var after = JSON.stringify(v0.toObj());
|
var after = JSON.stringify(v0.toObj());
|
||||||
if (after !== before) hasChanged ++;
|
if (after !== before) hasChanged++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -191,7 +192,7 @@ TxProposals.prototype.add = function(data) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TxProposals.prototype.setSent = function(ntxid,txid) {
|
TxProposals.prototype.setSent = function(ntxid, txid) {
|
||||||
//sent TxProposals are local an not broadcasted.
|
//sent TxProposals are local an not broadcasted.
|
||||||
this.txps[ntxid].setSent(txid);
|
this.txps[ntxid].setSent(txid);
|
||||||
};
|
};
|
||||||
|
|
@ -205,26 +206,28 @@ TxProposals.prototype.getTxProposal = function(ntxid, copayers) {
|
||||||
i.peerActions = {};
|
i.peerActions = {};
|
||||||
|
|
||||||
if (copayers) {
|
if (copayers) {
|
||||||
for(var j=0; j < copayers.length; j++) {
|
for (var j = 0; j < copayers.length; j++) {
|
||||||
var p = copayers[j];
|
var p = copayers[j];
|
||||||
i.peerActions[p] = {};
|
i.peerActions[p] = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var p in txp.seenBy){
|
for (var p in txp.seenBy) {
|
||||||
i.peerActions[p]={seen: txp.seenBy[p]};
|
i.peerActions[p] = {
|
||||||
|
seen: txp.seenBy[p]
|
||||||
|
};
|
||||||
}
|
}
|
||||||
for(var p in txp.signedBy){
|
for (var p in txp.signedBy) {
|
||||||
i.peerActions[p]= i.peerActions[p] || {};
|
i.peerActions[p] = i.peerActions[p] || {};
|
||||||
i.peerActions[p].sign = txp.signedBy[p];
|
i.peerActions[p].sign = txp.signedBy[p];
|
||||||
}
|
}
|
||||||
var r=0;
|
var r = 0;
|
||||||
for(var p in txp.rejectedBy){
|
for (var p in txp.rejectedBy) {
|
||||||
i.peerActions[p]= i.peerActions[p] || {};
|
i.peerActions[p] = i.peerActions[p] || {};
|
||||||
i.peerActions[p].rejected = txp.rejectedBy[p];
|
i.peerActions[p].rejected = txp.rejectedBy[p];
|
||||||
r++;
|
r++;
|
||||||
}
|
}
|
||||||
i.rejectCount=r;
|
i.rejectCount = r;
|
||||||
|
|
||||||
var c = txp.creator;
|
var c = txp.creator;
|
||||||
i.peerActions[c] = i.peerActions[c] || {};
|
i.peerActions[c] = i.peerActions[c] || {};
|
||||||
|
|
@ -235,14 +238,14 @@ TxProposals.prototype.getTxProposal = function(ntxid, copayers) {
|
||||||
//returns the unspent txid-vout used in PENDING Txs
|
//returns the unspent txid-vout used in PENDING Txs
|
||||||
TxProposals.prototype.getUsedUnspent = function(maxRejectCount) {
|
TxProposals.prototype.getUsedUnspent = function(maxRejectCount) {
|
||||||
var ret = {};
|
var ret = {};
|
||||||
for(var i in this.txps) {
|
for (var i in this.txps) {
|
||||||
var u = this.txps[i].builder.getSelectedUnspent();
|
var u = this.txps[i].builder.getSelectedUnspent();
|
||||||
var p = this.getTxProposal(i);
|
var p = this.getTxProposal(i);
|
||||||
if (p.rejectCount>maxRejectCount || p.sentTxid)
|
if (p.rejectCount > maxRejectCount || p.sentTxid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (var j in u) {
|
for (var j in u) {
|
||||||
ret[u[j].txid + ',' + u[j].vout]=1;
|
ret[u[j].txid + ',' + u[j].vout] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -255,10 +258,10 @@ TxProposals.prototype.merge = function(t) {
|
||||||
var res = [];
|
var res = [];
|
||||||
var hasChanged = 0;
|
var hasChanged = 0;
|
||||||
|
|
||||||
var myTxps = this.txps;
|
var myTxps = this.txps;
|
||||||
var theirTxps = t.txps;
|
var theirTxps = t.txps;
|
||||||
|
|
||||||
var mergeInfo = this._startMerge(myTxps, theirTxps);
|
var mergeInfo = this._startMerge(myTxps, theirTxps);
|
||||||
hasChanged += this._mergeMetadata(myTxps, theirTxps, mergeInfo);
|
hasChanged += this._mergeMetadata(myTxps, theirTxps, mergeInfo);
|
||||||
hasChanged += this._mergeBuilder(myTxps, theirTxps, mergeInfo);
|
hasChanged += this._mergeBuilder(myTxps, theirTxps, mergeInfo);
|
||||||
|
|
||||||
|
|
@ -268,7 +271,7 @@ TxProposals.prototype.merge = function(t) {
|
||||||
|
|
||||||
mergeInfo.stats.hasChanged = hasChanged;
|
mergeInfo.stats.hasChanged = hasChanged;
|
||||||
|
|
||||||
this.txps=mergeInfo.ready;
|
this.txps = mergeInfo.ready;
|
||||||
return mergeInfo.stats;
|
return mergeInfo.stats;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,9 +89,9 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
||||||
var wasIncomplete = !this.publicKeyRing.isComplete();
|
var wasIncomplete = !this.publicKeyRing.isComplete();
|
||||||
var hasChanged;
|
var hasChanged;
|
||||||
|
|
||||||
try{
|
try {
|
||||||
hasChanged = this.publicKeyRing.merge(inPKR, true);
|
hasChanged = this.publicKeyRing.merge(inPKR, true);
|
||||||
} catch (e){
|
} catch (e) {
|
||||||
this.log('## WALLET ERROR', e); //TODO
|
this.log('## WALLET ERROR', e); //TODO
|
||||||
this.emit('connectionError', e.message);
|
this.emit('connectionError', e.message);
|
||||||
return;
|
return;
|
||||||
|
|
@ -281,7 +281,7 @@ Wallet.prototype.scheduleConnect = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (self.network.isOnline()) {
|
if (self.network.isOnline()) {
|
||||||
self.connectToAll();
|
self.connectToAll();
|
||||||
self.currentDelay = self.currentDelay*2 || self.reconnectDelay;
|
self.currentDelay = self.currentDelay * 2 || self.reconnectDelay;
|
||||||
setTimeout(self.scheduleConnect.bind(self), self.currentDelay);
|
setTimeout(self.scheduleConnect.bind(self), self.currentDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -329,7 +329,7 @@ Wallet.prototype.toObj = function() {
|
||||||
opts: optsObj,
|
opts: optsObj,
|
||||||
publicKeyRing: this.publicKeyRing.toObj(),
|
publicKeyRing: this.publicKeyRing.toObj(),
|
||||||
txProposals: this.txProposals.toObj(),
|
txProposals: this.txProposals.toObj(),
|
||||||
privateKey: this.privateKey?this.privateKey.toObj():undefined
|
privateKey: this.privateKey ? this.privateKey.toObj() : undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
return walletObj;
|
return walletObj;
|
||||||
|
|
@ -454,7 +454,7 @@ Wallet.prototype.reject = function(ntxid) {
|
||||||
var myId = this.getMyCopayerId();
|
var myId = this.getMyCopayerId();
|
||||||
var txp = this.txProposals.txps[ntxid];
|
var txp = this.txProposals.txps[ntxid];
|
||||||
if (!txp || txp.rejectedBy[myId] || txp.signedBy[myId]) {
|
if (!txp || txp.rejectedBy[myId] || txp.signedBy[myId]) {
|
||||||
throw new Error('Invalid transaction to reject: '+ntxid);
|
throw new Error('Invalid transaction to reject: ' + ntxid);
|
||||||
}
|
}
|
||||||
|
|
||||||
txp.rejectedBy[myId] = Date.now();
|
txp.rejectedBy[myId] = Date.now();
|
||||||
|
|
@ -562,11 +562,12 @@ Wallet.prototype.addressIsOwn = function(addrStr, opts) {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//retunrs values in SATOSHIs
|
||||||
Wallet.prototype.getBalance = function(cb) {
|
Wallet.prototype.getBalance = function(cb) {
|
||||||
var balance = 0;
|
var balance = 0;
|
||||||
var safeBalance = 0;
|
var safeBalance = 0;
|
||||||
var balanceByAddr = {};
|
var balanceByAddr = {};
|
||||||
var COIN = bitcore.util.COIN;
|
var COIN = coinUtil.COIN;
|
||||||
|
|
||||||
this.getUnspent(function(err, safeUnspent, unspent) {
|
this.getUnspent(function(err, safeUnspent, unspent) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -580,11 +581,12 @@ Wallet.prototype.getBalance = function(cb) {
|
||||||
balanceByAddr[u.address] = (balanceByAddr[u.address] || 0) + amt;
|
balanceByAddr[u.address] = (balanceByAddr[u.address] || 0) + amt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we multiply and divide by COIN to avoid rounding errors when adding
|
// we multiply and divide by BIT to avoid rounding errors when adding
|
||||||
for (var a in balanceByAddr) {
|
for (var a in balanceByAddr) {
|
||||||
balanceByAddr[a] = balanceByAddr[a].toFixed(0) / COIN;
|
balanceByAddr[a] = parseInt(balanceByAddr[a].toFixed(0));
|
||||||
}
|
}
|
||||||
balance = balance / COIN;
|
|
||||||
|
balance = parseInt(balance.toFixed(0));
|
||||||
|
|
||||||
for (var i = 0; i < safeUnspent.length; i++) {
|
for (var i = 0; i < safeUnspent.length; i++) {
|
||||||
var u = safeUnspent[i];
|
var u = safeUnspent[i];
|
||||||
|
|
@ -592,7 +594,7 @@ Wallet.prototype.getBalance = function(cb) {
|
||||||
safeBalance += amt;
|
safeBalance += amt;
|
||||||
}
|
}
|
||||||
|
|
||||||
safeBalance = safeBalance.toFixed(0) / COIN;
|
safeBalance = parseInt(safeBalance.toFixed(0));
|
||||||
return cb(null, balance, balanceByAddr, safeBalance);
|
return cb(null, balance, balanceByAddr, safeBalance);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -610,8 +612,8 @@ Wallet.prototype.getUnspent = function(cb) {
|
||||||
var uu = self.txProposals.getUsedUnspent(maxRejectCount);
|
var uu = self.txProposals.getUsedUnspent(maxRejectCount);
|
||||||
|
|
||||||
for (var i in unspentList) {
|
for (var i in unspentList) {
|
||||||
var u=unspentList[i];
|
var u = unspentList[i];
|
||||||
if (! uu[u.txid +','+u.vout])
|
if (!uu[u.txid + ',' + u.vout])
|
||||||
safeUnspendList.push(u);
|
safeUnspendList.push(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
var bitcore = require('bitcore');
|
||||||
|
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('controllerUtils', function($rootScope, $sce, $location, $notification, Socket, video) {
|
.factory('controllerUtils', function($rootScope, $sce, $location, $notification, $timeout, Socket, video) {
|
||||||
var root = {};
|
var root = {};
|
||||||
var bitcore = require('bitcore');
|
|
||||||
|
|
||||||
root.getVideoMutedStatus = function(copayer) {
|
root.getVideoMutedStatus = function(copayer) {
|
||||||
var vi = $rootScope.videoInfo[copayer]
|
var vi = $rootScope.videoInfo[copayer]
|
||||||
|
|
@ -39,9 +39,42 @@ angular.module('copayApp.services')
|
||||||
message: msg
|
message: msg
|
||||||
};
|
};
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
}
|
};
|
||||||
|
|
||||||
|
root.installStartupHandlers = function(wallet, $scope) {
|
||||||
|
wallet.on('serverError', function(msg) {
|
||||||
|
$rootScope.$flashMessage = {
|
||||||
|
message: 'There was an error connecting to the PeerJS server.' + (msg || 'Check you settings and Internet connection.'),
|
||||||
|
type: 'error',
|
||||||
|
};
|
||||||
|
root.onErrorDigest($scope);
|
||||||
|
$location.path('addresses');
|
||||||
|
});
|
||||||
|
wallet.on('connectionError', function() {
|
||||||
|
var message = "Looks like you are already connected to this wallet, please logout from it and try importing it again.";
|
||||||
|
$rootScope.$flashMessage = {
|
||||||
|
message: message,
|
||||||
|
type: 'error'
|
||||||
|
};
|
||||||
|
root.onErrorDigest($scope);
|
||||||
|
});
|
||||||
|
wallet.on('serverError', function() {
|
||||||
|
$rootScope.$flashMessage = {
|
||||||
|
message: 'The PeerJS server is not responding, please try again',
|
||||||
|
type: 'error'
|
||||||
|
};
|
||||||
|
root.onErrorDigest($scope);
|
||||||
|
});
|
||||||
|
wallet.on('ready', function() {
|
||||||
|
$scope.loading = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
root.startNetwork = function(w, $scope) {
|
||||||
|
|
||||||
|
root.installStartupHandlers(w, $scope);
|
||||||
|
|
||||||
root.startNetwork = function(w) {
|
|
||||||
var handlePeerVideo = function(err, peerID, url) {
|
var handlePeerVideo = function(err, peerID, url) {
|
||||||
if (err) {
|
if (err) {
|
||||||
delete $rootScope.videoInfo[peerID];
|
delete $rootScope.videoInfo[peerID];
|
||||||
|
|
@ -77,12 +110,17 @@ angular.module('copayApp.services')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
w.on('txProposalsUpdated', function(dontDigest) {
|
w.on('txProposalsUpdated', function(dontDigest) {
|
||||||
root.updateTxs({onlyPending:true});
|
root.updateTxs({
|
||||||
root.updateBalance(function(){
|
onlyPending: true
|
||||||
if (!dontDigest) {
|
|
||||||
$rootScope.$digest();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
// give sometime to the tx to propagate.
|
||||||
|
$timeout(function() {
|
||||||
|
root.updateBalance(function() {
|
||||||
|
if (!dontDigest) {
|
||||||
|
$rootScope.$digest();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 3000);
|
||||||
});
|
});
|
||||||
w.on('connectionError', function(msg) {
|
w.on('connectionError', function(msg) {
|
||||||
root.onErrorDigest(null, msg);
|
root.onErrorDigest(null, msg);
|
||||||
|
|
@ -109,25 +147,33 @@ angular.module('copayApp.services')
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
if (!w) return root.onErrorDigest();
|
if (!w) return root.onErrorDigest();
|
||||||
|
|
||||||
|
|
||||||
$rootScope.balanceByAddr = {};
|
$rootScope.balanceByAddr = {};
|
||||||
$rootScope.updatingBalance = true;
|
$rootScope.updatingBalance = true;
|
||||||
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
|
||||||
|
w.getBalance(function(err, balanceSat, balanceByAddrSat, safeBalanceSat) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error: ' + err.message); //TODO
|
console.error('Error: ' + err.message); //TODO
|
||||||
root._setCommError();
|
root._setCommError();
|
||||||
return null;
|
return null;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
root._clearCommError();
|
root._clearCommError();
|
||||||
}
|
}
|
||||||
|
|
||||||
$rootScope.totalBalance = balance;
|
var satToUnit = 1 / config.unitToSatoshi;
|
||||||
|
var COIN = bitcore.util.COIN;
|
||||||
|
|
||||||
|
$rootScope.totalBalance = balanceSat * satToUnit;
|
||||||
|
$rootScope.totalBalanceBTC = (balanceSat / COIN).toFixed(4);
|
||||||
|
$rootScope.availableBalance = safeBalanceSat * satToUnit;
|
||||||
|
$rootScope.availableBalanceBTC = (safeBalanceSat / COIN).toFixed(4);
|
||||||
|
var balanceByAddr = {};
|
||||||
|
for (var ii in balanceByAddrSat) {
|
||||||
|
balanceByAddr[ii] = balanceByAddrSat[ii] * satToUnit;
|
||||||
|
}
|
||||||
$rootScope.balanceByAddr = balanceByAddr;
|
$rootScope.balanceByAddr = balanceByAddr;
|
||||||
$rootScope.availableBalance = safeBalance;
|
|
||||||
root.updateAddressList();
|
root.updateAddressList();
|
||||||
$rootScope.updatingBalance = false;
|
$rootScope.updatingBalance = false;
|
||||||
return cb?cb():null;
|
return cb ? cb() : null;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -136,12 +182,15 @@ angular.module('copayApp.services')
|
||||||
if (!w) return;
|
if (!w) return;
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
|
var satToUnit = 1 / config.unitToSatoshi;
|
||||||
var myCopayerId = w.getMyCopayerId();
|
var myCopayerId = w.getMyCopayerId();
|
||||||
var pendingForUs = 0;
|
var pendingForUs = 0;
|
||||||
var inT = w.getTxProposals().sort(function(t1, t2) { return t2.createdTs - t1.createdTs });
|
var inT = w.getTxProposals().sort(function(t1, t2) {
|
||||||
var txs = [];
|
return t2.createdTs - t1.createdTs
|
||||||
|
});
|
||||||
|
var txs = [];
|
||||||
|
|
||||||
inT.forEach(function(i, index){
|
inT.forEach(function(i, index) {
|
||||||
if (opts.skip && (index < opts.skip[0] || index >= opts.skip[1])) {
|
if (opts.skip && (index < opts.skip[0] || index >= opts.skip[1])) {
|
||||||
return txs.push(null);
|
return txs.push(null);
|
||||||
}
|
}
|
||||||
|
|
@ -150,23 +199,25 @@ angular.module('copayApp.services')
|
||||||
pendingForUs++;
|
pendingForUs++;
|
||||||
}
|
}
|
||||||
if (!i.finallyRejected && !i.sentTs) {
|
if (!i.finallyRejected && !i.sentTs) {
|
||||||
i.isPending=1;
|
i.isPending = 1;
|
||||||
}
|
}
|
||||||
if (!opts.onlyPending || i.isPending) {
|
if (!opts.onlyPending || i.isPending) {
|
||||||
var tx = i.builder.build();
|
var tx = i.builder.build();
|
||||||
var outs = [];
|
var outs = [];
|
||||||
tx.outs.forEach(function(o) {
|
tx.outs.forEach(function(o) {
|
||||||
var addr = bitcore.Address.fromScriptPubKey(o.getScript(), config.networkName)[0].toString();
|
var addr = bitcore.Address.fromScriptPubKey(o.getScript(), config.networkName)[0].toString();
|
||||||
if (!w.addressIsOwn(addr, {excludeMain:true})) {
|
if (!w.addressIsOwn(addr, {
|
||||||
|
excludeMain: true
|
||||||
|
})) {
|
||||||
outs.push({
|
outs.push({
|
||||||
address: addr,
|
address: addr,
|
||||||
value: bitcore.util.valueToBigInt(o.getValue())/bitcore.util.COIN,
|
value: bitcore.util.valueToBigInt(o.getValue()) * satToUnit,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// extra fields
|
// extra fields
|
||||||
i.outs = outs;
|
i.outs = outs;
|
||||||
i.fee = i.builder.feeSat/bitcore.util.COIN;
|
i.fee = i.builder.feeSat * satToUnit;
|
||||||
i.missingSignatures = tx.countInputMissingSignatures(0);
|
i.missingSignatures = tx.countInputMissingSignatures(0);
|
||||||
txs.push(i);
|
txs.push(i);
|
||||||
}
|
}
|
||||||
|
|
@ -180,17 +231,17 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root._setCommError = function(e) {
|
root._setCommError = function(e) {
|
||||||
if ($rootScope.insightError<0)
|
if ($rootScope.insightError < 0)
|
||||||
$rootScope.insightError=0;
|
$rootScope.insightError = 0;
|
||||||
$rootScope.insightError++;
|
$rootScope.insightError++;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
root._clearCommError = function(e) {
|
root._clearCommError = function(e) {
|
||||||
if ($rootScope.insightError>0)
|
if ($rootScope.insightError > 0)
|
||||||
$rootScope.insightError=-1;
|
$rootScope.insightError = -1;
|
||||||
else
|
else
|
||||||
$rootScope.insightError=0;
|
$rootScope.insightError = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setSocketHandlers = function() {
|
root.setSocketHandlers = function() {
|
||||||
|
|
@ -200,16 +251,16 @@ angular.module('copayApp.services')
|
||||||
Socket.sysOn('reconnect_failed', root._setCommError);
|
Socket.sysOn('reconnect_failed', root._setCommError);
|
||||||
Socket.sysOn('connect', root._clearCommError);
|
Socket.sysOn('connect', root._clearCommError);
|
||||||
Socket.sysOn('reconnect', root._clearCommError);
|
Socket.sysOn('reconnect', root._clearCommError);
|
||||||
Socket.sysEventsSet=true;
|
Socket.sysEventsSet = true;
|
||||||
}
|
}
|
||||||
if (!$rootScope.wallet) return;
|
if (!$rootScope.wallet) return;
|
||||||
|
|
||||||
var currentAddrs= Socket.getListeners();
|
var currentAddrs = Socket.getListeners();
|
||||||
var addrs = $rootScope.wallet.getAddressesStr();
|
var addrs = $rootScope.wallet.getAddressesStr();
|
||||||
|
|
||||||
var newAddrs=[];
|
var newAddrs = [];
|
||||||
for(var i in addrs){
|
for (var i in addrs) {
|
||||||
var a=addrs[i];
|
var a = addrs[i];
|
||||||
if (!currentAddrs[a])
|
if (!currentAddrs[a])
|
||||||
newAddrs.push(a);
|
newAddrs.push(a);
|
||||||
}
|
}
|
||||||
|
|
@ -219,7 +270,7 @@ angular.module('copayApp.services')
|
||||||
newAddrs.forEach(function(addr) {
|
newAddrs.forEach(function(addr) {
|
||||||
Socket.on(addr, function(txid) {
|
Socket.on(addr, function(txid) {
|
||||||
$rootScope.receivedFund = [txid, addr];
|
$rootScope.receivedFund = [txid, addr];
|
||||||
root.updateBalance(function(){
|
root.updateBalance(function() {
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,11 @@ module.exports = function(config) {
|
||||||
'lib/chai/chai.js',
|
'lib/chai/chai.js',
|
||||||
'test/lib/chai-should.js',
|
'test/lib/chai-should.js',
|
||||||
'test/lib/chai-expect.js',
|
'test/lib/chai-expect.js',
|
||||||
|
'test/mocks/FakeWallet.js',
|
||||||
|
|
||||||
//Mocha stuff
|
//Mocha stuff
|
||||||
'test/mocha.conf.js',
|
'test/mocha.conf.js',
|
||||||
|
|
||||||
|
|
||||||
//App-specific Code
|
//App-specific Code
|
||||||
'js/app.js',
|
'js/app.js',
|
||||||
'js/routes.js',
|
'js/routes.js',
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
var copay = require('copay');
|
var copay = require('copay');
|
||||||
</script>
|
</script>
|
||||||
<script src="test.blockchain.Insight.js"></script>
|
<script src="test.blockchain.Insight.js"></script>
|
||||||
<script src="test.performance.js"></script>
|
|
||||||
<script src="test.PrivateKey.js"></script>
|
<script src="test.PrivateKey.js"></script>
|
||||||
<script src="test.PublicKeyRing.js"></script>
|
<script src="test.PublicKeyRing.js"></script>
|
||||||
<script src="test.storage.LocalEncrypted.js"></script>
|
<script src="test.storage.LocalEncrypted.js"></script>
|
||||||
|
|
@ -26,6 +25,7 @@
|
||||||
<script src="test.TxProposals.js"></script>
|
<script src="test.TxProposals.js"></script>
|
||||||
<script src="test.Wallet.js"></script>
|
<script src="test.Wallet.js"></script>
|
||||||
<script src="test.Walletfactory.js"></script>
|
<script src="test.Walletfactory.js"></script>
|
||||||
|
<script src="test.performance.js"></script>
|
||||||
<!--
|
<!--
|
||||||
-->
|
-->
|
||||||
<script>
|
<script>
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ FakeBlockchain.prototype.getTransactions = function(addresses, cb) {
|
||||||
|
|
||||||
FakeBlockchain.prototype.fixUnspent = function(u) {
|
FakeBlockchain.prototype.fixUnspent = function(u) {
|
||||||
this.u = u;
|
this.u = u;
|
||||||
}
|
};
|
||||||
|
|
||||||
FakeBlockchain.prototype.getUnspent = function(addresses, cb) {
|
FakeBlockchain.prototype.getUnspent = function(addresses, cb) {
|
||||||
if (!addresses || !addresses.length) return cb(null, []);
|
if (!addresses || !addresses.length) return cb(null, []);
|
||||||
|
|
|
||||||
34
test/mocks/FakeWallet.js
Normal file
34
test/mocks/FakeWallet.js
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
|
||||||
|
var FakeWallet = function(){
|
||||||
|
this.balance=10000;
|
||||||
|
this.safeBalance=1000;
|
||||||
|
this.balanceByAddr={'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000};
|
||||||
|
};
|
||||||
|
|
||||||
|
FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr){
|
||||||
|
this.balance=balance;
|
||||||
|
this.safeBalance = safeBalance;
|
||||||
|
this.balanceByAddr = balanceByAddr;
|
||||||
|
};
|
||||||
|
|
||||||
|
FakeWallet.prototype.getAddressesInfo=function(){
|
||||||
|
var ret = [];
|
||||||
|
|
||||||
|
for(var ii in this.balanceByAddr){
|
||||||
|
ret.push({
|
||||||
|
address: ii,
|
||||||
|
isChange: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
FakeWallet.prototype.getBalance=function(cb){
|
||||||
|
return cb(null, this.balance, this.balanceByAddr, this.safeBalance);
|
||||||
|
};
|
||||||
|
|
||||||
|
// This mock is meant for karma, module.exports is not necesary.
|
||||||
|
try {
|
||||||
|
module.exports = require('soop')(FakeWallet);
|
||||||
|
} catch (e) {}
|
||||||
|
|
@ -308,15 +308,21 @@ describe('TxProposals model', function() {
|
||||||
|
|
||||||
it('#merge, merge signatures case 2', function() {
|
it('#merge, merge signatures case 2', function() {
|
||||||
|
|
||||||
var o1 ={ extendedPrivateKeyString: 'tprv8ZgxMBicQKsPdSF1avR6mXyDj5Uv1XY2UyUHSDpAXQ5TvPN7prGeDppjy4562rBB9gMMAhRfFdJrNDpQ4t69kkqHNEEen3PX1zBJqSehJDH',
|
var o1 = {
|
||||||
networkName: 'testnet',
|
extendedPrivateKeyString: 'tprv8ZgxMBicQKsPdSF1avR6mXyDj5Uv1XY2UyUHSDpAXQ5TvPN7prGeDppjy4562rBB9gMMAhRfFdJrNDpQ4t69kkqHNEEen3PX1zBJqSehJDH',
|
||||||
privateKeyCache: {} };
|
networkName: 'testnet',
|
||||||
var o2 ={ extendedPrivateKeyString: 'tprv8ZgxMBicQKsPdVeB5RzuxS9JQcACueZYgUaM5eWzaEBkHjW5Pg6Mqez1APSqoUP1jUdbT8WVG7ZJYTXvUL7XtPzFYBXjmdKuwSor1dcNQ8j',
|
privateKeyCache: {}
|
||||||
networkName: 'testnet',
|
};
|
||||||
privateKeyCache: {} };
|
var o2 = {
|
||||||
var o3 ={ extendedPrivateKeyString: 'tprv8ZgxMBicQKsPeHWNrPVZtQVgcCtXBr5TACNbDQ56rwqNJce9MEc64US6DJKxpWsrebEomxxWZFDtkvkZGkzA43uLvdF4XHiWqoNaL6Dq2Gd',
|
extendedPrivateKeyString: 'tprv8ZgxMBicQKsPdVeB5RzuxS9JQcACueZYgUaM5eWzaEBkHjW5Pg6Mqez1APSqoUP1jUdbT8WVG7ZJYTXvUL7XtPzFYBXjmdKuwSor1dcNQ8j',
|
||||||
networkName: 'testnet',
|
networkName: 'testnet',
|
||||||
privateKeyCache: {} };
|
privateKeyCache: {}
|
||||||
|
};
|
||||||
|
var o3 = {
|
||||||
|
extendedPrivateKeyString: 'tprv8ZgxMBicQKsPeHWNrPVZtQVgcCtXBr5TACNbDQ56rwqNJce9MEc64US6DJKxpWsrebEomxxWZFDtkvkZGkzA43uLvdF4XHiWqoNaL6Dq2Gd',
|
||||||
|
networkName: 'testnet',
|
||||||
|
privateKeyCache: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var priv = PrivateKey.fromObj(o1);
|
var priv = PrivateKey.fromObj(o1);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ describe('Wallet model', function() {
|
||||||
(function() {
|
(function() {
|
||||||
new Wallet(config)
|
new Wallet(config)
|
||||||
}).should.
|
}).should.
|
||||||
throw ();
|
throw();
|
||||||
});
|
});
|
||||||
|
|
||||||
var createW = function(netKey, N) {
|
var createW = function(netKey, N) {
|
||||||
|
|
@ -111,7 +111,7 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
var pkr = w.publicKeyRing;
|
var pkr = w.publicKeyRing;
|
||||||
|
|
||||||
for (var i = 0; i < N-1; i++) {
|
for (var i = 0; i < N - 1; i++) {
|
||||||
if (privateKeys) {
|
if (privateKeys) {
|
||||||
var k = privateKeys[i];
|
var k = privateKeys[i];
|
||||||
pkr.addCopayer(k ? k.deriveBIP45Branch().extendedPublicKeyString() : null);
|
pkr.addCopayer(k ? k.deriveBIP45Branch().extendedPublicKeyString() : null);
|
||||||
|
|
@ -246,7 +246,7 @@ describe('Wallet model', function() {
|
||||||
o = JSON.parse(JSON.stringify(o));
|
o = JSON.parse(JSON.stringify(o));
|
||||||
|
|
||||||
// non stored options
|
// non stored options
|
||||||
o.opts.reconnectDelay=100;
|
o.opts.reconnectDelay = 100;
|
||||||
|
|
||||||
var w2 = Wallet.fromObj(o,
|
var w2 = Wallet.fromObj(o,
|
||||||
new Storage(config.storage),
|
new Storage(config.storage),
|
||||||
|
|
@ -275,15 +275,15 @@ describe('Wallet model', function() {
|
||||||
(function() {
|
(function() {
|
||||||
Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoKM');
|
Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoKM');
|
||||||
}).should.not.
|
}).should.not.
|
||||||
throw ();
|
throw();
|
||||||
(function() {
|
(function() {
|
||||||
Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoK');
|
Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoK');
|
||||||
}).should.
|
}).should.
|
||||||
throw ();
|
throw();
|
||||||
(function() {
|
(function() {
|
||||||
Wallet.decodeSecret('12345');
|
Wallet.decodeSecret('12345');
|
||||||
}).should.
|
}).should.
|
||||||
throw ();
|
throw();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('call reconnect after interval', function(done) {
|
it('call reconnect after interval', function(done) {
|
||||||
|
|
@ -440,9 +440,69 @@ describe('Wallet model', function() {
|
||||||
r.length.should.equal(2);
|
r.length.should.equal(2);
|
||||||
r[0].should.not.equal(r[1]);
|
r[0].should.not.equal(r[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('#getBalance should call #getUnspent', function(done) {
|
||||||
|
var w = createW2();
|
||||||
|
var spy = sinon.spy(w.blockchain, 'getUnspent');
|
||||||
|
w.generateAddress();
|
||||||
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||||
|
sinon.assert.callCount(spy, 1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('#getBalance should return values in satoshis', function(done) {
|
||||||
|
var w = createW2();
|
||||||
|
w.generateAddress();
|
||||||
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||||
|
balance.should.equal(2500010000);
|
||||||
|
safeBalance.should.equal(2500010000);
|
||||||
|
balanceByAddr.mji7zocy8QzYywQakwWf99w9bCT6orY1C1.should.equal(2500010000);
|
||||||
|
Object.keys(balanceByAddr).length.should.equal(1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var roundErrorChecks = [{
|
||||||
|
unspent: [1.0001],
|
||||||
|
balance: 100010000
|
||||||
|
}, {
|
||||||
|
unspent: [1.0002, 1.0003, 1.0004],
|
||||||
|
balance: 300090000
|
||||||
|
}, {
|
||||||
|
unspent: [0.000002, 1.000003, 2.000004],
|
||||||
|
balance: 300000900
|
||||||
|
}, {
|
||||||
|
unspent: [0.0001, 0.0003],
|
||||||
|
balance: 40000
|
||||||
|
}, {
|
||||||
|
unspent: [0.0001, 0.0003, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0002],
|
||||||
|
balance: 110000
|
||||||
|
},
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
roundErrorChecks.forEach(function(c) {
|
||||||
|
it('check rounding errors ' + c.unspent[0], function(done) {
|
||||||
|
var w = createW2();
|
||||||
|
w.generateAddress();
|
||||||
|
w.blockchain.fixUnspent(c.unspent.map(function(u) {
|
||||||
|
return {
|
||||||
|
amount: u
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||||
|
balance.should.equal(c.balance);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should get balance', function(done) {
|
it('should get balance', function(done) {
|
||||||
var w = createW();
|
var w = createW();
|
||||||
|
var spy = sinon.spy(w.blockchain, 'getUnspent');
|
||||||
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||||
|
sinon.assert.callCount(spy, 1);
|
||||||
balance.should.equal(0);
|
balance.should.equal(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
if (typeof process === 'undefined' || !process.version) {
|
if (typeof process === 'undefined' || !process.version) {
|
||||||
// browser
|
// browser
|
||||||
var chai = chai || require('chai');
|
var chai = chai || require('chai');
|
||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
var copay = copay || require('../copay');
|
var copay = copay || require('../copay');
|
||||||
var LocalPlain = copay.StorageLocalPlain;
|
var LocalPlain = copay.StorageLocalPlain;
|
||||||
|
|
||||||
describe('Storage/LocalPlain model', function() {
|
describe.skip('Storage/LocalPlain model', function() {
|
||||||
|
|
||||||
it('should create an instance', function () {
|
it('should create an instance', function() {
|
||||||
var s = new LocalPlain();
|
var s = new LocalPlain();
|
||||||
should.exist(s);
|
should.exist(s);
|
||||||
});
|
});
|
||||||
|
|
@ -17,7 +17,12 @@ if (typeof process === 'undefined' || !process.version) {
|
||||||
describe('#setFromObj', function() {
|
describe('#setFromObj', function() {
|
||||||
it('should set keys from an object', function() {
|
it('should set keys from an object', function() {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
var obj = {test:'testval', opts: {name: 'testname'}};
|
var obj = {
|
||||||
|
test: 'testval',
|
||||||
|
opts: {
|
||||||
|
name: 'testname'
|
||||||
|
}
|
||||||
|
};
|
||||||
var storage = new LocalPlain();
|
var storage = new LocalPlain();
|
||||||
storage.setFromObj('walletId', obj);
|
storage.setFromObj('walletId', obj);
|
||||||
storage.get('walletId', 'test').should.equal('testval');
|
storage.get('walletId', 'test').should.equal('testval');
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ describe("Unit: Controllers", function() {
|
||||||
expect(rootScope.insightError).equal(1);
|
expect(rootScope.insightError).equal(1);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,14 @@ describe("Unit: Testing Directives", function() {
|
||||||
|
|
||||||
beforeEach(module('copayApp.directives'));
|
beforeEach(module('copayApp.directives'));
|
||||||
|
|
||||||
|
|
||||||
|
describe('Check config', function() {
|
||||||
|
it('unit should be set to BITS in config.js', function() {
|
||||||
|
expect(config.unitToSatoshi).to.equal(100);
|
||||||
|
expect(config.unitName).to.equal('bits');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Validate Address', function() {
|
describe('Validate Address', function() {
|
||||||
beforeEach(inject(function($compile, $rootScope) {
|
beforeEach(inject(function($compile, $rootScope) {
|
||||||
$scope = $rootScope;
|
$scope = $rootScope;
|
||||||
|
|
@ -15,8 +23,10 @@ describe("Unit: Testing Directives", function() {
|
||||||
'<form name="form">' +
|
'<form name="form">' +
|
||||||
'<input type="text" id="address" name="address" placeholder="Send to" ng-model="address" valid-address required>' +
|
'<input type="text" id="address" name="address" placeholder="Send to" ng-model="address" valid-address required>' +
|
||||||
'</form>'
|
'</form>'
|
||||||
);
|
);
|
||||||
$scope.model = { address: null };
|
$scope.model = {
|
||||||
|
address: null
|
||||||
|
};
|
||||||
$compile(element)($scope);
|
$compile(element)($scope);
|
||||||
$scope.$digest();
|
$scope.$digest();
|
||||||
form = $scope.form;
|
form = $scope.form;
|
||||||
|
|
@ -35,42 +45,47 @@ describe("Unit: Testing Directives", function() {
|
||||||
describe('Validate Amount', function() {
|
describe('Validate Amount', function() {
|
||||||
beforeEach(inject(function($compile, $rootScope) {
|
beforeEach(inject(function($compile, $rootScope) {
|
||||||
$scope = $rootScope;
|
$scope = $rootScope;
|
||||||
$rootScope.availableBalance = 0.101;
|
$rootScope.availableBalance = 1000;
|
||||||
var element = angular.element(
|
var element = angular.element(
|
||||||
'<form name="form">' +
|
'<form name="form">' +
|
||||||
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
||||||
'</form>'
|
'</form>'
|
||||||
);
|
);
|
||||||
$scope.model = { amount: null };
|
$scope.model = {
|
||||||
|
amount: null
|
||||||
|
};
|
||||||
$compile(element)($scope);
|
$compile(element)($scope);
|
||||||
$scope.$digest();
|
$scope.$digest();
|
||||||
form = $scope.form;
|
form = $scope.form;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it('should validate', function() {
|
it('should validate', function() {
|
||||||
form.amount.$setViewValue(0.1);
|
form.amount.$setViewValue(100);
|
||||||
expect(form.amount.$invalid).to.equal(false);
|
expect(form.amount.$invalid).to.equal(false);
|
||||||
form.amount.$setViewValue(0.1009);
|
form.amount.$setViewValue(900);
|
||||||
expect(form.amount.$invalid).to.equal(false);
|
expect(form.amount.$invalid).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not validate', function() {
|
it('should not validate', function() {
|
||||||
form.amount.$setViewValue(0);
|
form.amount.$setViewValue(0);
|
||||||
expect(form.amount.$invalid).to.equal(true);
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
form.amount.$setViewValue(9999999999);
|
form.amount.$setViewValue(9999999999);
|
||||||
expect(form.amount.$invalid).to.equal(true);
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
form.amount.$setViewValue(2.1);
|
form.amount.$setViewValue(901);
|
||||||
expect(form.amount.$invalid).to.equal(true);
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
form.amount.$setViewValue(0.10091);
|
form.amount.$setViewValue(1000);
|
||||||
expect(form.amount.$invalid).to.equal(true);
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Password strength', function() {
|
describe('Password strength', function() {
|
||||||
beforeEach(inject(function($compile, $rootScope) {
|
beforeEach(inject(function($compile, $rootScope) {
|
||||||
$scope = $rootScope;
|
$scope = $rootScope;
|
||||||
var element = angular.element(
|
var element = angular.element(
|
||||||
'<input type="password" name="password" ng-model="password" check-strength="passwordStrength" value="asd" required>'
|
'<input type="password" name="password" ng-model="password" check-strength="passwordStrength" value="asd" required>'
|
||||||
);
|
);
|
||||||
$compile(element)($scope);
|
$compile(element)($scope);
|
||||||
$scope.$digest();
|
$scope.$digest();
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,17 @@
|
||||||
//
|
//
|
||||||
// test/unit/services/servicesSpec.js
|
// test/unit/services/servicesSpec.js
|
||||||
//
|
//
|
||||||
describe("Unit: Testing Services", function() {
|
//
|
||||||
|
//
|
||||||
|
describe('Check config', function() {
|
||||||
|
it('unit should be set to BITS in config.js', function() {
|
||||||
|
expect(config.unitToSatoshi).to.equal(100);
|
||||||
|
expect(config.unitName).to.equal('bits');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe("Unit: Socket Service", function() {
|
||||||
beforeEach(angular.mock.module('copayApp.services'));
|
beforeEach(angular.mock.module('copayApp.services'));
|
||||||
|
|
||||||
it('should contain a Socket service', inject(function(Socket) {
|
it('should contain a Socket service', inject(function(Socket) {
|
||||||
|
|
@ -17,13 +26,13 @@ describe("Unit: Testing Services", function() {
|
||||||
|
|
||||||
it('Socket should support #sysOn', inject(function(Socket) {
|
it('Socket should support #sysOn', inject(function(Socket) {
|
||||||
expect(Socket.sysOn).to.be.a('function');
|
expect(Socket.sysOn).to.be.a('function');
|
||||||
}))
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('Socket should add handlers with #on', inject(function(Socket) {
|
it('Socket should add handlers with #on', inject(function(Socket) {
|
||||||
Socket.on('a', function (){});
|
Socket.on('a', function() {});
|
||||||
Socket.on('b', function (){});
|
Socket.on('b', function() {});
|
||||||
Socket.sysOn('c', function (){});
|
Socket.sysOn('c', function() {});
|
||||||
var ret = Socket.getListeners();
|
var ret = Socket.getListeners();
|
||||||
expect(ret.a).to.be.equal(1);
|
expect(ret.a).to.be.equal(1);
|
||||||
expect(ret.b).to.be.equal(1);
|
expect(ret.b).to.be.equal(1);
|
||||||
|
|
@ -31,28 +40,50 @@ describe("Unit: Testing Services", function() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('Socket should support #removeAllListeners', inject(function(Socket) {
|
it('Socket should support #removeAllListeners', inject(function(Socket) {
|
||||||
Socket.on('a', function (){});
|
Socket.on('a', function() {});
|
||||||
Socket.on('b', function (){});
|
Socket.on('b', function() {});
|
||||||
Socket.sysOn('c', function (){});
|
Socket.sysOn('c', function() {});
|
||||||
var ret = Socket.getListeners();
|
var ret = Socket.getListeners();
|
||||||
expect(Object.keys(ret)).to.have.length(2);
|
expect(Object.keys(ret)).to.have.length(2);
|
||||||
Socket.removeAllListeners();
|
Socket.removeAllListeners();
|
||||||
ret = Socket.getListeners();
|
ret = Socket.getListeners();
|
||||||
expect(Object.keys(ret)).to.have.length(0);
|
expect(Object.keys(ret)).to.have.length(0);
|
||||||
}));
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe("Unit: Walletfactory Service", function() {
|
||||||
|
beforeEach(angular.mock.module('copayApp.services'));
|
||||||
it('should contain a walletFactory service', inject(function(walletFactory) {
|
it('should contain a walletFactory service', inject(function(walletFactory) {
|
||||||
expect(walletFactory).not.to.equal(null);
|
expect(walletFactory).not.to.equal(null);
|
||||||
}));
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
// TODO
|
describe("Unit: controllerUtils", function() {
|
||||||
/*beforeEach(angular.mock.module('copayApp.controllerUtils'));
|
beforeEach(angular.mock.module('copayApp.services'));
|
||||||
|
beforeEach(angular.mock.module('notifications'));
|
||||||
it('should contain a controllerUtils service', inject(function(controllerUtils) {
|
|
||||||
expect(controllerUtils).not.to.equal(null);
|
it('should updateBalance in bits', inject(function(controllerUtils, $rootScope) {
|
||||||
}));
|
expect(controllerUtils.updateBalance).not.to.equal(null);
|
||||||
*/
|
scope = $rootScope.$new();
|
||||||
|
|
||||||
|
$rootScope.wallet = new FakeWallet();
|
||||||
|
var addr = '1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC';
|
||||||
|
var a = {};
|
||||||
|
a[addr] = 100;
|
||||||
|
//SATs
|
||||||
|
$rootScope.wallet.set(100000001, 90000002, a);
|
||||||
|
|
||||||
|
//retuns values in DEFAULT UNIT(bits)
|
||||||
|
controllerUtils.updateBalance(function() {
|
||||||
|
expect($rootScope.totalBalanceBTC).to.be.equal('1.0000');
|
||||||
|
expect($rootScope.availableBalanceBTC).to.be.equal('0.9000');
|
||||||
|
expect($rootScope.totalBalance).to.be.equal(1000000.01);
|
||||||
|
expect($rootScope.availableBalance).to.be.equal(900000.02);
|
||||||
|
expect($rootScope.addrInfos).not.to.equal(null);
|
||||||
|
expect($rootScope.addrInfos[0].address).to.equal(addr);
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue