From aaeef98b2327281919c486e07ff683f6d83fac68 Mon Sep 17 00:00:00 2001 From: 1aerostorm Date: Tue, 28 May 2024 22:11:20 +0300 Subject: [PATCH] Multi-step exchange - more fixes (all?) --- app/components/modules/ConvertAssets.jsx | 19 ++++++++++++++----- app/utils/market/exchange.js | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/components/modules/ConvertAssets.jsx b/app/components/modules/ConvertAssets.jsx index 2b0fbfb..1183433 100644 --- a/app/components/modules/ConvertAssets.jsx +++ b/app/components/modules/ConvertAssets.jsx @@ -371,15 +371,24 @@ class ConvertAssets extends React.Component { return null } - let res = (parseFloat(buyAmount.amountFloat) / parseFloat(sellAmount.amountFloat)).toString() - const dot = res.indexOf(res) - if (dot != -1) { - res = res.substring(0, dot + 9) + const price = Price(buyAmount, sellAmount) + const a = sellAmount.clone() + a.amountFloat = '1' + let res = a.mul(price) + + let str = res.amountFloat + const dot = str.indexOf('.') + if (dot !== -1) { + str = str.substring(0, dot + 1 + Math.min(res.precision, 6)) } + res = Asset(str + ' ' + res.symbol) + if (res.eq(0)) res.amount = 1 + res = res.toString() + return
{tt('convert_assets_jsx.price')} {'1 ' + sellAmount.symbol}:
- {' ~' + res + ' ' + buyAmount.symbol} + {' ~' + res}
} diff --git a/app/utils/market/exchange.js b/app/utils/market/exchange.js index 6759601..4f23e31 100644 --- a/app/utils/market/exchange.js +++ b/app/utils/market/exchange.js @@ -152,10 +152,10 @@ export async function getExchange(sellAmount, buyAmount, myBalance, } } else { const step = chain.steps[0] - const bp = Price(step.best_price) + const bp = Price(chain.best_price) if (!isDir) { bestPrice = bp - limitPrice = Price(step.limit_price) + limitPrice = Price(chain.limit_price) } amMul = Asset(chain.res) const remain = step.remain ? Asset(step.remain) : undefined