Skip to content

Commit

Permalink
Support recovering from invalid URLs using search
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Jan 11, 2024
1 parent ca3721c commit 4cb30ef
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions .changelog/1146.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support recovering from invalid URLs using search
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import AccountBalanceWalletIcon from '@mui/icons-material/AccountBalanceWallet'
import TokenIcon from '@mui/icons-material/Token'
import { RouteUtils } from '../../utils/route-utils'
import { OptionalBreak } from '../OptionalBreak'
import { SearchScope } from '../../../types/searchScope'
import { SearchScopeCandidate } from '../../../types/searchScope'
import { useScreenSize } from '../../hooks/useScreensize'
import { SxProps } from '@mui/material/styles'

interface Props {
scope: SearchScope | undefined
scope: SearchScopeCandidate | undefined
}

const iconSxProps: SxProps = {
Expand Down
7 changes: 6 additions & 1 deletion src/app/pages/SearchResultsPage/GlobalSearchResultsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export const GlobalSearchResultsView: FC<{ searchResults: SearchResults; tokenPr

return (
<>
{!mainnetResults.length && (otherResults.length ? <NoResultsOnMainnet /> : <NoResultsWhatsoever />)}
{!mainnetResults.length &&
(otherResults.length ? (
<NoResultsOnMainnet isScopeValid={true} />
) : (
<NoResultsWhatsoever isScopeValid={true} />
))}
{
<SearchResultsList
key={Network.mainnet}
Expand Down
26 changes: 18 additions & 8 deletions src/app/pages/SearchResultsPage/NoResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import Link from '@mui/material/Link'
import { SearchSuggestionsLinksForNoResults } from '../../components/Search/SearchSuggestionsLinksForNoResults'
import { OptionalBreak } from '../../components/OptionalBreak'
import { useTheme } from '@mui/material/styles'
import { getNameForScope, SearchScope } from '../../../types/searchScope'
import { getNameForScope, SearchScope, SearchScopeCandidate } from '../../../types/searchScope'

Check warning on line 10 in src/app/pages/SearchResultsPage/NoResults.tsx

View workflow job for this annotation

GitHub Actions / lint

'SearchScope' is defined but never used
import { getNetworkNames, Network } from '../../../types/network'
import { Layer } from '../../../oasis-nexus/api'

export const NoResults: FC<{
network?: Network
layer?: Layer
}> = ({ network, layer }) => {
isScopeValid: boolean
}> = ({ network, layer, isScopeValid }) => {
const { t } = useTranslation()
const theme = useTheme()
const title = network
Expand All @@ -41,19 +42,28 @@ export const NoResults: FC<{
/>
</p>
<p>
<SearchSuggestionsLinksForNoResults scope={layer && network ? { network, layer } : undefined} />
<SearchSuggestionsLinksForNoResults
scope={layer && network ? { network, layer, valid: isScopeValid } : undefined}
/>
</p>
</Box>
}
/>
)
}

export const NoResultsWhatsoever: FC = () => <NoResults />
export const NoResultsOnNetwork: FC<{ network: Network }> = ({ network }) => <NoResults network={network} />
export const NoResultsWhatsoever: FC<{ isScopeValid: boolean }> = ({ isScopeValid }) => (
<NoResults isScopeValid={isScopeValid} />
)
export const NoResultsOnNetwork: FC<{ network: Network; isScopeValid: boolean }> = ({
network,
isScopeValid,
}) => <NoResults network={network} isScopeValid={isScopeValid} />

export const NoResultsOnMainnet: FC = () => <NoResultsOnNetwork network={Network.mainnet} />
export const NoResultsOnMainnet: FC<{ isScopeValid: boolean }> = ({ isScopeValid }) => (
<NoResultsOnNetwork network={Network.mainnet} isScopeValid={isScopeValid} />
)

export const NoResultsInScope: FC<{ scope: SearchScope }> = ({ scope }) => (
<NoResults network={scope.network} layer={scope.layer} />
export const NoResultsInScope: FC<{ scope: SearchScopeCandidate }> = ({ scope }) => (
<NoResults network={scope.network} layer={scope.layer} isScopeValid={scope.valid} />
)
4 changes: 2 additions & 2 deletions src/app/pages/SearchResultsPage/ScopedSearchResultsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getFilterForScope,
getNameForScope,
getInverseFilterForScope,
SearchScope,
SearchScopeCandidate,
} from '../../../types/searchScope'
import { getThemesForNetworks } from '../../../styles/theme'
import { RouteUtils } from '../../utils/route-utils'
Expand All @@ -17,7 +17,7 @@ import { HideMoreResults, ShowMoreResults } from './notifications'
import { useRedirectIfSingleResult } from './useRedirectIfSingleResult'

export const ScopedSearchResultsView: FC<{
wantedScope: SearchScope
wantedScope: SearchScopeCandidate
searchResults: SearchResults
tokenPrices: AllTokenPrices
}> = ({ wantedScope, searchResults, tokenPrices }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/SearchResultsPage/SearchResultsView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC } from 'react'
import Divider from '@mui/material/Divider'
import { SearchScope } from '../../../types/searchScope'
import { SearchScopeCandidate } from '../../../types/searchScope'
import { PageLayout } from '../../components/PageLayout'
import { SubPageCard } from '../../components/SubPageCard'
import { TextSkeleton } from '../../components/Skeleton'
Expand All @@ -12,7 +12,7 @@ import { getFilterForLayer } from '../../../types/layers'
import { useScreenSize } from '../../hooks/useScreensize'

export const SearchResultsView: FC<{
wantedScope?: SearchScope
wantedScope?: SearchScopeCandidate
searchResults: SearchResults
isLoading: boolean
tokenPrices: AllTokenPrices
Expand Down
6 changes: 3 additions & 3 deletions src/app/utils/route-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isValidBlockHeight, isValidOasisAddress, isValidEthAddress } from './he
import { AppError, AppErrors } from '../../types/errors'
import { EvmTokenType, Layer } from '../../oasis-nexus/api'
import { Network } from '../../types/network'
import { SearchScope } from '../../types/searchScope'
import { SearchScope, SearchScopeCandidate } from '../../types/searchScope'

export type SpecifiedPerEnabledLayer<T = any> = {
[N in keyof (typeof RouteUtils)['ENABLED_LAYERS_FOR_NETWORK']]: {
Expand Down Expand Up @@ -73,8 +73,8 @@ export abstract class RouteUtils {
return tokenAddress ? `${tokenRoutes}#${encodeURIComponent(tokenAddress)}` : tokenRoutes
}

static getSearchRoute = (scope: SearchScope | undefined, searchTerm: string) => {
return scope
static getSearchRoute = (scope: SearchScopeCandidate | undefined, searchTerm: string) => {
return scope?.valid
? `/${scope.network}/${scope.layer}/search?q=${encodeURIComponent(searchTerm)}`
: `/search?q=${encodeURIComponent(searchTerm)}`
}
Expand Down

0 comments on commit 4cb30ef

Please sign in to comment.