From c6cdd4a72ad743f6e0c4cdbe3b45d42be7d02249 Mon Sep 17 00:00:00 2001 From: Sigve Date: Fri, 4 May 2018 05:53:25 +0100 Subject: [PATCH] 1481: Fix checkFeeStatusAsync duplicate asset resolution issues with BTS --- app/components/Exchange/Exchange.jsx | 23 ++++++++++++++--------- app/lib/common/trxHelper.js | 23 +++++++++++++++++------ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/app/components/Exchange/Exchange.jsx b/app/components/Exchange/Exchange.jsx index db8afd3cfc..f228fbbbbe 100644 --- a/app/components/Exchange/Exchange.jsx +++ b/app/components/Exchange/Exchange.jsx @@ -296,16 +296,21 @@ class Exchange extends React.Component { }) ); }); - Promise.all(p).then(status => { - assets.forEach((a, idx) => { - feeStatus[a.get("id")] = status[idx]; - }); - if (!utils.are_equal_shallow(this.state.feeStatus, feeStatus)) { - this.setState({ - feeStatus + Promise.all(p) + .then(status => { + assets.forEach((a, idx) => { + feeStatus[a.get("id")] = status[idx]; }); - } - }); + if (!utils.are_equal_shallow(this.state.feeStatus, feeStatus)) { + this.setState({ + feeStatus + }); + } + }) + .catch(err => { + console.log("checkFeeStatusAsync error", err); + this.setState({feeStatus: {}}); + }); } _getWindowSize() { diff --git a/app/lib/common/trxHelper.js b/app/lib/common/trxHelper.js index 8bb29844ed..6103d354b3 100644 --- a/app/lib/common/trxHelper.js +++ b/app/lib/common/trxHelper.js @@ -87,12 +87,22 @@ function checkFeeStatusAsync({ let coreBalanceID = account.getIn(["balances", "1.3.0"]), feeBalanceID = account.getIn(["balances", feeID]); - if (feeID === "1.3.0" && !coreBalanceID) - return res({ - fee: new Asset({amount: coreFee}), - hasBalance, - hasPoolBalance + if (feeID === "1.3.0" && !coreBalanceID) { + asyncCache[key].queue.forEach(promise => { + promise.res({ + fee: new Asset({amount: coreFee}), + hasBalance, + hasPoolBalance + }); }); + asyncCache[key] = { + result: {fee, hasBalance, hasPoolBalance, hasValidCER} + }; + setTimeout(() => { + delete asyncCache[key]; + }, feeStatusTTL); + return; + } Promise.all([ coreBalanceID @@ -147,6 +157,7 @@ function checkFeeStatusAsync({ feeBalance.get("balance") >= fee.getAmount() ) hasBalance = true; + asyncCache[key].queue.forEach(promise => { promise.res({ fee, @@ -164,7 +175,7 @@ function checkFeeStatusAsync({ }); }) .catch(() => { - asyncCache[key].forEach(promise => { + asyncCache[key].queue.forEach(promise => { promise.rej(); }); });