-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve BENS names from URL directly to address page (#2004)
* Resolve BENS names from URL directly to address page Fixes #1965 * fix tests
- Loading branch information
Showing
16 changed files
with
112 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useRouter } from 'next/router'; | ||
import React from 'react'; | ||
|
||
import config from 'configs/app'; | ||
import useApiQuery from 'lib/api/useApiQuery'; | ||
|
||
const DOMAIN_NAME_REGEXP = /.\../; | ||
|
||
export default function useCheckDomainNameParam(hashOrDomainName: string) { | ||
const router = useRouter(); | ||
const maybeDomainName = DOMAIN_NAME_REGEXP.test(hashOrDomainName); | ||
const isQueryEnabled = config.features.nameService.isEnabled && maybeDomainName; | ||
const [ isLoading, setIsLoading ] = React.useState(isQueryEnabled); | ||
|
||
const domainLookupQuery = useApiQuery('domains_lookup', { | ||
pathParams: { chainId: config.chain.id }, | ||
queryParams: { | ||
name: hashOrDomainName, | ||
only_active: false, | ||
}, | ||
queryOptions: { | ||
enabled: isQueryEnabled, | ||
}, | ||
}); | ||
|
||
React.useEffect(() => { | ||
if (domainLookupQuery.isPending) { | ||
return; | ||
} | ||
|
||
const firstDomainAddress = domainLookupQuery.data?.items[0]?.resolved_address?.hash; | ||
if (firstDomainAddress) { | ||
router.replace({ pathname: '/address/[hash]', query: { hash: firstDomainAddress } }); | ||
} else { | ||
setIsLoading(false); | ||
} | ||
}, [ domainLookupQuery.isPending, domainLookupQuery.data, router ]); | ||
|
||
React.useEffect(() => { | ||
if (!maybeDomainName) { | ||
setIsLoading(false); | ||
} | ||
}, [ maybeDomainName ]); | ||
|
||
return isLoading; | ||
} |
Oops, something went wrong.