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

feat(permit): allowance warning #3184

Merged
merged 23 commits into from
Oct 11, 2023

Conversation

alfetopito
Copy link
Collaborator

@alfetopito alfetopito commented Oct 6, 2023

Summary

Fixes #3146

Update allowance warning check for limit orders

Now the UI will take into account permits still not executed when calculating whether the allowance warning should be displayed:

Before:
image

After:
image

TODO:

  • Move to jotai/updater

  • Check periodically

  • Test more use cases

  • Add it to Activity modal (SWAP orders)

    To Test

  1. Make sure there's no allowance
  2. Place a LIMIT order for a permittable token
  • Allowance warning should NOT be displayed

@vercel
Copy link

vercel bot commented Oct 6, 2023

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

Name Status Preview Updated (UTC)
swap-dev ✅ Ready (Inspect) Visit Preview Oct 11, 2023 10:18am

🌃 Cosmos ↗︎

const recoveredOwner = await recoverPermitOwnerPromise

// Permit is valid when recovered owner matches order owner
return recoveredOwner.toLowerCase() === order.owner.toLowerCase()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is it.
If recovered owner matches order owner, permit is still valid!

Comment on lines 51 to 70
// TODO: Any way to make this typing mess any cleaner?
if (decodedValues && typeof decodedValues === 'object') {
const copy: Record<string, any> = {}

Object.keys(decodedValues).forEach((key) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const value = decodedValues[key]
if (BigNumber.isBigNumber(value)) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
copy[key] = value.toHexString()
} else {
copy[key] = value
}
})
console.log(`bug--decodeABIParameters`, decodedValues, copy)

return copy as T
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Open to suggestions on how to make this better/with no @ts-ignores

@alfetopito alfetopito self-assigned this Oct 6, 2023
@@ -29,3 +29,5 @@ export const ORDER_TYPE_SUPPORTS_PERMIT: Record<TradeType, boolean> = {
[TradeType.LIMIT_ORDER]: true,
[TradeType.ADVANCED_ORDERS]: false,
}

export const PENDING_ORDER_PERMIT_CHECK_INTERVAL = ms`1min`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we do it more often?

@alfetopito alfetopito requested a review from a team October 9, 2023 16:35
@alfetopito alfetopito marked this pull request as ready for review October 9, 2023 16:36
@alfetopito alfetopito changed the base branch from develop to release/1.48.0 October 10, 2023 15:40
@@ -410,6 +412,10 @@ export function OrdersTable({
if (isParsedOrder(item)) {
const order = item

const orderParams = getOrderParams(chainId, balancesAndAllowances, order)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Aha, there is a key of the changes

Copy link
Collaborator

@shoom3301 shoom3301 left a comment

Choose a reason for hiding this comment

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

Works perfectly!
Checked even with different browsers - everything is good.
I've left a couple of comments, but they are about code style, feel free to ignore them.

@alfetopito
Copy link
Collaborator Author

Merging, please post merge review

@alfetopito alfetopito merged commit f4700d9 into release/1.48.0 Oct 11, 2023
6 of 7 checks passed
@alfetopito alfetopito deleted the permit/3146_allowance-warning branch October 11, 2023 17:14
@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permit: Update allowance warning
2 participants