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

fix: remove liquidity fixes #1095

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions app/react-query.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ export const queryClient = new QueryClient({
queryCache: new QueryCache({
// Global handler for every react-query error
onError: (error, query) => {
const queryMeta = query?.meta
const sentryMeta = query?.meta as SentryMetadata
if (shouldIgnore(error.message, error.stack)) return
console.log('Sentry capturing query error', {
meta: queryMeta,
meta: sentryMeta,
error,
queryKey: query.queryKey,
})

const sentryContext = query?.meta?.context as ScopeContext
if (sentryContext?.extra && !getTenderlyUrl(sentryContext.extra)) {
sentryContext.extra.tenderlyUrl = getTenderlyUrlFromErrorMessage(error, queryMeta)
const sentryContext = sentryMeta?.context as ScopeContext
if (sentryContext?.extra && !getTenderlyUrl(sentryMeta)) {
sentryContext.extra.tenderlyUrl = getTenderlyUrlFromErrorMessage(error, sentryMeta)
}

if (queryMeta) return captureSentryError(error, queryMeta as SentryMetadata)
if (sentryMeta) return captureSentryError(error, sentryMeta as SentryMetadata)

// Unexpected error in query (as expected errors should have query.meta)
captureError(error, { extra: { queryKey: query.queryKey } })
Expand All @@ -39,14 +39,15 @@ export const queryClient = new QueryClient({
mutationCache: new MutationCache({
// Global handler for every react-query mutation error (i.e. useSendTransaction)
onError: (error, variables, _context, mutation) => {
const mutationMeta = mutation?.meta as SentryMetadata
if (shouldIgnore(error.message, error.stack)) return
console.log('Sentry capturing mutation error: ', {
meta: mutation?.meta,
error,
variables,
})

if (mutation?.meta) return captureSentryError(error, mutation?.meta as SentryMetadata)
if (mutationMeta) return captureSentryError(error, mutationMeta)

// Unexpected error in mutation (as expected errors should have query.meta)
captureError(error, { extra: { variables: variables } })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { LABELS } from '@/lib/shared/labels'
import { GqlToken } from '@/lib/shared/services/api/generated/graphql'
import { useMandatoryContext } from '@/lib/shared/utils/contexts'
import { isDisabledWithReason } from '@/lib/shared/utils/functions/isDisabledWithReason'
import { bn, safeSum } from '@/lib/shared/utils/numbers'
import { bn, isZero, safeSum } from '@/lib/shared/utils/numbers'
import { HumanAmount, TokenAmount, isSameAddress } from '@balancer/sdk'
import { PropsWithChildren, createContext, useEffect, useMemo, useState } from 'react'
import { usePool } from '../../PoolProvider'
Expand Down Expand Up @@ -112,6 +112,9 @@ export function _useRemoveLiquidity(urlTxHash?: Hash) {

const singleTokenOutAddress = singleTokenAddress || firstTokenAddress

const tokenOut =
wethIsEth && wNativeAsset ? (wNativeAsset.address as Address) : singleTokenOutAddress

/**
* Queries
*/
Expand All @@ -120,17 +123,17 @@ export function _useRemoveLiquidity(urlTxHash?: Hash) {
poolId: pool.id,
chainId,
humanBptIn,
tokenOut: wethIsEth && wNativeAsset ? (wNativeAsset.address as Address) : singleTokenOutAddress,
enabled: !urlTxHash,
tokenOut,
enabled: !urlTxHash && !!tokenOut,
})

const priceImpactQuery = useRemoveLiquidityPriceImpactQuery({
handler,
poolId: pool.id,
chainId,
humanBptIn,
tokenOut: wethIsEth && wNativeAsset ? (wNativeAsset.address as Address) : singleTokenOutAddress,
enabled: !urlTxHash,
tokenOut,
enabled: !urlTxHash && !!tokenOut,
})

/**
Expand Down Expand Up @@ -212,10 +215,12 @@ export function _useRemoveLiquidity(urlTxHash?: Hash) {
)

const totalUSDValue: string = safeSum(Object.values(usdAmountOutMap))
const totalAmountsOut: string = safeSum(quoteAmountsOut.map(a => a.amount))

const { isDisabled, disabledReason } = isDisabledWithReason(
[!isConnected, LABELS.walletNotConnected],
[Number(humanBptIn) === 0, 'You must specify a valid bpt in'],
[isZero(totalAmountsOut), 'Amount to remove cannot be zero'],
[needsToAcceptHighPI, 'Accept high price impact first'],
[simulationQuery.isLoading, 'Fetching quote...'],
[simulationQuery.isError, 'Error fetching quote'],
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/components/errors/GenericError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function GenericError({ error: _error, customErrorName, ...rest }: Props)
}
const errorMessage = error?.shortMessage || error.message

if (errorMessage === 'RPC Request failed.') {
if (errorMessage === 'RPC Request failed.' || errorMessage === 'An unknown RPC error occurred.') {
return (
<ErrorAlert title={errorMessage} {...rest}>
<Text variant="secondary" color="black">
Expand Down
7 changes: 3 additions & 4 deletions lib/shared/utils/query-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ export function captureSentryError(
e: unknown,
{ context, errorMessage, errorName }: SentryMetadata
) {
console.log('Context en captureSentryError', context)
const causeError = ensureError(e)
if (isUserRejectedError(causeError)) return

Expand Down Expand Up @@ -347,7 +346,7 @@ function sentryStackFramesToString(sentryStack?: SentryStack): string {
)
}

export function getTenderlyUrl(sentryExtras?: Extras) {
if (!sentryExtras) return
return sentryExtras.tenderlyUrl as string | undefined
export function getTenderlyUrl(sentryMetadata?: SentryMetadata) {
if (!sentryMetadata) return
return sentryMetadata?.context?.extra?.tenderlyUrl as string | undefined
}
Loading