diff --git a/plugin/src/components/CompiledContracts/index.tsx b/plugin/src/components/CompiledContracts/index.tsx index a9ba8d3b..a929554a 100644 --- a/plugin/src/components/CompiledContracts/index.tsx +++ b/plugin/src/components/CompiledContracts/index.tsx @@ -6,24 +6,38 @@ import { import { useAtom } from 'jotai' import { compiledContractsAtom, selectedCompiledContract } from '../../atoms/compiledContracts' import * as Select from '../../components/ui_components/Select' -import { ChevronDownIcon } from 'lucide-react' +import { ChevronDownIcon, TrashIcon } from 'lucide-react' interface CompiledContractsProps { show: 'class' | 'contract' } -const CompiledContracts: React.FC = (props) => { - const [contracts] = useAtom(compiledContractsAtom) +const CompiledContracts: React.FC = (props): JSX.Element => { + const [contracts, setContracts] = useAtom(compiledContractsAtom) const [selectedContract, setSelectedContract] = useAtom(selectedCompiledContract) const [selectedContractIdx, setSelectedContractIdx] = useState('0') const handleCompiledContractSelectionChange = (value: string): void => { console.log('handleCompiledContractSelectionChange', value) - setSelectedContract(contracts[value as unknown as number]) + setSelectedContract(contracts[parseInt(value)]) setSelectedContractIdx(value) } + const handleDeleteContract = (event: React.MouseEvent, index: number): void => { + event.stopPropagation() + setContracts((prevContracts) => prevContracts.filter((_, i) => i !== index)) + + if (contracts.length === 0) { + setSelectedContract(null) + } else { + setSelectedContract(contracts[0]) + setSelectedContractIdx('0') + } + } + + if (contracts.length === 0) return <> + return ( { handleCompiledContractSelectionChange(value) }}> @@ -34,29 +48,50 @@ const CompiledContracts: React.FC = (props) => { 4 )})` : 'Contract is not selected'}/> - - - - - - - - {contracts.map((contract, index) => ( - - - {`${getContractNameFromFullName(contract.name)} (${getShortenedHash( + + + + + + + + {contracts.map((contract, index) => ( + + {`${getContractNameFromFullName(contract.name)} (${getShortenedHash( contract.classHash ?? '', 6, 4 )})`} - - - ))} - - - - + + ))} + + + + ) } +const SelectItemWithDelete = React.forwardRef( + ({ children, onDelete, index, value, ...props }: any, ref: React.Ref): JSX.Element => ( +
+ + {children} + + + + +
+ ) +) + +SelectItemWithDelete.displayName = 'SelectItemWithDelete' + export default CompiledContracts diff --git a/plugin/src/components/ui_components/Select/select.css b/plugin/src/components/ui_components/Select/select.css index 449c06fa..8d4a9f36 100644 --- a/plugin/src/components/ui_components/Select/select.css +++ b/plugin/src/components/ui_components/Select/select.css @@ -46,6 +46,7 @@ button { user-select: none; outline: none; background: var(--bgPrimary); + border: 1px solid var(--bgPrimary); } .SelectItem:hover, @@ -53,6 +54,21 @@ button { border: 1px solid var(--secondary); } +.SelectItemWithDelete { + display: flex; + align-items: center; + justify-content: space-between; + position: relative; + background: var(--bgPrimary); + color: var(--text); + border: 1px solid var(--bgPrimary); +} + +.SelectItemWithDelete .deleteButton:hover{ + border: 1px solid var(--secondary); +} + + /* Keyframe animations */ @keyframes fadeInScaleUp { from { diff --git a/plugin/src/features/Deployment/index.tsx b/plugin/src/features/Deployment/index.tsx index 79575763..7484da3b 100644 --- a/plugin/src/features/Deployment/index.tsx +++ b/plugin/src/features/Deployment/index.tsx @@ -534,125 +534,116 @@ const Deployment: React.FC = ({ setActiveTab }) => { return ( <> - {contracts.length > 0 && selectedContract != null - ? ( -
-
-
- {'deploy-icon'} -
- Deploy your selected contract +
+
+
+ deploy-icon
- -
+ + + {contracts.length > 0 && selectedContract !== null + ? ( +
+ - - {account != null && - selectedContract.deployedInfo.some( - (info) => - info.address === account.address && info.chainId === chainId - ) && ( -
- -
- )} - {notEnoughInputs && ( - - )} -
- ) - : ( - - )} + + + {account != null && + selectedContract.deployedInfo.some( + (info) => + info.address === account.address && info.chainId === chainId + ) && ( +
+ +
+ )} + {notEnoughInputs && ( + + )} +
+ ) + : ( + <> + )} +
) } -const NoContractReadyView = (): JSX.Element => ( -
-
- {'deploy-icon'} -
-

No contracts ready for deployment yet, compile a cairo contract

-
-) export default Deployment