Skip to content

Commit 2c4b5e1

Browse files
committed
dynamically update deploy button text based on verification checkbox state
1 parent 7dc8e23 commit 2c4b5e1

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,13 @@ export function ContractDropdownUI(props: ContractDropdownProps) {
415415
evmVersion = JSON.parse(loadedContractData.metadata).settings.evmVersion
416416
}
417417
} catch (err) {}
418+
419+
const deployButtonTitle = isVerifyChecked
420+
? intl.formatMessage({ id: 'udapp.deployAndVerify', defaultMessage: 'Deploy & Verify' })
421+
: intl.formatMessage({ id: 'udapp.deploy' })
422+
423+
const deployButtonWidthClass = isVerifyChecked ? 'w-auto' : 'w-50'
424+
418425
return (
419426
<div className="udapp_container mb-2" data-id="contractDropdownContainer">
420427
<div className="d-flex justify-content-between">
@@ -492,7 +499,7 @@ export function ContractDropdownUI(props: ContractDropdownProps) {
492499
</span>
493500
}
494501
>
495-
<span className="udapp_evmVersion badge alert-warning">
502+
<span className="udapp_evmVersion badge alert-warning mb-2">
496503
<FormattedMessage id="udapp.evmVersion" />: {evmVersion}
497504
</span>
498505
</CustomTooltip>
@@ -501,8 +508,14 @@ export function ContractDropdownUI(props: ContractDropdownProps) {
501508
<div className="udapp_deployDropdown">
502509
{((contractList[currentFile] && contractList[currentFile].filter((contract) => contract)) || []).length > 0 && loadedContractData && (
503510
<div>
511+
{isNetworkSupported && (
512+
<VerificationSettingsUI
513+
isVerifyChecked={isVerifyChecked}
514+
onVerifyCheckedChange={handleVerifyCheckedChange}
515+
/>
516+
)}
504517
<ContractGUI
505-
title={intl.formatMessage({ id: 'udapp.deploy' })}
518+
title={deployButtonTitle}
506519
getCompilerDetails={props.getCompilerDetails}
507520
isDeploy={true}
508521
deployOption={deployOptions[currentFile] && deployOptions[currentFile][currentContract] ? deployOptions[currentFile][currentContract].options : null}
@@ -512,7 +525,7 @@ export function ContractDropdownUI(props: ContractDropdownProps) {
512525
funcABI={constructorInterface}
513526
clickCallBack={clickCallback}
514527
inputs={constructorInputs}
515-
widthClass="w-50"
528+
widthClass={deployButtonWidthClass}
516529
evmBC={loadedContractData.bytecodeObject}
517530
lookupOnly={false}
518531
proxy={props.proxy}
@@ -528,12 +541,6 @@ export function ContractDropdownUI(props: ContractDropdownProps) {
528541
plugin={props.plugin}
529542
runTabState={props.runTabState}
530543
/>
531-
{isNetworkSupported && (
532-
<VerificationSettingsUI
533-
isVerifyChecked={isVerifyChecked}
534-
onVerifyCheckedChange={handleVerifyCheckedChange}
535-
/>
536-
)}
537544
</div>
538545
)}
539546
</div>

libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function ContractGUI(props: ContractGUIProps) {
3232
const multiFields = useRef<Array<HTMLInputElement | null>>([])
3333
const initializeFields = useRef<Array<HTMLInputElement | null>>([])
3434
const basicInputRef = useRef<HTMLInputElement>()
35+
const [baseTitleForDataId, setBaseTitleForDataId] = useState<string>('')
3536

3637
const intl = useIntl()
3738
useEffect(() => {
@@ -42,19 +43,34 @@ export function ContractGUI(props: ContractGUIProps) {
4243
}, [props.deployOption])
4344

4445
useEffect(() => {
46+
let newTitle = ''
47+
let newBaseTitle = ''
48+
4549
if (props.title) {
46-
setTitle(props.title)
50+
newTitle = props.title
4751
} else if (props.funcABI.name) {
48-
setTitle(props.funcABI.name)
52+
newTitle = props.funcABI.name
4953
} else {
50-
setTitle(props.funcABI.type === 'receive' ? '(receive)' : '(fallback)')
54+
newTitle = props.funcABI.type === 'receive' ? '(receive)' : '(fallback)'
5155
}
56+
57+
if (props.isDeploy) {
58+
newBaseTitle = intl.formatMessage({ id: 'udapp.deploy', defaultMessage: 'Deploy' })
59+
} else if (props.funcABI.name) {
60+
newBaseTitle = props.funcABI.name
61+
} else {
62+
newBaseTitle = props.funcABI.type === 'receive' ? '(receive)' : '(fallback)'
63+
}
64+
65+
setTitle(newTitle)
66+
setBaseTitleForDataId(newBaseTitle)
67+
5268
setBasicInput('')
5369
// we have the reset the fields before resetting the previous references.
5470
basicInputRef.current.value = ''
5571
multiFields.current.filter((el) => el !== null && el !== undefined).forEach((el) => (el.value = ''))
5672
multiFields.current = []
57-
}, [props.title, props.funcABI])
73+
}, [props.title, props.funcABI, props.isDeploy, intl])
5874

5975
useEffect(() => {
6076
if (props.lookupOnly) {
@@ -63,26 +79,26 @@ export function ContractGUI(props: ContractGUIProps) {
6379
title: title + ' - call',
6480
content: 'call',
6581
classList: 'btn-primary',
66-
dataId: title + ' - call'
82+
dataId: baseTitleForDataId + ' - call'
6783
})
6884
} else if (props.funcABI.stateMutability === 'payable' || props.funcABI.payable) {
6985
// // transact. stateMutability = payable
7086
setButtonOptions({
7187
title: title + ' - transact (payable)',
7288
content: 'transact',
7389
classList: 'btn-danger',
74-
dataId: title + ' - transact (payable)'
90+
dataId: baseTitleForDataId + ' - transact (payable)'
7591
})
7692
} else {
7793
// // transact. stateMutability = nonpayable
7894
setButtonOptions({
7995
title: title + ' - transact (not payable)',
8096
content: 'transact',
8197
classList: 'btn-warning',
82-
dataId: title + ' - transact (not payable)'
98+
dataId: baseTitleForDataId + ' - transact (not payable)'
8399
})
84100
}
85-
}, [props.lookupOnly, props.funcABI, title])
101+
}, [props.lookupOnly, props.funcABI, title, baseTitleForDataId])
86102

87103
const getEncodedCall = () => {
88104
const multiString = getMultiValsString(multiFields.current)
@@ -305,7 +321,7 @@ export function ContractGUI(props: ContractGUIProps) {
305321
(props.funcABI.inputs && props.funcABI.inputs.length > 0) || props.funcABI.type === 'fallback' || props.funcABI.type === 'receive' ? 'udapp_hasArgs' : ''
306322
}`}
307323
>
308-
<div className="udapp_contractActionsContainerSingle pt-2" style={{ display: toggleContainer ? 'none' : 'flex' }}>
324+
<div className="udapp_contractActionsContainerSingle" style={{ display: toggleContainer ? 'none' : 'flex' }}>
309325
<CustomTooltip
310326
delay={0}
311327
placement={'auto-end'}

0 commit comments

Comments
 (0)