-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/release/1.48.0' into develop
- Loading branch information
Showing
27 changed files
with
470 additions
and
111 deletions.
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.