Skip to content

Conversation

@qwinndev
Copy link
Contributor

@qwinndev qwinndev commented Dec 4, 2025

Main changes:
Updated Tradebox:

  • leverage, collateral and pool selection moved to the top of tradebox
  • pay and receive changed to margin fields
  • sidecar orders updated to only include one full close TP and SL
  • updated buttons labels

Other changes:

  • Updated buttons in positions list
  • Size in positions list now is toggle between usd and token amount
  • TP/SL column in positions list
  • New TP/SL modal representing position TP/SL orders and buttons to manage them
  • New Add TP/SL modal

@qwinndev qwinndev changed the base branch from master to release-91 December 4, 2025 12:55
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 5, 2025

Deploying gmx-interface-home with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3a99e40
Status: ✅  Deploy successful!
Preview URL: https://7c3126ac.gmx-interface-home.pages.dev
Branch Preview URL: https://tradebox-ux-update.gmx-interface-home.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 5, 2025

Deploying gmx-interface with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3a99e40
Status: ✅  Deploy successful!
Preview URL: https://d314b12f.gmx-interface.pages.dev
Branch Preview URL: https://tradebox-ux-update.gmx-interface.pages.dev

View logs

@gmx-io gmx-io deleted a comment from cursor bot Dec 16, 2025
@gmx-io gmx-io deleted a comment from cursor bot Dec 16, 2025
@gmx-io gmx-io deleted a comment from cursor bot Dec 16, 2025
@qwinndev
Copy link
Contributor Author

bugbot review

@cursor
Copy link

cursor bot commented Dec 16, 2025

Skipping Bugbot: Bugbot is disabled for this repository

@qwinndev qwinndev changed the base branch from release-91 to release December 16, 2025 13:14
@divhead
Copy link
Contributor

divhead commented Dec 17, 2025

@cursor review

</span>
);
}, [order]);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: TP/SL receive amount calculated from size

Receive is derived from order.sizeDeltaUsd and converted using targetCollateralToken.prices.minPrice, but sizeDeltaUsd represents position size reduction, not the collateral/token amount the user receives. This can massively overstate the receive amount (especially for leveraged positions) and mislead users about TP/SL outcomes.

Additional Locations (1)

Fix in Cursor Fix in Web

const pnlPercentage = position.collateralUsd > 0n ? bigMath.mulDiv(pnlUsd, 10000n, position.collateralUsd) : 0n;

return { pnlUsd, pnlPercentage };
}, [order, position]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Division by zero in TP/SL PnL

estimatedPnl divides by entryPrice via bigMath.mulDiv(..., entryPrice). If position.entryPrice is unset or 0n (e.g., not fully loaded or opening state), this can throw at runtime and break the TP/SL modal rendering.

Additional Locations (1)

Fix in Cursor Fix in Web

@qwinndev qwinndev marked this pull request as ready for review December 17, 2025 11:33
@qwinndev qwinndev requested a review from divhead December 17, 2025 11:34
import { useLocalStorageSerializeKey } from "lib/localStorage";
import { TradeType } from "sdk/types/trade";

export const BEST_POOL_MARKER = "BEST_POOL";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid pseudo addresses and just store bestPool in some variable instead?


const orderSizeInTokens =
increaseAmounts?.sizeDeltaInTokens ??
(positionIndexToken && (sizeDeltaUsd ?? order.sizeDeltaUsd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too much independent checks
let's rewrite it to more controlled If-s
like

if (sizeDeltaUsd && triggerPrice) {
....
} else {
... use order values
}


const collateralDeltaAmountForTpSl =
increaseAmounts?.collateralDeltaAmount ??
(isLimitOrStopIncrease && order ? order.initialCollateralDeltaAmount : undefined) ??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't isLimitOrStopIncrease be the first check here?

(isLimitOrStopIncrease && order ? order.initialCollateralDeltaAmount : undefined) ??
0n;

const totalCollateralAmountForTpSl = (existingPosition?.collateralAmount ?? 0n) + collateralDeltaAmountForTpSl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be better to move all calcs to pure function(s) and just use it in hooks for better testability

updatedAtBlock: 0n,
});

const nextEntryPrice =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, would be good to move it to pure functions

userReferralInfo?.referralCodeForTxn,
]);

const hasTpSlValues = typeof tpPriceField.value === "bigint" || typeof slPriceField.value === "bigint";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hard to read these lines, can we simplify these checks somehow?

}
}

let closestSl: PositionOrderInfo | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also move it all to pure functions

const usdValue = (parsedInput * markPrice) / (10n ** BigInt(USD_DECIMALS) * visualMultiplier);
return formatUsd(usdValue, { fallbackToZero: true }) ?? "$0.00";
} else {
const tokenValue = (parsedInput * visualMultiplier * 10n ** BigInt(indexToken?.decimals ?? 18)) / markPrice;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please avoid magic numbers
maybe wrapping this into a functions would help also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants