Ionic modals. Fix select wallet to buy/sell

This commit is contained in:
Gustavo Maximiliano Cortez 2016-06-13 15:00:17 -03:00
commit 2b60bc3066
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
6 changed files with 243 additions and 298 deletions

View file

@ -59,7 +59,7 @@
<div <div
ng-init="buy.init()" ng-init="buy.init()"
ng-click="openWalletsModal(buy.otherWallets)"> ng-click="openWalletsModal(buy.allWallets)">
<label>Pay From Copay Wallet</label> <label>Pay From Copay Wallet</label>
<div class="input"> <div class="input">
<input type="text" id="address" name="address" ng-disabled="buy.selectedWalletId" <input type="text" id="address" name="address" ng-disabled="buy.selectedWalletId"
@ -73,7 +73,7 @@
<div class="input m20t"> <div class="input m20t">
<input class="button black round expand" <input class="button black round expand"
ng-disabled="buy.loading || !fiat" ng-disabled="!buy.selectedWalletId || buy.loading || !fiat"
type="submit" value="Buy now"> type="submit" value="Buy now">
</div> </div>
</form> </form>
@ -111,13 +111,13 @@
<div class="oh m20t size-12 text-center"> <div class="oh m20t size-12 text-center">
<img class="m10h" src="img/a_generic.jpg" alt="Amazon.com Gift Cards" width="230"> <img class="m10h" src="img/a_generic.jpg" alt="Amazon.com Gift Cards" width="230">
<div class="m10t"> <div class="m10t size-14">
Gift Card Amount: Gift Card Amount:
<span class="text-bold"> <span class="text-bold">
{{buy.giftCard.cardInfo.value.amount | currency : '$ ' : 2 }} {{buy.giftCard.cardInfo.value.amount | currency : '$ ' : 2 }}
</span> </span>
</div> </div>
<div> <div class="size-14">
Claim code: <span class="text-bold enable_text_select">{{buy.giftCard.gcClaimCode}}</span> Claim code: <span class="text-bold enable_text_select">{{buy.giftCard.gcClaimCode}}</span>
</div> </div>
<div class="m10t"> <div class="m10t">

View file

@ -32,9 +32,8 @@
</li> </li>
<li menu-toggle href ui-sref="amazon" ng-show="index.isComplete && index.amazonEnabled"> <li menu-toggle href ui-sref="amazon" ng-show="index.isComplete && index.amazonEnabled">
<i class="icon-arrow-right3 size-18 right m10t vm"></i> <i class="icon-arrow-right3 size-18 right m10t vm"></i>
<i class="fi-shopping-cart size-24 icon vm"></i>
<i class="fi-shopping-bag size-24 icon vm"></i> <i class="fi-shopping-bag size-24 icon vm"></i>
<div class="tu text-bold m5t"> <div class="tu text-bold m10t">
<span class="size-12" translate>Gift Cards</span> <span class="size-12" translate>Gift Cards</span>
</div> </div>
</li> </li>

View file

@ -1,3 +1,4 @@
<ion-modal-view ng-controller="amazonCardDetailsController">
<nav class="tab-bar"> <nav class="tab-bar">
<section class="left-small"> <section class="left-small">
<a ng-click="cancel()"> <a ng-click="cancel()">
@ -12,9 +13,9 @@
</section> </section>
</nav> </nav>
<div class="modal-content fix-modals-touch" <ion-content overflow-scroll="true">
ng-swipe-disable-mouse
ng-swipe-right="cancel()"> <div class="modal-content fix-modals-touch">
<div class="header-modal bg-gray text-center"> <div class="header-modal bg-gray text-center">
<img src="img/a_generic.jpg" alt="Amazon.com Gift Card" width="230" ng-click="refreshGiftCard()"> <img src="img/a_generic.jpg" alt="Amazon.com Gift Card" width="230" ng-click="refreshGiftCard()">
@ -152,3 +153,5 @@
<div class="extra-margin-bottom"></div> <div class="extra-margin-bottom"></div>
</div> </div>
</ion-content>
</ion-modal-view>

View file

@ -1,9 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('amazonController', angular.module('copayApp.controllers').controller('amazonController',
function($rootScope, $scope, $timeout, $modal, profileService, configService, amazonService, animationService, lodash) { function($scope, $timeout, $ionicModal, configService, amazonService) {
window.ignoreMobilePause = true;
this.init = function() { this.init = function() {
var self = this; var self = this;
@ -23,88 +21,13 @@ angular.module('copayApp.controllers').controller('amazonController',
}; };
this.openCardModal = function(card) { this.openCardModal = function(card) {
$rootScope.modalOpened = true;
var self = this;
var fc = profileService.focusedClient;
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.card = card; $scope.card = card;
$scope.cancelGiftCard = function() { $ionicModal.fromTemplateUrl('views/modals/amazon-card-details.html', {
$scope.refresh = true; scope: $scope
var dataSrc = { }).then(function(modal) {
creationRequestId: $scope.card.creationRequestId, $scope.amazonCardDetailsModal = modal;
gcId: $scope.card.gcId, $scope.amazonCardDetailsModal.show();
bitpayInvoiceId: $scope.card.bitpayInvoiceId,
bitpayInvoiceUrl: $scope.card.bitpayInvoiceUrl,
date: $scope.card.date
};
$scope.loading = true;
amazonService.cancelGiftCard(dataSrc, function(err, data) {
$scope.loading = null;
if (err || data.status != 'SUCCESS') {
$scope.error = err || data.status;
return;
}
$scope.refreshGiftCard();
}); });
}; };
$scope.remove = function() {
amazonService.saveGiftCard($scope.card, {remove: true}, function(err) {
$modalInstance.close(true);
});
};
$scope.refreshGiftCard = function() {
$scope.refresh = true;
var dataSrc = {
creationRequestId: $scope.card.creationRequestId,
amount: $scope.card.cardInfo.value.amount,
currencyCode: $scope.card.cardInfo.value.currencyCode,
bitpayInvoiceId: $scope.card.bitpayInvoiceId,
bitpayInvoiceUrl: $scope.card.bitpayInvoiceUrl,
date: $scope.card.date
};
$scope.loading = true;
amazonService.createGiftCard(dataSrc, function(err, data) {
$scope.loading = null;
if (err) {
$scope.error = err;
return;
}
$scope.card = data;
$timeout(function() {
$scope.$digest();
});
});
};
$scope.cancel = lodash.debounce(function() {
$modalInstance.close($scope.refresh);
}, 0, 1000);
};
var modalInstance = $modal.open({
templateUrl: 'views/modals/amazon-card-details.html',
windowClass: animationService.modalAnimated.slideRight,
controller: ModalInstanceCtrl,
});
var disableCloseModal = $rootScope.$on('closeModal', function() {
modalInstance.close($scope.refresh);
});
modalInstance.result.finally(function() {
$rootScope.modalOpened = false;
disableCloseModal();
var m = angular.element(document.getElementsByClassName('reveal-modal'));
m.addClass(animationService.modalAnimated.slideOutRight);
});
modalInstance.result.then(function(refresh) {
if (refresh) self.init();
}, function() {});
};
}); });

View file

@ -1,22 +1,15 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('buyAmazonController', angular.module('copayApp.controllers').controller('buyAmazonController',
function($rootScope, $scope, $modal, $log, $timeout, lodash, profileService, animationService, bwsError, configService, walletService, fingerprintService, amazonService) { function($rootScope, $scope, $ionicModal, $log, $timeout, lodash, profileService, bwsError, configService, walletService, fingerprintService, amazonService) {
window.ignoreMobilePause = true;
var self = this; var self = this;
var fc; var client;
var minimumAmount = 5; var minimumAmount = 5;
var stepAmount = 1; var stepAmount = 1;
var multiplierAmount = 5; var multiplierAmount = 5;
var maximumAmount = 500; var maximumAmount = 500;
var otherWallets = function(network) {
return lodash.filter(profileService.getWallets(network), function(w) {
return w.network == network && w.m == 1;
});
};
var handleEncryptedWallet = function(client, cb) { var handleEncryptedWallet = function(client, cb) {
if (!walletService.isEncrypted(client)) return cb(); if (!walletService.isEncrypted(client)) return cb();
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) { $rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
@ -31,68 +24,38 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
amazonService.setCredentials(network); amazonService.setCredentials(network);
amazonService.healthCheckRequest(); amazonService.healthCheckRequest();
amazonService.initUuid(); amazonService.initUuid();
self.otherWallets = otherWallets(network); self.allWallets = profileService.getWallets(network, 1);
// Choose focused wallet client = profileService.focusedClient;
try { if (client && client.credentials.m == 1) {
var currentWalletId = profileService.focusedClient.credentials.walletId;
lodash.find(self.otherWallets, function(w) {
if (w.id == currentWalletId) {
$timeout(function() { $timeout(function() {
self.selectedWalletId = w.id; self.selectedWalletId = client.credentials.walletId;
self.selectedWalletName = w.name; self.selectedWalletName = client.credentials.walletName;
fc = profileService.getClient(w.id);
$scope.$apply(); $scope.$apply();
}, 100); }, 100);
} }
});
} catch (e) {
$log.debug(e);
};
}; };
$scope.openWalletsModal = function(wallets) { $scope.openWalletsModal = function(wallets) {
if (self.loading) return;
self.error = null; self.error = null;
self.errorInfo = null;
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.type = 'SELL'; $scope.type = 'SELL';
$scope.wallets = wallets; $scope.wallets = wallets;
$scope.noColor = true;
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
$scope.selectWallet = function(walletId, walletName) { $ionicModal.fromTemplateUrl('views/modals/wallets.html', {
if (!profileService.getClient(walletId).isComplete()) { scope: $scope
self.error = bwsError.msg('WALLET_NOT_COMPLETE'); }).then(function(modal) {
$modalInstance.dismiss('cancel'); $scope.walletsModal = modal;
return; $scope.walletsModal.show();
}
$modalInstance.close({
'walletId': walletId,
'walletName': walletName,
});
};
};
var modalInstance = $modal.open({
templateUrl: 'views/modals/wallets.html',
windowClass: animationService.modalAnimated.slideUp,
controller: ModalInstanceCtrl,
}); });
modalInstance.result.finally(function() { $scope.$on('walletSelected', function(ev, obj) {
var m = angular.element(document.getElementsByClassName('reveal-modal'));
m.addClass(animationService.modalAnimated.slideOutDown);
});
modalInstance.result.then(function(obj) {
$timeout(function() { $timeout(function() {
self.selectedWalletId = obj.walletId; self.selectedWalletId = obj.walletId;
self.selectedWalletName = obj.walletName; self.selectedWalletName = obj.walletName;
fc = profileService.getClient(obj.walletId); client = obj.client;
$scope.$apply(); $scope.$apply();
}, 100); }, 100);
$scope.walletsModal.hide();
}); });
}; };
@ -156,7 +119,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
}; };
self.loading = 'Creating transaction...'; self.loading = 'Creating transaction...';
walletService.createTx(fc, txp, function(err, createdTxp) { walletService.createTx(client, txp, function(err, createdTxp) {
self.loading = null; self.loading = null;
if (err) { if (err) {
self.loading = null; self.loading = null;
@ -204,38 +167,38 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
this.confirmTx = function(txp, cb) { this.confirmTx = function(txp, cb) {
fingerprintService.check(fc, function(err) { fingerprintService.check(client, function(err) {
if (err) { if (err) {
$log.debug(err); $log.debug(err);
return cb(err); return cb(err);
} }
handleEncryptedWallet(fc, function(err) { handleEncryptedWallet(client, function(err) {
if (err) { if (err) {
$log.debug(err); $log.debug(err);
return bwsError.cb(err, null, cb); return bwsError.cb(err, null, cb);
} }
walletService.publishTx(fc, txp, function(err, publishedTxp) { walletService.publishTx(client, txp, function(err, publishedTxp) {
if (err) { if (err) {
$log.debug(err); $log.debug(err);
return bwsError.cb(err, null, cb); return bwsError.cb(err, null, cb);
} }
walletService.signTx(fc, publishedTxp, function(err, signedTxp) { walletService.signTx(client, publishedTxp, function(err, signedTxp) {
walletService.lock(fc); walletService.lock(client);
if (err) { if (err) {
$log.debug(err); $log.debug(err);
walletService.removeTx(fc, signedTxp, function(err) { walletService.removeTx(client, signedTxp, function(err) {
if (err) $log.debug(err); if (err) $log.debug(err);
}); });
return bwsError.cb(err, null, cb); return bwsError.cb(err, null, cb);
} }
walletService.broadcastTx(fc, signedTxp, function(err, broadcastedTxp) { walletService.broadcastTx(client, signedTxp, function(err, broadcastedTxp) {
if (err) { if (err) {
$log.debug(err); $log.debug(err);
walletService.removeTx(fc, broadcastedTxp, function(err) { walletService.removeTx(client, broadcastedTxp, function(err) {
if (err) $log.debug(err); if (err) $log.debug(err);
}); });
return bwsError.cb(err, null, cb); return bwsError.cb(err, null, cb);

View file

@ -0,0 +1,57 @@
'use strict';
angular.module('copayApp.controllers').controller('amazonCardDetailsController', function($scope, $timeout, amazonService) {
$scope.cancelGiftCard = function() {
var dataSrc = {
creationRequestId: $scope.card.creationRequestId,
gcId: $scope.card.gcId,
bitpayInvoiceId: $scope.card.bitpayInvoiceId,
bitpayInvoiceUrl: $scope.card.bitpayInvoiceUrl,
date: $scope.card.date
};
$scope.loading = true;
amazonService.cancelGiftCard(dataSrc, function(err, data) {
$scope.loading = null;
if (err || data.status != 'SUCCESS') {
$scope.error = err || data.status;
return;
}
$scope.refreshGiftCard();
});
};
$scope.remove = function() {
amazonService.saveGiftCard($scope.card, {remove: true}, function(err) {
$scope.cancel();
});
};
$scope.refreshGiftCard = function() {
var dataSrc = {
creationRequestId: $scope.card.creationRequestId,
amount: $scope.card.cardInfo.value.amount,
currencyCode: $scope.card.cardInfo.value.currencyCode,
bitpayInvoiceId: $scope.card.bitpayInvoiceId,
bitpayInvoiceUrl: $scope.card.bitpayInvoiceUrl,
date: $scope.card.date
};
$scope.loading = true;
amazonService.createGiftCard(dataSrc, function(err, data) {
$scope.loading = null;
if (err) {
$scope.error = err;
return;
}
$scope.card = data;
$timeout(function() {
$scope.$digest();
});
});
};
$scope.cancel = function() {
$scope.amazonCardDetailsModal.hide();
};
});