Testing coinbase

This commit is contained in:
Gustavo Maximiliano Cortez 2017-06-18 23:36:25 -03:00
parent f6245652d9
commit 04db3f9159
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
1 changed files with 26 additions and 5 deletions

View File

@ -1,9 +1,10 @@
'use strict';
angular.module('copayApp.controllers').controller('buyCoinbaseController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicScrollDelegate, $ionicConfig, lodash, coinbaseService, popupService, profileService, ongoingProcess, walletService, txFormatService) {
angular.module('copayApp.controllers').controller('buyCoinbaseController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicScrollDelegate, $ionicConfig, lodash, coinbaseService, popupService, profileService, ongoingProcess, walletService, txFormatService, feeService) {
var amount;
var currency;
var feeBTC;
var showErrorAndBack = function(err) {
$scope.sendStatus = '';
@ -44,13 +45,33 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.isFiat = data.stateParams.currency != 'bits' && data.stateParams.currency != 'BTC' ? true : false;
var parsedAmount = txFormatService.parseAmount(
data.stateParams.amount,
data.stateParams.amount,
data.stateParams.currency);
console.log('[buyCoinbase.js:46]',parsedAmount); //TODO/
// Buy always in BTC
amount = (parsedAmount.amountSat / 100000000).toFixed(8);
console.log('[buyCoinbase.js:52]',amount); //TODO/
currency = 'BTC';
console.log('[buyCoinbase.js:54]',currency); //TODO/
amount = parsedAmount.amount;
currency = parsedAmount.currency;
$scope.amountUnitStr = parsedAmount.amountUnitStr;
console.log('[buyCoinbase.js:57]',$scope.amountUnitStr); //TODO/
// Fee Normal for a single transaction
var txNormalFeeKB = 450 / 1024;
console.log('[buyCoinbase.js:60]',txNormalFeeKB); //TODO/
feeService.getCurrentFeeValue(null, 'normal', function(err, feePerKB) {
feeBTC = (feePerKB * txNormalFeeKB / 100000000).toFixed(8);
console.log('[buyCoinbase.js:60]',feePerKB, feeBTC, amount - feeBTC); //TODO/
// Check if transaction has enough funds to transfer bitcoin from Coinbase to Copay
if (amount - feeBTC < 0) {
showErrorAndBack('Not enough funds for fee');
return;
}
});
return; // TODO
$scope.network = coinbaseService.getNetwork();
$scope.wallets = profileService.getWallets({
onlyComplete: true,
@ -144,7 +165,7 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct
var cancelText = 'Cancel';
popupService.showConfirm(null, message, okText, cancelText, function(ok) {
if (!ok) return;
ongoingProcess.set('buyingBitcoin', true, statusChangeHandler);
coinbaseService.init(function(err, res) {
if (err) {