diff --git a/src/contexts/Filters/index.tsx b/src/contexts/Filters/index.tsx index 1d2a62a0f0..f1b4e8bae2 100644 --- a/src/contexts/Filters/index.tsx +++ b/src/contexts/Filters/index.tsx @@ -134,9 +134,14 @@ export const FiltersProvider = ({ children }: { children: ReactNode }) => { if (o === 'default') { newOrders = [...orders].filter((order) => order.key !== g); } else if (orders.length) { + // Attempt to replace the order record if it exists. newOrders = [...orders].map((order) => order.key !== g ? order : { ...order, order: o } ); + // If order for this key does not exist, add it. + if (newOrders.find(({ key }) => key === g) === undefined) { + newOrders.push({ key: g, order: o }); + } } else { newOrders = [{ key: g, order: o }]; } @@ -151,9 +156,15 @@ export const FiltersProvider = ({ children }: { children: ReactNode }) => { const setSearchTerm = (g: string, t: string) => { let newSearchTerms = []; if (orders.length) { + // Attempt to replace the search term if it exists. newSearchTerms = [...searchTerms].map((term) => term.key !== g ? term : { ...term, searchTerm: t } ); + + // If search term for this key does not exist, add it. + if (newSearchTerms.find(({ key }) => key === g) === undefined) { + newSearchTerms.push({ key: g, searchTerm: t }); + } } else { newSearchTerms = [{ key: g, searchTerm: t }]; } diff --git a/src/library/PoolList/index.tsx b/src/library/PoolList/index.tsx index ebff45c5a4..14e1c3d060 100644 --- a/src/library/PoolList/index.tsx +++ b/src/library/PoolList/index.tsx @@ -101,6 +101,7 @@ export const PoolList = ({ const handleSearchChange = (e: FormEvent) => { const newValue = e.currentTarget.value; + let filteredPools: BondedPool[] = Object.assign(poolsDefault); filteredPools = applyFilter(includes, excludes, filteredPools); filteredPools = poolSearchFilter(filteredPools, newValue); diff --git a/src/library/ValidatorList/index.tsx b/src/library/ValidatorList/index.tsx index 298c06b656..b9ab7be08e 100644 --- a/src/library/ValidatorList/index.tsx +++ b/src/library/ValidatorList/index.tsx @@ -212,8 +212,8 @@ export const ValidatorListInner = ({ index === self.findIndex((i) => i.address === value.address) ); - setValidators(filteredValidators); setPage(1); + setValidators(filteredValidators); setIsSearching(e.currentTarget.value !== ''); setSearchTerm('validators', newValue); };