diff --git a/src/js/controllers/buyCoinbase.js b/src/js/controllers/buyCoinbase.js index bdd5394d1..f654c388b 100644 --- a/src/js/controllers/buyCoinbase.js +++ b/src/js/controllers/buyCoinbase.js @@ -166,14 +166,14 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct showError(err); return; } - var tx = b.data ? b.data.transaction : null; - if (!tx) { - ongoingProcess.set('buyingBitcoin', false, statusChangeHandler); - showError('Transaction not found'); - return; - } - $timeout(function() { + var processBuyTx = function (tx) { + if (!tx) { + ongoingProcess.set('buyingBitcoin', false, statusChangeHandler); + showError('Transaction not found'); + return; + } + coinbaseService.getTransaction(accessToken, accountId, tx.id, function(err, updatedTx) { if (err) { ongoingProcess.set('buyingBitcoin', false, statusChangeHandler); @@ -196,7 +196,23 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct }); }); }); - }, 8000); + }; + + var tx = b.data ? b.data.transaction : null; + if (tx) { + processBuyTx(tx); + } + else { + coinbaseService.getBuyOrder(accessToken, accountId, b.data.id, function (err, buyResp) { + if (err) { + ongoingProcess.set('buyingBitcoin', false, statusChangeHandler); + showError(err); + return; + } + var tx = buyResp.data ? buyResp.data.transaction : null; + processBuyTx(tx); + }); + } }); }); }); diff --git a/src/js/services/coinbaseService.js b/src/js/services/coinbaseService.js index ac3bca0aa..cce8544de 100644 --- a/src/js/services/coinbaseService.js +++ b/src/js/services/coinbaseService.js @@ -302,6 +302,17 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }); }; + root.getBuyOrder = function(token, accountId, buyId, cb) { + if (!token) return cb('Invalid Token'); + $http(_get('/accounts/' + accountId + '/buys/' + buyId, token)).then(function(data) { + $log.info('Coinbase Buy Info: SUCCESS'); + return cb(null, data.data); + }, function(data) { + $log.error('Coinbase Buy Info: ERROR ' + data.statusText); + return cb(data.data); + }); + }; + root.getTransaction = function(token, accountId, transactionId, cb) { if (!token) return cb('Invalid Token'); $http(_get('/accounts/' + accountId + '/transactions/' + transactionId, token)).then(function(data) {