Merge pull request #1706 from matiaspando/feature/selectWalletOnBIP21

Added page and controller to select wallet
This commit is contained in:
Juan Ignacio Sosa Lopez 2014-11-04 11:30:11 -03:00
commit e9c160bd4d
6 changed files with 98 additions and 2 deletions

View File

@ -0,0 +1,27 @@
'use strict';
var bitcore = require('bitcore');
angular.module('copayApp.controllers').controller('PaymentIntentController', function($rootScope, $scope, $routeParams, $timeout, $location, controllerUtils) {
$rootScope.title = 'Select the wallet that you will use to spend your bitcoins';
$scope.wallets = [];
var wids = _.pluck($rootScope.iden.listWallets(), 'id');
_.each(wids, function(wid) {
var w = $rootScope.iden.getWalletById(wid);
if (w && w.isReady()) {
$scope.wallets.push(w);
controllerUtils.updateBalance(w, function() {
$rootScope.$digest();
});
}
});
$scope.switchWallet = function(wid) {
//go to send page
controllerUtils.setPaymentWallet(wid);
};
});

View File

@ -4,6 +4,34 @@ var preconditions = require('preconditions').singleton();
angular.module('copayApp.controllers').controller('SendController',
function($scope, $rootScope, $window, $timeout, $anchorScroll, $modal, isMobile, notification, controllerUtils, rateService) {
controllerUtils.redirIfNotComplete();
var w = $rootScope.wallet;
preconditions.checkState(w);
preconditions.checkState(w.settings.unitToSatoshi);
$rootScope.title = 'Send';
$scope.loading = false;
var satToUnit = 1 / w.settings.unitToSatoshi;
$scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit;
$scope.unitToBtc = w.settings.unitToSatoshi / bitcore.util.COIN;
$scope.unitToSatoshi = w.settings.unitToSatoshi;
$scope.alternativeName = w.settings.alternativeName;
$scope.alternativeIsoCode = w.settings.alternativeIsoCode;
$scope.isRateAvailable = false;
$scope.rateService = rateService;
rateService.whenAvailable(function() {
$scope.isRateAvailable = true;
$scope.$digest();
});
/**
* Setting the two related amounts as properties prevents an infinite
* recursion for watches while preserving the original angular updates

View File

@ -14,7 +14,8 @@ angular.module('copayApp.controllers').controller('UriPaymentController', functi
$rootScope.pendingPayment = new bitcore.BIP21(bitcoinURI);
$timeout(function() {
$location.path('/send');
console.log('Redirecting to /paymentIntent');
$location.path('/paymentIntent');
}, 1000);

View File

@ -22,6 +22,10 @@ angular
.when('/uri-payment/:data', {
templateUrl: 'views/uri-payment.html'
})
.when('/paymentIntent', {
templateUrl: 'views/paymentIntent.html',
logged: true
})
.when('/join', {
templateUrl: 'views/join.html',
logged: true

View File

@ -93,7 +93,7 @@ angular.module('copayApp.services')
if ($rootScope.initialConnection) {
$rootScope.initialConnection = false;
if ($rootScope.pendingPayment) {
$location.path('send');
$location.path('paymentIntent');
} else {
root.redirIfLogged();
}
@ -196,6 +196,11 @@ angular.module('copayApp.services')
});
};
root.setPaymentWallet = function(w) {
root.setFocusedWallet(w);
$location.path('/send');
};
root.setFocusedWallet = function(w) {
if (!_.isObject(w))
w = $rootScope.iden.getWalletById(w);

31
views/paymentIntent.html Normal file
View File

@ -0,0 +1,31 @@
<div ng-controller="PaymentIntentController" class="large-4 columns large-centered">
<!-- //TODO THIS SHOULD BE A POPUP -->
<ul class="side-nav wallets" 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">
<div class="col1">
<div class="avatar-wallet">{{(item.name || item.id) | limitTo: 1}}</div>
</div>
<div class="col2">
<a class="size-12 wallet-item" ng-click="switchWallet(item.id)">
<div class="oh">
<div class="right size-10 type-wallet">[ {{item.requiredCopayers}} of {{item.totalCopayers}} ]</div>
<div class="ellipsis name-wallet">{{item.name || item.id}}</div>
</div>
<div class="oh">
<span ng-if="item.balanceInfo.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
<div ng-if="!item.balanceInfo.updatingBalance" data-options="disable_for_touch:true">
<b class="m5r size-12">{{item.balanceInfo.totalBalance || 0 |noFractionNumber}} {{item.settings.unitName}}</b>
<span class="alt-currency size-10">{{item.balanceInfo.totalBalanceAlternative |noFractionNumber:2}} {{item.balanceInfo.alternativeIsoCode}}</span>
</div>
</div>
</a>
</div>
</li>
</ul>
</div>