Skip to content

Commit

Permalink
fix: can not open position
Browse files Browse the repository at this point in the history
  • Loading branch information
deep-path committed Nov 26, 2024
1 parent 6bb1a56 commit 646cc37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 8 additions & 1 deletion screens/Trading/components/ConfirmMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import DataSource from "../../../data/datasource";
import { getAccountId } from "../../../redux/accountSelectors";
import { useRouterQuery } from "../../../utils/txhashContract";
import { handleTransactionHash } from "../../../services/transaction";
import { useToastMessage } from "../../../hooks/hooks";

const getTokenSymbolOnly = (assetId) => {
return assetId === "wNEAR" ? "NEAR" : assetId || "";
};

export const ModalContext = createContext(null) as any;
const ConfirmMobile = ({ open, onClose, action, confirmInfo }) => {
const { toastMessage, showToast } = useToastMessage();
const { query } = useRouterQuery();
const accountId = useAppSelector(getAccountId);
const dispatch = useAppDispatch();
Expand All @@ -37,6 +39,7 @@ const ConfirmMobile = ({ open, onClose, action, confirmInfo }) => {
const actionShowRedColor = action === "Long";
const [isDisabled, setIsDisabled] = useState(false);
const { marginConfigTokens } = useMarginConfigToken();
const { max_active_user_margin_position } = marginConfigTokens;
const { marginAccountList, parseTokenValue, getAssetDetails, getAssetById } = useMarginAccount();
const {
price: priceP,
Expand All @@ -47,8 +50,12 @@ const ConfirmMobile = ({ open, onClose, action, confirmInfo }) => {
? getAssetById(confirmInfo.longOutputName?.token_id)
: getAssetById(confirmInfo.longInputName?.token_id),
);
const cateSymbol = getTokenSymbolOnly(ReduxcategoryAssets1.metadata.symbol);
const cateSymbol = getTokenSymbolOnly(ReduxcategoryAssets1?.metadata?.symbol);
const confirmOpenPosition = async () => {
if (Object.values(marginAccountList).length >= max_active_user_margin_position) {
return showToast("User has exceeded the maximum number of open positions!");
}

setIsDisabled(true);
if (action === "Long") {
try {
Expand Down
7 changes: 4 additions & 3 deletions screens/Trading/components/TradingOperate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const TradingOperate = () => {
const assets = useAppSelector(getAssets);
const config = useAppSelector(getMarginConfig);
const { categoryAssets1, categoryAssets2 } = useMarginConfigToken();
const { parseTokenValue, getAssetDetails, getAssetById } = useMarginAccount();
const { marginConfigTokens } = useMarginConfigToken();
const marginConfig = useAppSelector(getMarginConfig);
const { marginAccountList, parseTokenValue, getAssetDetails, getAssetById } = useMarginAccount();
const { marginConfigTokens, filterMarginConfigList } = useMarginConfigToken();
const { max_active_user_margin_position } = marginConfigTokens;
const {
ReduxcategoryAssets1,
Expand Down Expand Up @@ -125,7 +126,7 @@ const TradingOperate = () => {
// }, 200);
// };

const cateSymbol = getTokenSymbolOnly(ReduxcategoryAssets1.metadata.symbol);
const cateSymbol = getTokenSymbolOnly(ReduxcategoryAssets1?.metadata?.symbol);
// slippageTolerance change ecent
useEffect(() => {
dispatch(setSlippageToleranceFromRedux(0.5));
Expand Down

0 comments on commit 646cc37

Please sign in to comment.