1- import { useRouter } from 'next/router'
21import { useMemo } from 'react'
32import { useTranslation } from 'react-i18next'
43import { useCopyToClipboard } from 'react-use'
@@ -24,15 +23,17 @@ import { DynamicVerificationIcon } from '@app/assets/verification/DynamicVerific
2423import { VerificationBadgeAccountTooltipContent } from '@app/components/@molecules/VerificationBadge/components/VerificationBadgeAccountTooltipContent'
2524import { VerificationBadgeVerifierTooltipContent } from '@app/components/@molecules/VerificationBadge/components/VerificationBadgeVerifierTooltipContent'
2625import { VerificationBadge } from '@app/components/@molecules/VerificationBadge/VerificationBadge'
26+ import { useBlockExplorer } from '@app/hooks/chain/useBlockExplorer'
2727import { useCoinChain } from '@app/hooks/chain/useCoinChain'
2828import { usePrimaryName } from '@app/hooks/ensjs/public/usePrimaryName'
29+ import { useRouterWithHistory } from '@app/hooks/useRouterWithHistory'
2930import { getDestinationAsHref } from '@app/routes'
3031import { VerificationProtocol } from '@app/transaction-flow/input/VerifyProfile/VerifyProfile-flow'
3132import { useBreakpoint } from '@app/utils/BreakpointProvider'
3233import { getContentHashLink } from '@app/utils/contenthash'
3334import { getSocialData } from '@app/utils/getSocialData'
3435import { createUrlObject } from '@app/utils/urlObject'
35- import { makeEtherscanLink , shortenAddress } from '@app/utils/utils'
36+ import { shortenAddress } from '@app/utils/utils'
3637import { getVerifierData } from '@app/utils/verification/getVerifierData'
3738import { isVerificationProtocol } from '@app/utils/verification/isVerificationProtocol'
3839
@@ -120,13 +121,16 @@ export const AddressProfileButton = ({
120121 iconKey : string
121122 value : string
122123} ) => {
123- const router = useRouter ( )
124+ const router = useRouterWithHistory ( )
124125 const breakpoints = useBreakpoint ( )
125126 const iconKey = _iconKey . toLowerCase ( )
126127 const [ , copy ] = useCopyToClipboard ( )
127- const coinChainResults = useCoinChain ( { coinName : iconKey } )
128+ const { blockExplorer : currentChainBlockExplorer } = useBlockExplorer ( )
129+ const coinChainResults = useCoinChain ( { coinName : iconKey , enabled : iconKey !== 'eth' } )
128130 const { data } = coinChainResults
129- const defaultBlockExplorer = data ?. blockExplorers ?. default
131+ // For ETH addresses, use the current chain's block explorer; for other coins, use coin-specific explorer
132+ const defaultBlockExplorer =
133+ iconKey === 'eth' ? currentChainBlockExplorer : data ?. blockExplorers ?. default
130134 const referrer = router . query . referrer as string | undefined
131135
132136 const IconComponent = useMemo (
@@ -139,7 +143,8 @@ export const AddressProfileButton = ({
139143 ? {
140144 icon : UpRightArrowIcon ,
141145 label : 'View address' ,
142- href : getDestinationAsHref ( createUrlObject ( `/${ address } ` , { referrer } ) ) ,
146+ onClick : ( ) =>
147+ router . push ( getDestinationAsHref ( createUrlObject ( `/${ address } ` , { referrer } ) ) ) ,
143148 }
144149 : undefined ,
145150 {
@@ -151,7 +156,12 @@ export const AddressProfileButton = ({
151156 ? {
152157 icon : UpRightArrowIcon ,
153158 label : `View on ${ defaultBlockExplorer ?. name } ` ,
154- href : `${ defaultBlockExplorer ?. url } /address/${ address } ` ,
159+ onClick : ( ) =>
160+ window . open (
161+ `${ defaultBlockExplorer ?. url } /address/${ address } ` ,
162+ '_blank' ,
163+ 'noopener,noreferrer' ,
164+ ) ,
155165 }
156166 : undefined ,
157167 ] . filter ( ( item ) => item !== undefined ) as DropdownItem [ ]
@@ -278,19 +288,18 @@ export const OwnerProfileButton = ({
278288 value : string
279289 timestamp ?: number
280290} ) => {
281- const router = useRouter ( )
291+ const router = useRouterWithHistory ( )
292+ const { blockExplorer, buildAddressUrl } = useBlockExplorer ( )
282293 const { t } = useTranslation ( 'common' )
283294 const breakpoints = useBreakpoint ( )
284295 const referrer = router . query . referrer as string | undefined
285296
286297 const dataType = useMemo ( ( ) => {
287- if ( ! addressOrNameOrDate )
288- // eslint-disable-next-line no-nested-ternary
289- return label === 'name.expiry'
290- ? 'noExpiry'
291- : label === 'name.parent'
292- ? 'noParent'
293- : 'notOwned'
298+ if ( ! addressOrNameOrDate ) {
299+ if ( label === 'name.expiry' ) return 'noExpiry'
300+ if ( label === 'name.parent' ) return 'noParent'
301+ return 'notOwned'
302+ }
294303 if ( label === 'name.expiry' ) return 'expiry'
295304 if ( isAddress ( addressOrNameOrDate ) ) return 'address'
296305 const isTLD = addressOrNameOrDate . split ( '.' ) . length === 1
@@ -362,7 +371,7 @@ export const OwnerProfileButton = ({
362371 ? {
363372 icon : UpRightArrowIcon ,
364373 label : 'View profile' ,
365- href : link ,
374+ onClick : ( ) => router . push ( link ) ,
366375 }
367376 : undefined ,
368377 primary . data ?. name
@@ -377,21 +386,30 @@ export const OwnerProfileButton = ({
377386 {
378387 icon : UpRightArrowIcon ,
379388 label : 'View address' ,
380- href : getDestinationAsHref ( {
381- pathname : `/ ${ addressOrNameOrDate } ` ,
382- query : { referrer } ,
383- } ) ,
389+ onClick : ( ) =>
390+ router . push (
391+ getDestinationAsHref ( createUrlObject ( `/ ${ addressOrNameOrDate } ` , { referrer } ) ) ,
392+ ) ,
384393 } ,
385394 {
386395 icon : CopyIcon ,
387396 label : 'Copy address' ,
388397 onClick : ( ) => copy ( addressOrNameOrDate ) ,
389398 } ,
390- {
391- icon : UpRightArrowIcon ,
392- label : 'View on Etherscan' ,
393- href : makeEtherscanLink ( addressOrNameOrDate , 'mainnet' , 'address' ) ,
394- } ,
399+ ...( blockExplorer
400+ ? [
401+ {
402+ icon : UpRightArrowIcon ,
403+ label : `View on ${ blockExplorer . name } ` ,
404+ onClick : ( ) =>
405+ window . open (
406+ buildAddressUrl ( addressOrNameOrDate ) ,
407+ '_blank' ,
408+ 'noopener,noreferrer' ,
409+ ) ,
410+ } ,
411+ ]
412+ : [ ] ) ,
395413 ] as DropdownItem [ ] )
396414 : [ ] ) ,
397415 ] . filter ( ( item ) => item !== undefined ) as DropdownItem [ ]
0 commit comments