Skip to content

Commit

Permalink
feat: auto select first contract for deploy (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulyadav-57 authored Sep 19, 2024
1 parent 57aa32c commit f78a2b7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/workspace/BuildProject/BuildProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ interface Props {
}
const BuildProject: FC<Props> = ({ projectId, contract, updateContract }) => {
const [isLoading, setIsLoading] = useState('');
const [buildCount, setBuildCount] = useState(0);
const { createLog } = useLogActivity();
const [environment, setEnvironment] = useState<NetworkEnvironment>('SANDBOX');
const [buildOutput, setBuildoutput] = useState<{
Expand Down Expand Up @@ -609,6 +610,16 @@ const BuildProject: FC<Props> = ({ projectId, contract, updateContract }) => {
updateContract(_userContract);
};

const autoSelectFirstContract = () => {
const _contractsToDeploy = contractsToDeploy();
if (_contractsToDeploy.length > 0 && !selectedContract) {
deployForm.setFieldsValue({
contract: _contractsToDeploy[0]?.path, // Set the first contract as default
});
updateSelectedContract(_contractsToDeploy[0]?.path);
}
};

useEffect(() => {
updateABI().catch(() => {});
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down Expand Up @@ -681,6 +692,11 @@ const BuildProject: FC<Props> = ({ projectId, contract, updateContract }) => {
deploy().catch(() => {});
}, [buildOutput?.dataCell]);

useEffect(() => {
if (buildCount === 0) return;
autoSelectFirstContract();
}, [buildCount]);

return (
<div className={`${s.root} onboarding-build-deploy`}>
<h3 className={s.heading}>Build & Deploy</h3>
Expand Down Expand Up @@ -737,6 +753,7 @@ const BuildProject: FC<Props> = ({ projectId, contract, updateContract }) => {
environment == 'SANDBOX' &&
activeProject?.language === 'tact'
) {
setBuildCount((prevCount) => prevCount + 1);
if (selectedContract) {
await delay(500);
updateABI().catch(() => {});
Expand Down

0 comments on commit f78a2b7

Please sign in to comment.