Trying to fix bip72

This commit is contained in:
Gustavo Maximiliano Cortez 2014-12-01 05:24:19 -03:00
parent 6d72d00b99
commit 92737bc49c
8 changed files with 50 additions and 43 deletions

View File

@ -2,27 +2,12 @@
angular.module('copayApp.controllers').controller('PaymentIntentController', function($rootScope, $scope, $modal, $location, balanceService) {
$scope.wallets = [];
$rootScope.title = 'Payment intent';
$scope.wallets = $rootScope.iden.listWallets();
$rootScope.title = 'Payment intent';
var l = $scope.wallet.length;
_.each($scope.wallets, function(w, i) {
balanceService.update(w, function(){
if (i === l-1)
$rootScope.$digest();
});
});
$scope.open = function() {
$scope.open = function() {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
resolve: {
items: function() {
return $scope.wallets;
}
}
controller: ModalInstanceCtrl
});
};
@ -30,8 +15,22 @@ angular.module('copayApp.controllers').controller('PaymentIntentController', fun
// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $modal service used above.
var ModalInstanceCtrl = function($scope, $modalInstance, items, identityService) {
$scope.wallets = items;
var ModalInstanceCtrl = function($scope, $modalInstance, identityService) {
$scope.loading = true;
$scope.setWallets = function() {
if (!$rootScope.iden) return;
var ret = _.filter($rootScope.iden.listWallets(), function(w) {
return w.balanceInfo && w.balanceInfo.totalBalanceBTC;
});
$scope.wallets = ret;
$scope.loading = false;
};
if ($rootScope.iden) {
var iden = $rootScope.iden;
iden.on('newWallet', function() {
$scope.setWallets();
});
}
$scope.ok = function(selectedItem) {
identityService.setPaymentWallet(selectedItem);
$modalInstance.close();

View File

@ -11,10 +11,10 @@ angular.module('copayApp.controllers').controller('SendController',
$rootScope.title = 'Send';
$scope.loading = false;
$scope.error = $scope.success = null;
var satToUnit = 1 / w.settings.unitToSatoshi;
var unitToSatoshi = w.settings.unitToSatoshi;
var satToUnit = 1 / unitToSatoshi;
$scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit;
$scope.unitToBtc = w.settings.unitToSatoshi / bitcore.util.COIN;
$scope.unitToSatoshi = w.settings.unitToSatoshi;
$scope.unitToBtc = unitToSatoshi / bitcore.util.COIN;
$scope.alternativeName = w.settings.alternativeName;
$scope.alternativeIsoCode = w.settings.alternativeIsoCode;
@ -33,9 +33,9 @@ angular.module('copayApp.controllers').controller('SendController',
$scope.setAlternativeAmount = function(w, tx, cb) {
rateService.whenAvailable(function() {
_.each(tx.outs, function(out) {
var valueSat = out.value * w.settings.unitToSatoshi;
out.alternativeAmount = rateService.toFiat(valueSat, w.settings.alternativeIsoCode);
out.alternativeIsoCode = w.settings.alternativeIsoCode;
var valueSat = out.value * unitToSatoshi;
out.alternativeAmount = rateService.toFiat(valueSat, $scope.alternativeIsoCode);
out.alternativeIsoCode = $scope.alternativeIsoCode;
});
if (cb) return cb(tx);
});
@ -78,7 +78,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO
this._alternative = newValue;
if (typeof(newValue) === 'number' && $scope.isRateAvailable) {
this._amount = parseFloat(
(rateService.fromFiat(newValue, w.settings.alternativeIsoCode) * satToUnit).toFixed(w.settings.unitDecimals), 10);
(rateService.fromFiat(newValue, $scope.alternativeIsoCode) * satToUnit).toFixed(w.settings.unitDecimals), 10);
} else {
this._amount = 0;
}
@ -96,7 +96,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO
if (typeof(newValue) === 'number' && $scope.isRateAvailable) {
this._alternative = parseFloat(
(rateService.toFiat(newValue * w.settings.unitToSatoshi, w.settings.alternativeIsoCode)).toFixed(2), 10);
(rateService.toFiat(newValue * unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10);
} else {
this._alternative = 0;
}
@ -124,12 +124,19 @@ console.log('[send.js.44:updateTxs:]'); //TODO
if ($rootScope.pendingPayment) {
var pp = $rootScope.pendingPayment;
$scope.address = pp.address + '';
var amount = pp.data.amount / w.settings.unitToSatoshi * 100000000;
$scope.amount = $filter('noFractionNumber')(amount);
var alternativeAmount = rateService.toFiat((amount + defaultFee) * unitToSatoshi, alternativeIsoCode);
$scope.alternativeAmountPayPro = $filter('noFractionNumber')(alternativeAmount, 2);
var amount = pp.data.amount * 100000000 * satToUnit;
var alternativeAmountPayPro = rateService.toFiat((amount + $scope.defaultFee) * unitToSatoshi, $scope.alternativeIsoCode);
if (pp.data.merchant) {
$scope.address = 'bitcoin:' + pp.address.data + '?amount=' + amount + '&r=' + pp.data.r;
}
else {
$scope.address = pp.address + '';
$scope.amount = amount;
$scope.alternative = alternativeAmountPayPro;
}
$scope.alternativeAmountPayPro = $filter('noFractionNumber')(alternativeAmountPayPro, 2);
$scope.commentText = pp.data.message;
$scope.onChanged();
}
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
@ -165,7 +172,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO
$scope.loading = true;
var address = form.address.$modelValue;
var amount = parseInt((form.amount.$modelValue * w.settings.unitToSatoshi).toFixed(0));
var amount = parseInt((form.amount.$modelValue * unitToSatoshi).toFixed(0));
var commentText = form.comment.$modelValue;
@ -539,7 +546,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO
apply();
var balance = $rootScope.availableBalance;
var available = +(balance * w.settings.unitToSatoshi).toFixed(0);
var available = +(balance * unitToSatoshi).toFixed(0);
if (merchantData && available < +merchantData.total) {
err = new Error('Insufficient funds.');
err.amount = merchantData.total;
@ -547,7 +554,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO
if (err) {
if (err.amount) {
$scope.sendForm.amount.$setViewValue(+err.amount / w.settings.unitToSatoshi);
$scope.sendForm.amount.$setViewValue(+err.amount / unitToSatoshi);
$scope.sendForm.amount.$render();
$scope.sendForm.amount.$isValid = false;
$scope.notEnoughAmount = true;
@ -578,7 +585,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO
var url = merchantData.request_url;
var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1];
merchantData.unitTotal = (+merchantData.total / w.settings.unitToSatoshi) + '';
merchantData.unitTotal = (+merchantData.total / unitToSatoshi) + '';
merchantData.expiration = new Date(
merchantData.pr.pd.expires * 1000);
merchantData.domain = domain;

View File

@ -629,7 +629,7 @@ Wallet.prototype._onAddressBook = function(senderId, data) {
var self = this,
hasChange;
_.each(data.addressBook, function(value, key) {
if (!self.addressBook[key] && Address.validate(key)) {
if (key && !self.addressBook[key] && Address.validate(key)) {
self.addressBook[key] = _.pick(value, ['createdTs', 'label']);

View File

@ -17,13 +17,13 @@
<div class="text-right">
<span class="size-21">
<strong>
<span ng-if="!$root.updatingBalance">{{$root.wallet.balanceInfo.totalBalance || 0 |noFractionNumber}}</span>
<span ng-if="!$root.updatingBalance">{{$root.wallet.balanceInfo.totalBalance || 0}}</span>
<span ng-if="$root.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
{{$root.wallet.settings.unitName}}
</strong>
</span>
<span class="size-14 db m5t text-gray">
<span ng-if="!$root.wallet.balanceInfo.updatingBalance && alternativeBalanceAvailable">{{$root.wallet.balanceInfo.totalBalanceAlternative |noFractionNumber:2}} {{$root.wallet.balanceInfo.alternativeIsoCode}}</span>
<span ng-if="!$root.wallet.balanceInfo.updatingBalance && $root.wallet.balanceInfo.alternativeBalanceAvailable">{{$root.wallet.balanceInfo.totalBalanceAlternative}} {{$root.wallet.balanceInfo.alternativeIsoCode}}</span>
<span ng-if="!$root.wallet.balanceInfo.updatingBalance && !$root.wallet.balanceInfo.alternativeBalanceAvailable">N/A</span>
<span ng-if="$root.wallet.balanceInfo.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
</span>

View File

@ -13,7 +13,7 @@
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
</span>
<span ng-show="!$root.updatingBalance">
{{address.balance || 0|noFractionNumber}} {{$root.wallet.settings.unitName}}
{{address.balance || 0}} {{$root.wallet.settings.unitName}}
</span>
</p>
</div>

View File

@ -1,6 +1,7 @@
<div ng-controller="PaymentIntentController" ng-init="open()">
<script type="text/ng-template" id="myModalContent.html">
<h3>Select a wallet to make the payment</h3>
<span ng-show="loading">Loading...</span>
<ul class="w-popup-menu" ng-show="wallets[0]"
ng-class="{'large':wallets.length > 4, 'medium':wallets.length > 2 && wallets.length < 5}">
<li data-ng-repeat="item in wallets track by $index" class="nav-item" ng-click="ok(item)">

View File

@ -67,7 +67,7 @@
<td>
<span ng-if="!isComplete">-</span>
<span ng-if="isComplete">
{{item.balanceInfo.totalBalance || 0 |noFractionNumber}} {{item.settings.unitName}}
{{item.balanceInfo.totalBalance || 0}} {{item.settings.unitName}}
</span>
</td>
<td>

View File

@ -108,7 +108,7 @@
<div class="input">
<input type="number" id="alternative_amount"
ng-disabled="loading || !isRateAvailable || ($root.merchant && +$root.merchant.total > 0)"
name="alternative" placeholder="{{'Amount'|translate}}" ng-model="alternative"requiredautocomplete="off">
name="alternative" placeholder="{{'Amount'|translate}}" ng-model="alternative" requiredautocomplete="off">
<i class="icon-usd"></i>
</div>
</div>