From cf9be8982d78899332ec0d1433b2521916cd193b Mon Sep 17 00:00:00 2001 From: fetok12 Date: Tue, 6 Jun 2023 23:30:59 +0300 Subject: [PATCH 1/6] Throw errors --- server/messages.js | 2 ++ server/utils/hollaex-tools-lib/tools/order.js | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/server/messages.js b/server/messages.js index 085e4a8cda..c65eaf2d4e 100644 --- a/server/messages.js +++ b/server/messages.js @@ -59,6 +59,8 @@ exports.QUICK_TRADE_QUOTE_INVALID = 'Invalid quote'; exports.QUICK_TRADE_QUOTE_CALCULATING_ERROR = 'Error calculating the quote'; exports.QUICK_TRADE_ORDER_CAN_NOT_BE_FILLED = 'The order with the current size can not be filled'; +exports.QUICK_TRADE_ORDER_CURRENT_PRICE_ERROR = + 'The order with the current price can not be filled'; exports.QUICK_TRADE_INSUFFICIENT_BALANCE = 'Insufficient balance to perform the order'; exports.QUICK_TRADE_DISABLED = 'Broker service is currently disabled'; diff --git a/server/utils/hollaex-tools-lib/tools/order.js b/server/utils/hollaex-tools-lib/tools/order.js index cf73ea348c..fa139d5381 100644 --- a/server/utils/hollaex-tools-lib/tools/order.js +++ b/server/utils/hollaex-tools-lib/tools/order.js @@ -5,7 +5,7 @@ const { SERVER_PATH } = require('../constants'); const { getModel } = require('./database/model'); const { fetchBrokerQuote, generateRandomToken, executeBrokerDeal } = require('./broker'); const { getNodeLib } = require(`${SERVER_PATH}/init`); -const { INVALID_SYMBOL, NO_DATA_FOR_CSV, USER_NOT_FOUND, USER_NOT_REGISTERED_ON_NETWORK, TOKEN_EXPIRED, BROKER_NOT_FOUND, BROKER_PAUSED, BROKER_SIZE_EXCEED } = require(`${SERVER_PATH}/messages`); +const { INVALID_SYMBOL, NO_DATA_FOR_CSV, USER_NOT_FOUND, USER_NOT_REGISTERED_ON_NETWORK, TOKEN_EXPIRED, BROKER_NOT_FOUND, BROKER_PAUSED, BROKER_SIZE_EXCEED, QUICK_TRADE_ORDER_CAN_NOT_BE_FILLED, QUICK_TRADE_ORDER_CURRENT_PRICE_ERROR } = require(`${SERVER_PATH}/messages`); const { parse } = require('json2csv'); const { subscribedToPair, getKitTier, getDefaultFees, getAssetsPrices, getPublicTrades, validatePair } = require('./common'); const { reject } = require('bluebird'); @@ -182,8 +182,12 @@ const getUserQuickTrade = async (spending_currency, spending_amount, receiving_a isSourceChanged: spending_amount != null ? true : false, }, opts); - if (spending_amount != null) responseObj.receiving_amount = priceValues.estimatedPrice == 0 ? null : priceValues.targetAmount; - else if (receiving_amount != null) responseObj.spending_amount = priceValues.estimatedPrice == 0 ? null : priceValues.sourceAmount; + if (priceValues.estimatedPrice === 0) { + throw new Error(QUICK_TRADE_ORDER_CAN_NOT_BE_FILLED); + } + + if (spending_amount != null) responseObj.receiving_amount = priceValues.targetAmount; + else if (receiving_amount != null) responseObj.spending_amount = priceValues.sourceAmount; //Check if the estimated price is 50% greater than the last trade const lastTrades = await getPublicTrades(symbol); @@ -191,8 +195,7 @@ const getUserQuickTrade = async (spending_currency, spending_amount, receiving_a const lastPrice = math.number(lastTrades[symbol][0].price) * 1.50 if (priceValues.estimatedPrice > lastPrice) { - responseObj.receiving_amount = null; - responseObj.spending_amount = null; + throw new Error(QUICK_TRADE_ORDER_CURRENT_PRICE_ERROR); } } From 7e13b14007ff4ad3f5453cfeea1626d1e348a08b Mon Sep 17 00:00:00 2001 From: fetok12 Date: Fri, 9 Jun 2023 01:50:24 +0300 Subject: [PATCH 2/6] Fix quick trade amount logic --- web/src/components/QuickTrade/index.js | 32 ++++++++++++-------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/web/src/components/QuickTrade/index.js b/web/src/components/QuickTrade/index.js index 049ca05bef..680df3310f 100644 --- a/web/src/components/QuickTrade/index.js +++ b/web/src/components/QuickTrade/index.js @@ -228,39 +228,37 @@ const QuickTrade = ({ spending, }) => { if (spending) { - const spending_amount = - spending === SPENDING.SOURCE ? sourceAmount : targetAmount; - const [spending_currency, receiving_currency] = - spending === SPENDING.SOURCE - ? [selectedSource, selectedTarget] - : [selectedTarget, selectedSource]; - const [setSpendingAmount, setReceivingAmount] = - spending === SPENDING.SOURCE - ? [setSourceAmount, setTargetAmount] - : [setTargetAmount, setSourceAmount]; - - if (spending_amount && spending_currency && receiving_currency) { + const spending_amount = sourceAmount; + const receiving_amount = targetAmount; + + const [spending_currency, receiving_currency] = [selectedSource, selectedTarget]; + const amount = spending === SPENDING.SOURCE ? spending_amount : receiving_amount; + const amountPayload = spending === SPENDING.SOURCE ? { spending_amount } : { receiving_amount }; + + if (amount && spending_currency && receiving_currency) { setLoading(true); - setReceivingAmount(); + setTargetAmount(); + setSourceAmount(); setToken(); getQuickTrade({ - spending_amount, + ...amountPayload, spending_currency, receiving_currency, }) .then(({ data: { token, spending_amount, receiving_amount } }) => { setSpending(); setToken(token); - setReceivingAmount(receiving_amount); - setSpendingAmount(spending_amount); + setTargetAmount(receiving_amount); + setSourceAmount(spending_amount); }) .catch((err) => handleError(err, true)) .finally(() => { setLoading(false); }); } else { - setReceivingAmount(); + setTargetAmount(); + setSourceAmount(); setSpending(); setToken(); } From 0da2a82dfb6c9915ca30d7356737fa9197147943 Mon Sep 17 00:00:00 2001 From: fetok12 Date: Fri, 9 Jun 2023 02:12:29 +0300 Subject: [PATCH 3/6] Fix ReviewOrder component --- web/src/components/QuickTrade/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/src/components/QuickTrade/index.js b/web/src/components/QuickTrade/index.js index 680df3310f..af28e4f49e 100644 --- a/web/src/components/QuickTrade/index.js +++ b/web/src/components/QuickTrade/index.js @@ -476,11 +476,11 @@ const QuickTrade = ({ onExecuteTrade(token)} - selectedSource={spendingCurrency} + selectedSource={selectedSource} decimalPoint={decimalPoint} - sourceAmount={spendingAmount} - targetAmount={receivingAmount} - selectedTarget={receivingCurrency} + sourceAmount={sourceAmount} + targetAmount={targetAmount} + selectedTarget={selectedTarget} disabled={submitting} /> ) : ( From 5d74f621780d7d6d4c3d5c98747d89ef1d227fda Mon Sep 17 00:00:00 2001 From: Ali Beikverdi Date: Fri, 9 Jun 2023 15:13:37 +0900 Subject: [PATCH 4/6] version update --- server/api/swagger/swagger.js | 2 +- server/package.json | 2 +- version | 2 +- web/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/api/swagger/swagger.js b/server/api/swagger/swagger.js index f8496ed2da..228470efe7 100644 --- a/server/api/swagger/swagger.js +++ b/server/api/swagger/swagger.js @@ -4,7 +4,7 @@ const definition = { swagger: '2.0', info: { title: 'HollaEx Kit', - version: '2.6.5' + version: '2.6.6' }, host: 'api.hollaex.com', basePath: '/v2', diff --git a/server/package.json b/server/package.json index 51e5e03167..ccc56bb02c 100644 --- a/server/package.json +++ b/server/package.json @@ -1,5 +1,5 @@ { - "version": "2.6.5", + "version": "2.6.6", "private": false, "description": "HollaEx Kit", "keywords": [ diff --git a/version b/version index 68167133b9..952f449f1f 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.6.5 \ No newline at end of file +2.6.6 \ No newline at end of file diff --git a/web/package.json b/web/package.json index 6ae9da121f..b24ff22796 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "hollaex-kit", - "version": "2.6.5", + "version": "2.6.6", "private": true, "dependencies": { "@ant-design/compatible": "1.0.5", From 0b5123fa62b52b3e18cf0a167e4aaacb72347de8 Mon Sep 17 00:00:00 2001 From: fetok12 Date: Fri, 9 Jun 2023 10:12:34 +0300 Subject: [PATCH 5/6] Order value too small --- server/messages.js | 2 ++ server/utils/hollaex-tools-lib/tools/order.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/server/messages.js b/server/messages.js index c65eaf2d4e..c3b6cfda21 100644 --- a/server/messages.js +++ b/server/messages.js @@ -59,6 +59,8 @@ exports.QUICK_TRADE_QUOTE_INVALID = 'Invalid quote'; exports.QUICK_TRADE_QUOTE_CALCULATING_ERROR = 'Error calculating the quote'; exports.QUICK_TRADE_ORDER_CAN_NOT_BE_FILLED = 'The order with the current size can not be filled'; +exports.QUICK_TRADE_VALUE_IS_TOO_SMALL = + 'The order with the current size is too small to be filled'; exports.QUICK_TRADE_ORDER_CURRENT_PRICE_ERROR = 'The order with the current price can not be filled'; exports.QUICK_TRADE_INSUFFICIENT_BALANCE = diff --git a/server/utils/hollaex-tools-lib/tools/order.js b/server/utils/hollaex-tools-lib/tools/order.js index fa139d5381..8191ab94a3 100644 --- a/server/utils/hollaex-tools-lib/tools/order.js +++ b/server/utils/hollaex-tools-lib/tools/order.js @@ -5,7 +5,7 @@ const { SERVER_PATH } = require('../constants'); const { getModel } = require('./database/model'); const { fetchBrokerQuote, generateRandomToken, executeBrokerDeal } = require('./broker'); const { getNodeLib } = require(`${SERVER_PATH}/init`); -const { INVALID_SYMBOL, NO_DATA_FOR_CSV, USER_NOT_FOUND, USER_NOT_REGISTERED_ON_NETWORK, TOKEN_EXPIRED, BROKER_NOT_FOUND, BROKER_PAUSED, BROKER_SIZE_EXCEED, QUICK_TRADE_ORDER_CAN_NOT_BE_FILLED, QUICK_TRADE_ORDER_CURRENT_PRICE_ERROR } = require(`${SERVER_PATH}/messages`); +const { INVALID_SYMBOL, NO_DATA_FOR_CSV, USER_NOT_FOUND, USER_NOT_REGISTERED_ON_NETWORK, TOKEN_EXPIRED, BROKER_NOT_FOUND, BROKER_PAUSED, BROKER_SIZE_EXCEED, QUICK_TRADE_ORDER_CAN_NOT_BE_FILLED, QUICK_TRADE_ORDER_CURRENT_PRICE_ERROR, QUICK_TRADE_VALUE_IS_TOO_SMALL } = require(`${SERVER_PATH}/messages`); const { parse } = require('json2csv'); const { subscribedToPair, getKitTier, getDefaultFees, getAssetsPrices, getPublicTrades, validatePair } = require('./common'); const { reject } = require('bluebird'); @@ -147,6 +147,11 @@ const getUserQuickTrade = async (spending_currency, spending_amount, receiving_a ); responseObj.spending_amount = sourceAmount; } + + const baseCoinSize = side === 'buy' ? responseObj.receiving_amount : responseObj.spending_amount; + if (baseCoinSize < broker.min_size || baseCoinSize > broker.max_size) { + throw new Error(BROKER_SIZE_EXCEED) + } return responseObj; }) @@ -186,6 +191,10 @@ const getUserQuickTrade = async (spending_currency, spending_amount, receiving_a throw new Error(QUICK_TRADE_ORDER_CAN_NOT_BE_FILLED); } + if (priceValues.targetAmount === 0 || priceValues.sourceAmount === 0) { + throw new Error(QUICK_TRADE_VALUE_IS_TOO_SMALL); + } + if (spending_amount != null) responseObj.receiving_amount = priceValues.targetAmount; else if (receiving_amount != null) responseObj.spending_amount = priceValues.sourceAmount; From 389c250e85407c268ba153a7455326fe3a871683 Mon Sep 17 00:00:00 2001 From: fetok12 Date: Fri, 9 Jun 2023 10:20:18 +0300 Subject: [PATCH 6/6] Update index.js --- web/src/components/QuickTrade/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/QuickTrade/index.js b/web/src/components/QuickTrade/index.js index af28e4f49e..0726c5dc1f 100644 --- a/web/src/components/QuickTrade/index.js +++ b/web/src/components/QuickTrade/index.js @@ -240,6 +240,7 @@ const QuickTrade = ({ setTargetAmount(); setSourceAmount(); setToken(); + setError(); getQuickTrade({ ...amountPayload, @@ -303,7 +304,6 @@ const QuickTrade = ({ }, [selectedSource, selectedTarget, pairs, brokerPairs]); useEffect(() => { - setError(); debouncedQuote.current({ sourceAmount, targetAmount,