From 4dc44afdd06565cecef95942f072f8b2b74d8cb6 Mon Sep 17 00:00:00 2001 From: 1aerostorm Date: Wed, 1 Nov 2023 17:00:08 +0000 Subject: [PATCH] Fix register --- db/reg_pollers.lua | 30 +++++++++++++++---------- src/locales/en.json | 3 ++- src/locales/ru-RU.json | 3 ++- src/modules/register/TransferWaiter.jsx | 2 +- src/modules/register/UIARegister.jsx | 19 +++++++++++++++- src/pages/api/reg/[...all].js | 3 ++- 6 files changed, 43 insertions(+), 17 deletions(-) diff --git a/db/reg_pollers.lua b/db/reg_pollers.lua index f4a5395..94d9e13 100644 --- a/db/reg_pollers.lua +++ b/db/reg_pollers.lua @@ -23,17 +23,6 @@ function reg_pollers_bootstrap() }) end -function get_free_reg_poller(amount, sym) - local rps = nil - repeat - if rps ~= nil then - amount = amount + 1 - end - rps = box.space.reg_pollers.index.by_amount:select{sym, amount} - until #rps == 0 - return amount -end - local function wrap_rp(rp) return { id = rp[1], @@ -45,6 +34,23 @@ local function wrap_rp(rp) } end +function get_free_reg_poller(amount, sym) + local rps = nil + repeat + if rps ~= nil then + local now = fiber.clock64() + local rp = wrap_rp(rps[1]) + if (now - rp['created']) >= 20*60*1000000 then + box.space.reg_pollers:delete(rp['id']) + break + end + amount = amount + 1 + end + rps = box.space.reg_pollers.index.by_amount:select{sym, amount} + until #rps == 0 + return amount +end + function upsert_reg_poller(amount, sym, uid, init_bal) local now = fiber.clock64() local rps = box.space.reg_pollers.index.by_amount:select{sym, amount} @@ -54,7 +60,7 @@ function upsert_reg_poller(amount, sym, uid, init_bal) if rp['uid'] ~= uid then return { err = 'Someone already waits for such transfer.', res = nil } end - if (now - rp['created']) >= 15*60*1000 then + if (now - rp['created']) >= 20*60*1000000 then box.space.reg_pollers:delete(rp['id']) else return { err = nil, res = rp } diff --git a/src/locales/en.json b/src/locales/en.json index ff84c8b..acf0153 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -105,7 +105,8 @@ "memo_fixed": "Memo", "to": "Send tokens to address/account", "api_error": "Cannot get address. Try again later. If problem still occurs, contact the issuer of ", - "api_error_details": "and send the error details:" + "api_error_details": "and send the error details:", + "free_poller": "НCannot calculate minimal amount. Try again later, please. Or try another currency." }, "invites_jsx": { "claim_wrong_secret": "Wrong secret", diff --git a/src/locales/ru-RU.json b/src/locales/ru-RU.json index ba646cb..810766e 100644 --- a/src/locales/ru-RU.json +++ b/src/locales/ru-RU.json @@ -105,7 +105,8 @@ "memo_fixed": "Заметка/memo", "to": "Отправьте токены на адрес/аккаунт", "api_error": "Не удается получить адрес. Попробуйте позднее. Если проблема сохраняется, свяжитесь с эмитентом ", - "api_error_details": "и сообщите подробности ошибки:" + "api_error_details": "и сообщите подробности ошибки:", + "free_poller": "Не удается рассчитать минимальную сумму. Попробуйте позже, или другую валюту." }, "invites_jsx": { "claim_wrong_secret": "Неверно указан ключ", diff --git a/src/modules/register/TransferWaiter.jsx b/src/modules/register/TransferWaiter.jsx index 0df38e4..f94ea44 100644 --- a/src/modules/register/TransferWaiter.jsx +++ b/src/modules/register/TransferWaiter.jsx @@ -37,7 +37,7 @@ class TransferWaiter extends React.Component { start = async () => { this.setState({ - seconds: 30*60, + seconds: 15*60, stopped: false }) diff --git a/src/modules/register/UIARegister.jsx b/src/modules/register/UIARegister.jsx index 2262e69..57bfcad 100644 --- a/src/modules/register/UIARegister.jsx +++ b/src/modules/register/UIARegister.jsx @@ -91,7 +91,11 @@ class UIARegister extends React.Component { let registrar = await golos.api.getAccounts([accName]) registrar = registrar[0] - const { to_type, to_api, } = deposit + const { to_type, to_api, fee, } = deposit + if (fee && (isNaN(fee) || parseFloat(fee) !== 0)) { + error = sym + tt('uia_register_jsx.transfer_not_supported') + break + } if (to_type === 'transfer') { error = sym + tt('uia_register_jsx.transfer_not_supported') break @@ -128,6 +132,19 @@ class UIARegister extends React.Component { } } + try { + let fp = await callApi('/api/reg/get_free_poller/' + minAmount.toString()) + fp = await fp.json() + if (fp.error) { + throw new Error(fp.error) + } + minAmount = Asset(fp.amount) + } catch (err) { + console.error(err) + error = tt('uia_register_jsx.free_poller') + break + } + this.setState({ rules: { ...deposit, creator: asset.creator, telegram }, minAmount, diff --git a/src/pages/api/reg/[...all].js b/src/pages/api/reg/[...all].js index 97a4699..49c272b 100644 --- a/src/pages/api/reg/[...all].js +++ b/src/pages/api/reg/[...all].js @@ -400,6 +400,7 @@ let handler = nextConnect({ attachParams: true, }) try { initBal = await getBalance() } catch (err) { + console.error('wait_for_transfer getBalance', initBal) throwErr(req, 400, ['Blockchain unavailable']) } @@ -438,7 +439,7 @@ let handler = nextConnect({ attachParams: true, }) } console.log('wait_for_transfer', initBal.toString(), bal.toString()) - const delta = bal.amount.minus(initBal.amount) + const delta = bal.minus(initBal.amount) if (delta.gte(amount)) { let stopMe = false