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

fix: Add undefined check for trade order #10754

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

memoyil
Copy link
Collaborator

@memoyil memoyil commented Sep 28, 2024


PR-Codex overview

This PR focuses on improving the handling of optional values in the useAllTypeBestTrade hook and the V3SwapForm component. It ensures that properties are accessed safely, preventing potential runtime errors when values are undefined.

Detailed summary

  • Updated classicAmmOrder to return undefined if ammCurrentTrade is falsy.
  • Changed bestOrder type to allow undefined.
  • Modified validTrade assignment to safely access ammOrder.trade.
  • Updated ammInputAmount and ammOutputAmount to safely access values from ammOrder.
  • Adjusted ammOrder structure to safely access type.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

vercel bot commented Sep 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 30, 2024 6:54am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
aptos-web ⬜️ Ignored (Inspect) Visit Preview Sep 30, 2024 6:54am
blog ⬜️ Ignored (Inspect) Visit Preview Sep 30, 2024 6:54am
bridge ⬜️ Ignored (Inspect) Visit Preview Sep 30, 2024 6:54am
games ⬜️ Ignored (Inspect) Visit Preview Sep 30, 2024 6:54am
gamification ⬜️ Ignored (Inspect) Visit Preview Sep 30, 2024 6:54am
uikit ⬜️ Ignored (Inspect) Visit Preview Sep 30, 2024 6:54am

Copy link

changeset-bot bot commented Sep 28, 2024

⚠️ No Changeset found

Latest commit: cb2a277

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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 make sure on sdk typing end we don't allow undefined trade

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On https://github.com/pancakeswap/pancake-frontend/blob/develop/apps/web/src/views/Swap/V3Swap/hooks/useSwapBestTrade.ts#L181 , trade is set to undefined as well as it can be set to undefined from this hook https://github.com/pancakeswap/pancake-frontend/blob/develop/apps/web/src/hooks/useBestAMMTrade.ts . So imo type should contain undefined therefore it must be checked on compile time when it is used

Copy link
Collaborator

Choose a reason for hiding this comment

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

it doesn't make sense if we have a order with type but no trade. Let's make sure if we initialize a order it has to have a valid trade or we don't initialize the order at all

Copy link
Collaborator Author

@memoyil memoyil Sep 30, 2024

Choose a reason for hiding this comment

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

Done, @chefjackson you can review it again

@memoyil memoyil force-pushed the feature/fix_add_undefined_check_for_trade_order branch from 1ad2e5f to 1cd3b89 Compare September 30, 2024 06:33
@pull-request-size pull-request-size bot added size/S and removed size/M labels Sep 30, 2024
@chefjackson chefjackson merged commit cff2588 into develop Sep 30, 2024
19 checks passed
@chefjackson chefjackson deleted the feature/fix_add_undefined_check_for_trade_order branch September 30, 2024 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants