Skip to content

Commit

Permalink
refactor build status state
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlescano committed Sep 15, 2024
1 parent 343cc79 commit bf1b6e8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
17 changes: 9 additions & 8 deletions packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ function QueueFromGitOps() {
);

useEffect(() => {
if (!buildInfo.finishedBuilding) return;
uploadToPublishIpfs.writeToIpfsMutation.mutate();
}, [buildInfo.finishedBuilding]);
if (['success', 'error'].includes(buildInfo.buildStatus)) {
uploadToPublishIpfs.writeToIpfsMutation.mutate();
}
}, [buildInfo.buildStatus]);

const refsInfo = useGitRefsList(gitUrl);
const foundRef = refsInfo.refs?.find(
Expand Down Expand Up @@ -396,7 +397,7 @@ function QueueFromGitOps() {
cannonPkgPreviousInfo.isFetching ||
partialDeployInfo.isFetching ||
cannonPkgVersionInfo.isFetching ||
buildInfo.isBuilding;
buildInfo.buildStatus === 'building';

const handlePreviewTxnsClick = async () => {
if (!isConnected) {
Expand Down Expand Up @@ -462,7 +463,7 @@ function QueueFromGitOps() {
cannonPkgPreviousInfo.isFetching ||
partialDeployInfo.isFetching ||
cannonPkgVersionInfo.isFetching ||
buildInfo.isBuilding;
buildInfo.buildStatus === 'building';

function PreviewButton(props: any) {
return (
Expand Down Expand Up @@ -550,7 +551,7 @@ function QueueFromGitOps() {
return <PreviewButton message="Fetching package info, please wait..." />;
}

if (buildInfo.isBuilding) {
if (buildInfo.buildStatus === 'building') {
return <PreviewButton message="Generating build info, please wait..." />;
}

Expand Down Expand Up @@ -697,10 +698,10 @@ function QueueFromGitOps() {

{renderAlertMessage()}
<RenderPreviewButtonTooltip />
{buildInfo.buildStatus && (
{buildInfo.buildMessage && (
<Alert mt="6" status="info" bg="gray.800">
<Spinner mr={3} boxSize={4} />
<strong>{buildInfo.buildStatus}</strong>
<strong>{buildInfo.buildMessage}</strong>
</Alert>
)}
{buildInfo.buildError && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,9 @@ function TransactionDetailsPage() {
<Card title="Verify Transactions">
{queuedWithGitOps && (
<Box>
{buildInfo.buildStatus && (
{buildInfo.buildMessage && (
<Text fontSize="sm" mb="2">
{buildInfo.buildStatus}
{buildInfo.buildMessage}
</Text>
)}
{buildInfo.buildError && (
Expand Down
23 changes: 10 additions & 13 deletions packages/website/src/hooks/cannon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ export function useCannonBuild(safe: SafeDefinition | null, def?: ChainDefinitio
const { addLog } = useLogs();
const settings = useStore((s) => s.settings);

const [finishedBuilding, setFinishedBuilding] = useState(false);
const [isBuilding, setIsBuilding] = useState(false);
const [buildStatus, setBuildStatus] = useState('');
const [buildMessage, setBuildMessage] = useState('');
const [buildStatus, setBuildStatus] = useState<'idle' | 'building' | 'success' | 'error'>('idle');

const [buildResult, setBuildResult] = useState<{
runtime: ChainBuilderRuntime;
Expand All @@ -103,7 +102,7 @@ export function useCannonBuild(safe: SafeDefinition | null, def?: ChainDefinitio

const chain = getChainById(safe.chainId);

setBuildStatus('Creating fork...');
setBuildMessage('Creating fork...');
// eslint-disable-next-line no-console
console.log(`Creating fork with RPC: ${chain?.rpcUrls.default.http[0]}`);
const fork = await createFork({
Expand All @@ -117,7 +116,7 @@ export function useCannonBuild(safe: SafeDefinition | null, def?: ChainDefinitio

const ipfsLoader = new IPFSBrowserLoader(settings.ipfsApiUrl || externalLinks.IPFS_CANNON);

setBuildStatus('Loading deployment data...');
setBuildMessage('Loading deployment data...');

addLog('info', `cannon.ts: upgrade from: ${prevDeploy?.def.name}:${prevDeploy?.def.version}`);

Expand Down Expand Up @@ -185,7 +184,7 @@ export function useCannonBuild(safe: SafeDefinition | null, def?: ChainDefinitio
stepOutput.txns![txn].hash = '';
}

setBuildStatus(`Building ${stepName}...`);
setBuildMessage(`Building ${stepName}...`);

// a step that deploys a contract is a step that has no txns deployed but contract(s) deployed
if (_.keys(stepOutput.txns).length === 0 && _.keys(stepOutput.contracts).length > 0) {
Expand Down Expand Up @@ -249,33 +248,31 @@ export function useCannonBuild(safe: SafeDefinition | null, def?: ChainDefinitio
};

return {
finishedBuilding,
isBuilding,
buildStatus,
buildMessage,
buildResult,
buildError,
buildSkippedSteps,
doBuild() {
setFinishedBuilding(false);
setBuildResult(null);
setBuildError(null);
setBuildSkippedSteps([]);
setIsBuilding(true);
setBuildStatus('building');

buildFn()
.then((res) => {
setBuildResult(res);
setBuildStatus('success');
})
.catch((err) => {
// eslint-disable-next-line no-console
console.error(err);
addLog('error', `cannon.ts: full build error ${err.toString()}`);
setBuildError(err.toString());
setBuildStatus('error');
})
.finally(() => {
setFinishedBuilding(true);
setIsBuilding(false);
setBuildStatus('');
setBuildMessage('');
});
},
};
Expand Down

0 comments on commit bf1b6e8

Please sign in to comment.