From 92acbb181813a9a25d247acaffdaa05b772a2ca8 Mon Sep 17 00:00:00 2001 From: 1aerostorm Date: Mon, 15 Apr 2024 13:52:49 +0300 Subject: [PATCH] UIA register - fix get_free_poller --- db/reg_pollers.lua | 4 +++- src/locales/en.json | 1 + src/locales/ru-RU.json | 1 + src/modules/register/UIARegister.jsx | 6 +++++- src/pages/api/reg/[...all].js | 1 - 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/db/reg_pollers.lua b/db/reg_pollers.lua index 20287ab..b6702f3 100644 --- a/db/reg_pollers.lua +++ b/db/reg_pollers.lua @@ -1,4 +1,5 @@ fiber = require 'fiber' +decimal = require 'decimal' function reg_pollers_migration_v1() if box.space.reg_pollers ~= nil then @@ -43,6 +44,7 @@ local function wrap_rp(rp) end function get_free_reg_poller(amount, sym, step, now) + amount = decimal.new(amount) -- fix "1.1 + 0.1 ~= 1.2" problem local rps = nil repeat if rps ~= nil then @@ -55,7 +57,7 @@ function get_free_reg_poller(amount, sym, step, now) end rps = box.space.reg_pollers.index.by_amount:select{sym, amount} until #rps == 0 - return amount + return tostring(amount) end local function clean_reg_pollers(now) diff --git a/src/locales/en.json b/src/locales/en.json index 27f147b..87828e7 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -103,6 +103,7 @@ "min_amount": "Minimal amount is ", "enter_amount": "Exact amount, which will be transferred by gate: ", "slot_is_used": "Try another amount.", + "eg": " E.g.: ", "fee": "Fee", "memo_fixed": "Memo", "to": "Send tokens to address/account", diff --git a/src/locales/ru-RU.json b/src/locales/ru-RU.json index d5ab5c8..177db6b 100644 --- a/src/locales/ru-RU.json +++ b/src/locales/ru-RU.json @@ -103,6 +103,7 @@ "min_amount": "Минимальная сумма - ", "enter_amount": "Точная сумма, которую вы отправите шлюзу: ", "slot_is_used": "Введите другую сумму.", + "eg": " Например: ", "fee": "Комиссия", "memo_fixed": "Заметка/memo", "to": "Отправьте токены на адрес/аккаунт", diff --git a/src/modules/register/UIARegister.jsx b/src/modules/register/UIARegister.jsx index c1307b8..371dd3c 100644 --- a/src/modules/register/UIARegister.jsx +++ b/src/modules/register/UIARegister.jsx @@ -494,6 +494,7 @@ class UIARegister extends React.Component { _onAmountSubmit = async (values) => { const waitAmount = values.amount.asset + let freeAmount try { let fp = await callApi('/api/reg/get_free_poller/' + waitAmount.toString()) fp = await fp.json() @@ -501,11 +502,14 @@ class UIARegister extends React.Component { throw new Error(fp.error || 'Unknown error') } if (fp.amount !== waitAmount.toString()) { + freeAmount = parseFloat(fp.amount) throw new Error('Slot is used') } } catch (err) { this.setState({ - amountSubmitError: err.message === 'Slot is used' ? tt('uia_register_jsx.slot_is_used') : err.message + amountSubmitError: err.message === 'Slot is used' ? + tt('uia_register_jsx.slot_is_used') + (freeAmount ? (tt('uia_register_jsx.eg') + freeAmount + '.') : '' ) + : err.message }) return } diff --git a/src/pages/api/reg/[...all].js b/src/pages/api/reg/[...all].js index 96cd669..65a0047 100644 --- a/src/pages/api/reg/[...all].js +++ b/src/pages/api/reg/[...all].js @@ -536,7 +536,6 @@ let handler = nextConnect({ attachParams: true, }) error = tt('uia_register_jsx.cannot_check_orders') + exAmount.symbol + '/' + sym2 } if (error) break - console.log(exAmount.toString(), sym2, JSON.stringify(resEx)) if (resEx.remain) { error = tt('uia_register_jsx.too_low_orders') + exAmount.symbol + '/' + sym2 + tt('uia_register_jsx.cannot_register_with_it') break