-
Notifications
You must be signed in to change notification settings - Fork 102
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
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6216f3a
refactor: remove unnecessary toString()
alfetopito 52ca3b5
chore: fix typo
alfetopito d7b4a96
fix: transform BigNumber instances into hex strings for compatibility…
alfetopito 8732312
feat: add fullAppData to local order instance
alfetopito ab3e5c5
feat: add decodeAppData to appData module
alfetopito 5dc302a
feat: add getAppDataHooks to appData module
alfetopito 1573e5c
feat: add useCheckHasValidPendingPermit to permit module
alfetopito ae952f0
feat: add permit checking to OrderRow allowance warning
alfetopito a6f3f1c
refactor: rename getParsedOrderFromItem to getParsedOrderFromTableItem
alfetopito 161e637
refactor: change isParsed order to be a bit more semantic
alfetopito e34bc56
feat: add ordersPermitStatusAtom
alfetopito 92f7eef
feat: add PendingPermitUpdater
alfetopito 4aeb8bf
feat: add useGetOrdersPermitStatus
alfetopito 243abce
feat: pass down ordersPermitStatus
alfetopito 7e8f905
feat: add PendingPermitUpdater to OrdersTableWidget
alfetopito 8fa8ddf
chore: remove unused export
alfetopito aed5c0e
refactor: sort exports
alfetopito 3263718
fix: add back export. I removed the wrong one 🤦
alfetopito a432bf6
refactor: extract useGetOrdersToCheckPendingPermit
alfetopito 21c3f16
chore: debug statements
alfetopito 2ae222a
fix: force atoms to load so stored value is respected
alfetopito 113788f
refactor: use the handy atomWithPartialUpdate
alfetopito f874fc6
refactor: move useGetOrdersToCheckPendingPermit to its own file
alfetopito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
apps/cowswap-frontend/src/modules/appData/utils/decodeAppData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { AnyAppDataDocVersion } from '@cowprotocol/app-data' | ||
|
||
import { Nullish } from 'types' | ||
|
||
/** | ||
* Decode appData from a string to a AnyAppDataDocVersion instance | ||
* Keep in mind it can be a valid JSON but not necessarily a valid AppDataDoc | ||
* | ||
* Returns undefined if the given appData is not a valid JSON | ||
*/ | ||
export function decodeAppData(appData: Nullish<string>): AnyAppDataDocVersion | undefined { | ||
if (!appData) { | ||
return undefined | ||
} | ||
|
||
try { | ||
// TODO: returned value can be a valid JSON but not necessarily a valid AppDataDoc | ||
return JSON.parse(appData) | ||
} catch (e) { | ||
console.info(`[decodeAppData] given appData is not a valid JSON`, appData) | ||
|
||
return undefined | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
apps/cowswap-frontend/src/modules/appData/utils/getAppDataHooks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { AnyAppDataDocVersion } from '@cowprotocol/app-data' | ||
|
||
import { Nullish } from 'types' | ||
|
||
import { decodeAppData } from './decodeAppData' | ||
|
||
import { AppDataHooks } from '../types' | ||
|
||
/** | ||
* Get hooks from fullAppData, which can be JSON stringified or the instance | ||
* | ||
* Returns undefined if the fullAppData is falsy or if there are no hooks | ||
*/ | ||
export function getAppDataHooks(fullAppData: Nullish<AnyAppDataDocVersion | string>): AppDataHooks | undefined { | ||
const decodedAppData = typeof fullAppData === 'string' ? decodeAppData(fullAppData) : fullAppData | ||
|
||
if (!decodedAppData || !('hooks' in decodedAppData.metadata)) return undefined | ||
|
||
// TODO: this requires app-data v0.9.0. Might not work for newer versions... | ||
return decodedAppData.metadata.hooks as AppDataHooks | ||
} |
34 changes: 34 additions & 0 deletions
34
...odules/ordersTable/containers/OrdersTableWidget/hooks/useGetOrdersToCheckPendingPermit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useMemo } from 'react' | ||
|
||
import { SupportedChainId } from '@cowprotocol/cow-sdk' | ||
|
||
import { BalancesAndAllowances } from 'modules/tokens' | ||
|
||
import { ParsedOrder } from 'utils/orderUtils/parseOrder' | ||
|
||
import { OrdersTableList } from './useOrdersTableList' | ||
|
||
import { getOrderParams } from '../../../pure/OrdersTableContainer/utils/getOrderParams' | ||
import { isParsedOrder } from '../../../utils/orderTableGroupUtils' | ||
|
||
export function useGetOrdersToCheckPendingPermit( | ||
ordersList: OrdersTableList, | ||
chainId: SupportedChainId, | ||
balancesAndAllowances: BalancesAndAllowances | ||
) { | ||
return useMemo(() => { | ||
// Pick only the pending orders | ||
return ordersList.pending.reduce((acc: ParsedOrder[], item) => { | ||
// Only do it for regular orders (not TWAP) | ||
if (isParsedOrder(item)) { | ||
const { hasEnoughAllowance } = getOrderParams(chainId, balancesAndAllowances, item) | ||
|
||
// Only if the order has not enough allowance | ||
if (hasEnoughAllowance === false) { | ||
acc.push(item) | ||
} | ||
} | ||
return acc | ||
}, []) | ||
}, [balancesAndAllowances, chainId, ordersList.pending]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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