Skip to content

Commit

Permalink
Multi-step register - golos-dex-lib-js, small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Apr 9, 2024
1 parent 52044ae commit 92cbc23
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 113 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"formik": "^2.2.9",
"git-rev-sync": "^3.0.1",
"gmail-send": "^1.8.10",
"golos-lib-js": "^0.9.62",
"golos-dex-lib-js": "^1.0.2",
"golos-lib-js": "^0.9.68",
"iron-session": "6.0.4",
"jspdf": "^2.3.0",
"lodash": "^4.17.11",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@
"cannot_register_with_it": ", cannot register.",
"too_low_orders": "Too low orders in ",
"unknown_error": " - error in ",
"too_low_amount_to_register": "Too low amount to register."
"too_low_amount_to_register": "Too low amount to register.",
"no_assets_available": "No UIA assets available now."
},
"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 @@ -118,7 +118,8 @@
"cannot_register_with_it": ", не можем зарегистрировать за такую сумму.",
"too_low_orders": "Слишком мало ордеров по направлению ",
"unknown_error": " - ошибка по направлению ",
"too_low_amount_to_register": "Слишком малая сумма для регистрации."
"too_low_amount_to_register": "Слишком малая сумма для регистрации.",
"no_assets_available": "Регистрация через криптовалюту сейчас не работает."
},
"invites_jsx": {
"claim_wrong_secret": "Неверно указан ключ",
Expand Down
13 changes: 11 additions & 2 deletions src/modules/register/UIARegister.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import cn from 'classnames'
import golos, { api, } from 'golos-lib-js'
import { Asset, AssetEditor } from 'golos-lib-js/lib/utils';
import { key_utils, PrivateKey } from 'golos-lib-js/lib/auth/ecc'
import GolosDexApi from 'golos-dex-lib-js'
import Link from 'next/link'
import { Formik, ErrorMessage, } from 'formik'

Expand All @@ -13,7 +14,6 @@ import AmountField from '@/elements/forms/AmountField'
import AccountName from '@/elements/register/AccountName'
import VerifyWayTabs from '@/elements/register/VerifyWayTabs'
import TransferWaiter from '@/modules/register/TransferWaiter'
import { apidexGetPrices } from '@/utils/ApidexApiClient'
import KeyFile from '@/utils/KeyFile'
import { delay, } from '@/utils/misc'
import { emptyAuthority } from '@/utils/RecoveryUtils'
Expand Down Expand Up @@ -69,6 +69,14 @@ class UIARegister extends React.Component {
golos.config.set('chain_id', clientCfg.config.chain_id)

const { apidex_service } = clientCfg.config
try {
new GolosDexApi(golos, {
host: apidex_service.host
})
} catch (err) {
console.error('GolosDexApi init error:', err)
}

const { uias } = clientCfg.config.registrar
const syms = uias.assets

Expand Down Expand Up @@ -113,7 +121,7 @@ class UIARegister extends React.Component {

let cmc
try {
cmc = await apidexGetPrices(apidex_service, sym)
cmc = await golos.libs.dex.apidexGetPrices({ sym })
if (!cmc.price_usd) {
console.error('Cannot obtain price_usd', cmc)
throw Error('Cannot obtain price_usd')
Expand Down Expand Up @@ -618,6 +626,7 @@ class UIARegister extends React.Component {
{syms}
{this.state.sym && <hr />}
{form}
{!syms.length && !form ? <div>{tt('uia_register_jsx.no_assets_available')}</div> : null}
</div>
}

Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/reg/[...all].js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { getDailyLimit, obtainUid, getClientCfg, } from '@/server/reg';
import { regSessionMiddleware, } from '@/server/regSession';
import Tarantool from '@/server/tarantool';
import { delay, } from '@/utils/misc'
import { apidexExchange } from '@/utils/ApidexApiClient'

initGolos();

Expand Down Expand Up @@ -526,7 +525,8 @@ let handler = nextConnect({ attachParams: true, })
const [ sym1, sym2 ] = ex.split('/')
let resEx
try {
resEx = await apidexExchange(apidex_service, exAmount, sym2)
const { dex } = golos.libs
resEx = await dex.apidexExchange({sell: exAmount, buySym: sym2})
} catch (err) {
console.error(err)
}
Expand Down
12 changes: 11 additions & 1 deletion src/server/initGolos.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const golos = require('golos-lib-js');
const golos = require('golos-lib-js')
const GolosDexApi = require('golos-dex-lib-js').default
const config = require('config');

function initGolos() {
Expand All @@ -9,6 +10,15 @@ function initGolos() {
}

golos.config.set('broadcast_transaction_with_callback', true);

const apidex_service = config.get('apidex_service')
try {
new GolosDexApi(golos, {
host: apidex_service.host
})
} catch (err) {
console.error('GolosDexApi init error:', err)
}
}

module.exports = {
Expand Down
101 changes: 0 additions & 101 deletions src/utils/ApidexApiClient.js

This file was deleted.

15 changes: 11 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2968,10 +2968,17 @@ gmail-send@^1.8.10:
lodash "^4.17.15"
nodemailer "^6.3.0"

golos-lib-js@^0.9.62:
version "0.9.62"
resolved "https://registry.yarnpkg.com/golos-lib-js/-/golos-lib-js-0.9.62.tgz#d3c48db7cb808b59158f2c878ff59936c24d88e3"
integrity sha512-npQBa353iju1vsL6z8u8ZnluzRhavCElG23OFMFHAyapLuy/1TyYU10aCAyrRc+bJro7QR91tKedmPLgFPBa8Q==
golos-dex-lib-js@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/golos-dex-lib-js/-/golos-dex-lib-js-1.0.2.tgz#e0fe5d29781da8d0830ccb6bcfa5386bc73a2c5d"
integrity sha512-wrTzbMdoXlarjFu15liuTdcZjHlPXbdGyMouvCVlMKVqcldUbvi5SMR5egtLBjMKZfmFnFxbFrv798ukGqqSUg==
dependencies:
golos-lib-js "^0.9.64"

golos-lib-js@^0.9.64, golos-lib-js@^0.9.68:
version "0.9.68"
resolved "https://registry.yarnpkg.com/golos-lib-js/-/golos-lib-js-0.9.68.tgz#62f3c4a7755eacfbe6dc2f6ebc3111f2ff74e6dd"
integrity sha512-KoQMFHtINYdM0hhe9dKPpWXZLo3MkFXyRxY/zQq0kbBjAwJBU4P1WEMwmPS+MPujjizfvU6nerUOLI4Lj7ChFw==
dependencies:
abort-controller "^3.0.0"
assert "^2.0.0"
Expand Down

0 comments on commit 92cbc23

Please sign in to comment.