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

View file

@ -32,9 +32,8 @@
</li>
<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="fi-shopping-cart 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>
</div>
</li>

View file

@ -1,3 +1,4 @@
<ion-modal-view ng-controller="amazonCardDetailsController">
<nav class="tab-bar">
<section class="left-small">
<a ng-click="cancel()">
@ -12,9 +13,9 @@
</section>
</nav>
<div class="modal-content fix-modals-touch"
ng-swipe-disable-mouse
ng-swipe-right="cancel()">
<ion-content overflow-scroll="true">
<div class="modal-content fix-modals-touch">
<div class="header-modal bg-gray text-center">
<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>
</ion-content>
</ion-modal-view>

View file

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