Skip to content

Commit

Permalink
Merge branch 'main' into feat/addLiquidityPermit2
Browse files Browse the repository at this point in the history
  • Loading branch information
agualis committed Sep 26, 2024
2 parents aaafbbd + fcb0fee commit 0cfdcf9
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 12 deletions.
6 changes: 6 additions & 0 deletions lib/modules/pool/alerts/usePoolAlerts.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ describe('Creates pool alerts for', () => {
"learnMoreLink": "https://forum.balancer.fi/t/vulnerability-found-in-some-pools/5102/1",
"status": "error",
},
{
"content": "This pool is in recovery mode",
"identifier": "poolIsInRecoveryMode",
"isSoftWarning": false,
"status": "warning",
},
]
`)
})
Expand Down
32 changes: 31 additions & 1 deletion lib/modules/pool/alerts/usePoolAlerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,42 @@ export function usePoolAlerts(pool: Pool) {
return alerts
}

const getPoolAlerts = (pool: Pool): PoolAlert[] => {
const alerts: PoolAlert[] = []

if (pool.dynamicData.isPaused && pool.dynamicData.isInRecoveryMode) {
alerts.push({
identifier: 'poolIsPausedAndInRecoveryMode',
content: 'This pool is paused and in recovery mode',
status: 'warning',
isSoftWarning: false,
})
} else if (pool.dynamicData.isPaused) {
alerts.push({
identifier: 'poolIsPaused',
content: 'This pool is paused',
status: 'warning',
isSoftWarning: false,
})
} else if (pool.dynamicData.isInRecoveryMode) {
alerts.push({
identifier: 'poolIsInRecoveryMode',
content: 'This pool is in recovery mode',
status: 'warning',
isSoftWarning: false,
})
}

return alerts
}

useEffect(() => {
const networkPoolAlerts = getNetworkPoolAlerts(pool)
const tokenPoolAlerts = getTokenPoolAlerts(pool)
const userAlerts = getUserAlerts(pool)
const poolAlerts = getPoolAlerts(pool)

setPoolAlerts([...networkPoolAlerts, ...tokenPoolAlerts, ...userAlerts])
setPoolAlerts([...networkPoolAlerts, ...tokenPoolAlerts, ...userAlerts, ...poolAlerts])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pool])

Expand Down
6 changes: 4 additions & 2 deletions lib/modules/pool/pool.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ export function hasReviewedRateProvider(token: GqlPoolTokenDetail): boolean {
export function shouldBlockAddLiquidity(pool: Pool) {
const poolTokens = pool.poolTokens as GqlPoolTokenDetail[]

// If pool is an LBP, we should block adding liquidity
if (isLBP(pool.type)) return true
// If pool is an LBP, paused or in recovery mode, we should block adding liquidity
if (isLBP(pool.type) || pool.dynamicData.isPaused || pool.dynamicData.isInRecoveryMode) {
return true
}

return poolTokens.some(token => {
// if token is not allowed - we should block adding liquidity
Expand Down
13 changes: 12 additions & 1 deletion lib/shared/components/errors/GenericError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { AlertProps, Text } from '@chakra-ui/react'
import { ErrorAlert } from './ErrorAlert'
import { isUserRejectedError, isViemHttpFetchError } from '../../utils/error-filters'
import { isPausedError, isUserRejectedError, isViemHttpFetchError } from '../../utils/error-filters'
import { ensureError } from '../../utils/errors'
import { BalAlertLink } from '../alerts/BalAlertLink'

Expand All @@ -28,6 +28,17 @@ export function GenericError({ error: _error, customErrorName, ...rest }: Props)
</ErrorAlert>
)
}
if (isPausedError(_error)) {
return (
<ErrorAlert title={customErrorName} {...rest}>
<Text variant="secondary" color="black">
The pool or one of the pool tokens is paused. Check{' '}
<BalAlertLink href="https://discord.balancer.fi/">our discord</BalAlertLink> for more
information.
</Text>
</ErrorAlert>
)
}
const errorMessage = error?.shortMessage || error.message

if (errorMessage === 'RPC Request failed.' || errorMessage === 'An unknown RPC error occurred.') {
Expand Down
19 changes: 12 additions & 7 deletions lib/shared/utils/error-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ export function isUserRejectedError(error: Error): boolean {
*/
export function isViemHttpFetchError(error?: Error | null): boolean {
if (!error) return false
if (
error.message.startsWith('HTTP request failed.') &&
error.message.includes('Failed to fetch')
) {
return true
}
return false
return (
error.message.startsWith('HTTP request failed.') && error.message.includes('Failed to fetch')
)
}

export function isPausedError(error?: Error | null): boolean {
if (!error) return false
return isPausedErrorMessage(error.message)
}

export function isPausedErrorMessage(errorMessage: string): boolean {
return errorMessage.includes('reverted with the following reason:\nBAL#402\n')
}
4 changes: 3 additions & 1 deletion lib/shared/utils/query-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Exception as SentryException,
} from '@sentry/types'
import { SentryError, ensureError } from './errors'
import { isUserRejectedError } from './error-filters'
import { isPausedErrorMessage, isUserRejectedError } from './error-filters'
import {
AddLiquidityParams,
stringifyHumanAmountsIn,
Expand Down Expand Up @@ -332,6 +332,8 @@ export function shouldIgnore(message: string, stackTrace = ''): boolean {
return true
}

if (isPausedErrorMessage(message)) return true

return false
}

Expand Down

0 comments on commit 0cfdcf9

Please sign in to comment.