Skip to content

Commit

Permalink
UIA register
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Nov 11, 2023
1 parent 4684f47 commit a83f034
Show file tree
Hide file tree
Showing 17 changed files with 732 additions and 214 deletions.
7 changes: 5 additions & 2 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"signing_key": "5K67PNheLkmxkgJ5UjvR8Nyt3GVPoLEN1dMZjFuNETzrNyMecPG",
"delegation": "75000.000000 GESTS",
"free_regs_per_day": 10,
"uias": ["YMUSDT", "YMPZM", "YMHIVE"]
"uias": ["YMUSDT", "YMPZM", "YMHIVE", "TESTF"]
},
"server_session_secret": "exiKdyF+IwRIXJDmtGIl4vWUz4i3eVSISpfZoeYc0s4=",
"session_cookie_key": "X-Reg-ISession",
Expand All @@ -39,7 +39,7 @@
"styleSrc": "'self' 'unsafe-inline' fonts.googleapis.com",
"imgSrc": "* data:",
"fontSrc": "data: fonts.gstatic.com",
"connectSrc": "'self' apibeta.golos.today wss://apibeta.golos.today",
"connectSrc": "'self' apibeta.golos.today wss://apibeta.golos.today *.golos.app",
"frameAncestors": "'none'"
}
},
Expand Down Expand Up @@ -76,6 +76,9 @@
"bot_token": "6390290192:AAEGipeCa4P0V4HZzoXvITCij8on6OItsGM"
}
},
"apidex_service": {
"host": "https://api-dex.golos.app"
},
"default_client": "blogs",
"clients": {
"blogs": {
Expand Down
2 changes: 2 additions & 0 deletions db/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require 'guid'
require 'oauth'
require 'server_tokens'
require 'cryptostore'
require 'reg_pollers'

io.output():setvbuf('no')

Expand Down Expand Up @@ -91,4 +92,5 @@ box.once('bootstrap', function()
oauth_bootstrap()
server_tokens_bootstrap()
cryptostore_bootstrap()
reg_pollers_bootstrap()
end)
92 changes: 92 additions & 0 deletions db/reg_pollers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
fiber = require 'fiber'

function reg_pollers_bootstrap()
box.schema.sequence.create('reg_pollers')
reg_pollers = box.schema.create_space('reg_pollers', {
format = {
{name = 'id', type = 'unsigned'},
{name = 'sym', type = 'STR'},
{name = 'amount', type = 'number'},
{name = 'uid', type = 'STR'},
{name = 'created', type = 'unsigned'},
{name = 'init_balance', type = 'number'},
}
})
reg_pollers:create_index('primary', {
sequence='reg_pollers'
})
reg_pollers:create_index('by_amount', {
type = 'tree', parts = {
'sym',
'amount'
}, unique = true
})
reg_pollers:create_index('by_created', {
type = 'tree', parts = {
'created'
}, unique = false
})
end

local function wrap_rp(rp)
return {
id = rp[1],
sym = rp[2],
amount = rp[3],
uid = rp[4],
created = rp[5],
init_bal = rp[6],
}
end

function get_free_reg_poller(amount, sym, now)
local rps = nil
repeat
if rps ~= nil then
local rp = wrap_rp(rps[1])
if (now - rp['created']) >= 20*60*1000 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

local function clean_reg_pollers(now)
for i,rp in box.space.reg_pollers.index.by_created:pairs(0, {iterator = 'GT', limit = 100}) do
local rp = wrap_rp(rp)
if (now - rp['created']) > 20*60*1000 then
box.space.reg_pollers:delete(rp['id'])
else
break
end
end
end

function upsert_reg_poller(amount, sym, uid, init_bal, now)
clean_reg_pollers(now)
local rps = box.space.reg_pollers.index.by_amount:select{sym, amount}
if #rps ~= 0 then
local rp = rps[1]
rp = wrap_rp(rp)
if rp['uid'] ~= uid then
return { err = 'Someone already waits for such transfer.', res = nil }
end
return { err = nil, res = rp }
end
local rp = box.space.reg_pollers:insert{nil, sym, amount, uid, now, init_bal}
return { err = nil, res = wrap_rp(rp) }
end

function delete_reg_poller(amount, sym)
local rps = box.space.reg_pollers.index.by_amount:select{sym, amount}
if #rps ~= 0 then
local rp = rps[1]
box.space.reg_pollers:delete(rp['id'])
return true
end
return false
end
3 changes: 3 additions & 0 deletions public/icons/copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions public/icons/copy_ok.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,18 @@
"register_with": "Register with...",
"no_such_asset": " - no such UIA.",
"deposit_unavailable": " - deposit temporarily unavailable.",
"cmc_error": " - cannot get min amount from CoinMarketCap.",
"transfer_not_supported": " - not yet supported.",
"min_amount": "Min amount",
"fee": "Fee",
"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.",
"deposited": "Received ",
"deposited2": ". Placing limit order to exchange it to GOLOS to register your account.",
"cannot_place_order": "Cannot place order: "
},
"invites_jsx": {
"claim_wrong_secret": "Wrong secret",
Expand Down
8 changes: 7 additions & 1 deletion src/locales/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,18 @@
"register_with": "Регистрация с помощью...",
"no_such_asset": " - такого UIA не существует.",
"deposit_unavailable": " - депозит временно недоступен.",
"cmc_error": " - не удается получить минимальную сумму с CoinMarketCap.",
"transfer_not_supported": " - пока не поддерживается.",
"min_amount": "Минимальная сумма",
"fee": "Комиссия",
"memo_fixed": "Заметка/memo",
"to": "Отправьте токены на адрес/аккаунт",
"api_error": "Не удается получить адрес. Попробуйте позднее. Если проблема сохраняется, свяжитесь с эмитентом ",
"api_error_details": "и сообщите подробности ошибки:"
"api_error_details": "и сообщите подробности ошибки:",
"free_poller": "Не удается рассчитать минимальную сумму. Попробуйте позже, или другую валюту.",
"deposited": "Получено ",
"deposited2": ". Размещаем ордер для обмена их на GOLOS для регистрации вашего аккаунта...",
"cannot_place_order": "Не удается разместить ордер: "
},
"invites_jsx": {
"claim_wrong_secret": "Неверно указан ключ",
Expand Down
45 changes: 27 additions & 18 deletions src/modules/register/TransferWaiter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import tt from 'counterpart'
import { Asset } from 'golos-lib-js/lib/utils';

import LoadingIndicator from '@/elements/LoadingIndicator'
import { delay, } from '@/utils/misc'
import { callApi, } from '@/utils/RegApiClient'

class TransferWaiter extends React.Component {
Expand All @@ -13,18 +14,20 @@ class TransferWaiter extends React.Component {
super(props)
}

poll = async (sym) => {
poll = async (minAmount) => {
const retry = async () => {
await new Promise(resolve => setTimeout(resolve, 1000))
if (!this.state.stopped)
this.poll(sym)
await delay(1000)
if (!this.stopped)
this.poll(minAmount)
else
this.stoppedPolling = true
}
try {
let res = await callApi('/api/reg/wait_for_transfer/' + sym)
let res = await callApi('/api/reg/wait_for_transfer/' + minAmount.toString())
res = await res.json()
if (res.status === 'ok') {
const { onTransfer } = this.props
onTransfer(Asset(res.delta))
onTransfer(Asset(res.deposited))
} else {
console.error(res)
await retry()
Expand All @@ -36,9 +39,10 @@ class TransferWaiter extends React.Component {
}

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

this.countdown = setInterval(() => {
Expand All @@ -53,29 +57,34 @@ class TransferWaiter extends React.Component {
})
}, 1000)

const { sym, } = this.props
const { minAmount, } = this.props

this.poll(sym)
this.poll(minAmount)
}

componentDidMount() {
this.start()
}

stop = () => {
stop = async () => {
if (this.countdown) clearInterval(this.countdown)
this.setState({
stopped: true
})
this.stopped = true
await delay(1000)
if (!this.stoppedPolling) {
await delay(3000)
}
}

componentWillUnmount() {
this.stop()
}

componentDidUpdate(prevProps) {
if (this.props.sym !== prevProps.sym) {
this.stop()
async componentDidUpdate(prevProps) {
const { minAmount } = this.props
if (minAmount && (!prevProps.minAmount ||
minAmount.symbol !== prevProps.minAmount.symbol ||
minAmount.amount !== prevProps.minAmount.amount)) {
await this.stop()
this.start()
}
}
Expand All @@ -86,7 +95,7 @@ class TransferWaiter extends React.Component {
const min = Math.floor(seconds / 60)
const sec = seconds % 60
const remaining = min.toString().padStart(2, '0') + ':' + sec.toString().padStart(2, '0')
const { sym, title } = this.props
const { title } = this.props
return <div align="center" style={{ marginTop: '1rem', }}>
{title}
<div style={{ marginTop: '0.5rem', }}>
Expand Down
Loading

0 comments on commit a83f034

Please sign in to comment.