mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
Filter websocket events for tokens with reputation=scam when hide sca… (#3116)
Filter websocket events for tokens with reputation=scam when hide scam tokens is true
This commit is contained in:
@@ -5,14 +5,21 @@ import type { SocketMessage } from 'lib/socket/types';
|
||||
import type { AddressTokenTransferResponse } from 'types/api/address';
|
||||
import type { TokenTransfer } from 'types/api/tokenTransfer';
|
||||
|
||||
import config from 'configs/app';
|
||||
import { getResourceKey } from 'lib/api/useApiQuery';
|
||||
import { useAppContext } from 'lib/contexts/app';
|
||||
import { useMultichainContext } from 'lib/contexts/multichain';
|
||||
import * as cookies from 'lib/cookies';
|
||||
import useSocketChannel from 'lib/socket/useSocketChannel';
|
||||
import useSocketMessage from 'lib/socket/useSocketMessage';
|
||||
|
||||
import type { Filters } from './useAddressTokenTransfersQuery';
|
||||
|
||||
const matchFilters = (filters: Filters, tokenTransfer: TokenTransfer, address?: string) => {
|
||||
const matchFilters = (filters: Filters, tokenTransfer: TokenTransfer, address?: string, shouldHideScamTokens?: boolean) => {
|
||||
if (shouldHideScamTokens && tokenTransfer.token?.reputation === 'scam') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (filters.filter) {
|
||||
if (filters.filter === 'from' && tokenTransfer.from.hash !== address) {
|
||||
return false;
|
||||
@@ -41,9 +48,12 @@ interface Props {
|
||||
}
|
||||
|
||||
export default function useAddressTokenTransfersSocket({ filters, addressHash, data, overloadCount = OVERLOAD_COUNT, enabled }: Props) {
|
||||
const { cookies: appCookies } = useAppContext();
|
||||
const [ showSocketAlert, setShowSocketAlert ] = React.useState(false);
|
||||
const [ newItemsCount, setNewItemsCount ] = React.useState(0);
|
||||
|
||||
const shouldHideScamTokens = config.UI.views.token.hideScamTokensEnabled && !(cookies.get(cookies.NAMES.SHOW_SCAM_TOKENS, appCookies) === 'true');
|
||||
|
||||
const multichainContext = useMultichainContext();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -55,11 +65,11 @@ export default function useAddressTokenTransfersSocket({ filters, addressHash, d
|
||||
|
||||
payload.token_transfers.forEach(transfer => {
|
||||
if (data?.items && data.items.length + newItems.length >= overloadCount && enabled) {
|
||||
if (matchFilters(filters, transfer, addressHash)) {
|
||||
if (matchFilters(filters, transfer, addressHash, shouldHideScamTokens)) {
|
||||
newCount++;
|
||||
}
|
||||
} else {
|
||||
if (matchFilters(filters, transfer, addressHash)) {
|
||||
if (matchFilters(filters, transfer, addressHash, shouldHideScamTokens)) {
|
||||
newItems.push(transfer);
|
||||
}
|
||||
}
|
||||
@@ -93,7 +103,7 @@ export default function useAddressTokenTransfersSocket({ filters, addressHash, d
|
||||
);
|
||||
}
|
||||
|
||||
}, [ data?.items, overloadCount, enabled, filters, addressHash, multichainContext?.chain?.slug, queryClient ]);
|
||||
}, [ data?.items, overloadCount, enabled, filters, addressHash, multichainContext?.chain?.slug, queryClient, shouldHideScamTokens ]);
|
||||
|
||||
const handleSocketClose = React.useCallback(() => {
|
||||
setShowSocketAlert(true);
|
||||
|
||||
Reference in New Issue
Block a user