@@ -5,28 +5,29 @@ import { ContractData, FuncABI } from '@remix-project/core-plugin'
55import * as ethJSUtil from 'ethereumjs-util'
66import { ContractGUI } from './contractGUI'
77import { deployWithProxyMsg , upgradeWithProxyMsg } from '@remix-ui/helper'
8- import { OverlayTrigger , Tooltip } from 'react-bootstrap'
8+ import { Dropdown , OverlayTrigger , Tooltip } from 'react-bootstrap'
99
10- export function ContractDropdownUI ( props : ContractDropdownProps ) {
10+ export function ContractDropdownUI ( props : ContractDropdownProps ) {
1111 const [ abiLabel , setAbiLabel ] = useState < {
1212 display : string ,
1313 content : string
1414 } > ( {
1515 display : '' ,
1616 content : ''
1717 } )
18- const [ atAddressOptions , setAtAddressOptions ] = useState < { title : string , disabled : boolean } > ( {
18+ const [ atAddressOptions , setAtAddressOptions ] = useState < { title : string , disabled : boolean } > ( {
1919 title : 'address of contract' ,
2020 disabled : true
2121 } )
2222 const [ loadedAddress , setLoadedAddress ] = useState < string > ( '' )
23- const [ contractOptions , setContractOptions ] = useState < { title : string , disabled : boolean } > ( {
23+ const [ contractOptions , setContractOptions ] = useState < { title : string , disabled : boolean } > ( {
2424 title : 'Please compile *.sol file to deploy or access a contract' ,
2525 disabled : true
2626 } )
2727 const [ loadedContractData , setLoadedContractData ] = useState < ContractData > ( null )
2828 const [ constructorInterface , setConstructorInterface ] = useState < FuncABI > ( null )
2929 const [ constructorInputs , setConstructorInputs ] = useState ( null )
30+ const [ compilerName , setCompilerName ] = useState < string > ( '' )
3031 const contractsRef = useRef < HTMLSelectElement > ( null )
3132 const atAddressValue = useRef < HTMLInputElement > ( null )
3233 const { contractList, loadType, currentFile, compilationSource, currentContract, compilationCount, deployOptions, proxyKey } = props . contracts
@@ -97,20 +98,23 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
9798
9899 useEffect ( ( ) => {
99100 initSelectedContract ( )
101+ updateCompilerName ( )
100102 } , [ contractList ] )
101103
102104 useEffect ( ( ) => {
103105 // if the file change the ui is already feed with another bunch of contracts.
104106 // we also need to update the state
105- const contracts = contractList [ currentFile ]
107+ const contracts = contractList [ currentFile ]
106108 if ( contracts && contracts . length > 0 ) {
107109 props . setSelectedContract ( contracts [ 0 ] . alias )
108110 }
111+ updateCompilerName ( )
109112 } , [ currentFile ] )
110113
111114 const initSelectedContract = ( ) => {
112115 const contracts = contractList [ currentFile ]
113-
116+
117+
114118 if ( contracts && contracts . length > 0 ) {
115119 const contract = contracts . find ( contract => contract . alias === currentContract )
116120
@@ -122,9 +126,9 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
122126
123127 const isContractFile = ( file ) => {
124128 return / .( .s o l ) $ / . exec ( file ) ||
125- / .( .v y ) $ / . exec ( file ) || // vyper
126- / .( .l e x ) $ / . exec ( file ) || // lexon
127- / .( .c o n t r a c t ) $ / . exec ( file )
129+ / .( .v y ) $ / . exec ( file ) || // vyper
130+ / .( .l e x ) $ / . exec ( file ) || // lexon
131+ / .( .c o n t r a c t ) $ / . exec ( file )
128132 }
129133
130134 const enableAtAddress = ( enable : boolean ) => {
@@ -161,20 +165,20 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
161165
162166 const createInstance = ( selectedContract , args , deployMode ?: DeployMode [ ] ) => {
163167 if ( selectedContract . bytecodeObject . length === 0 ) {
164- return props . modal ( 'Alert' , 'This contract may be abstract, it may not implement an abstract parent\'s methods completely or it may not invoke an inherited contract\'s constructor correctly.' , 'OK' , ( ) => { } )
168+ return props . modal ( 'Alert' , 'This contract may be abstract, it may not implement an abstract parent\'s methods completely or it may not invoke an inherited contract\'s constructor correctly.' , 'OK' , ( ) => { } )
165169 }
166170 if ( ( selectedContract . name !== currentContract ) && ( selectedContract . name === 'ERC1967Proxy' ) ) selectedContract . name = currentContract
167171 const isProxyDeployment = ( deployMode || [ ] ) . find ( mode => mode === 'Deploy with Proxy' )
168172 const isContractUpgrade = ( deployMode || [ ] ) . find ( mode => mode === 'Upgrade with Proxy' )
169-
173+
170174 if ( isProxyDeployment ) {
171175 props . modal ( 'Deploy Implementation & Proxy (ERC1967)' , deployWithProxyMsg ( ) , 'Proceed' , ( ) => {
172176 props . createInstance ( loadedContractData , props . gasEstimationPrompt , props . passphrasePrompt , props . publishToStorage , props . mainnetPrompt , isOverSizePrompt , args , deployMode )
173- } , 'Cancel' , ( ) => { } )
177+ } , 'Cancel' , ( ) => { } )
174178 } else if ( isContractUpgrade ) {
175179 props . modal ( 'Deploy Implementation & Update Proxy' , upgradeWithProxyMsg ( ) , 'Proceed' , ( ) => {
176180 props . createInstance ( loadedContractData , props . gasEstimationPrompt , props . passphrasePrompt , props . publishToStorage , props . mainnetPrompt , isOverSizePrompt , args , deployMode )
177- } , 'Cancel' , ( ) => { } )
181+ } , 'Cancel' , ( ) => { } )
178182 } else {
179183 props . createInstance ( loadedContractData , props . gasEstimationPrompt , props . passphrasePrompt , props . publishToStorage , props . mainnetPrompt , isOverSizePrompt , args , deployMode )
180184 }
@@ -211,9 +215,25 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
211215 window . localStorage . setItem ( `ipfs/${ props . exEnvironment } /${ props . networkName } ` , checkedState . toString ( ) )
212216 }
213217
218+ const updateCompilerName = ( ) => {
219+ console . log ( 'updateCompilerName' , contractsRef . current . value )
220+ if ( contractsRef . current . value ) {
221+ console . log ( contractsRef . current . value )
222+ const compilerNames = [ ...new Set ( [ ...contractList [ currentFile ] . map ( contract => contract . compilerName ) ] ) ]
223+ console . log ( compilerNames )
224+ contractList [ currentFile ] . forEach ( contract => {
225+ if ( contract . alias === contractsRef . current . value ) {
226+ setCompilerName ( contract . compilerName )
227+ }
228+ } )
229+ } else {
230+ setCompilerName ( '' )
231+ }
232+ }
233+
214234 const handleContractChange = ( e ) => {
215235 const value = e . target . value
216-
236+ updateCompilerName ( )
217237 props . setSelectedContract ( value )
218238 }
219239
@@ -230,7 +250,7 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
230250 const isOverSizePrompt = ( ) => {
231251 return (
232252 < div > Contract creation initialization returns data with length of more than 24576 bytes. The deployment will likely fails. < br />
233- More info: < a href = "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md" target = "_blank" rel = "noreferrer" > eip-170</ a >
253+ More info: < a href = "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md" target = "_blank" rel = "noreferrer" > eip-170</ a >
234254 </ div >
235255 )
236256 }
@@ -240,30 +260,34 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
240260 < div className = 'd-flex justify-content-between' >
241261 < div className = "d-flex justify-content-between align-items-end" >
242262 < label className = "udapp_settingsLabel pr-1" > Contract</ label >
243- < div className = "d-flex" > { Object . keys ( props . contracts . contractList ) . length > 0 && compilationSource !== '' && < label className = "text-capitalize" style = { { maxHeight : '0.6rem' , lineHeight : '1rem' } } data-id = "udappCompiledBy" > (Compiled by { compilationSource } )</ label > } </ div >
263+ < div className = "d-flex" > { compilerName && compilerName !== '' && < label className = "text-capitalize" style = { { maxHeight : '0.6rem' , lineHeight : '1rem' } } data-id = "udappCompiledBy" > (Compiled by { compilerName } )</ label > } </ div >
244264 </ div >
245- < OverlayTrigger placement = { 'right' } overlay = {
246- < Tooltip className = "text-nowrap" id = "info-sync-compiled-contract" >
247- < div > Click here to import contracts compiled from an external framework.</ div >
248- < div > This action is enabled when Remix is connected to an external framework (hardhat, truffle, foundry) through remixd.</ div >
249- </ Tooltip >
250- } >
251- < button className = "btn d-flex py-0" onClick = { _ => props . syncContracts ( ) } >
252- < i style = { { cursor : 'pointer' } } className = "fa fa-refresh mr-2 mt-2" aria-hidden = "true" > </ i >
253- </ button >
254- </ OverlayTrigger >
265+ { props . remixdActivated ?
266+ < OverlayTrigger placement = { 'right' } overlay = {
267+ < Tooltip className = "text-nowrap" id = "info-sync-compiled-contract" >
268+ < div > Click here to import contracts compiled from an external framework.</ div >
269+ < div > This action is enabled when Remix is connected to an external framework (hardhat, truffle, foundry) through remixd.</ div >
270+ </ Tooltip >
271+ } >
272+ < button className = "btn d-flex py-0" onClick = { _ => props . syncContracts ( ) } >
273+ < i style = { { cursor : 'pointer' } } className = "fa fa-refresh mr-2 mt-2" aria-hidden = "true" > </ i >
274+ </ button >
275+ </ OverlayTrigger >
276+ : null }
255277 </ div >
256278 < div className = "udapp_subcontainer" >
257- < select ref = { contractsRef } value = { currentContract } onChange = { handleContractChange } className = "udapp_contractNames custom-select" disabled = { contractOptions . disabled } title = { contractOptions . title } style = { { display : loadType === 'abi' && ! isContractFile ( currentFile ) ? 'none' : 'block' } } >
258- { ( contractList [ currentFile ] || [ ] ) . map ( ( contract , index ) => {
259- return < option key = { index } value = { contract . alias } > { contract . alias } - { contract . file } </ option >
260- } ) }
279+ < select ref = { contractsRef } value = { currentContract } onChange = { handleContractChange } className = "udapp_contractNames custom-select" disabled = { contractOptions . disabled } title = { contractOptions . title } style = { { display : loadType === 'abi' && ! isContractFile ( currentFile ) ? 'none' : 'block' } } >
280+ { ( contractList [ currentFile ] || [ ] ) . map ( ( contract , index ) => {
281+ return < option key = { index } value = { contract . alias } >
282+ { contract . alias } - { contract . file }
283+ </ option >
284+ } ) }
261285 </ select >
262- < span className = "py-1" style = { { display : abiLabel . display } } > { abiLabel . content } </ span >
286+ < span className = "py-1" style = { { display : abiLabel . display } } > { abiLabel . content } </ span >
263287 </ div >
264288 < div >
265289 < div className = "udapp_deployDropdown" >
266- { ( ( contractList [ currentFile ] && contractList [ currentFile ] . filter ( contract => contract ) ) || [ ] ) . length <= 0 ? 'No compiled contracts'
290+ { ( ( contractList [ currentFile ] && contractList [ currentFile ] . filter ( contract => contract ) ) || [ ] ) . length <= 0 ? 'No compiled contracts'
267291 : loadedContractData ? < div >
268292 < ContractGUI
269293 title = 'Deploy'
0 commit comments