- {item[1].slice(0, 10)}... |
+ {item[1]} |
{item[0]} |
- {item[2].slice(0, 10)}... |
+ {item[2]} |
{item[3]} |
{/*
diff --git a/app/client/src/pages/Trading/Trading.tsx b/app/client/src/pages/Trading/Trading.tsx
index 205c1f38..60b16e19 100644
--- a/app/client/src/pages/Trading/Trading.tsx
+++ b/app/client/src/pages/Trading/Trading.tsx
@@ -13,36 +13,44 @@ import TokenSelect from "../../components/dashboard/select/TokenSelect";
import { useEffect, useState } from "react";
import { useAuth } from "../../contexts/AuthContext";
import TradingAside from "./TradingAside";
+import { TokenOption } from "../../components/commons/Select";
const tabs = ['Bids', 'Asks']
const Trading = () => {
- const { fetchTradingInfoPage, tradingPageLoading, orders, tokens } = useAuth();
-
+ const { fetchTradingInfoPage, tradingPageLoading, orders, tokens, setCurrentToken, currentToken, tokenBalances, currentAddress } = useAuth();
+ console.log(tokenBalances)
const [activeTab, setActiveTab] = useState('Bids');
-
- const options = tokens.map((token) => {
- const item = assetsItems.find((k) => k.name == token) || assetsItems[0]
- return ({
- label: item.icon,
- value: token,
+ const options: TokenOption[] = tokens
+ .map((token) => {
+ if (token !== "QU") {
+ const item = assetsItems.find((k) => k.name === token) || assetsItems[0];
+ return {
+ label: item.icon,
+ value: token,
+ } as TokenOption;
+ }
+ return undefined;
})
- });
- // const dateOptions = [
- // "04 Dec 23",
- // "05 Dec 23",
- // "08 Dec 23",
- // "29 Dec 23",
- // "26 Jan 24",
- // "26 Mar 24",
- // ];
+ .filter((option): option is TokenOption => option !== undefined);
useEffect(() => {
async function init() {
const orders = await fetchTradingInfoPage();
console.log(orders, 'fffffffff')
}
- init();
+ if (currentToken.value !== 'QU') {
+ init();
+ }
+ }, [currentToken, activeTab])
+
+ useEffect(() => {
+ setInterval(() => {
+ fetchTradingInfoPage();
+ }, 60000)
+ if (currentToken.value == 'QU') {
+ setCurrentToken(options[0])
+ }
}, [])
return (
@@ -55,12 +63,20 @@ const Trading = () => {
/>
-
-
+ {
+ Array.isArray(options) && options.length > 0 &&
+
+
+ {tokenBalances[`${currentToken.value}`] ? tokenBalances[`${currentToken.value}`][currentAddress] : 0}
+
+ }
+
+ Issuer: {orders?.issuer}
+
{/*
@@ -160,7 +176,7 @@ const Trading = () => {
}
-
+
diff --git a/app/client/src/pages/Trading/TradingAside.tsx b/app/client/src/pages/Trading/TradingAside.tsx
index ae2bebbe..fab75ed2 100644
--- a/app/client/src/pages/Trading/TradingAside.tsx
+++ b/app/client/src/pages/Trading/TradingAside.tsx
@@ -1,16 +1,18 @@
import Button from "../../components/commons/Button";
import Input from "../../components/commons/Input";
import Section from "../../components/commons/Section";
-import { assetsItems } from "../../utils/constants";
import { useState } from "react";
import TokenSelect from "../../components/dashboard/select/TokenSelect";
import { useAuth } from "../../contexts/AuthContext";
import { toast } from "react-toastify";
import TxModal from "../../components/dashboard/modal/TxModal";
+import { TokenOption } from "../../components/commons/Select";
+import { isNaturalNumber, isPositiveNumber } from "../../utils/helper";
-const TradingAside = () => {
- const { handleBuyCell, txStatus, tokens } = useAuth();
+const TradingAside = ({ options }: { options: TokenOption[] }) => {
+ const { handleBuyCell, txStatus, setTxStatus, tokenBalances, currentAddress, currentToken } = useAuth();
+ const [command, setCommand] = useState<'buy' | 'sell' | 'cancelbuy' | 'cancelsell'>();
const [quantity, setQuantity] = useState();
const [price, setPrice] = useState();
@@ -22,26 +24,36 @@ const TradingAside = () => {
setPrice(e.target.value);
}
- const _handleBuyCell = (flag: 'buy' | 'sell' | 'cancelbuy' | 'cancelsell',) => {
- if (!quantity || !price) {
- toast.error('Input valid quantity or price.')
- return
+ const handleTx = () => {
+ if (!quantity || !price || !command) {
+ toast.error('Invalid command.');
+ return;
}
- handleBuyCell(flag, quantity, price)
+ handleBuyCell(command, quantity, price);
+ }
+
+ const handleAction = (command: 'buy' | 'sell' | 'cancelbuy' | 'cancelsell') => {
+ if (!quantity || !price || !isPositiveNumber(quantity) || !isNaturalNumber(price)) {
+ toast.error('Input valid quantity or price.');
+ return;
+ }
+ if (command == 'buy' && parseInt(price) > tokenBalances['QU'][currentAddress]) {
+ toast.error('Input valid QU amount.');
+ return;
+ }
+ if (command == 'sell' && parseInt(quantity) > tokenBalances[currentToken.value as string][currentAddress]) {
+ toast.error(`Input valid ${currentToken.value} amount.`);
+ return;
+ }
+ setTxStatus('confirm');
+ setCommand(command);
}
- const options = tokens.map((token) => {
- const item = assetsItems.find((k) => k.name == token) || assetsItems[0]
- return ({
- label: item.icon,
- value: token,
- })
- });
return (
{txStatus != "" &&
-
+
}
{/*
SELECT A STRIKE PRICE
@@ -66,18 +78,18 @@ const TradingAside = () => {
-
- _handleBuyCell('cancelbuy')}>
+ handleAction('cancelbuy')}>
Cancel Buy
- _handleBuyCell('cancelsell')}>
+ handleAction('cancelsell')}>
Cancel Sell
diff --git a/app/client/src/utils/constants.ts b/app/client/src/utils/constants.ts
index 6dae57ea..cb371a2c 100644
--- a/app/client/src/utils/constants.ts
+++ b/app/client/src/utils/constants.ts
@@ -1,6 +1,8 @@
import { SettingsItems } from "../enums/SettingsItems";
import { AssetItemProps, ModeProps, SidebarItemProps, SummaryItemProps } from "./interfaces";
+const EXPECTEDTICKGAP = 5;
+
const autoLockTimes = [{
label: '1 minute',
value: '1m'
@@ -193,4 +195,4 @@ const currencies = [{ label: "US Dollar", value: "USDT" }]
const SERVER_URL = import.meta.env.VITE_SERVER_URL || "http://localhost:3000";
-export { sideBarItems, summaryItems, assetsItems, summaryAccountItems, marketOptions, SERVER_URL, MODES, settingsSidebarItems, currencies, autoLockTimes };
\ No newline at end of file
+export { sideBarItems, summaryItems, assetsItems, summaryAccountItems, marketOptions, SERVER_URL, MODES, settingsSidebarItems, currencies, autoLockTimes, EXPECTEDTICKGAP };
\ No newline at end of file
diff --git a/app/client/src/utils/helper.ts b/app/client/src/utils/helper.ts
index 319509ec..151420c9 100644
--- a/app/client/src/utils/helper.ts
+++ b/app/client/src/utils/helper.ts
@@ -5,4 +5,16 @@ const handleCopy = async (value: any) => {
await navigator.clipboard.writeText(`${value}`);
}
-export {handleCopy}
\ No newline at end of file
+function isNaturalNumber(str: string): boolean {
+ // Regular expression to match a natural number (non-negative integer)
+ const naturalNumberRegex = /^[0-9]+$/;
+ return naturalNumberRegex.test(str);
+}
+
+function isPositiveNumber(str: string): boolean {
+ // Regular expression to match a positive integer (greater than zero)
+ const positiveNumberRegex = /^[1-9][0-9]*$/;
+ return positiveNumberRegex.test(str);
+}
+
+export { handleCopy, isNaturalNumber, isPositiveNumber }
\ No newline at end of file
diff --git a/app/client/src/utils/interfaces.ts b/app/client/src/utils/interfaces.ts
index 15538095..97fc2aca 100644
--- a/app/client/src/utils/interfaces.ts
+++ b/app/client/src/utils/interfaces.ts
@@ -56,4 +56,8 @@ interface OrderInterface {
asks: [string, string, string][];
}
-export type { SelectOption, SidebarItemProps, SummaryItemProps, AssetItemProps, ModeProps, AccountInfoInterface, MarketcapInterface, RichListInterface, OrderInterface }
\ No newline at end of file
+interface TokenPriceInterface {
+ [key: string]: [number, number];
+}
+
+export type { SelectOption, SidebarItemProps, SummaryItemProps, AssetItemProps, ModeProps, AccountInfoInterface, MarketcapInterface, RichListInterface, OrderInterface, TokenPriceInterface }
\ No newline at end of file
diff --git a/app/server/controllers/mainController.js b/app/server/controllers/mainController.js
index 5776486f..ec6391cf 100644
--- a/app/server/controllers/mainController.js
+++ b/app/server/controllers/mainController.js
@@ -125,6 +125,7 @@ exports.fetchUser = async (req, res) => {
const balances = await socketSync('balances');
const marketcap = await socketSync('marketcap');
const tokens = await socketSync('tokenlist');
+ const tokenPrices = await socketSync('tokenprices');
// const richlist = {};
// const qurichlist = await socketSync('richlist');
// richlist[qurichlist.name] = qurichlist.richlist;
@@ -136,7 +137,7 @@ exports.fetchUser = async (req, res) => {
// } catch (error) {
// }
- const updatedUserState = { ...userState, ...{ balances: balances.balances, marketcap, tokens: tokens.tokens } };
+ const updatedUserState = { ...userState, ...{ balances: balances.balances, marketcap, tokens: tokens.tokens, tokenPrices: tokenPrices } };
stateManager.setUserState(updatedUserState);
res.send(updatedUserState);
}
diff --git a/mobile/App.tsx b/mobile/App.tsx
index 3afd6c79..06217c03 100644
--- a/mobile/App.tsx
+++ b/mobile/App.tsx
@@ -16,6 +16,7 @@ import { ColorProvider } from "@app/context/ColorContex";
import getTheme from "@app/utils/ThemeConfig";
import local from "@app/utils/locales";
import toastConfig from "@app/utils/ToastConfig";
+import { StatusBar } from "react-native";
interface ISettings {
init: string;
@@ -73,18 +74,19 @@ export default function App() {
local.setLanguage(settings.lang);
return (
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
);
}
diff --git a/mobile/app.json b/mobile/app.json
index c92f69c5..1cc13182 100644
--- a/mobile/app.json
+++ b/mobile/app.json
@@ -20,7 +20,11 @@
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#192B3B"
},
- "package": "com.qsilver.qwallet"
+ "package": "com.qsilver.qwallet",
+ // "statusBar": {
+ // "barStyle": "light-content",
+ // "backgroundColor": "#000000"
+ // }
// "config": {
// "emulatorPort": 5555
// }
diff --git a/mobile/assets/images/tokens/cfb.svg b/mobile/assets/images/tokens/cfb.svg
index 6a1ed419..037d1ab7 100644
--- a/mobile/assets/images/tokens/cfb.svg
+++ b/mobile/assets/images/tokens/cfb.svg
@@ -1,9 +1,10 @@
- |