Merge pull request #2902 from matiu/feat/send-wallet

Send wallet
This commit is contained in:
Ivan Socolsky 2015-06-27 21:23:02 -03:00
commit 8677bbe3b2
10 changed files with 278 additions and 104 deletions

View file

@ -0,0 +1,45 @@
<nav class="tab-bar">
<section class="left-small">
<a ng-click="cancel()" class="p10">
<span class="text-close" translate>Close</span>
</a>
</section>
<section class="middle tab-bar-section">
<h1 class="title ellipsis" ng-style="{'color':color}" translate>
Choose a wallet to send funds
</h1>
</section>
</nav>
<div class="modal-content">
<div class="onGoingProcess" ng-if="gettingAddress">
<div class="onGoingProcess-content" ng-style="{'background-color':'#222'}">
<div class="spinner">
<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>
<div class="rect4"></div>
<div class="rect5"></div>
</div>
<span translate> Getting address for wallet {{selectedWalletName}} ...</span>
</div>
</div>
<div ng-if="!gettingAddress">
<ul class="no-bullet">
<li class="panel" ng-repeat="w in wallets">
<a ng-click="selectWallet(w.id, w.name)">
<div class="avatar-wallet"
ng-style="{'background-color':w.color}">{{(w.name || w.id) | limitTo: 1}}</div>
<div class="ellipsis">{{w.name || w.id}}</div>
<div class="size-12">{{w.m}} of {{w.n}}
<span ng-show="w.network=='testnet'">[Testnet]</span>
</div>
</a>
</li>
</ul>
</div>
<div class="extra-margin-bottom"></div>
</div>

View file

@ -9,7 +9,7 @@
<div class="panel text-center" ng-if="!payment.uri">
<h1 translate>Bitcoin URI is NOT valid!</h1>
</div>
<div ng-if="payment.uri">
<div ng-if="payment.uri" ng-init="wallets = payment.getWallets(payment.uri.network)">
<h1 translate>Make a payment to</h1>
<div class="panel size-14">
<div class="ellipsis"><b translate>Address</b>: {{payment.uri.address.toString()}}</div>
@ -17,19 +17,30 @@
<div ng-show="payment.uri.message"><b translate>Message</b>: {{payment.uri.message}}</div>
<div ng-show="payment.uri.network == 'testnet'"><b translate>Network</b>: {{payment.uri.network}}</div>
</div>
<h2 translate>Select a wallet</h2>
<ul class="no-bullet" ng-init="wallets = payment.getWallets(payment.uri.network)">
<li class="panel" ng-repeat="w in wallets">
<a ng-click="payment.selectWallet(w.id)">
<div class="avatar-wallet"
ng-style="{'background-color':w.color}">{{(w.name || w.id) | limitTo: 1}}</div>
<div class="ellipsis">{{w.name || w.id}}</div>
<div class="size-12">{{w.m}} of {{w.n}}
<span ng-show="w.network=='testnet'">[Testnet]</span>
</div>
</a>
</li>
</ul>
<div ng-if="!wallets || !wallets.length">
<div class="box-notification">
<span class="text-warning" translate>
There are not wallets to make this payment
<span ng-show="payment.uri.network == 'testnet'">[testnet]</span>
</span>
</div>
</div>
<div ng-if="wallets.length">
<h2 translate>Select a wallet</h2>
<ul class="no-bullet">
<li class="panel" ng-repeat="w in wallets">
<a ng-click="payment.selectWallet(w.id)">
<div class="avatar-wallet"
ng-style="{'background-color':w.color}">{{(w.name || w.id) | limitTo: 1}}</div>
<div class="ellipsis">{{w.name || w.id}}</div>
<div class="size-12">{{w.m}} of {{w.n}}
<span ng-show="w.network=='testnet'">[Testnet]</span>
</div>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>

View file

@ -258,7 +258,7 @@
</div>
<div class="row m20t">
<div class="large-12 columns">
<button class="button black expand round" ng-click="home.setNewAddress()"
<button class="button black expand round" ng-click="home.setAddress(true)"
ng-style="{'background-color':index.backgroundColor}" ng-disabled="home.blockUx || index.isOffline ||home.generatingAddress" translate>
Generate new address
</button>
@ -266,7 +266,7 @@
</div>
<div class="text-center" ng-show="!home.generatingAddress && home.addr[index.walletId]">
<a class="size-12" ng-click="home.openCustomizedAmountModal(home.addr[index.walletId])" translate>
Request a specific amount
Receive a specific amount
</a>
</div>
</div>
@ -327,6 +327,11 @@
<div ng-hide="home._paypro || home.hideAddress">
<div class="row collapse">
<div class="right size-12 m0 text-gray" ng-click="openWalletsModal(index.otherWallets)" ng-if="index.otherWallets">
send to my wallets
</div>
<label for="address" class="left" >
<span translate>To</span>
</label>

View file

@ -285,7 +285,7 @@ a.missing-copayers {
background-color: #122232;
}
.sidebar .avatar-wallet, .payment-uri .avatar-wallet {
.sidebar .avatar-wallet, .payment-uri .avatar-wallet, .modal-content .avatar-wallet {
background-color: #2C3E50;
color: #fff;
font-size: 20px;

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, gettextCatalog, gettext, amMoment) {
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment) {
var self = this;
self.isCordova = isCordova;
@ -237,6 +237,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.copayers = walletStatus.wallet.copayers;
self.preferences = walletStatus.preferences;
self.setBalance(walletStatus.balance);
self.otherWallets = lodash.filter(profileService.getWallets(self.network), function(w) {
return w.id != self.walletId;
});;
$rootScope.$apply();
});
});
@ -463,7 +466,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.alternativeIsoCode = config.alternativeIsoCode;
// Check address
self.checkLastAddress(balance.byAddress);
addressService.isUsed(self.walletId, balance.byAddress, function(err, used){
if (used) {
$log.debug('Address used. Creating new');
$rootScope.$emit('Local/NeedNewAddress');
}
});
rateService.whenAvailable(function() {
@ -487,20 +495,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}
};
self.checkLastAddress = function(byAddress, cb) {
storageService.getLastAddress(self.walletId, function(err, addr) {
var used = lodash.find(byAddress, {
address: addr
});
if (used) {
$log.debug('Address ' + addr + ' was used. Cleaning Cache.')
storageService.clearLastAddress(self.walletId, function(err) {
$rootScope.$emit('Local/NeedNewAddress', err);
if (cb) return cb();
});
};
});
};
self.clientError = function(err) {
if (isCordova) {
@ -728,7 +722,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/WalletImported', function(event, walletId) {
self.needsBackup = false;
storageService.setBackupFlag(walletId, function() {
storageService.clearLastAddress(walletId, function(err) {
addressService.expireAddress(walletId, function(err) {
self.startScan(walletId);
});
});
@ -791,7 +785,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (val) {
$log.debug('Clear last address cache and Scan');
lodash.each(lodash.keys(profileService.walletClients), function(walletId) {
storageService.clearLastAddress(walletId, function(err) {
addressService.expireAddress(walletId, function(err) {
self.startScan(walletId);
});
});

View file

@ -38,24 +38,7 @@ angular.module('copayApp.controllers').controller('paymentUriController',
};
this.getWallets = function(network) {
if (!profileService.profile) return;
var config = configService.getSync();
config.colorFor = config.colorFor || {};
config.aliasFor = config.aliasFor || {};
var ret = lodash.map(profileService.profile.credentials, function(c) {
return {
m: c.m,
n: c.n,
name: config.aliasFor[c.walletId] || c.walletName,
id: c.walletId,
network: c.network,
color: config.colorFor[c.walletId] || '#2C3E50'
};
});
ret = lodash.filter(ret, function(w) {
return (w.network == network);
});
return lodash.sortBy(ret, 'name');
return profileService.getWallets(network);
};
this.selectWallet = function(wid) {

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit) {
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService) {
var self = this;
$rootScope.hideMenuBar = false;
@ -38,7 +38,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
});
var disableAddrListener = $rootScope.$on('Local/NeedNewAddress', function() {
self.setNewAddress();
self.setAddress(true);
});
var disableFocusListener = $rootScope.$on('Local/NewFocusedWallet', function() {
@ -90,6 +90,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
var parseError = function(err) {
if (!err) return;
if (err.message) {
// TODO : this is not used anymore?
if (err.message.indexOf('CORS') >= 0) {
@ -125,6 +127,52 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
});
};
$scope.openWalletsModal = function(wallets) {
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.wallets = wallets;
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
$scope.selectWallet = function(walletId, walletName) {
$scope.gettingAddress=true;
$scope.selectedWalletName=walletName;
$timeout(function(){
$scope.$apply();
});
addressService.getAddress(walletId, false, function(err,addr) {
$scope.gettingAddress=false;
if (!err || addr)
$modalInstance.close(addr);
else {
parseError(err);
self.error = err;
$modalInstance.dismiss('cancel');
}
});
};
};
var modalInstance = $modal.open({
templateUrl: 'views/modals/wallets.html',
windowClass: 'full animated slideInUp',
controller: ModalInstanceCtrl,
});
modalInstance.result.finally(function() {
var m = angular.element(document.getElementsByClassName('reveal-modal'));
m.addClass('slideOutDown');
});
modalInstance.result.then(function(addr) {
if (addr) {
self.setForm(addr);
}
});
};
this.openTxpModal = function(tx, copayers) {
var fc = profileService.focusedClient;
var refreshUntilItChanges = false;
@ -339,56 +387,31 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
};
// Receive
this.setNewAddress = function() {
var fc = profileService.focusedClient;
self.generatingAddress = true;
self.addrError = null;
fc.createAddress(function(err, addr) {
self.generatingAddress = false;
if (err) {
if (err.error && err.error.match(/locked/gi)) {
$log.debug(err.error);
$timeout(function() {
self.setNewAddress();
}, 5000);
} else {
$log.debug('Creating address ERROR:', err);
parseError(err);
self.addrError = err.message || gettext('Could not create address. Check you connection and try again');
$scope.$digest();
}
return;
}
self.addrError = null;
self.addr[fc.credentials.walletId] = addr.address;
storageService.storeLastAddress(fc.credentials.walletId, addr.address, function() {
self.generatingAddress = false;
$scope.$digest();
});
});
};
this.setAddress = function() {
this.setAddress = function(forceNew) {
self.addrError = null;
var fc = profileService.focusedClient;
if (!fc)
return;
if (self.addr[fc.credentials.walletId]) {
// Address already set?
if (!forceNew && self.addr[fc.credentials.walletId]) {
return;
}
self.generatingAddress = true;
$timeout(function() {
storageService.getLastAddress(fc.credentials.walletId, function(err, addr) {
if (addr) {
self.addr[fc.credentials.walletId] = addr;
$scope.$digest();
} else {
self.setNewAddress();
addressService.getAddress(fc.credentials.walletId, forceNew, function(err,addr){
self.generatingAddress = false;
if (err) {
parseError(err);
self.addrError = err.message || gettext('Could not create address. Check you connection and try again');
}
if (addr)
self.addr[fc.credentials.walletId] = addr;
$scope.$digest();
});
});
};
@ -1028,6 +1051,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}
}
/* Start setup */
this.bindTouchDown();
this.setAddress();

View file

@ -6,6 +6,15 @@ angular.element(document).ready(function() {
var startAngular = function() {
angular.bootstrap(document, ['copayApp']);
};
var handleBitcoinURI = function(url) {
if (!url) return;
setTimeout(function() {
window.location = '#/uri-payment/' + url;
}, 1000);
};
/* Cordova specific Init */
if (window.cordova !== undefined) {
@ -37,8 +46,7 @@ angular.element(document).ready(function() {
var loc = window.location;
if (loc.toString().match(/index\.html#\/$/)) {
navigator.app.exitApp();
}
else {
} else {
window.location = '#/cordova/walletHome';
}
}, false);
@ -53,13 +61,6 @@ angular.element(document).ready(function() {
navigator.splashscreen.hide();
}, 2000);
function handleBitcoinURI(url) {
if (!url) return;
setTimeout(function() {
window.location = '#/uri-payment/' + url;
}, 1000);
}
window.plugins.webintent.getUri(handleBitcoinURI);
window.plugins.webintent.onNewIntent(handleBitcoinURI);
window.handleOpenURL = handleBitcoinURI;
@ -67,6 +68,13 @@ angular.element(document).ready(function() {
startAngular();
}, false);
} else {
try {
window.handleOpenURL = handleBitcoinURI;
window.plugins.webintent.getUri(handleBitcoinURI);
window.plugins.webintent.onNewIntent(handleBitcoinURI);
} catch (e) {}
startAngular();
}

View file

@ -0,0 +1,75 @@
'use strict';
'use strict';
angular.module('copayApp.services')
.factory('addressService', function(storageService, profileService, $log, $timeout, lodash) {
var root = {};
root.expireAddress = function(walletId,cb) {
$log.debug('Cleaning Address ' + addr );
storageService.clearLastAddress(walletId, function(err) {
return cb(err);
});
};
root.isUsed = function(walletId, byAddress, cb) {
storageService.getLastAddress(walletId, function(err, addr) {
var used = lodash.find(byAddress, {
address: addr
});
return cb(null, used);
});
};
root._createAddress = function(walletId, cb) {
var client = profileService.getClient(walletId);
$log.debug('Creating address for wallet:', walletId);
client.createAddress(function(err, addr) {
if (err) {
if (err.error && err.error.match(/locked/gi)) {
$log.debug(err.error);
return $timeout(function() {
root._createAddress(walletId, cb);
}, 5000);
}
$log.debug('Creating address ERROR:', err);
return cb(err);
}
return cb(null, addr.address);
});
};
root.getAddress = function(walletId, forceNew, cb) {
var firstStep;
if (forceNew) {
firstStep = storageService.clearLastAddress;
} else {
firstStep = function(walletId, cb) {
return cb();
};
}
firstStep(walletId, function(err) {
if (err) return cb(err);
storageService.getLastAddress(walletId, function(err, addr) {
if (err) return cb(err);
if (addr) return cb(null, addr);
root._createAddress(walletId, function(err, addr) {
if (err) return cb(err);
storageService.storeLastAddress(walletId, addr, function() {
if (err) return cb(err);
return cb(null, addr);
});
});
});
});
};
return root;
});

View file

@ -233,6 +233,11 @@ angular.module('copayApp.services')
})
};
root.getClient = function(walletId) {
return root.walletClients[walletId];
};
root.deleteWalletFC = function(opts, cb) {
var fc = root.focusedClient;
$log.debug('Deleting Wallet:', fc.credentials.walletName);
@ -396,5 +401,29 @@ angular.module('copayApp.services')
});
};
root.getWallets = function(network) {
if (!root.profile) return [];
var config = configService.getSync();
config.colorFor = config.colorFor || {};
config.aliasFor = config.aliasFor || {};
var ret = lodash.map(root.profile.credentials, function(c) {
return {
m: c.m,
n: c.n,
name: config.aliasFor[c.walletId] || c.walletName,
id: c.walletId,
network: c.network,
color: config.colorFor[c.walletId] || '#2C3E50'
};
});
ret = lodash.filter(ret, function(w) {
return (w.network == network);
});
return lodash.sortBy(ret, 'name');
};
return root;
});