From 4ac64582a768dc0c098a4560889a080005c73eff Mon Sep 17 00:00:00 2001 From: Jin Date: Tue, 10 Oct 2023 10:51:12 -0400 Subject: [PATCH] Cleanup unnecessary fetching for ratio txn history which is causing errors in Sentry (#5101) --- src/redux/data.ts | 139 +------------------------------------ src/resources/f2c/index.ts | 13 ---- 2 files changed, 3 insertions(+), 149 deletions(-) diff --git a/src/redux/data.ts b/src/redux/data.ts index b163bd8fae9..3a92aa7811f 100644 --- a/src/redux/data.ts +++ b/src/redux/data.ts @@ -2,7 +2,7 @@ import { StaticJsonRpcProvider, TransactionResponse, } from '@ethersproject/providers'; -import { isEmpty, isNil, mapValues, partition, cloneDeep } from 'lodash'; +import { isEmpty, isNil, mapValues, partition } from 'lodash'; import { Dispatch } from 'redux'; import { ThunkDispatch } from 'redux-thunk'; import { @@ -47,13 +47,9 @@ import { getTransactionSocketStatus, } from '@/handlers/transactions'; import { SwapType } from '@rainbow-me/swaps'; -import { FiatProviderName } from '@/entities/f2c'; -import { logger as loggr, RainbowError } from '@/logger'; -import { analyticsV2 } from '@/analytics'; +import { logger as loggr } from '@/logger'; import { queryClient } from '@/react-query'; import { nftsQueryKey } from '@/resources/nfts'; -import { QueryClient } from '@tanstack/react-query'; -import { ratioGetUserActivityItem } from '@/resources/f2c'; const BACKUP_SHEET_DELAY_MS = android ? 10000 : 3000; @@ -618,11 +614,8 @@ export const transactionsReceived = ( }, 60000); } - const maybeUpdatedPendingTransactions = await maybeFetchF2CHashForPendingTransactions( - cloneDeep(pendingTransactions) - ); const txHashes = parsedTransactions.map(tx => ethereumUtils.getHash(tx)); - const updatedPendingTransactions = maybeUpdatedPendingTransactions.filter( + const updatedPendingTransactions = pendingTransactions.filter( tx => !txHashes.includes(ethereumUtils.getHash(tx)) ); @@ -658,132 +651,6 @@ export const transactionsReceived = ( } }; -/** - * Maps over every pendingTransaction, and if it's a F2C transaction, fetches - * the transaction has and updates the pendingTransaction with its hash. - * - * This method returns all pendingTransactions that were passed in, so 5 go in, - * 5 come out, but they might have a tx hash added. - */ -export const maybeFetchF2CHashForPendingTransactions = async ( - pendingTransactions: RainbowTransaction[] -) => { - loggr.debug( - `maybeFetchF2CHashForPendingTransactions`, - {}, - loggr.DebugContext.f2c - ); - - /** - * A CUSTOM query client used for this query only. We don't need to store tx - * data on this device. - */ - const queryClient = new QueryClient(); - - return Promise.all( - pendingTransactions.map(async tx => { - // If not from a F2C provider, return the original tx - if (!tx.fiatProvider) return tx; - if (tx.hash) { - /** - * Sometimes `transactionsReceived` gets called more than once in quick - * succession, which can result it fetching order data more than once. - * - * So if we already have a tx hash, then we don't need to fetch - * anything else. - */ - return tx; - } - - // If it is from an F2C provider, see if we can add the tx hash to it - switch (tx.fiatProvider?.name) { - // handle Ratio case - case FiatProviderName.Ratio: { - loggr.debug( - `maybeFetchF2CHashForPendingTransactions`, - { provider: tx.fiatProvider?.name }, - loggr.DebugContext.f2c - ); - - const { userId, orderId } = tx.fiatProvider; - - loggr.debug( - `maybeFetchF2CHashForPendingTransactions: fetching order` - ); - - try { - const data = await queryClient.fetchQuery({ - queryKey: ['f2c', 'ratio', 'pending_tx_check'], - staleTime: 10_000, // only fetch AT MOST once every 10 seconds - async queryFn() { - const { data, error } = await ratioGetUserActivityItem({ - userId, - orderId, - }); - - if (!data || error) { - const [{ message }] = error.errors; - - if (error) { - throw new Error(message); - } else { - throw new Error( - 'Ratio API returned no data for this transaction' - ); - } - } - - return data; - }, - }); - - loggr.debug( - `maybeFetchF2CHashForPendingTransactions: fetched order`, - { - hasData: Boolean(data), - hasHash: Boolean(data?.crypto?.transactionHash), - } - ); - - if (data.crypto.transactionHash) { - tx.hash = data.crypto.transactionHash; - - analyticsV2.track(analyticsV2.event.f2cTransactionReceived, { - provider: FiatProviderName.Ratio, - sessionId: tx.fiatProvider.analyticsSessionId, - }); - - loggr.debug( - `maybeFetchF2CHashForPendingTransactions: fetched order and updated hash on transaction` - ); - } else { - loggr.info( - `maybeFetchF2CHashForPendingTransactions: fetcher returned no transaction data` - ); - } - } catch (e: any) { - loggr.error( - new RainbowError( - `maybeFetchF2CHashForPendingTransactions: failed to fetch transaction data` - ), - { - message: e.message, - provider: tx.fiatProvider.name, - } - ); - } - - break; - } - - // handle other cases here once we have more providers - } - - return tx; - }) - ); -}; - const callbacksOnAssetReceived: { [address: string]: ((asset: ParsedAddressAsset) => unknown) | undefined; } = {}; diff --git a/src/resources/f2c/index.ts b/src/resources/f2c/index.ts index 341a214185a..65423304d6f 100644 --- a/src/resources/f2c/index.ts +++ b/src/resources/f2c/index.ts @@ -1,5 +1,4 @@ import { create } from 'gretchen'; -import { ActivityItem } from '@ratio.me/ratio-react-native-library'; import qs from 'query-string'; import { IS_PROD } from '@/env'; @@ -39,18 +38,6 @@ export function ratioGetClientSession({ ).json(); } -export function ratioGetUserActivityItem({ - userId, - orderId, -}: { - userId: string; - orderId: string; -}) { - return gretch( - `/v1/providers/ratio/users/${userId}/activity/${orderId}` - ).json(); -} - export function coinbaseGetWidgetURL({ depositAddress, }: {