From 432c1233b66f1f9baedeacc1eb6834c6cb7d4074 Mon Sep 17 00:00:00 2001 From: infinite-persistence <64950861+infinite-persistence@users.noreply.github.com> Date: Tue, 4 May 2021 23:08:01 +0800 Subject: [PATCH] Swap: populate 'status' from 'btc/swap' response instead of waiting for first websocket input. (#5997) * Swap: populate 'status' from 'btc/swap' response instead of waiting for first websocket input. ## Issue Clsoes 5975: swap stop at processing even though response comes through ## Notes Occasionally, the first websocket message doesn't come through (seems like the commerce didn't send?). There's really no need to wait for one more 'status=NEW' message to ensure the right data is being populated (being over-cautious here). * Beautify the "exact amount" advice. --- static/app-strings.json | 2 +- ui/component/walletSwap/view.jsx | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/static/app-strings.json b/static/app-strings.json index c9f9eaa9c..40eea5808 100644 --- a/static/app-strings.json +++ b/static/app-strings.json @@ -1786,7 +1786,7 @@ "Remove %address%?": "Remove %address%?", "This process cannot be reversed.": "This process cannot be reversed.", "View transaction": "View transaction", - "Send (USE COPY BUTTON, ENSURE EXACT AMOUNT IS SENT!)": "Send (USE COPY BUTTON, ENSURE EXACT AMOUNT IS SENT!)", + "Use the copy button to ensure the EXACT amount is sent!": "Use the copy button to ensure the EXACT amount is sent!", "Amount copied.": "Amount copied.", "Copy transaction ID": "Copy transaction ID", "Transaction ID copied.": "Transaction ID copied.", diff --git a/ui/component/walletSwap/view.jsx b/ui/component/walletSwap/view.jsx index c0c8f3416..1f49cd6de 100644 --- a/ui/component/walletSwap/view.jsx +++ b/ui/component/walletSwap/view.jsx @@ -301,16 +301,25 @@ function WalletSwap(props: Props) { const btcAmount = response.Charge.data.pricing['bitcoin'].amount; const rate = response.Exchange.rate; - const swap = { + const timeline = response.Charge.data.timeline; + const lastTimeline = timeline[timeline.length - 1]; + + const newSwap = { chargeCode: response.Exchange.charge_code, coins: Object.keys(response.Charge.data.addresses), sendAddresses: response.Charge.data.addresses, sendAmounts: response.Charge.data.pricing, lbcAmount: (btcAmount * BTC_SATOSHIS) / rate, + status: { + status: lastTimeline.status, + receiptCurrency: lastTimeline.payment.value.currency, + receiptTxid: lastTimeline.payment.transaction_id, + lbcTxid: response.Exchange.lbc_txid || '', + }, }; - setSwap({ ...swap }); - addCoinSwap({ ...swap }); + setSwap({ ...newSwap }); + addCoinSwap({ ...newSwap }); }) .catch((err) => { setNag({ msg: err === INTERNAL_APIS_DOWN ? NAG_SWAP_CALL_FAILED : err.message, type: 'error' }); @@ -532,7 +541,7 @@ function WalletSwap(props: Props) { {getGap()} > )} -