@@ -5,7 +5,6 @@ import { memo, useCallback, useMemo } from 'react';
5
5
6
6
import { getObjectUrl , getAddressUrl , getTransactionUrl } from './Explorer' ;
7
7
import { ExplorerLinkType } from './ExplorerLinkType' ;
8
- import { API_ENV } from '_app/ApiProvider' ;
9
8
import ExternalLink from '_components/external-link' ;
10
9
import Icon , { SuiIcons } from '_components/icon' ;
11
10
import { useAppSelector } from '_hooks' ;
@@ -48,34 +47,40 @@ function useAddress(props: ExplorerLinkProps) {
48
47
function ExplorerLink ( props : ExplorerLinkProps ) {
49
48
const { type, children, className, title, showIcon = true } = props ;
50
49
const address = useAddress ( props ) ;
51
- const selectedApiEnv = useAppSelector ( ( { app } ) => app . apiEnv ) ;
52
- const notCustomRPC = selectedApiEnv !== API_ENV . customRPC ;
50
+ const [ selectedApiEnv , customRPC ] = useAppSelector ( ( { app } ) => [
51
+ app . apiEnv ,
52
+ app . customRPC ,
53
+ ] ) ;
53
54
54
55
const objectID = type === ExplorerLinkType . object ? props . objectID : null ;
55
56
const transactionID =
56
57
type === ExplorerLinkType . transaction ? props . transactionID : null ;
58
+
59
+ // fallback to localhost if customRPC is not set
60
+ const customRPCUrl = customRPC || 'http://localhost:3000/' ;
57
61
const explorerHref = useMemo ( ( ) => {
58
62
switch ( type ) {
59
63
case ExplorerLinkType . address :
60
64
return (
61
65
address &&
62
- notCustomRPC &&
63
- getAddressUrl ( address , selectedApiEnv )
66
+ getAddressUrl ( address , selectedApiEnv , customRPCUrl )
64
67
) ;
65
68
case ExplorerLinkType . object :
66
69
return (
67
70
objectID &&
68
- notCustomRPC &&
69
- getObjectUrl ( objectID , selectedApiEnv )
71
+ getObjectUrl ( objectID , selectedApiEnv , customRPCUrl )
70
72
) ;
71
73
case ExplorerLinkType . transaction :
72
74
return (
73
75
transactionID &&
74
- notCustomRPC &&
75
- getTransactionUrl ( transactionID , selectedApiEnv )
76
+ getTransactionUrl (
77
+ transactionID ,
78
+ selectedApiEnv ,
79
+ customRPCUrl
80
+ )
76
81
) ;
77
82
}
78
- } , [ type , address , notCustomRPC , selectedApiEnv , objectID , transactionID ] ) ;
83
+ } , [ type , address , selectedApiEnv , objectID , transactionID , customRPCUrl ] ) ;
79
84
80
85
const handleclick = useCallback ( ( ) => {
81
86
if ( props . track ) {
@@ -86,9 +91,7 @@ function ExplorerLink(props: ExplorerLinkProps) {
86
91
if ( ! explorerHref ) {
87
92
return null ;
88
93
}
89
- if ( selectedApiEnv === API_ENV . customRPC ) {
90
- return null ;
91
- }
94
+
92
95
return (
93
96
< ExternalLink
94
97
href = { explorerHref }
0 commit comments