Merge pull request #2 from cmgustavo/ref/design-02

[Amazon] Adds support multisign. Common widget to select wallet
This commit is contained in:
Matias Alejo Garcia 2016-08-29 12:00:08 -03:00 committed by GitHub
commit 77e0d26f82
4 changed files with 60 additions and 96 deletions

View file

@ -10,7 +10,7 @@
<ion-content ng-controller="amazonController as amazon" ng-init="amazon.init()"> <ion-content ng-controller="amazonController as amazon" ng-init="amazon.init()">
<div class="text-center" 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>
@ -40,8 +40,10 @@
</a> </a>
</div> </div>
<h4 class="padding">Your cards</h4> <div class="card">
<div class="list card"> <div class="item item-divider">
Your cards
</div>
<div ng-repeat="(id, item) in giftCards | orderObjectBy:'date':true track by $index" <div ng-repeat="(id, item) in giftCards | orderObjectBy:'date':true track by $index"
ng-click="amazon.openCardModal(item)" ng-click="amazon.openCardModal(item)"
class="item item-avatar"> class="item item-avatar">

View file

@ -12,12 +12,12 @@
<div ng-show="!buy.giftCard"> <div ng-show="!buy.giftCard">
<div class="assertive" ng-show="buy.error" ng-click="buy.error = null"> <div class="box-notification error" ng-show="buy.error" ng-click="buy.error = null">
{{buy.error}} {{buy.error}}
<div class="m10t size-12" ng-show="buy.errorInfo"> <div ng-show="buy.errorInfo">
There was an error when trying to buy gift card, but the funds were sent to BitPay Invoice. Please, contact There was an error when trying to buy gift card, but the funds were sent to BitPay Invoice. Please, contact
BitPay to refund your bitcoin BitPay to refund your bitcoin
<div class="p10 m10t"> <div>
Amount: {{buy.errorInfo.amount}} {{buy.errorInfo.currency}}<br> Amount: {{buy.errorInfo.amount}} {{buy.errorInfo.currency}}<br>
BitPay Invoice ID: {{buy.errorInfo.invoiceId}}. BitPay Invoice ID: {{buy.errorInfo.invoiceId}}.
</div> </div>
@ -53,23 +53,11 @@
</label> </label>
<wallets ng-if="wallets[0]" wallets="wallets"></wallets>
<label class="item item-input item-stacked-label">
<span class="input-label">Pay From Copay Wallet</span>
<input type="text"
id="address"
name="address"
ng-disabled="buy.selectedWalletId"
ng-attr-placeholder="{{'Choose your source wallet'}}"
ng-model="buy.selectedWalletName" required>
<a on-tap="openWalletsModal(buy.allWallets)" class="button button-light">
<i class="icon ion-folder size-18"></i>
</a>
</label>
</div> </div>
<button class="button button-block" <button class="button button-block"
ng-disabled="!buy.selectedWalletId || !fiat" ng-disabled="!fiat"
type="submit" type="submit"
value="Buy now"> value="Buy now">
Buy now Buy now

View file

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

View file

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