Skip to content

Commit

Permalink
Merge branch 'develop' into feat/explorer-sepolia-1
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 authored Jan 10, 2024
2 parents bb504fa + 878e99f commit f73e1ad
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSetAtom } from 'jotai'
import { useCallback, useEffect, useMemo, useRef } from 'react'
import { useCallback, useEffect, useRef } from 'react'

import { priceOutOfRangeAnalytics } from '@cowprotocol/analytics'
import { useTokensBalances } from '@cowprotocol/balances-and-allowances'
Expand Down Expand Up @@ -44,9 +44,7 @@ export function UnfillableOrdersUpdater(): null {
const updatePendingOrderPrices = useSetAtom(updatePendingOrderPricesAtom)
const isWindowVisible = useIsWindowVisible()

const pendingLimit = useOnlyPendingOrders(chainId, UiOrderType.LIMIT)
const pendingTwap = useOnlyPendingOrders(chainId, UiOrderType.TWAP)
const pending = useMemo(() => pendingLimit.concat(pendingTwap), [pendingLimit, pendingTwap])
const pending = useOnlyPendingOrders(chainId)

const setIsOrderUnfillable = useSetIsOrderUnfillable()
const strategy = useGetGpPriceStrategy()
Expand Down Expand Up @@ -225,6 +223,9 @@ async function _getOrderPrice(

const amount = getRemainderAmount(order.kind, order)

// Don't quote if there's nothing left to match in this order
if (amount === '0') return null

if (order.kind === 'sell') {
// this order sell amount is sellAmountAfterFees
// this is an issue as it will be adjusted again in the backend
Expand Down Expand Up @@ -262,6 +263,8 @@ async function _getOrderPrice(
receiver: order.receiver,
isEthFlow,
priceQuality: getPriceQuality({ verifyQuote }),
appData: order.appData ?? undefined,
appDataHash: order.appDataHash ?? undefined,
}
try {
return getBestQuote({ strategy, quoteParams, fetchFee: false, isPriceRefresh: false })
Expand Down
9 changes: 3 additions & 6 deletions apps/cowswap-frontend/src/legacy/state/orders/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,16 @@ export const useCombinedPendingOrders = ({
* The difference is that this hook returns only orders that have the status PENDING
* while usePendingOrders aggregates all pending states
*/
export const useOnlyPendingOrders = (chainId: SupportedChainId, uiOrderType: UiOrderType): Order[] => {
export const useOnlyPendingOrders = (chainId: SupportedChainId): Order[] => {
const state = useSelector<AppState, PartialOrdersMap | undefined>(
(state) => chainId && state.orders?.[chainId]?.pending
)

return useMemo(() => {
if (!state) return []

return Object.values(state)
.filter((order) => order && getUiOrderType(order.order) === uiOrderType)
.map(_deserializeOrder)
.filter(isTruthy)
}, [state, uiOrderType])
return Object.values(state).map(_deserializeOrder).filter(isTruthy)
}, [state])
}

export const useCancelledOrders = ({ chainId }: GetOrdersParams): Order[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useGetPermitInfo(chainId: SupportedChainId): (tokenAddress: stri
const permittableTokens = useAtomValue(permittableTokensAtom)

return useCallback(
(tokenAddress: string) => permittableTokens[chainId][tokenAddress.toLowerCase()],
(tokenAddress: string) => permittableTokens[chainId]?.[tokenAddress.toLowerCase()],
[chainId, permittableTokens]
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ function _usePermitInfo(chainId: SupportedChainId, tokenAddress: string | undefi
return useMemo(() => {
if (!tokenAddress) return undefined

return permittableTokens[chainId][tokenAddress.toLowerCase()]
return permittableTokens[chainId]?.[tokenAddress.toLowerCase()]
}, [chainId, permittableTokens, tokenAddress])
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type PermittableTokens = Record<string, PermitInfo>
* Contains either the permit info for every token checked locally
*/

export const permittableTokensAtom = atomWithStorage<Record<SupportedChainId, PermittableTokens>>(
export const permittableTokensAtom = atomWithStorage<Record<SupportedChainId, PermittableTokens | undefined>>(
'permittableTokens:v2',
mapSupportedNetworks({})
)
Expand All @@ -28,7 +28,10 @@ export const addPermitInfoForTokenAtom = atom(
(get, set, { chainId, tokenAddress, permitInfo }: AddPermitTokenParams) => {
const permittableTokens = { ...get(permittableTokensAtom) }

permittableTokens[chainId][tokenAddress.toLowerCase()] = permitInfo
permittableTokens[chainId] = {
...permittableTokens[chainId],
[tokenAddress.toLowerCase()]: permitInfo,
}

set(permittableTokensAtom, permittableTokens)
}
Expand Down

0 comments on commit f73e1ad

Please sign in to comment.