This commit is contained in:
Matias Alejo Garcia 2016-08-18 10:08:23 -03:00
parent 78b51ff938
commit 09425dc344
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
11 changed files with 391 additions and 282 deletions

View File

@ -1,5 +1,5 @@
<!doctype html>
<html lang="en" ng-controller="indexController as index">
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

View File

@ -1,38 +0,0 @@
<div class="row collapse last-transactions-content line-b"
ng-class="{'text-gray':!tx.pendingForUs}"
ng-click="home.openTxpModal(tx, index.copayers, !!index.glideraStatus)">
<div class="large-6 medium-6 small-6 columns size-14">
<div class="m10r left pr">
<i class="icon-circle-active size-10" ng-show="tx.pendingForUs" ng-style="{'color':index.backgroundColor}"></i>
<img src="img/icon-proposal.svg" alt="sync" width="40">
</div>
<div class="m10t">
<div ng-show="!tx.merchant">
<span ng-show="index.addressbook[tx.toAddress] && !tx.message">
{{index.addressbook[tx.toAddress]}}
</span>
<span class="ellipsis" ng-show="!index.addressbook[tx.toAddress] && tx.message">
{{tx.message}}
</span>
<span ng-show="!index.addressbook[tx.toAddress] && !tx.message" translate>
Sending
</span>
</div>
<div ng-show="tx.merchant">
<span ng-show="tx.merchant.pr.ca"><i class="fi-lock"></i> {{tx.merchant.domain}}</span>
<span ng-show="!tx.merchant.pr.ca"><i class="fi-unlock"></i> {{tx.merchant.domain}}</span>
</div>
</div>
</div>
<div class="large-5 medium-5 small-5 columns text-right">
<span class="size-16">
- {{tx.amountStr}}
</span>
<div class="size-12 text-gray">
<time>{{ (tx.ts || tx.createdOn ) * 1000 | amTimeAgo}}</time>
</div>
</div>
<div class="large-1 medium-1 small-1 columns text-right m10t">
<i class="icon-arrow-right3 size-18"></i>
</div>
</div>

View File

@ -8,8 +8,10 @@
<h1 class="title ellipsis" translate>Payment Proposal</h1>
</ion-header-bar>
<ion-content ng-style="{'background-color': '#F6F7F9'}">
<div class="modal-content fix-modals-touch" ng-init="updateCopayerList()">
<ion-content ng-style="{'background-color': '#F6F7F9'}" ng-init="updateCopayerList()">
<div class="list card">
<ul>
<li class="item" >
<div class="payment-proposal-head" ng-style="{'background-color':color}">
<div class="size-36">{{tx.amountStr}}</div>
<div class="size-14 text-light" ng-show="tx.alternativeAmountStr">{{tx.alternativeAmountStr}}</div>
@ -21,8 +23,9 @@
</span>
</div>
<div class="oh">
<div class="box-notification" ng-show="error">
</li>
<li class="item">
<div class="assertive" ng-show="error">
<span class="text-warning size-14">{{error|translate}}</span>
</div>
@ -31,27 +34,28 @@
The payment was removed by creator
</div>
</div>
</li>
<li class="item">
<div class="row p20t white" ng-if="tx.pendingForUs">
<div class="large-6 medium-6 small-6 columns" ng-show="isShared">
<button class="button outline round dark-gray expand" ng-click="reject(tx)" ng-disabled="loading">
<i class="fi-x"></i>
<span translate>Reject</span>
</button>
</div>
<div class="large-6 medium-6 small-6 columns text-right" ng-show="canSign">
<button class="button primary round expand" ng-click="sign(tx)" ng-style="{'background-color':color}" ng-disabled="loading || paymentExpired">
<i class="fi-check"></i>
<span translate>Accept</span>
</button>
</div>
<div class="button-bar" ng-if="tx.pendingForUs">
<button class="button button-assertive button-block" ng-click="reject()" ng-disabled="loading" ng-show="isShared">
<i class="fi-x"></i>
<span translate>Reject</span>
</button>
<button class="button button-balanced button-block" ng-click="sign()" ng-style="{'background-color':color}" ng-disabled="loading || paymentExpired" ng-show="canSign">
<i class="fi-check"></i>
<span translate>Accept</span>
</button>
</div>
<div class="text-center text-gray size-12 m20t" ng-show="tx.status != 'pending'">
</li>
<li class="item">
<div ng-show="tx.status != 'pending'">
<div ng-show="tx.status=='accepted' && !tx.isGlidera">
<div class="m10b" translate>Payment accepted, but not yet broadcasted</div>
<button class="primary round m0" ng-style="{'background-color':color}" ng-click="broadcast(tx)" ng-disabled="loading">
<button class="button button-balanced button-block" ng-style="{'background-color':color}" ng-click="broadcast(tx)" ng-disabled="loading">
<i class="fi-upload-cloud"></i>
<span translate>Broadcast Payment</span>
</button>
@ -59,11 +63,11 @@
<div ng-show="tx.status=='accepted' && tx.isGlidera" >
<div class="m10h" translate>Payment accepted. It will be broadcasted by Glidera. In case there is a problem, it can be deleted 6 hours after it was created.</div>
</div>
<div class="text-success" ng-show="tx.status == 'broadcasted'" translate>Payment Sent</div>
<div class="text-warning" ng-show="tx.status=='rejected'" translate>Payment Rejected</div>
<div class="balanced" ng-show="tx.status == 'broadcasted'" translate>Payment Sent</div>
<div class="assertive" ng-show="tx.status=='rejected'" translate>Payment Rejected</div>
</div>
</div>
</li>
<li class="item">
<h4 class="title m0" translate>Details</h4>
<ul class="no-bullet size-14 m0">
@ -105,6 +109,8 @@
<div class="p10 text-center size-12" ng-show="!currentSpendUnconfirmed && tx.hasUnconfirmedInputs">
<span class="text-warning" translate>Warning: this transaction has unconfirmed inputs</span>
</div>
</li>
<li class="item">
<div ng-if="tx.paypro">
<h4 class="title m0" translate>Payment details</h4>
@ -138,7 +144,8 @@
</ul>
</div>
<div ng-if="tx.actions[0] && !txRejected && !txBroadcasted">
</li>
<li class="item" ng-if="tx.actions[0] && !txRejected && !txBroadcasted">
<h4 class="title m0">
<div class="right size-12 text-gray m10r">
{{tx.requiredSignatures}}/{{tx.walletN}}
@ -157,15 +164,17 @@
</ul>
</div>
<div class="columns text-center m20t" ng-if="tx.canBeRemoved || (tx.status == 'accepted' && !tx.broadcastedOn)">
</li>
<li class="item" ng-if="tx.canBeRemoved || (tx.status == 'accepted' && !tx.broadcastedOn)">
<div class="text-gray size-12 m20b" ng-show="!tx.isGlidera && isShared" translate>
* A payment proposal can be deleted if 1) you are the creator, and no other copayer has signed, or 2) 24 hours have passed since the proposal was created.
</div>
<button class="tiny round outline dark-gray warning" ng-click="remove(tx)" ng-disabled="loading">
<button class="button button-assertive button-block" ng-click="remove()" ng-disabled="loading">
<i class="fi-trash size-14 m5r"></i>
<span translate>Delete Payment Proposal</span>
</button>
</div>
</li>
</ul>
</div>
</ion-content>
</ion-modal-view>

View File

@ -4,6 +4,48 @@
<ion-nav-title>Home</ion-nav-title>
</ion-nav-bar>
<ion-content class="padding home" ng-controller="tabHomeController">
<h2 class="title m0" translate>Payment Proposals</h2>
<div class="list card" ng-if="txps[0]">
<ul>
<li ng-repeat="tx in txps" class="item item-icon-left"
ng-click="openTxpModal(tx)">
<i class="icon ion-ios-circle-filled" ng-show="tx.pendingForUs" ng-style="{'color':tx.wallet.color}"></i>
<span ng-show="!tx.merchant">
<span ng-show="addressbook[tx.toAddress] && !tx.message">
{{addressbook[tx.toAddress]}}
</span>
<span class="ellipsis" ng-show="!addressbook[tx.toAddress] && tx.message">
{{tx.message}}
</span>
<span ng-show="!addressbook[tx.toAddress] && !tx.message" translate>
Sending
</span>
</span>
<span ng-show="tx.merchant">
<span ng-show="tx.merchant.pr.ca"><i class="fi-lock"></i> {{tx.merchant.domain}}</span>
<span ng-show="!tx.merchant.pr.ca"><i class="fi-unlock"></i> {{tx.merchant.domain}}</span>
</span>
<span >
<span>
- {{tx.amountStr}}
</span>
<div class="item item-divider">
{{tx.wallet.name}} &middot; <time>{{ (tx.ts || tx.createdOn ) * 1000 | amTimeAgo}}</time>
</div>
</span>
</li>
</ul>
<div ng-show="lockedBalanceSat">
<span translate>Total Locked Balance</span>:
<b>{{lockedBalanceStr}} </b>
<span> {{lockedBalanceAlternative}} {{alternativeIsoCode}} </span>
</div>
</div>
<a href="#/add"><i class="ion-ios-plus-outline right"></i></a>
<h2>Wallets </h2>
<div class="list card">

View File

@ -1,6 +1,6 @@
'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, ongoingProcess, fingerprintService, 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) {
// An alert dialog
var showAlert = function(title, msg, cb) {
@ -16,49 +16,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
};
// An alert dialog
var askPassword = function(name, cb) {
$scope.data = [];
var pass = $ionicPopup.show({
template: '<input type="password" ng-model="data.pass">',
title: 'Enter Spending Password',
subTitle: name,
scope: $scope,
buttons: [{
text: 'Cancel'
}, {
text: '<b>OK</b>',
type: 'button-positive',
onTap: function(e) {
console.log('[confirm.js.32]', $scope, $scope.data); //TODO
if (!$scope.data.pass) {
//don't allow the user to close unless he enters wifi password
e.preventDefault();
return;
}
return $scope.data.pass;
}
}]
});
pass.then(function(res) {
console.log('Tapped!', res);
return cb(res);
});
};
var handleEncryptedWallet = function(wallet, cb) {
if (!walletService.isEncrypted(wallet)) return cb();
askPassword(wallet.name, function(password) {
if (!password) return cb('no password');
return cb(walletService.unlock(wallet, password));
});
};
var unitToSatoshi;
var satToUnit;
@ -118,6 +76,7 @@ console.log('[confirm.js.32]', $scope, $scope.data); //TODO
};
var createTx = function(toAddress, toAmount, comment) {
console.log('[confirm.js.78:toAddress:]',toAddress); //TODO
//
var currentSpendUnconfirmed = config.spendUnconfirmed;
@ -146,37 +105,39 @@ console.log('[confirm.js.32]', $scope, $scope.data); //TODO
return setSendError(gettext(msg));
};
$timeout(function() {
outputs.push({
'toAddress': toAddress,
'amount': toAmount,
'message': comment
});
var txp = {};
var txp = {};
// TODO
if (!lodash.isEmpty($scope.sendMaxInfo)) {
txp.sendMax = true;
txp.inputs = $scope.sendMaxInfo.inputs;
txp.fee = $scope.sendMaxInfo.fee;
// TODO
if (!lodash.isEmpty($scope.sendMaxInfo)) {
txp.sendMax = true;
txp.inputs = $scope.sendMaxInfo.inputs;
txp.fee = $scope.sendMaxInfo.fee;
}
txp.outputs = outputs;
txp.message = comment;
txp.payProUrl = paypro ? paypro.url : null;
txp.excludeUnconfirmedUtxos = config.spendUnconfirmed ? false : true;
txp.feeLevel = config.feeLevel || 'normal';
console.log('[confirm.js.129]'); //TODO
walletService.createTx(wallet, txp, function(err, createdTxp) {
console.log('[confirm.js.132]', err); //TODO
if (err) {
return setSendError(err);
}
txp.outputs = outputs;
txp.message = comment;
txp.payProUrl = paypro ? paypro.url : null;
txp.excludeUnconfirmedUtxos = config.spendUnconfirmed ? false : true;
txp.feeLevel = config.feeLevel || 'normal';
walletService.createTx(wallet, txp, function(err, createdTxp) {
if (err) {
return setSendError(err);
}
$scope.fee = ((createdTxp.fee) * satToUnit).toFixed(unitDecimals);
$scope.txp = createdTxp;
});
$scope.fee = ((createdTxp.fee) * satToUnit).toFixed(unitDecimals);
$scope.txp = createdTxp;
$scope.$apply();
});
};
@ -196,76 +157,16 @@ console.log('[confirm.js.32]', $scope, $scope.data); //TODO
if (!wallet.canSign() && !wallet.isPrivKeyExternal()) {
$log.info('No signing proposal: No private key');
ongoingProcess.set('sendingTx', true);
walletService.publishTx(wallet, txp, function(err, publishedTxp) {
ongoingProcess.set('sendingTx', false);
if (err) {
return setSendError(err);
}
$state.transitionTo('tab.home');
var type = txStatus.notify(createdTxp);
$scope.openStatusModal(type, createdTxp, function() {
return $scope.$emit('Local/TxProposalAction');
});
return walletService.onlyPublish(wallet,txp, function(err, txp){
if (err) return setSendError(err);
$state.transitionTo('tabs.home');
});
return;
}
fingerprintService.check(wallet, function(err) {
if (err) {
return setSendError(err);
}
handleEncryptedWallet(wallet, function(err) {
if (err) {
return setSendError(err);
}
ongoingProcess.set('sendingTx', true);
walletService.publishTx(wallet, txp, function(err, publishedTxp) {
ongoingProcess.set('sendingTx', false);
if (err) {
return setSendError(err);
}
ongoingProcess.set('signingTx', true);
walletService.signTx(wallet, txp, function(err, signedTxp) {
ongoingProcess.set('signingTx', false);
walletService.lock(wallet);
if (err) {
$scope.$emit('Local/TxProposalAction');
return setSendError(
err.message ?
err.message :
gettext('The payment was created but could not be completed. Please try again from home screen'));
}
if (signedTxp.status == 'accepted') {
ongoingProcess.set('broadcastingTx', true);
walletService.broadcastTx(wallet, signedTxp, function(err, broadcastedTxp) {
ongoingProcess.set('broadcastingTx', false);
if (err) {
return setSendError(err);
}
$state.transitionTo('tabs.send');
var type = txStatus.notify(broadcastedTxp);
$scope.openStatusModal(type, broadcastedTxp, function() {
$scope.$emit('Local/TxProposalAction', broadcastedTxp.status == 'broadcasted');
});
});
} else {
$state.transitionTo('tabs.send');
var type = txStatus.notify(signedTxp);
$scope.openStatusModal(type, signedTxp, function() {
$scope.$emit('Local/TxProposalAction');
});
}
});
});
});
walletService.publishAndSign(wallet, txp, function(err, txp) {
if (err) return setSendError(err);
$state.transitionTo('tabs.home');
});
};

View File

@ -1,17 +1,18 @@
'use strict';
angular.module('copayApp.controllers').controller('txpDetailsController', function($scope, $rootScope, $timeout, $interval, $ionicModal, ongoingProcess, platformInfo, txStatus, $ionicScrollDelegate, txFormatService, fingerprintService, bwcError, gettextCatalog, lodash, profileService, walletService) {
angular.module('copayApp.controllers').controller('txpDetailsController', function($scope, $rootScope, $timeout, $interval, $ionicModal, ongoingProcess, platformInfo, txStatus, $ionicScrollDelegate, txFormatService, fingerprintService, bwcError, gettextCatalog, lodash, walletService) {
var self = $scope.self;
var tx = $scope.tx;
var copayers = $scope.copayers;
var isGlidera = $scope.isGlidera;
var now = Math.floor(Date.now() / 1000);
var fc = profileService.focusedClient;
$scope.loading = null;
$scope.copayerId = fc.credentials.copayerId;
$scope.isShared = fc.credentials.n > 1;
$scope.canSign = fc.canSign() || fc.isPrivKeyExternal();
$scope.color = fc.backgroundColor;
$scope.copayerId = $scope.wallet.credentials.copayerId;
$scope.isShared = $scope.wallet.credentials.n > 1;
$scope.canSign = $scope.wallet.canSign() || $scope.wallet.isPrivKeyExternal();
$scope.color = $scope.wallet.color;
checkPaypro();
@ -23,51 +24,18 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
}
}
$scope.sign = function(txp) {
var setSendError = function(msg) {
$scope.error = msg || gettextCatalog.getString('Could not send payment');
}
$scope.sign = function() {
$scope.error = null;
$scope.loading = true;
$timeout(function() {
fingerprintService.check(fc, function(err) {
if (err) {
$scope.error = gettextCatalog.getString('Could not send payment');
$scope.loading = false;
$timeout(function() {
$scope.$digest();
}, 1);
return;
}
handleEncryptedWallet(function(err) {
if (err) {
return setError(err);
}
ongoingProcess.set('signingTx', true);
walletService.signTx(fc, txp, function(err, signedTxp) {
ongoingProcess.set('signingTx', false);
if (err) {
return setError(err);
}
if (signedTxp.status == 'accepted') {
ongoingProcess.set('broadcastingTx', true);
walletService.broadcastTx(fc, signedTxp, function(err, broadcastedTxp) {
ongoingProcess.set('broadcastingTx', false);
$scope.$emit('UpdateTx');
$scope.close(broadcastedTxp);
if (err) {
return setError(err);
}
});
} else {
$scope.$emit('UpdateTx');
$scope.close(signedTxp);
}
});
});
});
}, 10);
walletService.publishAndSign($scope.wallet, $scope.tx, function(err, txp) {
$scope.$emit('UpdateTx');
if (err) return setSendError(err);
$scope.close(signedTxp);
});
};
function setError(err, prefix) {
@ -79,7 +47,7 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
};
$scope.$on('$destroy', function() {
walletService.lock(fc);
walletService.lock($scope.wallet);
});
$scope.reject = function(txp) {
@ -88,7 +56,7 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
$timeout(function() {
ongoingProcess.set('rejectTx', true);
walletService.rejectTx(fc, txp, function(err, txpr) {
walletService.rejectTx($scope.wallet, $scope.tx, function(err, txpr) {
ongoingProcess.set('rejectTx', false);
if (err) {
@ -101,13 +69,13 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
}, 10);
};
$scope.remove = function(txp) {
$scope.remove = function() {
$scope.loading = true;
$scope.error = null;
$timeout(function() {
ongoingProcess.set('removeTx', true);
walletService.removeTx(fc, txp, function(err) {
walletService.removeTx($scope.wallet, $scope.tx, function(err) {
ongoingProcess.set('removeTx', false);
// Hacky: request tries to parse an empty response
@ -127,7 +95,7 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
$timeout(function() {
ongoingProcess.set('broadcastTx', true);
walletService.broadcastTx(fc, txp, function(err, txpb) {
walletService.broadcastTx($scope.wallet, $scope.tx, function(err, txpb) {
ongoingProcess.set('broadcastTx', false);
if (err) {

View File

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('tabHomeController',
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService ) {
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log) {
var self = this;
@ -23,10 +23,88 @@ angular.module('copayApp.controllers').controller('tabHomeController',
$scope.wallets = profileService.getWallets();
};
var setPendingTxps = function(txps) {
$scope.pendingTxProposalsCountForUs = 0;
var now = Math.floor(Date.now() / 1000);
/* To test multiple outputs...
var txp = {
message: 'test multi-output',
fee: 1000,
createdOn: new Date() / 1000,
outputs: []
};
function addOutput(n) {
txp.outputs.push({
amount: 600,
toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
message: 'output #' + (Number(n) + 1)
});
};
lodash.times(150, addOutput);
txps.push(txp);
*/
lodash.each(txps, function(tx) {
tx = txFormatService.processTx(tx);
// no future transactions...
if (tx.createdOn > now)
tx.createdOn = now;
tx.wallet = profileService.getWallet(tx.walletId);
if (!tx.wallet) {
$log.error("no wallet at txp?");
return;
}
var action = lodash.find(tx.actions, {
copayerId: tx.wallet.copayerId
});
if (!action && tx.status == 'pending') {
tx.pendingForUs = true;
}
if (action && action.type == 'accept') {
tx.statusForUs = 'accepted';
} else if (action && action.type == 'reject') {
tx.statusForUs = 'rejected';
} else {
tx.statusForUs = 'pending';
}
if (!tx.deleteLockTime)
tx.canBeRemoved = true;
if (tx.creatorId != tx.wallet.copayerId) {
$scope.pendingTxProposalsCountForUs = $scope.pendingTxProposalsCountForUs + 1;
}
});
$scope.txps = txps;
};
self.updateAllClients = function() {
lodash.each(profileService.getWallets(), function(wallet) {
walletService.updateStatus(wallet, {}, function(err, status) {
if (err) {} // TODO
var txps = [];
var wallets = profileService.getWallets();
var l = wallets.length,
i = 0;
lodash.each(wallets, function(wallet) {
walletService.updateStatus(wallet, {}, function(err) {
var status = wallet.status;
if (err) {
console.log('[tab-home.js.35:err:]',$log.error(err)); //TODO
return;
} // TODO
if (status.pendingTxps && status.pendingTxps[0]) {
txps = txps.concat(status.pendingTxps);
}
if (++i == l) {
setPendingTxps(txps);
}
});
});
}
@ -36,5 +114,28 @@ angular.module('copayApp.controllers').controller('tabHomeController',
$scope.bitpayCardEnabled = true; // TODO
// $state.transitionTo('confirm', {toAmount:555500, toAddress: 'mvfAwUJohJWibGzBZgAUGsDarsr4Z4NovU', toName: 'bla bla'});
var config = configService.getSync().wallet;
var GLIDERA_LOCK_TIME = 6 * 60 * 60;
var glideraActive = true; // TODO TODO TODO
// isGlidera flag is a security measure so glidera status is not
// only determined by the tx.message
$scope.openTxpModal = function(tx) {
var scope = $rootScope.$new(true);
scope.tx = tx;
scope.wallet = tx.wallet;
scope.copayers = tx.wallet.copayers;
scope.isGlidera = glideraActive;
scope.currentSpendUnconfirmed = config.spendUnconfirmed;
$ionicModal.fromTemplateUrl('views/modals/txp-details.html', {
scope: scope
}).then(function(modal) {
scope.txpDetailsModal = modal;
scope.txpDetailsModal.show();
});
};
// $state.transitionTo('confirm', {toAmount:555500, toAddress: 'mvfAwUJohJWibGzBZgAUGsDarsr4Z4NovU', toName: 'bla bla'});
});

View File

@ -82,6 +82,7 @@ angular.module('copayApp.services')
c.name = config.aliasFor[walletId] || client.credentials.walletName;
c.color = config.colorFor[walletId] || '#4A90E2';
c.network = client.credentials.network;
c.copayerId = client.credentials.copayerId;
c.m = client.credentials.m;
c.n = client.credentials.n;

View File

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('txFormatService', function(profileService, rateService, configService, lodash) {
angular.module('copayApp.services').factory('txFormatService', function(walletService, rateService, configService, lodash) {
var root = {};
var formatAmountStr = function(amount) {

View File

@ -1,7 +1,7 @@
'use strict';
// DO NOT INCLUDE STORAGE HERE \/ \/
angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, storageService, configService, rateService, uxLanguage, bwcService, $filter, gettextCatalog, bwcError) {
angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, storageService, configService, rateService, uxLanguage, bwcService, $filter, gettextCatalog, bwcError, $ionicPopup, fingerprintService, ongoingProcess, gettext, $rootScope, txStatus) {
// DO NOT INCLUDE STORAGE HERE ^^
//
//
@ -10,6 +10,26 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
var root = {};
// UI Related
root.openStatusModal = function(type, txp, cb) {
var scope = $rootScope.$new(true);
scope.type = type;
scope.tx = txFormatService.processTx(txp);
scope.color = txp.color;
scope.cb = cb;
$ionicModal.fromTemplateUrl('views/modals/tx-status.html', {
scope: scope,
animation: 'slide-in-up'
}).then(function(modal) {
scope.txStatusModal = modal;
scope.txStatusModal.show();
});
};
// // RECEIVE
// // Check address
// root.isUsed(wallet.walletId, balance.byAddress, function(err, used) {
@ -108,12 +128,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
self.notAuthorized = true;
go.walletHome();
} else if (err instanceof errors.NOT_FOUND) {
self.showErrorPopup(gettext('Could not access Wallet Service: Not found'));
root.showErrorPopup(gettext('Could not access Wallet Service: Not found'));
} else {
var msg = ""
$scope.$emit('Local/ClientError', (err.error ? err.error : err));
$rootScope.$emit('Local/ClientError', (err.error ? err.error : err));
var msg = bwcError.msg(err, gettext('Error at Wallet Service'));
self.showErrorPopup(msg);
root.showErrorPopup(msg);
}
};
root.handleError = lodash.debounce(_handleError, 1000);
@ -183,6 +203,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
wallet.isValid = true;
root.setBalance(wallet, status.balance);
wallet.email = status.preferences.email;
wallet.copayers = status.wallet.copayers;
};
root.updateStatus = function(wallet, opts, cb, initStatusHash, tries) {
@ -692,26 +713,18 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
root.updateHistory();
}, 5000);
self.showErrorPopup = function(msg, cb) {
root.showErrorPopup = function(msg, cb) {
$log.warn('Showing err popup:' + msg);
function openErrorPopup(msg, cb) {
$scope.msg = msg;
self.errorPopup = $ionicPopup.show({
templateUrl: 'views/includes/alert.html',
scope: $scope,
});
$scope.close = function() {
return cb();
};
}
openErrorPopup(msg, function() {
self.errorPopup.close();
if (cb) return cb();
// An alert dialog
var alertPopup = $ionicPopup.alert({
title: title,
template: msg
});
if (!cb) cb = function() {};
alertPopup.then(cb);
};
root.recreate = function(wallet, cb) {
@ -841,12 +854,124 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
};
// An alert dialog
var askPassword = function(name, cb) {
var scope = $rootScope.$new(true);
scope.data = [];
var pass = $ionicPopup.show({
template: '<input type="password" ng-model="data.pass">',
title: 'Enter Spending Password',
subTitle: name,
scope: scope,
buttons: [{
text: 'Cancel'
}, {
text: '<b>OK</b>',
type: 'button-positive',
onTap: function(e) {
if (!scope.data.pass) {
//don't allow the user to close unless he enters wifi password
e.preventDefault();
return;
root.handleEncryptedWallet = function(client, cb) {
if (!root.isEncrypted(client)) return cb();
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
}
return scope.data.pass;
}
}]
});
pass.then(function(res) {
console.log('Tapped!', res);
return cb(res);
});
};
root.handleEncryptedWallet = function(wallet, cb) {
if (!root.isEncrypted(wallet)) return cb();
askPassword(wallet.name, function(password) {
if (!password) return cb('no password');
return cb(root.unlock(wallet, password));
});
};
root.onlyPublish = function(wallet, txp, cb) {
ongoingProcess.set('sendingTx', true);
root.publishTx(wallet, txp, function(err, publishedTxp) {
ongoingProcess.set('sendingTx', false);
if (err) return cb(err);
return cb(walletService.unlock(client, password));
var type = txStatus.notify(createdTxp);
root.openStatusModal(type, createdTxp, function() {
// TODO?
//return $scope.$emit('Local/TxProposalAction');
});
return cb(null, publishedTxp);
});
};
root.publishAndSign = function(wallet, txp, cb) {
var publishFn = root.publishTx;
// Already published?
if (txp.status == 'pending') {
publishFn = function(wallet, txp, cb) {
return cb(null, txp);
};
}
fingerprintService.check(wallet, function(err) {
if (err) return cb(err);
root.handleEncryptedWallet(wallet, function(err) {
if (err) return cb(err);
ongoingProcess.set('sendingTx', true);
publishFn(wallet, txp, function(err, publishedTxp) {
ongoingProcess.set('sendingTx', false);
if (err) return cb(err);
ongoingProcess.set('signingTx', true);
root.signTx(wallet, txp, function(err, signedTxp) {
ongoingProcess.set('signingTx', false);
root.lock(wallet);
if (err) {
// TODO?
//$scope.$emit('Local/TxProposalAction');
var msg = err.message ?
err.message :
gettext('The payment was created but could not be completed. Please try again from home screen');
return cb(err);
}
if (signedTxp.status == 'accepted') {
ongoingProcess.set('broadcastingTx', true);
root.broadcastTx(wallet, signedTxp, function(err, broadcastedTxp) {
ongoingProcess.set('broadcastingTx', false);
if (err) return cb(err);
var type = txStatus.notify(broadcastedTxp);
root.openStatusModal(type, broadcastedTxp, function() {
// TODO?
//$scope.$emit('Local/TxProposalAction', broadcastedTxp.status == 'broadcasted');
});
return cb(null, broadcastedTxp)
});
} else {
var type = txStatus.notify(signedTxp);
root.openStatusModal(type, signedTxp, function() {
// TODO?
//$scope.$emit('Local/TxProposalAction');
});
return cb(null, signedTxp);
}
});
});
});
});
};