1
1
import { useState } from "react" ;
2
2
import { fetchFromEtherscan , processEtherscanResult } from "../../utils/etherscanApi" ;
3
- import { hasEtherscanApiKey , getEtherscanApiKey } from "../../utils/etherscanStorage" ;
3
+ import { useEtherscanApiKey , getEtherscanApiKey } from "../../utils/etherscanStorage" ;
4
4
5
5
interface ImportFromEtherscanProps {
6
6
chainId : string ;
@@ -24,7 +24,10 @@ export default function ImportFromEtherscan({ chainId, address, onImportSuccess
24
24
const [ error , setError ] = useState < string | null > ( null ) ;
25
25
const [ success , setSuccess ] = useState < string | null > ( null ) ;
26
26
27
- const canImport = hasEtherscanApiKey ( ) && chainId && address ;
27
+ // Use the custom hook to reactively track API key changes
28
+ const hasApiKey = useEtherscanApiKey ( ) ;
29
+
30
+ const canImport = hasApiKey && chainId && address ;
28
31
29
32
const handleImport = async ( ) => {
30
33
if ( ! canImport ) return ;
@@ -58,7 +61,7 @@ export default function ImportFromEtherscan({ chainId, address, onImportSuccess
58
61
59
62
const getButtonText = ( ) => {
60
63
if ( isImporting ) return "Importing..." ;
61
- if ( ! hasEtherscanApiKey ( ) ) return "Add API key in settings" ;
64
+ if ( ! hasApiKey ) return "Add API key in settings" ;
62
65
if ( ! chainId || ! address ) return "Select chain and address" ;
63
66
return "Import from Etherscan" ;
64
67
} ;
@@ -99,7 +102,7 @@ export default function ImportFromEtherscan({ chainId, address, onImportSuccess
99
102
</ div >
100
103
) }
101
104
102
- { ! hasEtherscanApiKey ( ) && (
105
+ { ! hasApiKey && (
103
106
< p className = "text-xs text-gray-500" >
104
107
Add your Etherscan API key in settings to import verified contracts
105
108
</ p >
0 commit comments