Bitpay Card: uses common widget for selecting wallet. Minor fixes

This commit is contained in:
Gustavo Maximiliano Cortez 2016-08-29 17:01:34 -03:00
commit 6e1b7ec620
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
6 changed files with 61 additions and 90 deletions

View file

@ -30,10 +30,10 @@
</div> </div>
<div class="item item-text-wrap item-button-right"> <div class="item item-text-wrap item-button-right">
<button class="button black" ng-click="toggleAlternative()" ng-show="showAlternativeAmount">{{alternativeIsoCode}}</button> <a class="postfix" ng-click="toggleAlternative()" ng-show="showAlternativeAmount">{{alternativeIsoCode}}</a>
<button class="button transform-none" ng-click="toggleAlternative()" ng-show="!showAlternativeAmount">{{unitName}}</button> <a class="postfix" ng-click="toggleAlternative()" ng-show="!showAlternativeAmount">{{unitName}}</a>
<div class="text-light text-black m15b" ng-class="{'size-28': smallFont, 'size-36': !smallFont}"> <span> {{amount || "0.00" }}</div> <div class="text-light text-black m15b" ng-class="{'size-28': smallFont, 'size-36': !smallFont}"> <span> {{amount || "0.00" }}</div>
<div class="text-light text-black" ng-class="{'size-16': smallFont, 'size-17': !smallFont}" ng-show="!showAlternativeAmount"> <div class="text-light text-black" ng-class="{'size-16': smallFont, 'size-17': !smallFont}" ng-show="!showAlternativeAmount">

View file

@ -15,7 +15,7 @@
<ion-content ng-controller="bitpayCardController as bitpayCard" ng-init="bitpayCard.init()"> <ion-content ng-controller="bitpayCardController as bitpayCard" ng-init="bitpayCard.init()">
<div class="text-center size-12" ng-show="network == 'testnet'"> <div class="box-notification warning" ng-show="network == 'testnet'">
Sandbox version. Only for testing purpose Sandbox version. Only for testing purpose
</div> </div>
@ -31,7 +31,7 @@
<span ng-show="!bitpayCard.bitpayCardTwoFactorPending">Login to your account</span> <span ng-show="!bitpayCard.bitpayCardTwoFactorPending">Login to your account</span>
<span ng-show="bitpayCard.bitpayCardTwoFactorPending">2-Step Verification</span> <span ng-show="bitpayCard.bitpayCardTwoFactorPending">2-Step Verification</span>
</h4> </h4>
<div class="m10b size-12" <div class="box-notification error"
ng-show="bitpayCard.error" ng-show="bitpayCard.error"
ng-click="bitpayCard.error = null"> ng-click="bitpayCard.error = null">
{{bitpayCard.error}} {{bitpayCard.error}}
@ -63,7 +63,7 @@
</label> </label>
</div> </div>
<input class="button button-block button-positive" <input class="button button-block"
type="submit" type="submit"
ng-disabled="!authenticateForm.$valid || bitpayCard.authenticating" ng-disabled="!authenticateForm.$valid || bitpayCard.authenticating"
value="Login"> value="Login">
@ -90,7 +90,7 @@
</label> </label>
</div> </div>
<input class="button button-block button-positive" <input class="button button-block"
type="submit" type="submit"
ng-disabled="!authenticate2FAForm.$valid || bitpayCard.authenticating" ng-disabled="!authenticate2FAForm.$valid || bitpayCard.authenticating"
value="Login"> value="Login">
@ -121,7 +121,7 @@
<option value="all">All Activity</option> <option value="all">All Activity</option>
</select> </select>
<div class="m20v size-12 text-center text-warning" <div class="box-notification error"
ng-show="bitpayCard.error"> ng-show="bitpayCard.error">
{{bitpayCard.error}} {{bitpayCard.error}}
</div> </div>
@ -176,7 +176,7 @@
</div> </div>
<div ng-show="bitpayCard.bitpayCardAuthenticated && !bitpayCard.visaCardActivated && addFunds"> <div ng-show="bitpayCard.bitpayCardAuthenticated && !bitpayCard.visaCardActivated && addFunds">
<div class="m10b box-notification size-12 text-warning" <div class="box-notification error"
ng-show="bitpayCard.error" ng-show="bitpayCard.error"
ng-click="bitpayCard.error = null"> ng-click="bitpayCard.error = null">
{{bitpayCard.error}} {{bitpayCard.error}}
@ -199,25 +199,11 @@
ng-model="fiat" ng-model="fiat"
autocomplete="off" autocomplete="off"
required> required>
<a class="postfix button black">USD</a> <a class="postfix">USD</a>
</label> </label>
<label class="item item-input item-stacked-label"> <wallets ng-if="wallets[0]" wallets="wallets"></wallets>
<span class="input-label">Add From Copay Wallet</span>
<input
type="text"
id="address"
name="address"
ng-disabled="bitpayCard.selectedWalletId"
ng-attr-placeholder="{{'Choose your source wallet'}}"
ng-model="bitpayCard.selectedWalletName" required>
<a
class="postfix size-12 m0 text-gray"
ng-style="{'color': '#293C92'}"
on-tap="openWalletsModal(bitpayCard.allWallets)">
<i class="icon-wallet size-18"></i>
</a>
</label>
</div> </div>
<p class="size-12 text-warning" ng-show="bitpayCard.isMultisigWallet"> <p class="size-12 text-warning" ng-show="bitpayCard.isMultisigWallet">
@ -234,8 +220,8 @@
</button> </button>
</div> </div>
<div class="col"> <div class="col">
<button class="button button-block button-positive" <button class="button button-block"
ng-disabled="!bitpayCard.selectedWalletId || !fiat" ng-disabled="!fiat"
type="submit"> type="submit">
Send Send
</button> </button>

View file

@ -50,7 +50,7 @@
max="500" max="500"
ng-model="fiat" ng-model="fiat"
autocomplete="off" ignore-mouse-wheel required> autocomplete="off" ignore-mouse-wheel required>
<a class="postfix">USD</a>
</label> </label>
<wallets ng-if="wallets[0]" wallets="wallets"></wallets> <wallets ng-if="wallets[0]" wallets="wallets"></wallets>

View file

@ -9,6 +9,15 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
StatusBar.backgroundColorByHexString("#293C92"); StatusBar.backgroundColorByHexString("#293C92");
} }
$scope.$on('Wallet/Changed', function(event, w) {
if (lodash.isEmpty(w)) {
$log.debug('No wallet provided');
return;
}
wallet = w;
$log.debug('Wallet changed: ' + w.name);
});
var processTransactions = function(invoices, history) { var processTransactions = function(invoices, history) {
for (var i = 0; i < invoices.length; i++) { for (var i = 0; i < invoices.length; i++) {
var matched = false; var matched = false;
@ -63,7 +72,6 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
bitpayCardService.isAuthenticated(function(err, bpSession) { bitpayCardService.isAuthenticated(function(err, bpSession) {
self.loadingSession = false; self.loadingSession = false;
if (err) { if (err) {
self.error = err.data.error || 'Incorrect email or password';
return; return;
} }
@ -79,7 +87,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
bitpayCardService.transactionHistory(dateRange, function(err, history) { bitpayCardService.transactionHistory(dateRange, function(err, history) {
$scope.loadingHistory = false; $scope.loadingHistory = false;
if (err) { if (err) {
self.error = err.error || err; self.error = 'Error getting transactions';
return; return;
} }
@ -98,60 +106,24 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
$scope.dateRange = 'last30Days'; $scope.dateRange = 'last30Days';
$scope.network = bitpayCardService.getEnvironment(); $scope.network = bitpayCardService.getEnvironment();
self.allWallets = profileService.getWallets({ $scope.wallets = profileService.getWallets({
network: $scope.network, network: $scope.network,
n: 1,
onlyComplete: true onlyComplete: true
}); });
self.update(); self.update();
if (lodash.isEmpty(self.allWallets)) return; wallet = $scope.wallets[0];
wallet = self.allWallets[0]; if (wallet && wallet.credentials.n > 1)
if (wallet.credentials.n > 1)
self.isMultisigWallet = true; self.isMultisigWallet = true;
$timeout(function() {
self.selectedWalletId = wallet.credentials.walletId;
self.selectedWalletName = wallet.credentials.walletName;
$scope.$apply();
}, 100);
};
$scope.openWalletsModal = function(wallets) {
self.error = null;
$scope.wallets = wallets;
$scope.noColor = true;
$scope.self = self;
$ionicModal.fromTemplateUrl('views/modals/wallets.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.walletsModal = modal;
$scope.walletsModal.show();
});
$scope.$on('walletSelected', function(ev, walletId) {
$timeout(function() {
wallet = profileService.getClient(walletId);
self.isMultisigWallet = false;
self.selectedWalletId = walletId;
self.selectedWalletName = wallet.credentials.walletName;
if (wallet.credentials.n > 1)
self.isMultisigWallet = true;
$scope.$apply();
}, 100);
$scope.walletsModal.hide();
});
}; };
this.sendFunds = function() { this.sendFunds = function() {
self.error = null; self.error = null;
if (lodash.isEmpty(wallet)) return;
if (!wallet.canSign() && !wallet.isPrivKeyExternal()) { if (!wallet.canSign() && !wallet.isPrivKeyExternal()) {
$log.info('No signing proposal: No private key'); $log.info('No signing proposal: No private key');
self.error = bwcError.msg('MISSING_PRIVATE_KEY'); self.error = bwcError.msg('MISSING_PRIVATE_KEY');
@ -297,8 +269,8 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
self.authenticating = true; self.authenticating = true;
bitpayCardService.authenticate(data, function(err, auth) { bitpayCardService.authenticate(data, function(err, auth) {
self.authenticating = false; self.authenticating = false;
if (err && !err.data.error.twoFactorPending) { if (err && err.data && err.data.error && !err.data.error.twoFactorPending) {
self.error = 'Authentiation error'; self.error = err.statusText || err.data.error || 'Authentiation error';
return; return;
} }

View file

@ -19,6 +19,11 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
}; };
}; };
var _setError = function(msg, e) {
$log.error(msg);
return e;
};
var _getUser = function(cb) { var _getUser = function(cb) {
_setCredentials(); _setCredentials();
storageService.getBitpayCard(credentials.NETWORK, function(err, user) { storageService.getBitpayCard(credentials.NETWORK, function(err, user) {
@ -53,8 +58,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
bpSession = data.data.data; bpSession = data.data.data;
return cb(null, bpSession); return cb(null, bpSession);
}, function(data) { }, function(data) {
$log.error('BitPay Get Session: ERROR ' + data.data.error); return cb(_setError('BitPay Card Error: Get Session', data));
return cb(data.data.error);
}); });
}; };
@ -97,8 +101,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
$log.info('BitPay TopUp: SUCCESS'); $log.info('BitPay TopUp: SUCCESS');
return cb(null, data.data.data.invoice); return cb(null, data.data.data.invoice);
}, function(data) { }, function(data) {
$log.error('BitPay TopUp: ERROR ' + data.data.error); return cb(_setError('BitPay Card Error: TopUp', data));
return cb(data.data.error);
}); });
}; };
@ -113,8 +116,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
$log.info('BitPay Get Transaction History: SUCCESS'); $log.info('BitPay Get Transaction History: SUCCESS');
return cb(null, data.data.data); return cb(null, data.data.data);
}, function(data) { }, function(data) {
$log.error('BitPay Get Transaction History: ERROR ' + data.data); return cb(_setError('BitPay Card Error: Get Transaction History', data));
return cb(data.data);
}); });
}; };
@ -123,8 +125,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
$log.info('BitPay Get Invoice History: SUCCESS'); $log.info('BitPay Get Invoice History: SUCCESS');
return cb(null, data.data.data); return cb(null, data.data.data);
}, function(data) { }, function(data) {
$log.error('BitPay Get Invoice History: ERROR ' + data.data); return cb(_setError('BitPay Card Error: Get Invoice History', data));
return cb(data.data);
}); });
}; };
@ -133,8 +134,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
$log.info('BitPay Get Invoice: SUCCESS'); $log.info('BitPay Get Invoice: SUCCESS');
return cb(null, data.data.data); return cb(null, data.data.data);
}, function(data) { }, function(data) {
$log.error('BitPay Get Invoice: ERROR ' + data.data.error); return cb(_setError('BitPay Card Error: Get Invoice', data));
return cb(data.data.error);
}); });
}; };
@ -147,8 +147,8 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
return cb(null, session); return cb(null, session);
}); });
}, function(data) { }, function(data) {
$log.error('BitPay Authenticate: ERROR'); if (data && data.data && data.data.error.twoFactorPending) {
if (data.data.error.twoFactorPending) { $log.error('BitPay Card needs 2FA Authentication');
_getSession(function(err, session) { _getSession(function(err, session) {
if (err) return cb(err); if (err) return cb(err);
return cb(null, session); return cb(null, session);
@ -165,8 +165,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
$log.info('BitPay 2FA: SUCCESS'); $log.info('BitPay 2FA: SUCCESS');
return cb(null, data); return cb(null, data);
}, function(data) { }, function(data) {
$log.error('BitPay 2FA: ERROR'); return cb(_setError('BitPay Card Error: 2FA', data));
return cb(data);
}); });
}; };
@ -195,8 +194,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
$log.info('BitPay Logout: SUCCESS'); $log.info('BitPay Logout: SUCCESS');
return cb(data); return cb(data);
}, function(data) { }, function(data) {
$log.error('BitPay Logout: ERROR ' + data.data.error); return cb(_setError('BitPay Card Error: Logout ', data));
return cb(data.data.error);
}); });
}); });
}; };

View file

@ -426,6 +426,21 @@ ul.wallet-selection.wallets {
} }
} }
// POSTFIX
.postfix {
position: absolute;
right: 10px;
background-color: #f8f8f8;
color: #444;
border-radius: 4px;
padding: 2px 10px;
cursor: pointer;
label &{
top: 38px;
padding: 0 5px;
}
}
// QR Code // QR Code