Buy, enter amount
This commit is contained in:
parent
539583a2af
commit
ec2801ef37
4 changed files with 88 additions and 8 deletions
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicScrollDelegate, $ionicHistory, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService, profileService, bitcore, amazonService, glideraService) {
|
||||
angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicScrollDelegate, $ionicHistory, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService, profileService, bitcore, amazonService, glideraService, coinbaseService) {
|
||||
var unitToSatoshi;
|
||||
var satToUnit;
|
||||
var unitDecimals;
|
||||
|
|
@ -20,6 +20,9 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
$scope.isGlidera = data.stateParams.isGlidera;
|
||||
$scope.glideraAccessToken = data.stateParams.glideraAccessToken;
|
||||
|
||||
// Coinbase parameters
|
||||
$scope.isCoinbase = data.stateParams.isCoinbase;
|
||||
|
||||
$scope.cardId = data.stateParams.cardId;
|
||||
$scope.showMenu = $ionicHistory.backView() && $ionicHistory.backView().stateName == 'tabs.send';
|
||||
var isWallet = data.stateParams.isWallet || 'false';
|
||||
|
|
@ -27,13 +30,13 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
$scope.toAddress = data.stateParams.toAddress;
|
||||
$scope.toName = data.stateParams.toName;
|
||||
$scope.toEmail = data.stateParams.toEmail;
|
||||
$scope.showAlternativeAmount = !!$scope.cardId || !!$scope.isGiftCard || !!$scope.isGlidera;
|
||||
$scope.showAlternativeAmount = !!$scope.cardId || !!$scope.isGiftCard || !!$scope.isGlidera || !!$scope.isCoinbase;
|
||||
$scope.toColor = data.stateParams.toColor;
|
||||
$scope.showSendMax = false;
|
||||
|
||||
$scope.customAmount = data.stateParams.customAmount;
|
||||
|
||||
if (!$scope.cardId && !$scope.isGiftCard && !$scope.isGlidera && !data.stateParams.toAddress) {
|
||||
if (!$scope.cardId && !$scope.isGiftCard && !$scope.isGlidera && !$scope.isCoinbase && !data.stateParams.toAddress) {
|
||||
$log.error('Bad params at amount')
|
||||
throw ('bad params');
|
||||
}
|
||||
|
|
@ -47,6 +50,33 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
});
|
||||
}
|
||||
|
||||
if ($scope.isCoinbase) {
|
||||
var currency = 'USD';
|
||||
coinbaseService.init($scope.coinbaseAccessToken, function(err, data) {
|
||||
if ($scope.isCoinbase == 'buy') {
|
||||
coinbaseService.buyPrice(data.accessToken, currency, function(err, b) {
|
||||
$scope.coinbaseBuyPrice = b.data || null;
|
||||
});
|
||||
} else {
|
||||
coinbaseService.sellPrice(data.accessToken, currency, function(err, b) {
|
||||
$scope.coinbaseSellPrice = b.data || null;
|
||||
});
|
||||
}
|
||||
|
||||
$scope.coinbasePaymentMethods = [];
|
||||
coinbaseService.getPaymentMethods(data.accessToken, function(err, p) {
|
||||
lodash.each(p.data, function(pm) {
|
||||
if (pm.allow_buy) {
|
||||
$scope.coinbasePaymentMethods.push(pm);
|
||||
}
|
||||
if (pm.allow_buy && pm.primary_buy) {
|
||||
$scope.coinbaseSelectedPaymentMethod = pm;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var reNr = /^[1234567890\.]$/;
|
||||
var reOp = /^[\*\+\-\/]$/;
|
||||
|
||||
|
|
@ -350,6 +380,17 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
isGlidera: $scope.isGlidera,
|
||||
glideraAccessToken: $scope.glideraAccessToken
|
||||
});
|
||||
} else if ($scope.isCoinbase) {
|
||||
if (lodash.isEmpty($scope.coinbaseSelectedPaymentMethod)) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), 'No Payment Method Selected');
|
||||
return;
|
||||
}
|
||||
var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount;
|
||||
$state.transitionTo('tabs.buyandsell.glidera.confirm', {
|
||||
toAmount: (amount * unitToSatoshi).toFixed(0),
|
||||
isCoinbase: $scope.isCoinbase,
|
||||
coinbasePaymentMethodId: $scope.coinbaseSelectedPaymentMethod.id
|
||||
});
|
||||
} else {
|
||||
var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount;
|
||||
if ($scope.customAmount) {
|
||||
|
|
|
|||
|
|
@ -945,6 +945,25 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
}
|
||||
}
|
||||
})
|
||||
.state('tabs.buyandsell.coinbase.amount', {
|
||||
url: '/amount/:isCoinbase',
|
||||
views: {
|
||||
'tab-home@tabs': {
|
||||
controller: 'amountController',
|
||||
templateUrl: 'views/amount.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('tabs.buyandsell.coinbase.confirm', {
|
||||
url: '/confirm/:toAmount/:isCoinbase/:coinbasePaymentMethodId',
|
||||
views: {
|
||||
'tab-home@tabs': {
|
||||
controller: 'confirmController',
|
||||
templateUrl: 'views/confirm.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
/*
|
||||
.state('tabs.buyandsell.coinbase.buy', {
|
||||
url: '/buy',
|
||||
'tab-home@tabs': {
|
||||
|
|
@ -961,6 +980,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
templateUrl: 'views/sellCoinbase.html'
|
||||
}
|
||||
})
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
|
|||
|
|
@ -14,14 +14,14 @@
|
|||
|
||||
<ion-content scroll="false">
|
||||
|
||||
<div ng-if="!customAmount && !isGlidera">
|
||||
<div ng-if="!customAmount && !isGlidera && !isCoinbase">
|
||||
<div class="item item-no-bottom-border recipient-label" translate>Recipient</div>
|
||||
|
||||
<div class="item item-text-wrap item-icon-left bitcoin-address" ng-class="{'item-big-icon-left':cardId}">
|
||||
<i class="icon big-icon-svg" ng-if="isWallet">
|
||||
<img src="img/icon-wallet.svg" ng-style="{'background-color': toColor}" class="bg"/>
|
||||
</i>
|
||||
<span ng-if="!isWallet && !isGiftCard && !isGlidera">
|
||||
<span ng-if="!isWallet && !isGiftCard">
|
||||
<i class="icon big-icon-svg" ng-if="isChromeApp">
|
||||
<img src="img/contact-placeholder.svg" class="bg"/>
|
||||
</i>
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-class="{'amount-pane-recipient': !customAmount && !isGlidera, 'amount-pane-no-recipient': customAmount || isGlidera}">
|
||||
<div ng-class="{'amount-pane-recipient': !customAmount && !isGlidera && !isCoinbase, 'amount-pane-no-recipient': customAmount || isGlidera || isCoinbase}">
|
||||
|
||||
<div class="amount-bar oh">
|
||||
<div class="title">
|
||||
|
|
@ -66,6 +66,25 @@
|
|||
(remaining {{limits.monthlySellRemaining|currency:'':2}} {{limits.currency}})
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-show="isCoinbase">
|
||||
<div class="limits" ng-show="coinbaseBuyPrice && isCoinbase == 'buy'">
|
||||
1 BTC ~ {{coinbaseBuyPrice.amount}} {{coinbaseBuyPrice.currency}}
|
||||
</div>
|
||||
<div class="limits" ng-show="coinbaseSellPrice && isCoinbase == 'sell'">
|
||||
1 BTC ~ {{coinbaseSellPrice.amount}} {{coinbaseSellPrice.currency}}
|
||||
</div>
|
||||
<div class="list">
|
||||
<label class="item item-input item-select">
|
||||
<div class="input-label">
|
||||
Payment Method
|
||||
</div>
|
||||
<select ng-model="coinbaseSelectedPaymentMethod.id"
|
||||
ng-options="item.id as item.name for item in coinbasePaymentMethods">
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -68,13 +68,13 @@
|
|||
<div class="list card"
|
||||
ng-show="accountId">
|
||||
<a class="item item-icon-right"
|
||||
href ui-sref="tabs.buyandsell.coinbase.buy">
|
||||
href ui-sref="tabs.buyandsell.coinbase.amount({isCoinbase: 'buy'})">
|
||||
<img src="img/buy-bitcoin.svg" alt="buy bitcoin" width="35" class="item-img-buy">
|
||||
Buy Bitcoin
|
||||
<i class="icon bp-arrow-right"></i>
|
||||
</a>
|
||||
<a class="item item-icon-right"
|
||||
href ui-sref="tabs.buyandsell.coinbase.sell">
|
||||
href ui-sref="tabs.buyandsell.coinbase.amount({isCoinbase: 'sell'})">
|
||||
<img src="img/sell-bitcoin.svg" alt="buy bitcoin" width="35" class="item-img-sell">
|
||||
Sell Bitcoin
|
||||
<i class="icon bp-arrow-right"></i>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue