only show matching network wallet in payment intents

This commit is contained in:
Matias Alejo Garcia 2015-04-23 16:17:18 -03:00
commit cd901f5b3e
4 changed files with 88 additions and 66 deletions

View file

@ -9,15 +9,18 @@
<div class="ellipsis"><b translate>Address</b>: {{uri.address.toString()}}</div> <div class="ellipsis"><b translate>Address</b>: {{uri.address.toString()}}</div>
<div ng-show="uri.amount"><b translate>Amount</b>: {{uri.amount}}</div> <div ng-show="uri.amount"><b translate>Amount</b>: {{uri.amount}}</div>
<div ng-show="uri.message"><b translate>Message</b>: {{uri.message}}</div> <div ng-show="uri.message"><b translate>Message</b>: {{uri.message}}</div>
<div ng-show="uri.network == 'testnet'"><b translate>Network</b>: {{uri.network}}</div>
</div> </div>
<h2 translate>Select a wallet</h2> <h2 translate>Select a wallet</h2>
<ul class="no-bullet" ng-init="wallets = payment.getWallets()"> <ul class="no-bullet" ng-init="wallets = payment.getWallets(uri.network)">
<li class="panel" ng-repeat="w in wallets"> <li class="panel" ng-repeat="w in wallets">
<a ng-click="payment.selectWallet(w.id)"> <a ng-click="payment.selectWallet(w.id)">
<div class="avatar-wallet" <div class="avatar-wallet"
ng-style="{'background-color':w.color}">{{(w.name || w.id) | limitTo: 1}}</div> ng-style="{'background-color':w.color}">{{(w.name || w.id) | limitTo: 1}}</div>
<div class="ellipsis">{{w.name || w.id}}</div> <div class="ellipsis">{{w.name || w.id}}</div>
<div class="size-12">{{w.m}} of {{w.n}}</div> <div class="size-12">{{w.m}} of {{w.n}}
<span ng-show="w.network=='testnet'">[Testnet]</span>
</div>
</a> </a>
</li> </li>
</ul> </ul>

View file

@ -104,11 +104,20 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}; };
self.setTab = function(tab) { self.setTab = function(tab) {
if (self.tab && document.getElementById(self.tab)) {
if (self.tab === tab)
return;
if (!self.tab)
self.tab = 'walletHome';
if (document.getElementById(self.tab)) {
document.getElementById(self.tab).className = 'tab-out tab-view ' + self.tab; document.getElementById(self.tab).className = 'tab-out tab-view ' + self.tab;
var old = document.getElementById('menu-' + self.tab); var old = document.getElementById('menu-' + self.tab);
old.className = ''; if (old) {
old.style.borderTopColor = ''; old.className = '';
old.style.borderTopColor = '';
}
} }
if (document.getElementById(tab)) { if (document.getElementById(tab)) {

View file

@ -1,63 +1,68 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('paymentUriController', angular.module('copayApp.controllers').controller('paymentUriController',
function($rootScope, $stateParams, $location, $timeout, profileService, configService, lodash, bitcore, go) { function($rootScope, $stateParams, $location, $timeout, profileService, configService, lodash, bitcore, go) {
function strip(number) { function strip(number) {
return (parseFloat(number.toPrecision(12))); return (parseFloat(number.toPrecision(12)));
}; };
// Build bitcoinURI with querystring // Build bitcoinURI with querystring
this.checkBitcoinUri = function() { this.checkBitcoinUri = function() {
var query = []; var query = [];
angular.forEach($location.search(), function(value, key) { angular.forEach($location.search(), function(value, key) {
query.push(key + "=" + value); query.push(key + "=" + value);
}); });
var queryString = query ? query.join("&") : null; var queryString = query ? query.join("&") : null;
this.bitcoinURI = $stateParams.data + ( queryString ? '?' + queryString : ''); this.bitcoinURI = $stateParams.data + (queryString ? '?' + queryString : '');
var URI = bitcore.URI; var URI = bitcore.URI;
var isUriValid = URI.isValid(this.bitcoinURI); var isUriValid = URI.isValid(this.bitcoinURI);
if (!URI.isValid(this.bitcoinURI)) { if (!URI.isValid(this.bitcoinURI)) {
this.error = true; this.error = true;
return; return;
} }
var uri = new URI(this.bitcoinURI); var uri = new URI(this.bitcoinURI);
if (uri && uri.address) { if (uri && uri.address) {
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
var unitToSatoshi = config.unitToSatoshi; var unitToSatoshi = config.unitToSatoshi;
var satToUnit = 1 / unitToSatoshi; var satToUnit = 1 / unitToSatoshi;
var unitName = config.unitName; var unitName = config.unitName;
uri.amount = strip(uri.amount * satToUnit) + ' ' + unitName; uri.amount = strip(uri.amount * satToUnit) + ' ' + unitName;
return uri; uri.network = uri.address.network.name;
} return uri;
}; }
};
this.getWallets = function() { this.getWallets = function(network) {
if (!profileService.profile) return; if (!profileService.profile) return;
var config = configService.getSync(); var config = configService.getSync();
config.colorFor = config.colorFor || {}; config.colorFor = config.colorFor || {};
var ret = lodash.map(profileService.profile.credentials, function(c) { var ret = lodash.map(profileService.profile.credentials, function(c) {
return { return {
m: c.m, m: c.m,
n: c.n, n: c.n,
name: c.walletName, name: c.walletName,
id: c.walletId, id: c.walletId,
color: config.colorFor[c.walletId] || '#2C3E50' network: c.network,
}; color: config.colorFor[c.walletId] || '#2C3E50'
}); };
return lodash.sortBy(ret, 'walletName'); });
}; ret = lodash.filter(ret, function(w) {
return (w.network == network);
});
return lodash.sortBy(ret, 'walletName');
};
this.selectWallet = function(wid) { this.selectWallet = function(wid) {
var self = this; var self = this;
if (wid != profileService.focusedClient.credentials.walletId) { if (wid != profileService.focusedClient.credentials.walletId) {
profileService.setAndStoreFocus(wid, function() {}); profileService.setAndStoreFocus(wid, function() {});
} }
go.send(); go.send();
$timeout(function() { $timeout(function() {
$rootScope.$emit('paymentUri', self.bitcoinURI); $rootScope.$emit('paymentUri', self.bitcoinURI);
}, 100); }, 100);
}; };
}); });

View file

@ -36,8 +36,11 @@ angular.module('copayApp.services').factory('go', function($window, $rootScope,
var ref = window.open(url, '_blank', 'location=no'); var ref = window.open(url, '_blank', 'location=no');
}; };
root.path = function(path) { root.path = function(path, cb) {
$state.transitionTo(path); $state.transitionTo(path)
.then(function() {
if (cb) return cb();
});
hideSidebars(); hideSidebars();
}; };
@ -51,15 +54,17 @@ angular.module('copayApp.services').factory('go', function($window, $rootScope,
if (fc && !fc.isComplete()) { if (fc && !fc.isComplete()) {
root.path('copayers'); root.path('copayers');
} else { } else {
root.path('walletHome'); root.path('walletHome', function() {
$rootScope.$emit('Local/SetTab', 'walletHome'); $rootScope.$emit('Local/SetTab', 'walletHome');
});
} }
}; };
root.send = function() { root.send = function() {
root.path('walletHome'); root.path('walletHome', function() {
$rootScope.$emit('Local/SetTab', 'walletHome'); $rootScope.$emit('Local/SetTab', 'send');
});
}; };
root.home = function() { root.home = function() {