From b9c3cf3517779f4fd4d3d624919080c180f00ffc Mon Sep 17 00:00:00 2001 From: diminator Date: Sun, 19 Mar 2017 14:41:14 +0100 Subject: [PATCH] cached fetch of outputs --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index d5dceb3..2901022 100644 --- a/index.js +++ b/index.js @@ -311,20 +311,24 @@ export function listTransactions({ asset_id, operation }, API_PATH) { }) } -export function pollStatusAndFetchTransaction(transaction, API_PATH) { +export function pollStatusAndFetchTransaction(tx_id, API_PATH) { return new Promise((resolve, reject) => { const timer = setInterval(() => { - getStatus(transaction.id, API_PATH) + getStatus(tx_id, API_PATH) .then((res) => { console.log('Fetched transaction status:', res); if (res.status === 'valid') { clearInterval(timer); - getTransaction(transaction.id, API_PATH) + getTransaction(tx_id, API_PATH) .then((res) => { console.log('Fetched transaction:', res); - resolve(); + resolve(res); }); } + }) + .catch((err) => { + clearInterval(timer); + reject(err); }); }, 500) })