[Amazon] Adds support multisign. Common widget to select wallet

This commit is contained in:
Gustavo Maximiliano Cortez 2016-08-29 11:55:26 -03:00
commit 32a94d115f
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
4 changed files with 60 additions and 96 deletions

View file

@ -6,6 +6,15 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
var self = this;
var wallet;
$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);
});
$scope.openExternalLink = function(url, target) {
if (platformInfo.isNW) {
nodeWebkit.openExternalLink(url);
@ -17,53 +26,18 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
this.init = function() {
var network = amazonService.getEnvironment();
self.allWallets = profileService.getWallets({
$scope.wallets = profileService.getWallets({
network: network,
n: 1,
onlyComplete: true
});
if (lodash.isEmpty(self.allWallets)) return;
wallet = self.allWallets[0];
$timeout(function() {
self.selectedWalletId = wallet.credentials.walletId;
self.selectedWalletName = wallet.credentials.walletName;
$scope.$apply();
}, 100);
};
$scope.openWalletsModal = function(wallets) {
self.error = null;
$scope.type = 'SELL';
$scope.wallets = wallets;
$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.selectedWalletId = walletId;
self.selectedWalletName = wallet.credentials.walletName;
$scope.$apply();
}, 100);
$scope.walletsModal.hide();
});
};
this.createTx = function() {
self.error = null;
self.errorInfo = null;
if (lodash.isEmpty(wallet)) return;
if (!wallet.canSign() && !wallet.isPrivKeyExternal()) {
$log.info('No signing proposal: No private key');
self.error = bwcError.msg('MISSING_PRIVATE_KEY');
@ -73,7 +47,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
var dataSrc = {
currency: 'USD',
amount: $scope.fiat,
uuid: self.selectedWalletId
uuid: wallet.id
};
var outputs = [];
var config = configService.getSync();
@ -241,7 +215,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
$log.debug("Saving new gift card with status: " + newData.status);
self.giftCard = newData;
if (newData.status == 'PENDING') $state.transitionTo('amazon');
if (newData.status == 'PENDING') $state.transitionTo('amazon.main');
$timeout(function() {
$scope.$digest();
});
@ -278,18 +252,24 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
});
return bwcError.cb(err, null, cb);
}
walletService.broadcastTx(wallet, signedTxp, function(err, broadcastedTxp) {
if (err) {
$log.debug(err);
walletService.removeTx(wallet, broadcastedTxp, function(err) {
if (err) $log.debug(err);
});
return bwcError.cb(err, null, cb);
}
if (signedTxp.status == 'accepted') {
walletService.broadcastTx(wallet, signedTxp, function(err, broadcastedTxp) {
if (err) {
$log.debug(err);
walletService.removeTx(wallet, broadcastedTxp, function(err) {
if (err) $log.debug(err);
});
return bwcError.cb(err, null, cb);
}
$timeout(function() {
return cb(null, broadcastedTxp);
}, 5000);
});
} else {
$timeout(function() {
return cb(null, broadcastedTxp);
return cb(null, signedTxp);
}, 5000);
});
}
});
});
});

View file

@ -81,32 +81,26 @@ h3.title {
}
.box-notification {
position: relative;
font-size: 12px;
padding: 0.5rem;
border-radius: 2px;
background: #FFFFFF;
.box-icon {
position: absolute;
top: 0;
left: 0;
color: white;
background-color: #1ABC9C;
padding: 0 0.5rem;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
height: 100%;
i {
position: relative;
top: 10%;
display: block;
}
&.error {
background-color: #ED4A43;
}
&.secondary {
background-color: #3498DB;
}
border: 1px solid;
margin-bottom: 20px;
a {
color: #fff;
}
&.notice {
border-color: #b2b2b2;
background-color: #f8f8f8;
color: #444;
}
&.warning {
border-color: #e6b500;
background-color: #ffc900;
color: #fff;
}
&.error {
background-color: #ef473a;
border-color: #e42112;
color: #fff;
}
}
@ -878,7 +872,7 @@ input[type=file] {
}
.wallets {
height: 105px;
height: 90px;
}
/*
* Calculator