Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Side orders from modals & refactoring #903

Merged
merged 26 commits into from May 14, 2024
Merged

Conversation

onemicky
Copy link
Collaborator

@onemicky onemicky commented Apr 8, 2024


Copy link

cloudflare-pages bot commented Apr 10, 2024

Deploying gmx-interface with  Cloudflare Pages  Cloudflare Pages

Latest commit: c70e90b
Status: ✅  Deploy successful!
Preview URL: https://b21a909a.gmx-interface.pages.dev
Branch Preview URL: https://tpsl-from-modals-v2-rebased.gmx-interface.pages.dev

View logs

@onemicky onemicky force-pushed the tpsl-from-modals-v2-rebased branch from d5f05b5 to 506b667 Compare April 11, 2024 11:45
Base automatically changed from selectors-refactoring-part-2.1 to release-22 April 16, 2024 09:21
@onemicky onemicky changed the title DON'T MERGE: tpsl from modals over refactoring Side orders from modals & refactoring Apr 23, 2024
@onemicky onemicky changed the base branch from release-22 to master April 23, 2024 12:06
@onemicky onemicky force-pushed the tpsl-from-modals-v2-rebased branch from ae8858b to 334f2b7 Compare April 23, 2024 12:08
Copy link

netlify bot commented Apr 23, 2024

Deploy Preview for vigilant-albattani-df38ec ready!

Name Link
🔨 Latest commit ec54c99
🔍 Latest deploy log https://app.netlify.com/sites/vigilant-albattani-df38ec/deploys/66423e284bc83d0007b49424
😎 Deploy Preview https://deploy-preview-903--vigilant-albattani-df38ec.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Apr 23, 2024

Deploy Preview for superb-tarsier-e2aa29 ready!

Name Link
🔨 Latest commit ec54c99
🔍 Latest deploy log https://app.netlify.com/sites/superb-tarsier-e2aa29/deploys/66423e280aa22f0008fa4729
😎 Deploy Preview https://deploy-preview-903--superb-tarsier-e2aa29.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@onemicky onemicky force-pushed the tpsl-from-modals-v2-rebased branch from 5231ad5 to ec54c99 Compare May 13, 2024 16:21
@onemicky onemicky changed the base branch from master to release-26 May 13, 2024 16:22
gmxer
gmxer previously requested changes May 14, 2024

function onCancelOrderClick(key: string): void {
if (!signer) return;
cancelOrdersTxn(chainId, signer, subaccount, {
orderKeys: [key],
setPendingTxns: p.setPendingTxns,
isLastSubaccountAction,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I remember it was needed for some subacc notification, isn't it needed anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As i can see, now we don't use this param inside the function


if (existingPosition || !entriesInfo) return;
if (!entriesInfo || !entriesInfo.entries.some((e) => e.txnType !== "cancel")) return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

would be slower but much more readable entriesInfo.entries.every((e) => e.txnType === "cancel")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good suggestion, thanks


function handleAddEntry() {
addEntry();
setTimeout(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

requestAnimationFrame?


return (
<div className="SidecarEntries-wrapper" ref={containerRef}>
{displayableEntries?.map((entry) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's introduce <SidecarEntry key={..} entry={..} />?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yap, good suggestion to improve


<NumberInput
value={entry.price.input}
onValueChange={(e) => updateEntry(entry.id, "price", e.target.value)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can memoize it in SidecarEntry component

@@ -97,7 +92,6 @@ export function OrderList(p: Props) {
cancelOrdersTxn(chainId, signer, subaccount, {
orderKeys: [key],
setPendingTxns: p.setPendingTxns,
isLastSubaccountAction,
Copy link
Collaborator

Choose a reason for hiding this comment

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

same question, probably with same reason

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

answered on the first note

if (pendingOrder.txnType === "cancel") {
return Boolean(orderStatus?.cancelledTxnHash);
}
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

throw mustNeverExist(pendingOrder.txnType)


function findMatchedOrderStatus(orderList: OrderStatus[], orderData: PendingOrderData) {
return orderList.find((status) => {
const isPendingOrderMatch = status.data && getPendingOrderKey(orderData) === getPendingOrderKey(status.data);
Copy link
Collaborator

Choose a reason for hiding this comment

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

not a biggie but you can do getPendingOrderKey(orderData) outside of a loop

: priceError
: inputPrice.lt(triggerPrice)
? t`Price below Limit Price.`
: priceError;
Copy link
Collaborator

Choose a reason for hiding this comment

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

these conditions looks very repetitive but don't have a strong idea what to do with it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, it's a tricky place, hope it's a bit more readable now

}, [effect]);
}

export default useEffectOnce;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this hook seems like a workaround, are you sure we need to re-use it somewhere else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem forced me to create this helper was that i'm unable to set an initial state on a component mount when i use a centralized state & selectors. I agree that it's not a best solution. Ideally, we should maintain state independently of whether the component is mounted or not. But at the moment it makes code a bit more readable. I'll have no problem removing it when it will be no longer needed

midas-myth
midas-myth previously approved these changes May 14, 2024
@@ -333,7 +334,7 @@ export function OrdersStatusNotificiation({
if (pendingOrder.txnType === "cancel") {
return Boolean(orderStatus?.cancelledTxnHash);
}
return false;
throw mustNeverExist(pendingOrder.txnType);
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think throw is redundant because mustNeverExist already throws inside of it

@midas-myth midas-myth requested a review from gmxer May 14, 2024 16:26
@midas-myth midas-myth dismissed gmxer’s stale review May 14, 2024 16:28

Changes applyed, Midas checked

@onemicky onemicky merged commit 7af2427 into release-26 May 14, 2024
1 check passed
@midas-myth midas-myth deleted the tpsl-from-modals-v2-rebased branch May 14, 2024 16:32
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.

None yet

3 participants