send send

This commit is contained in:
Matias Alejo Garcia 2016-08-18 14:51:35 -03:00
parent 02c8cb44d6
commit 2b5a3bb5a2
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
5 changed files with 123 additions and 119 deletions

View File

@ -14,34 +14,32 @@
<ion-content scroll="false" ng-controller="confirmController" ng-init="init()">
<ion-content ng-style="{'background-color':'#f6f7f9'}">
<div class="card">
<div class="item item-text-wrap">
<i class="icon ion-arrow-up-c"></i> <span class="text-bold size-16">Sending</span>
<div class="text-bold size-28 m15t">{{amount}} {{unitName}}</div>
<div class="text-light size-20 m5t">{{alternativeAmount || '...'}} {{alternativeIsoCode}}</div>
<div class="text-bold size-28 m15t">{{amountStr}} </div>
<div class="text-light size-20 m5t">{{alternativeAmountStr}} </div>
</div>
</div>
<div class="list card">
<div class="item">Fee: {{feeLevel}} ({{fee || '...'}} {{unitName}})</div>
<div class="item">Fee: {{feeLevel}}
<span class="item-note">
{{fee || '...'}}
</span>
</div>
<div class="item item-icon-left">
<i class="icon ion-ios-person-outline"></i>
<label translate>To</label>
<p>{{toName || toAddress}}</p>
<label translate>To</label> {{toAddress}}
<p ng-show="toName">{{toName}}</p>
</div>
<div class="item item-icon-left">
<i class="icon icon-wallet size-21" ng-style="{'color':recipientColor}"></i>
<label translate>From</label>
<p ng-show="network=='testnet'">[Only showing testnet wallets]</p>
<p ng-show="someFiltered">[Filtering wallets with no enought balance]</p>
</div>
<div class="item item-text-wrap" ng-style="{'height' : '200px'}">
@ -51,14 +49,10 @@
<ul class="pr">
<li ng-show="wallets[0]" class="item item-icon-left">
<i class="icon ion-briefcase size-21" ng-style="{'color':item.color}"></i>
{{item.name || item.id}}
<span class="item-note" ng-show="item.n > 1 && item.isComplete()">
{{item.m}}-of-{{item.n}}
{{item.name || item.id}}
<span class="item-note" ng-show="item.isComplete()">
{{item.availableBalanceStr}}
</span>
<span class="badge badge-assertive" ng-show="!item.isComplete()" translate>
Incomplete
</span>
</li>
</ul>
</div>
@ -74,9 +68,9 @@
</div>
<div class="card">
<button class="item button button-full button-positive" ng-click="approve()" ng-disabled="!txp">
Approve
</button>
<button class="item button button-full button-balanced" ng-click="approve()" ng-disabled="!txp" ng-show="wallet.canSign()"> Approve </button>
<button class="item button button-full button-balanced" ng-click="approve()" ng-disabled="!txp" ng-show="!wallet.canSign()"> Send </button>
</div>
</div>
</ion-content>

View File

@ -1,6 +1,8 @@
'use strict';
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, walletService, platformInfo, lodash, configService, go, rateService, $stateParams, $window, $state, $log, profileService, bitcore, $ionicPopup, txStatus, gettext) {
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, walletService, platformInfo, lodash, configService, go, rateService, $stateParams, $window, $state, $log, profileService, bitcore, $ionicPopup, txStatus, gettext, txFormatService) {
var cachedTxp = {};
// An alert dialog
var showAlert = function(title, msg, cb) {
@ -15,17 +17,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
alertPopup.then(cb);
};
var unitToSatoshi;
var satToUnit;
var unitDecimals;
var satToBtc;
var SMALL_FONT_SIZE_LIMIT = 13;
var LENGTH_EXPRESSION_LIMIT = 19;
var config;
$scope.init = function() {
// TODO (URL , etc)
@ -36,38 +27,75 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.isCordova = platformInfo.isCordova;
config = configService.getSync().wallet;
$scope.feeLevel = config.feeLevel;
var config = configService.getSync().wallet;
$scope.feeLevel = config.settings ? config.settings.feeLevel : '';
$scope.unitName = config.settings.unitName;
$scope.alternativeIsoCode = config.settings.alternativeIsoCode;
var amount = $scope.toAmount = parseInt($stateParams.toAmount);
$scope.amountStr = txFormatService.formatAmountStr($scope.toAmount);
unitToSatoshi = config.settings.unitToSatoshi;
satToUnit = 1 / unitToSatoshi;
satToBtc = 1 / 100000000;
$scope.toAmount = parseInt($stateParams.toAmount);
$scope.amount = (($stateParams.toAmount) * satToUnit).toFixed(unitDecimals);
$scope.toAddress = $stateParams.toAddress;
$scope.toName = $stateParams.toName;
var network = (new bitcore.Address($scope.toAddress)).network.name;
$scope.network = network;
$scope.setWallets(network);
function setWallets() {
var w = profileService.getWallets({
onlyComplete: true,
network: network,
});
$scope.wallets = lodash.filter(w, function(x) {
if (!x.availableBalanceSat) return true;
return x.availableBalanceSat > amount;
});
toFiat($scope.amount, function(v) {
$scope.alternativeAmount = v;
$scope.someFiltered = $scope.wallets.length != w.length;
};
var stop;
function setWallet(wallet, delayed) {
$scope.wallet = wallet;
$scope.fee = $scope.txp = null;
$timeout(function() {
$scope.$apply();
}, 10);
if (stop) {
$timeout.cancel(stop);
stop = null;
}
function apply(txp) {
$scope.fee = txFormatService.formatAmountStr(txp.fee);
$scope.txp = txp;
$scope.$apply();
};
if (cachedTxp[wallet.id]) {
apply(cachedTxp[wallet.id]);
} else {
stop = $timeout(function() {
createTx(wallet, $scope.toAddress, $scope.toAmount, $scope.comment, function(err, txp) {
if (err) return;
cachedTxp[wallet.id] = txp;
apply(txp);
});
}, delayed ? 2000 : 1);
}
};
txFormatService.formatAlternativeStr(amount, function(v) {
$scope.alternativeAmountStr = v;
});
unitDecimals = config.settings.unitDecimals;
$scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
$scope.wallet = $scope.wallets[data.slider.activeIndex];
setWallet($scope.wallets[data.slider.activeIndex], true);
});
createTx($scope.toAddress, $scope.toAmount);
setWallets();
setWallet($scope.wallets[0]);
$timeout(function() {
$ionicScrollDelegate.resize();
@ -78,22 +106,14 @@ angular.module('copayApp.controllers').controller('confirmController', function(
showAlert(gettext('Error creating transaction'), msg);
};
var createTx = function(toAddress, toAmount, comment) {
console.log('[confirm.js.78:toAddress:]',toAddress); //TODO
var createTx = function(wallet, toAddress, toAmount, comment, cb) {
var config = configService.getSync().wallet;
//
var currentSpendUnconfirmed = config.spendUnconfirmed;
////
var wallet = $scope.wallet;
if (!wallet) {
$log.error('No wallet selected')
return;
};
console.log('[confirm.js.85:wallet:]',wallet); //TODO
var outputs = [];
var comment = $scope.comment;
// TODO
var paypro = $scope.paypro;
// ToDo: use a credential's (or fc's) function for this
@ -109,11 +129,11 @@ console.log('[confirm.js.85:wallet:]',wallet); //TODO
return setSendError(gettext(msg));
};
outputs.push({
'toAddress': toAddress,
'amount': toAmount,
'message': comment
});
outputs.push({
'toAddress': toAddress,
'amount': toAmount,
'message': comment
});
var txp = {};
@ -128,20 +148,13 @@ console.log('[confirm.js.85:wallet:]',wallet); //TODO
txp.message = comment;
txp.payProUrl = paypro ? paypro.url : null;
txp.excludeUnconfirmedUtxos = config.spendUnconfirmed ? false : true;
txp.feeLevel = config.feeLevel || 'normal';
txp.feeLevel = config.settings.feeLevel || 'normal';
console.log('[confirm.js.129]'); //TODO
walletService.createTx(wallet, txp, function(err, createdTxp) {
console.log('[confirm.js.132]', err); //TODO
walletService.createTx(wallet, txp, function(err, ctxp) {
if (err) {
return setSendError(err);
}
$scope.fee = ((createdTxp.fee) * satToUnit).toFixed(unitDecimals);
$scope.txp = createdTxp;
$scope.$apply();
return cb(null, ctxp);
});
};
@ -162,21 +175,15 @@ console.log('[confirm.js.132]', err); //TODO
if (!wallet.canSign() && !wallet.isPrivKeyExternal()) {
$log.info('No signing proposal: No private key');
return walletService.onlyPublish(wallet,txp, function(err, txp){
return walletService.onlyPublish(wallet, txp, function(err, txp) {
if (err) return setSendError(err);
$state.transitionTo('tabs.home');
});
}
walletService.publishAndSign(wallet, txp, function(err, txp) {
if (err) return setSendError(err);
$state.transitionTo('tabs.home');
});
};
function toFiat(val, cb) {
rateService.whenAvailable(function() {
return cb(parseFloat((rateService.toFiat(val * unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10));
if (err) return setSendError(err);
$state.transitionTo('tabs.home');
});
};
@ -184,13 +191,6 @@ console.log('[confirm.js.132]', err); //TODO
$state.transitionTo('tabs.send');
};
$scope.setWallets = function(network) {
$scope.wallets = profileService.getWallets({
onlyComplete: true,
network: network
});
$scope.wallet = $scope.wallets[0];
};
});

View File

@ -34,7 +34,7 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
walletService.publishAndSign($scope.wallet, $scope.tx, function(err, txp) {
$scope.$emit('UpdateTx');
if (err) return setSendError(err);
$scope.close(signedTxp);
$scope.close(txp);
});
};

View File

@ -15,35 +15,45 @@ angular.module('copayApp.services').factory('txFormatService', function(bwcServi
//
root.Utils = bwcService.getUtils();
root.formatAmount = function(amount, fullPrecision) {
root.formatAmount = function(satoshis, fullPrecision) {
var config = configService.getSync().wallet.settings;
if (config.unitCode == 'sat') return amount;
if (config.unitCode == 'sat') return satoshis;
//TODO : now only works for english, specify opts to change thousand separator and decimal separator
var opts = {
fullPrecision: !!fullPrecision
};
return this.Utils.formatAmount(amount, config.unitCode, opts);
return this.Utils.formatAmount(satoshis, config.unitCode, opts);
};
var formatAmountStr = function(amount) {
if (!amount) return;
root.formatAmountStr = function(satoshis) {
if (!satoshis) return;
var config = configService.getSync().wallet.settings;
return root.formatAmount(amount) + ' ' + config.unitName;
return root.formatAmount(satoshis) + ' ' + config.unitName;
};
var formatAlternativeStr = function(amount) {
if (!amount) return;
root.formatAlternativeStr = function(satoshis, cb) {
if (!satoshis) return;
var config = configService.getSync().wallet.settings;
return (rateService.toFiat(amount, config.alternativeIsoCode) ? rateService.toFiat(amount, config.alternativeIsoCode).toFixed(2) : 'N/A') + ' ' + config.alternativeIsoCode;
};
var formatFeeStr = function(fee) {
if (!fee) return;
var config = configService.getSync().wallet.settings;
return root.formatAmount(fee) + ' ' + config.unitName;
var val = function() {
var v1 = rateService.toFiat(satoshis, config.alternativeIsoCode);
if (!v1) return null;
return v1.toFixed(2) + ' ' + config.alternativeIsoCode;
};
// Async version
if (cb) {
rateService.whenAvailable(function() {
return cb(val());
});
} else {
if (!rateService.isAvailable()) return null;
return val();
};
};
root.processTx = function(tx) {
@ -61,17 +71,17 @@ angular.module('copayApp.services').factory('txFormatService', function(bwcServi
tx.hasMultiplesOutputs = true;
}
tx.amount = lodash.reduce(tx.outputs, function(total, o) {
o.amountStr = formatAmountStr(o.amount);
o.alternativeAmountStr = formatAlternativeStr(o.amount);
o.amountStr = root.formatAmountStr(o.amount);
o.alternativeAmountStr = root.formatAlternativeStr(o.amount);
return total + o.amount;
}, 0);
}
tx.toAddress = tx.outputs[0].toAddress;
}
tx.amountStr = formatAmountStr(tx.amount);
tx.alternativeAmountStr = formatAlternativeStr(tx.amount);
tx.feeStr = formatFeeStr(tx.fee || tx.fees);
tx.amountStr = root.formatAmountStr(tx.amount);
tx.alternativeAmountStr = root.formatAlternativeStr(tx.amount);
tx.feeStr = root.formatAmountStr(tx.fee || tx.fees);
return tx;
};

View File

@ -911,7 +911,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (err) return cb(err);
ongoingProcess.set('signingTx', true);
root.signTx(wallet, txp, function(err, signedTxp) {
root.signTx(wallet, publishedTxp, function(err, signedTxp) {
ongoingProcess.set('signingTx', false);
root.lock(wallet);