Clean UI. Adds amount parser for coinbaseService
This commit is contained in:
parent
89639a8d48
commit
8d1d59cb3b
9 changed files with 85 additions and 46 deletions
|
|
@ -358,10 +358,9 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
glideraAccessToken: $scope.glideraAccessToken
|
||||
});
|
||||
} else if ($scope.nextStep) {
|
||||
var amountAlternative = $scope.showAlternativeAmount ? _amount : $filter('formatFiatAmount')(toFiat(_amount));
|
||||
$state.transitionTo($scope.nextStep, {
|
||||
amount: amountAlternative,
|
||||
currency: $scope.alternativeIsoCode
|
||||
amount: _amount,
|
||||
currency: $scope.showAlternativeAmount ? $scope.alternativeIsoCode : ''
|
||||
});
|
||||
} else {
|
||||
var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount;
|
||||
|
|
|
|||
|
|
@ -36,14 +36,10 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct
|
|||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
coinbaseService.setCredentials();
|
||||
|
||||
amount = data.stateParams.amount;
|
||||
currency = data.stateParams.currency;
|
||||
[amount, currency, $scope.amountUnitStr] = coinbaseService.parseAmount(
|
||||
data.stateParams.amount,
|
||||
data.stateParams.currency);
|
||||
|
||||
if (amount < 1) {
|
||||
showErrorAndBack('Amount must be at least 1.00 ' + currency);
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.network = coinbaseService.getNetwork();
|
||||
$scope.wallets = profileService.getWallets({
|
||||
onlyComplete: true,
|
||||
|
|
@ -60,6 +56,10 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct
|
|||
}
|
||||
var accessToken = res.accessToken;
|
||||
|
||||
coinbaseService.buyPrice(accessToken, coinbaseService.getAvailableCurrency(), function(err, b) {
|
||||
$scope.buyPrice = b.data || null;
|
||||
});
|
||||
|
||||
$scope.paymentMethods = [];
|
||||
$scope.selectedPaymentMethodId = { value : null };
|
||||
coinbaseService.getPaymentMethods(accessToken, function(err, p) {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('coinbaseController', function($rootScope, $scope, $timeout, $ionicModal, $log, profileService, configService, storageService, coinbaseService, lodash, platformInfo, ongoingProcess, popupService, gettextCatalog, externalLinkService) {
|
||||
angular.module('copayApp.controllers').controller('coinbaseController', function($scope, $timeout, $ionicModal, $log, coinbaseService, lodash, platformInfo, ongoingProcess, popupService, externalLinkService) {
|
||||
|
||||
var isNW = platformInfo.isNW;
|
||||
var isCordova = platformInfo.isCordova;
|
||||
|
||||
var init = function() {
|
||||
var config = configService.getSync().wallet.settings;
|
||||
$scope.currency = getCurrency(config.alternativeIsoCode);
|
||||
$scope.currency = coinbaseService.getAvailableCurrency();
|
||||
coinbaseService.getStoredToken(function(at) {
|
||||
$scope.accessToken = at;
|
||||
|
||||
|
|
@ -17,7 +16,7 @@ angular.module('copayApp.controllers').controller('coinbaseController', function
|
|||
$scope.loading = false;
|
||||
if (err || lodash.isEmpty(data)) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
popupService.showAlert('Error', err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -41,14 +40,6 @@ angular.module('copayApp.controllers').controller('coinbaseController', function
|
|||
});
|
||||
};
|
||||
|
||||
var getCurrency = function(code) {
|
||||
// ONLY "USD" and "EUR"
|
||||
switch(code) {
|
||||
case 'EUR' : return 'EUR';
|
||||
default : return 'USD'
|
||||
};
|
||||
};
|
||||
|
||||
$scope.updateTransactions = function() {
|
||||
$log.debug('Getting transactions...');
|
||||
$scope.pendingTransactions = { data: {} };
|
||||
|
|
@ -93,7 +84,7 @@ angular.module('copayApp.controllers').controller('coinbaseController', function
|
|||
coinbaseService.getToken(code, function(err, accessToken) {
|
||||
ongoingProcess.set('connectingCoinbase', false);
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
popupService.showAlert('Error', err);
|
||||
return;
|
||||
}
|
||||
$scope.accessToken = accessToken;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController', func
|
|||
var accountId = res.accountId;
|
||||
var sellPrice = null;
|
||||
|
||||
coinbaseService.sellPrice(accessToken, currency, function(err, sell) {
|
||||
coinbaseService.sellPrice(accessToken, coinbaseService.getAvailableCurrency(), function(err, sell) {
|
||||
if (err) {
|
||||
$log.debug(err);
|
||||
checkTransaction(count, txp);
|
||||
|
|
@ -119,14 +119,10 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController', func
|
|||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
coinbaseService.setCredentials();
|
||||
|
||||
amount = data.stateParams.amount;
|
||||
currency = data.stateParams.currency;
|
||||
[amount, currency, $scope.amountUnitStr] = coinbaseService.parseAmount(
|
||||
data.stateParams.amount,
|
||||
data.stateParams.currency);
|
||||
|
||||
if (amount < 1) {
|
||||
showErrorAndBack('Amount must be at least 1.00 ' + currency);
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.priceSensitivity = coinbaseService.priceSensitivity;
|
||||
$scope.selectedPriceSensitivity = { data: coinbaseService.selectedPriceSensitivity };
|
||||
|
||||
|
|
@ -147,6 +143,10 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController', func
|
|||
}
|
||||
var accessToken = res.accessToken;
|
||||
|
||||
coinbaseService.sellPrice(accessToken, coinbaseService.getAvailableCurrency(), function(err, s) {
|
||||
$scope.sellPrice = s.data || null;
|
||||
});
|
||||
|
||||
$scope.paymentMethods = [];
|
||||
$scope.selectedPaymentMethodId = { value : null };
|
||||
coinbaseService.getPaymentMethods(accessToken, function(err, p) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('coinbaseService', function($http, $log, $window, platformInfo, lodash, storageService, configService, appConfigService) {
|
||||
angular.module('copayApp.services').factory('coinbaseService', function($http, $log, $window, $filter, platformInfo, lodash, storageService, configService, appConfigService, txFormatService) {
|
||||
var root = {};
|
||||
var credentials = {};
|
||||
var isCordova = platformInfo.isCordova;
|
||||
|
|
@ -104,6 +104,35 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
|||
});
|
||||
};
|
||||
|
||||
root.getAvailableCurrency = function() {
|
||||
var config = configService.getSync().wallet.settings;
|
||||
// ONLY "USD" and "EUR"
|
||||
switch(config.alternativeIsoCode) {
|
||||
case 'EUR' : return 'EUR';
|
||||
default : return 'USD'
|
||||
};
|
||||
};
|
||||
|
||||
root.parseAmount = function(amount, currency) {
|
||||
var config = configService.getSync().wallet.settings;
|
||||
var satToBtc = 1 / 100000000;
|
||||
var unitToSatoshi = config.unitToSatoshi;
|
||||
var amountUnitStr;
|
||||
|
||||
// IF 'USD'
|
||||
if (currency) {
|
||||
amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency;
|
||||
} else {
|
||||
var amountSat = parseInt((amount * unitToSatoshi).toFixed(0));
|
||||
amountUnitStr = txFormatService.formatAmountStr(amountSat);
|
||||
// convert unit to BTC
|
||||
amount = (amountSat * satToBtc).toFixed(8);
|
||||
currency = 'BTC';
|
||||
}
|
||||
|
||||
return [amount, currency, amountUnitStr];
|
||||
};
|
||||
|
||||
root.getOauthCodeUrl = function() {
|
||||
return credentials.HOST
|
||||
+ '/oauth/authorize?response_type=code&client_id='
|
||||
|
|
|
|||
|
|
@ -81,6 +81,10 @@
|
|||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.total-amount {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
&.single-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
|
|
|||
|
|
@ -15,8 +15,10 @@
|
|||
<span>Buying</span>
|
||||
</div>
|
||||
<div class="amount-label">
|
||||
<div class="amount">{{buyRequestInfo.amount.amount}} {{buyRequestInfo.amount.currency}}</div>
|
||||
<div class="alternative">{{buyRequestInfo.subtotal.amount}} {{buyRequestInfo.subtotal.currency}}</div>
|
||||
<div class="amount">{{amountUnitStr}}</div>
|
||||
<div class="alternative" ng-if="buyPrice">
|
||||
@ ${{buyPrice.amount}} per BTC
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -43,19 +45,25 @@
|
|||
</div>
|
||||
|
||||
<div class="item item-divider">
|
||||
Total to pay
|
||||
Transaction details
|
||||
</div>
|
||||
<div class="item">
|
||||
Amount
|
||||
<span class="item-note">
|
||||
{{buyRequestInfo.subtotal.amount}} {{buyRequestInfo.subtotal.currency}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="item" ng-repeat="fee in buyRequestInfo.fees">
|
||||
<span class="capitalized">
|
||||
{{fee.type}}
|
||||
{{fee.type}} fee
|
||||
</span>
|
||||
<span class="item-note">
|
||||
{{fee.amount.amount}} {{fee.amount.currency}}
|
||||
{{fee.amount.amount}} {{fee.amount.currency}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="item">
|
||||
Total
|
||||
<span class="item-note">
|
||||
Total to pay
|
||||
<span class="item-note total-amount">
|
||||
{{buyRequestInfo.total.amount}} {{buyRequestInfo.total.currency}}
|
||||
</span>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
</div>
|
||||
|
||||
<div class="m10t size-12 text-center text-gray">
|
||||
<span ng-show="!buyPrice || !sellPrice"> ... | ... </span>
|
||||
<span ng-show="!buyPrice || !sellPrice">...</span>
|
||||
<span ng-show="buyPrice && sellPrice">
|
||||
{{buyPrice.amount}} {{buyPrice.currency}}
|
||||
|
|
||||
|
|
|
|||
|
|
@ -15,8 +15,10 @@
|
|||
<span>Selling</span>
|
||||
</div>
|
||||
<div class="amount-label">
|
||||
<div class="amount">{{sellRequestInfo.amount.amount}} {{sellRequestInfo.amount.currency}}</div>
|
||||
<div class="alternative">{{sellRequestInfo.subtotal.amount}} {{sellRequestInfo.subtotal.currency}}</div>
|
||||
<div class="amount">{{amountUnitStr}}</div>
|
||||
<div class="alternative" ng-if="sellPrice">
|
||||
@ ${{sellPrice.amount}} per BTC
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -75,11 +77,17 @@
|
|||
</div>
|
||||
|
||||
<div class="item item-divider">
|
||||
Total to receive
|
||||
Transaction details
|
||||
</div>
|
||||
<div class="item">
|
||||
Amount
|
||||
<span class="item-note">
|
||||
{{sellRequestInfo.subtotal.amount}} {{sellRequestInfo.subtotal.currency}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="item" ng-repeat="fee in sellRequestInfo.fees">
|
||||
<span class="capitalized">
|
||||
{{fee.type}}
|
||||
{{fee.type}} fee
|
||||
</span>
|
||||
<span class="item-note">
|
||||
<span ng-if="fee.amount.amount != '0.00'">-</span>
|
||||
|
|
@ -87,8 +95,8 @@
|
|||
</span>
|
||||
</div>
|
||||
<div class="item">
|
||||
Total
|
||||
<span class="item-note">
|
||||
Total to receive
|
||||
<span class="item-note total-amount">
|
||||
{{sellRequestInfo.total.amount}} {{sellRequestInfo.total.currency}}
|
||||
</span>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue