handle error / incomplete on receive

This commit is contained in:
Matias Alejo Garcia 2016-08-15 11:56:59 -03:00
commit 6dba17937f
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
5 changed files with 102 additions and 55 deletions

View file

@ -9,17 +9,19 @@
<li ng-show="wallets[0]"
ng-repeat="item in wallets track by $index" class="item item-icon-left"
menu-toggle href ui-sref="walletDetails({'walletId': item.id})">
<i class="icon icon-wallet size-21" ng-style="{'color':item.color}"></i>
<i class="icon ion-briefcase size-21" ng-style="{'color':item.color}"></i>
{{item.name || item.id}}
<span ng-show="item.n > 1">
[ {{item.m}}-of-{{item.n}} ]
<span ng-show="item.n > 1" class="text-gray">
{{item.m}}-of-{{item.n}}
</span>
<span class="item-note">
<span class="badge badge-assertive" ng-show="!item.isComplete()" translate>
Incomplete
</span>
<span class="item-note" ng-show="item.isComplete()">
{{item.availableBalanceStr}}
</span>
</li>
</ul>
</div>

View file

@ -1,19 +1,46 @@
<ion-view ng-controller="tabReceiveController" cache-view="false">
<ion-nav-title>Receive</ion-nav-title>
<ion-content ng-init="init()">
<div class="text-center" ng-click="copyToClipboard(addr, $event)" ng-show="addr || generatingAddress">
<qrcode size="220" data="bitcoin:{{addr}}"></qrcode>
<div ng-show="home.generatingAddress" style="position:relative; top:-226px; height:0px">
<div style="height:220px; width:220px; margin:auto; background: white">
<ion-spinner class="spinner-stable" icon="lines" style="margin-top: 85px"></ion-spinner>
<div class="text-center m30v" ng-click="copyToClipboard(addr, $event)" ng-show="addr" >
<qrcode size="220" data="bitcoin:{{addr}}" ng-show="addr"></qrcode>
</div>
<div ng-show="generatingAddress" class="m30v">
<div style="height:220px; width:220px; margin:auto; background: #eee; text-align:center">
<ion-spinner class="spinner-stable" icon="lines" style="stroke:black; margin-top: 85px"></ion-spinner>
</div>
</div>
<div ng-show="incomplete">
<div style="height:220px; width:220px; margin: 30px auto; background: #eee; text-align:center">
incomplete wallet
</div>
<div class="item item-icon-left" ng-click="shareAddress(addr)" ng-show="index.isCordova && home.addr" ng-disabled="generatingAddress">
<div class="item item-icon-left" ng-click="shareAddress(addr)" ng-show="isCordova && addr" ng-disabled="generatingAddress">
<i class="icon ion-ios-upload-outline"></i>
</div>
<div class="item item-icon-left" ng-click="setAddress(true)" ng-show="!generatingAddress">
<i class="icon ion-ios-loop"></i>
</div>
<div class="item item-icon-left">
<i class="icon ion-social-bitcoin-outline"></i>
</div>
</div>
<div ng-show="addrError">
<div style="height:220px; width:220px; margin: 30px auto; background: #eee; text-align:center">
Error: {{addrError}}
</div>
</div>
<div ng-show="!incomplete">
<div class="item item-icon-left" ng-click="shareAddress(addr)" ng-show="isCordova && addr" ng-disabled="generatingAddress">
<i class="icon ion-ios-upload-outline"></i>
<span translate>Share address</span>
</div>
<div class="item item-icon-left" ng-click="setAddress(true)" ng-show="!home.generatingAddress">
<div class="item item-icon-left" ng-click="setAddress(true)" ng-disabled="">
<i class="icon ion-ios-loop"></i>
<span translate>Next Address</span>
</div>
@ -21,17 +48,22 @@
<i class="icon ion-social-bitcoin-outline"></i>
{{generatingAddress ? '...' : addr}}
</div>
</div>
<div class="item item-text-wrap" ng-style="{'height' : '200px'}">
<ion-slides class="slides" options="options" slider="data.slider">
<ion-slide-page ng-repeat="item in wallets track by $index" >
<div class="list card">
<ul class="pr">
<li ng-show="wallets[0]" class="item item-icon-left">
<i class="icon icon-wallet size-21" ng-style="{'color':item.color}"></i>
<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">
<span class="item-note" ng-show="item.n > 1 && item.isComplete()">
{{item.m}}-of-{{item.n}}
</span>
<span class="badge badge-assertive" ng-show="!item.isComplete()" translate>
Incomplete
</span>
</li>
</ul>
</div>

View file

@ -1,6 +1,8 @@
'use strict';
angular.module('copayApp.controllers').controller('tabReceiveController', function($scope, $ionicPopover, $timeout, platformInfo, nodeWebkit, addressService, profileService, configService, lodash) {
angular.module('copayApp.controllers').controller('tabReceiveController', function($scope, $ionicPopover, $timeout, platformInfo, nodeWebkit, walletService, profileService, configService, lodash, gettextCatalog) {
$scope.isCordova = platformInfo.isCordova;
$scope.init = function() {
$scope.index = 0;
@ -26,7 +28,7 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
$scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
$scope.index = data.slider.activeIndex;
$scope.setAddress(false);
$scope.setAddress();
});
}
@ -70,10 +72,24 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
};
$scope.setAddress = function(forceNew) {
if ($scope.generatingAddress) return;
$scope.addr = null;
$scope.addrError = null;
var wallet = $scope.wallets[$scope.index];
if (!wallet.isComplete()) {
$scope.incomplete = true;
$timeout(function() {
$scope.$digest();
});
return;
}
$scope.incomplete = false;
$scope.generatingAddress = true;
$timeout(function() {
addressService.getAddress($scope.wallets[$scope.index].id, forceNew, function(err, addr) {
walletService.getAddress($scope.wallets[$scope.index], forceNew, function(err, addr) {
$scope.generatingAddress = false;
if (err) {
$scope.addrError = err;
@ -88,25 +104,7 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
$scope.setWallets = function() {
if (!profileService.profile) return;
var config = configService.getSync();
config.colorFor = config.colorFor || {};
config.aliasFor = config.aliasFor || {};
// Sanitize empty wallets (fixed in BWC 1.8.1, and auto fixed when wallets completes)
var credentials = lodash.filter(profileService.profile.credentials, 'walletName');
var ret = lodash.map(credentials, function(c) {
return {
m: c.m,
n: c.n,
name: config.aliasFor[c.walletId] || c.walletName,
id: c.walletId,
color: config.colorFor[c.walletId] || '#4A90E2',
};
});
$scope.wallets = lodash.sortBy(ret, 'name');
$scope.wallets = profileService.getWallets();
};
});

View file

@ -82,8 +82,10 @@ angular.module('copayApp.services')
c.name = config.aliasFor[walletId] || client.credentials.walletName;
c.color = config.colorFor[walletId] || '#4A90E2';
c.network = client.credentials.network;
root.setCustomBWSFlag(c);
c.m = client.credentials.m;
c.n = client.credentials.n;
root.setCustomBWSFlag(c);
root.wallet[walletId] = c;
client.removeAllListeners();
@ -713,18 +715,30 @@ angular.module('copayApp.services')
storageService.storeProfile(root.profile, cb);
};
root.getWallets = function(network, n) {
root.getWallets = function(opts) {
if (opts && !lodash.isObject(opts))
throw "bad argument";
opts = opts || {};
var ret = lodash.values(root.wallet);
if (network) {
if (opts.network) {
ret = lodash.filter(ret, function(x) {
return (x.credentials.network == network);
return (x.credentials.network == opts.network);
});
}
if (n) {
if (opts.n) {
ret = lodash.filter(ret, function(w) {
return (w.credentials.n == n);
return (w.credentials.n == opts.n);
});
}
if (opts.onlyComplete) {
ret = lodash.filter(ret, function(w) {
return w.isComplete();
});
}

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) {
angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, storageService, configService, rateService, uxLanguage, bwcService, $filter, gettextCatalog, bwcError) {
// DO NOT INCLUDE STORAGE HERE ^^
//
//
@ -755,7 +755,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
});
};
root._createAddress = function(wallet, cb) {
var createAddress = function(wallet, cb) {
$log.debug('Creating address for wallet:', wallet.id);
wallet.createAddress({}, function(err, addr) {
@ -764,7 +764,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (err.error && err.error.match(/locked/gi)) {
$log.debug(err.error);
return $timeout(function() {
root._createAddress(walletId, cb);
createAddress(wallet, cb);
}, 5000);
} else if (err.message && err.message == 'MAIN_ADDRESS_GAP_REACHED') {
$log.warn(err.message);
@ -784,6 +784,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
};
root.getAddress = function(wallet, forceNew, cb) {
console.log('[walletService.js.786:wallet:]',wallet, forceNew); //TODO
var firstStep;
if (forceNew) {
@ -802,7 +803,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (addr) return cb(null, addr);
root._createAddress(wallet, function(err, addr) {
createAddress(wallet, function(err, addr) {
if (err) return cb(err);
storageService.storeLastAddress(wallet.id, addr, function() {
if (err) return cb(err);