Skip to content

Commit

Permalink
Fix register
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Nov 1, 2023
1 parent 0a1bdf2 commit ecc18a9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
30 changes: 18 additions & 12 deletions db/reg_pollers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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}
Expand All @@ -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 }
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
"memo_fixed": "Заметка/memo",
"to": "Отправьте токены на адрес/аккаунт",
"api_error": "Не удается получить адрес. Попробуйте позднее. Если проблема сохраняется, свяжитесь с эмитентом ",
"api_error_details": "и сообщите подробности ошибки:"
"api_error_details": "и сообщите подробности ошибки:",
"free_poller": "Не удается рассчитать минимальную сумму. Попробуйте позже, или другую валюту."
},
"invites_jsx": {
"claim_wrong_secret": "Неверно указан ключ",
Expand Down
2 changes: 1 addition & 1 deletion src/modules/register/TransferWaiter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TransferWaiter extends React.Component {

start = async () => {
this.setState({
seconds: 30*60,
seconds: 15*60,
stopped: false
})

Expand Down
13 changes: 13 additions & 0 deletions src/modules/register/UIARegister.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,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,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/api/reg/[...all].js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
}

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ecc18a9

Please sign in to comment.