mirror of https://github.com/BTCPrivate/copay.git
make unit configurable in settings. update after @cmgustavo comments
This commit is contained in:
parent
12b45fcfb9
commit
00ca9f1c32
|
@ -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,
|
||||||
|
|
54
index.html
54
index.html
|
@ -35,7 +35,7 @@
|
||||||
<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" tooltip="{{totalBalanceBTC}} BTC" tooltip-trigger="mouseenter" tooltip-placement="bottom">{{totalBalance || 0 |number}} bits
|
<span ng-if="!$root.updatingBalance" tooltip="{{totalBalanceBTC}} BTC" tooltip-trigger="mouseenter" tooltip-placement="bottom">{{totalBalance || 0 |number}} {{$root.unitName}}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="large-4 medium-4 columns">
|
<div class="large-4 medium-4 columns">
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
<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-show="!$root.updatingBalance" tooltip="{{availableBalanceBTC}} BTC" tooltip-trigger="mouseenter" tooltip-placement="bottom">{{availableBalance || 0|number}} bits
|
<span ng-show="!$root.updatingBalance" tooltip="{{availableBalanceBTC}} BTC" tooltip-trigger="mouseenter" tooltip-placement="bottom">{{availableBalance || 0|number}} {{$root.unitName}}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -381,11 +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|number}} bits
|
{{$root.balanceByAddr[addr.address] || 0|number}} {{$root.unitName}}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="addrWithFund != addr.address">
|
<span ng-if="addrWithFund != addr.address">
|
||||||
{{addr.balance || 0|number}} bits
|
{{addr.balance || 0|number}} {{$root.unitName}}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
@ -408,7 +408,7 @@
|
||||||
</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|number}} bits
|
{{selectedAddr.balance || 0|number}} {{$root.unitName}}
|
||||||
</span>
|
</span>
|
||||||
</strong>
|
</strong>
|
||||||
</p>
|
</p>
|
||||||
|
@ -439,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 | number}} bits</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>
|
||||||
|
@ -521,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> {{tx.fee|number}} bits
|
<strong>Fee:</strong> {{tx.fee|number}} {{$root.unitName}}
|
||||||
<strong>Proposal ID:</strong> {{tx.ntxid}}
|
<strong>Proposal ID:</strong> {{tx.ntxid}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -565,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| number}} bits</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>
|
||||||
|
@ -574,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| number}} bits</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>
|
||||||
|
@ -582,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 | number}} bits</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| number}} bits</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>
|
||||||
|
@ -646,11 +646,11 @@
|
||||||
<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"
|
||||||
|
@ -660,7 +660,7 @@
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-3 columns">
|
<div class="small-3 columns">
|
||||||
<span class="postfix">bits</span>
|
<span class="postfix">{{$root.unitName}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -669,13 +669,13 @@
|
||||||
Total amount for this transaction:
|
Total amount for this transaction:
|
||||||
</small>
|
</small>
|
||||||
<div class="totalAmount">
|
<div class="totalAmount">
|
||||||
<b>{{amount + defaultFee |number}}</b> bits
|
<b>{{amount + defaultFee |number}}</b> {{$root.unitName}}
|
||||||
<small>
|
<small>
|
||||||
{{((amount + defaultFee)/1e6).toFixed(3) |number}} BTC
|
{{ ((amount + defaultFee) * unitToBtc) |number}} BTC
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
<small>
|
<small>
|
||||||
Including fee of {{defaultFee|number}} bits
|
Including fee of {{defaultFee|number}} {{$root.unitName}}
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -750,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>
|
||||||
|
@ -768,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;
|
||||||
|
|
|
@ -5,7 +5,9 @@ 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;
|
||||||
$scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT / bitcore.util.BIT;
|
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.
|
// TODO this shouldnt be on a particular controller.
|
||||||
// Detect mobile devices
|
// Detect mobile devices
|
||||||
|
@ -49,7 +51,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
|
|
||||||
var address = form.address.$modelValue;
|
var address = form.address.$modelValue;
|
||||||
var amount = (form.amount.$modelValue * 100) | 0;
|
var amount = (form.amount.$modelValue * config.unitToSatoshi) | 0;
|
||||||
var commentText = form.comment.$modelValue;
|
var commentText = form.comment.$modelValue;
|
||||||
|
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
|
|
|
@ -13,6 +13,31 @@ angular.module('copayApp.controllers').controller('SettingsController',
|
||||||
$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';
|
||||||
});
|
});
|
||||||
|
@ -36,8 +61,9 @@ angular.module('copayApp.controllers').controller('SettingsController',
|
||||||
},
|
},
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,6 +13,8 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
$scope.txpItemsPerPage = 4;
|
$scope.txpItemsPerPage = 4;
|
||||||
$scope.blockchain_txs = [];
|
$scope.blockchain_txs = [];
|
||||||
|
|
||||||
|
var satToUnit = 1 / config.unitToSatoshi;
|
||||||
|
|
||||||
$scope.update = function() {
|
$scope.update = function() {
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
var from = ($scope.txpCurrentPage - 1) * $scope.txpItemsPerPage;
|
var from = ($scope.txpCurrentPage - 1) * $scope.txpItemsPerPage;
|
||||||
|
@ -80,14 +82,14 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
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 += (items[i].value * bitcore.util.COIN)|0;
|
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.valueSat|0) / bitcore.util.BIT;
|
v.value = (parseInt(v.valueSat || 0).toFixed(0)) * satToUnit;
|
||||||
ret.push(v);
|
ret.push(v);
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -105,10 +107,13 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
$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
|
||||||
;
|
} : {
|
||||||
|
type: 'error',
|
||||||
|
message: 'There was an error sending the Transaction'
|
||||||
|
};
|
||||||
if (cb) return cb();
|
if (cb) return cb();
|
||||||
else $scope.update();
|
else $scope.update();
|
||||||
});
|
});
|
||||||
|
@ -130,8 +135,7 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
$scope.send(ntxid, function() {
|
$scope.send(ntxid, function() {
|
||||||
$scope.update();
|
$scope.update();
|
||||||
});
|
});
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
$scope.update();
|
$scope.update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -149,15 +153,14 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
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)|0) / bitcore.util.BIT;
|
txs[i].valueOut = ((txs[i].valueOut * bitcore.util.COIN).toFixed(0)) * satToUnit;
|
||||||
txs[i].fees = ((txs[i].fees * bitcore.util.COIN)|0) / bitcore.util.BIT;
|
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;
|
||||||
|
@ -175,7 +178,10 @@ angular.module('copayApp.controllers').controller('TransactionsController',
|
||||||
$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);
|
||||||
|
@ -128,7 +128,9 @@ angular.module('copayApp.directives')
|
||||||
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -167,20 +171,32 @@ angular.module('copayApp.directives')
|
||||||
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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,15 +93,17 @@ 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++;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +213,9 @@ TxProposals.prototype.getTxProposal = function(ntxid, copayers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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] || {};
|
||||||
|
|
|
@ -562,20 +562,13 @@ 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 BIT = coinUtil.BIT;
|
|
||||||
var COIN = coinUtil.COIN;
|
var COIN = coinUtil.COIN;
|
||||||
|
|
||||||
if (!BIT)
|
|
||||||
throw new Error('BIT not defined. A newer version of bitcore is needed');
|
|
||||||
|
|
||||||
console.log('[Wallet.js.574] getBalance'); //TODO
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.getUnspent(function(err, safeUnspent, unspent) {
|
this.getUnspent(function(err, safeUnspent, unspent) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
@ -590,9 +583,10 @@ Wallet.prototype.getBalance = function(cb) {
|
||||||
|
|
||||||
// we multiply and divide by BIT 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) / BIT;
|
balanceByAddr[a] = parseInt(balanceByAddr[a].toFixed(0));
|
||||||
}
|
}
|
||||||
balance = balance.toFixed(0) / BIT;
|
|
||||||
|
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];
|
||||||
|
@ -600,7 +594,7 @@ Wallet.prototype.getBalance = function(cb) {
|
||||||
safeBalance += amt;
|
safeBalance += amt;
|
||||||
}
|
}
|
||||||
|
|
||||||
safeBalance = safeBalance.toFixed(0) / BIT;
|
safeBalance = parseInt(safeBalance.toFixed(0));
|
||||||
return cb(null, balance, balanceByAddr, safeBalance);
|
return cb(null, balance, balanceByAddr, safeBalance);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -608,7 +602,6 @@ Wallet.prototype.getBalance = function(cb) {
|
||||||
Wallet.prototype.getUnspent = function(cb) {
|
Wallet.prototype.getUnspent = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.blockchain.getUnspent(this.getAddressesStr(), function(err, unspentList) {
|
this.blockchain.getUnspent(this.getAddressesStr(), function(err, unspentList) {
|
||||||
console.log('[Wallet.js.606:unspentList:]', unspentList); //TODO
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
@ -642,7 +635,6 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getUnspent(function(err, safeUnspent) {
|
this.getUnspent(function(err, safeUnspent) {
|
||||||
console.log('[Wallet.js.639:safeUnspent:]', safeUnspent); //TODO
|
|
||||||
var ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts);
|
var ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts);
|
||||||
if (ntxid) {
|
if (ntxid) {
|
||||||
self.sendIndexes();
|
self.sendIndexes();
|
||||||
|
|
|
@ -44,8 +44,7 @@ angular.module('copayApp.services')
|
||||||
root.installStartupHandlers = function(wallet, $scope) {
|
root.installStartupHandlers = function(wallet, $scope) {
|
||||||
wallet.on('serverError', function(msg) {
|
wallet.on('serverError', function(msg) {
|
||||||
$rootScope.$flashMessage = {
|
$rootScope.$flashMessage = {
|
||||||
message: 'There was an error connecting to the PeerJS server.'
|
message: 'There was an error connecting to the PeerJS server.' + (msg || 'Check you settings and Internet connection.'),
|
||||||
+(msg||'Check you settings and Internet connection.'),
|
|
||||||
type: 'error',
|
type: 'error',
|
||||||
};
|
};
|
||||||
root.onErrorDigest($scope);
|
root.onErrorDigest($scope);
|
||||||
|
@ -53,11 +52,17 @@ angular.module('copayApp.services')
|
||||||
});
|
});
|
||||||
wallet.on('connectionError', function() {
|
wallet.on('connectionError', function() {
|
||||||
var message = "Looks like you are already connected to this wallet, please logout from it and try importing it again.";
|
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.$flashMessage = {
|
||||||
|
message: message,
|
||||||
|
type: 'error'
|
||||||
|
};
|
||||||
root.onErrorDigest($scope);
|
root.onErrorDigest($scope);
|
||||||
});
|
});
|
||||||
wallet.on('serverError', function() {
|
wallet.on('serverError', function() {
|
||||||
$rootScope.$flashMessage = { message: 'The PeerJS server is not responding, please try again', type: 'error'};
|
$rootScope.$flashMessage = {
|
||||||
|
message: 'The PeerJS server is not responding, please try again',
|
||||||
|
type: 'error'
|
||||||
|
};
|
||||||
root.onErrorDigest($scope);
|
root.onErrorDigest($scope);
|
||||||
});
|
});
|
||||||
wallet.on('ready', function() {
|
wallet.on('ready', function() {
|
||||||
|
@ -105,11 +110,11 @@ angular.module('copayApp.services')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
w.on('txProposalsUpdated', function(dontDigest) {
|
w.on('txProposalsUpdated', function(dontDigest) {
|
||||||
root.updateTxs({onlyPending:true});
|
root.updateTxs({
|
||||||
|
onlyPending: true
|
||||||
|
});
|
||||||
// give sometime to the tx to propagate.
|
// give sometime to the tx to propagate.
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
|
|
||||||
console.log('[controllerUtils.js.111] UPDATE BALANCE'); //TODO
|
|
||||||
root.updateBalance(function() {
|
root.updateBalance(function() {
|
||||||
if (!dontDigest) {
|
if (!dontDigest) {
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
|
@ -145,23 +150,26 @@ console.log('[controllerUtils.js.111] UPDATE BALANCE'); //TODO
|
||||||
$rootScope.balanceByAddr = {};
|
$rootScope.balanceByAddr = {};
|
||||||
$rootScope.updatingBalance = true;
|
$rootScope.updatingBalance = true;
|
||||||
|
|
||||||
console.log('[controllerUtils.js.147] GET'); //TODO
|
w.getBalance(function(err, balanceSat, balanceByAddrSat, safeBalanceSat) {
|
||||||
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
|
||||||
|
|
||||||
console.log('[controllerUtils.js.150]', err, balance); //TODO
|
|
||||||
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;
|
||||||
$rootScope.totalBalanceBTC = (balance / 1e6).toFixed(3) ;
|
var COIN = bitcore.util.COIN;
|
||||||
$rootScope.availableBalance = safeBalance;
|
|
||||||
$rootScope.availableBalanceBTC = (safeBalance / 1e6).toFixed(3);
|
$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;
|
||||||
root.updateAddressList();
|
root.updateAddressList();
|
||||||
$rootScope.updatingBalance = false;
|
$rootScope.updatingBalance = false;
|
||||||
|
@ -174,9 +182,12 @@ console.log('[controllerUtils.js.150]', err, balance); //TODO
|
||||||
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) {
|
||||||
|
return t2.createdTs - t1.createdTs
|
||||||
|
});
|
||||||
var txs = [];
|
var txs = [];
|
||||||
|
|
||||||
inT.forEach(function(i, index) {
|
inT.forEach(function(i, index) {
|
||||||
|
@ -195,16 +206,18 @@ console.log('[controllerUtils.js.150]', err, balance); //TODO
|
||||||
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.BIT,
|
value: bitcore.util.valueToBigInt(o.getValue()) * satToUnit,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// extra fields
|
// extra fields
|
||||||
i.outs = outs;
|
i.outs = outs;
|
||||||
i.fee = i.builder.feeSat/bitcore.util.BIT;
|
i.fee = i.builder.feeSat * satToUnit;
|
||||||
i.missingSignatures = tx.countInputMissingSignatures(0);
|
i.missingSignatures = tx.countInputMissingSignatures(0);
|
||||||
txs.push(i);
|
txs.push(i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 = {
|
||||||
|
extendedPrivateKeyString: 'tprv8ZgxMBicQKsPdSF1avR6mXyDj5Uv1XY2UyUHSDpAXQ5TvPN7prGeDppjy4562rBB9gMMAhRfFdJrNDpQ4t69kkqHNEEen3PX1zBJqSehJDH',
|
||||||
networkName: 'testnet',
|
networkName: 'testnet',
|
||||||
privateKeyCache: {} };
|
privateKeyCache: {}
|
||||||
var o2 ={ extendedPrivateKeyString: 'tprv8ZgxMBicQKsPdVeB5RzuxS9JQcACueZYgUaM5eWzaEBkHjW5Pg6Mqez1APSqoUP1jUdbT8WVG7ZJYTXvUL7XtPzFYBXjmdKuwSor1dcNQ8j',
|
};
|
||||||
|
var o2 = {
|
||||||
|
extendedPrivateKeyString: 'tprv8ZgxMBicQKsPdVeB5RzuxS9JQcACueZYgUaM5eWzaEBkHjW5Pg6Mqez1APSqoUP1jUdbT8WVG7ZJYTXvUL7XtPzFYBXjmdKuwSor1dcNQ8j',
|
||||||
networkName: 'testnet',
|
networkName: 'testnet',
|
||||||
privateKeyCache: {} };
|
privateKeyCache: {}
|
||||||
var o3 ={ extendedPrivateKeyString: 'tprv8ZgxMBicQKsPeHWNrPVZtQVgcCtXBr5TACNbDQ56rwqNJce9MEc64US6DJKxpWsrebEomxxWZFDtkvkZGkzA43uLvdF4XHiWqoNaL6Dq2Gd',
|
};
|
||||||
|
var o3 = {
|
||||||
|
extendedPrivateKeyString: 'tprv8ZgxMBicQKsPeHWNrPVZtQVgcCtXBr5TACNbDQ56rwqNJce9MEc64US6DJKxpWsrebEomxxWZFDtkvkZGkzA43uLvdF4XHiWqoNaL6Dq2Gd',
|
||||||
networkName: 'testnet',
|
networkName: 'testnet',
|
||||||
privateKeyCache: {} };
|
privateKeyCache: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var priv = PrivateKey.fromObj(o1);
|
var priv = PrivateKey.fromObj(o1);
|
||||||
|
|
|
@ -450,13 +450,13 @@ describe('Wallet model', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('#getBalance should return values in bits', function(done) {
|
it('#getBalance should return values in satoshis', function(done) {
|
||||||
var w = createW2();
|
var w = createW2();
|
||||||
w.generateAddress();
|
w.generateAddress();
|
||||||
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||||
balance.should.equal(25000100.00);
|
balance.should.equal(2500010000);
|
||||||
safeBalance.should.equal(25000100.00);
|
safeBalance.should.equal(2500010000);
|
||||||
balanceByAddr.mji7zocy8QzYywQakwWf99w9bCT6orY1C1.should.equal(25000100.00);
|
balanceByAddr.mji7zocy8QzYywQakwWf99w9bCT6orY1C1.should.equal(2500010000);
|
||||||
Object.keys(balanceByAddr).length.should.equal(1);
|
Object.keys(balanceByAddr).length.should.equal(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -464,19 +464,19 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
var roundErrorChecks = [{
|
var roundErrorChecks = [{
|
||||||
unspent: [1.0001],
|
unspent: [1.0001],
|
||||||
balance: 1000100
|
balance: 100010000
|
||||||
}, {
|
}, {
|
||||||
unspent: [1.0002, 1.0003, 1.0004],
|
unspent: [1.0002, 1.0003, 1.0004],
|
||||||
balance: 3000900
|
balance: 300090000
|
||||||
}, {
|
}, {
|
||||||
unspent: [0.000002, 1.000003, 2.000004],
|
unspent: [0.000002, 1.000003, 2.000004],
|
||||||
balance: 3000009
|
balance: 300000900
|
||||||
}, {
|
}, {
|
||||||
unspent: [0.0001, 0.0003],
|
unspent: [0.0001, 0.0003],
|
||||||
balance: 400
|
balance: 40000
|
||||||
}, {
|
}, {
|
||||||
unspent: [0.0001, 0.0003, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0002],
|
unspent: [0.0001, 0.0003, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0002],
|
||||||
balance: 1100
|
balance: 110000
|
||||||
},
|
},
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -16,7 +24,9 @@ describe("Unit: Testing Directives", function() {
|
||||||
'<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,32 +45,37 @@ 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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,16 @@
|
||||||
//
|
//
|
||||||
// test/unit/services/servicesSpec.js
|
// test/unit/services/servicesSpec.js
|
||||||
//
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
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() {
|
describe("Unit: Socket Service", function() {
|
||||||
beforeEach(angular.mock.module('copayApp.services'));
|
beforeEach(angular.mock.module('copayApp.services'));
|
||||||
|
|
||||||
|
@ -59,14 +69,17 @@ describe("Unit: controllerUtils", function() {
|
||||||
|
|
||||||
$rootScope.wallet = new FakeWallet();
|
$rootScope.wallet = new FakeWallet();
|
||||||
var addr = '1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC';
|
var addr = '1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC';
|
||||||
var a = {}; a[addr]=100;
|
var a = {};
|
||||||
$rootScope.wallet.set(1000000,900000,a);
|
a[addr] = 100;
|
||||||
|
//SATs
|
||||||
|
$rootScope.wallet.set(100000001, 90000002, a);
|
||||||
|
|
||||||
|
//retuns values in DEFAULT UNIT(bits)
|
||||||
controllerUtils.updateBalance(function() {
|
controllerUtils.updateBalance(function() {
|
||||||
expect($rootScope.totalBalance).to.be.equal(1000000);
|
expect($rootScope.totalBalanceBTC).to.be.equal('1.0000');
|
||||||
expect($rootScope.totalBalanceBTC).to.be.equal('1.000');
|
expect($rootScope.availableBalanceBTC).to.be.equal('0.9000');
|
||||||
expect($rootScope.availableBalance).to.be.equal(900000);
|
expect($rootScope.totalBalance).to.be.equal(1000000.01);
|
||||||
expect($rootScope.availableBalanceBTC).to.be.equal('0.900');
|
expect($rootScope.availableBalance).to.be.equal(900000.02);
|
||||||
expect($rootScope.addrInfos).not.to.equal(null);
|
expect($rootScope.addrInfos).not.to.equal(null);
|
||||||
expect($rootScope.addrInfos[0].address).to.equal(addr);
|
expect($rootScope.addrInfos[0].address).to.equal(addr);
|
||||||
});
|
});
|
||||||
|
@ -74,4 +87,3 @@ describe("Unit: controllerUtils", function() {
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue