From 23cc08574eea7a89fbcf031bd21e1b1ac14d3454 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Wed, 16 Aug 2017 11:12:56 -0300 Subject: [PATCH] Purchase throught from Coinbase: Force buyInfo request until get transaction id --- src/js/controllers/buyCoinbase.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/js/controllers/buyCoinbase.js b/src/js/controllers/buyCoinbase.js index 6066207ba..257dbc685 100644 --- a/src/js/controllers/buyCoinbase.js +++ b/src/js/controllers/buyCoinbase.js @@ -209,21 +209,31 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct }); }; + var _getBuyOrder = function() { + 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; + if (tx && tx.id) { + processBuyTx(tx); + } else { + $timeout(function() { + _getBuyOrder(); + }, 5000); + } + }); + } + $timeout(function() { var tx = b.data ? b.data.transaction : null; - if (tx) { + if (tx && tx.id) { 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); - }); + _getBuyOrder(); } }, 8000); });