Skip to content

Commit

Permalink
feat(website): refactor fetch cannonfile (website-build-refactor) (#1639
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nicosampler authored Jan 17, 2025
1 parent 0ef0551 commit 38ed522
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
33 changes: 4 additions & 29 deletions packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { BuildStateAlerts } from '@/features/Deploy/BuildStateAlerts';
import { WalletConnectionButtons } from '@/features/Deploy/WalletConnectionButtons';
import { useToast } from '@/hooks/use-toast';
import { useForm, FormProvider } from 'react-hook-form';
import { useGitInfoFromCannonFileUrl } from '@/hooks/useGitInfoFromCannonFileUrl';

const EMPTY_IPFS_MISC_URL =
'ipfs://QmeSt2mnJKE8qmRhLyYbHQQxDKpsFbcWnw5e7JF4xVbN6k';
Expand Down Expand Up @@ -101,37 +102,13 @@ export default function QueueFromGitOps() {
} | null>(null);
const [inputError, setInputError] = useState<string | null>(null);

const gitInfo = useMemo(() => {
if (
!isCannonFileURL(cannonfileUrlInput) ||
!cannonfileUrlInput.includes('/blob/')
) {
return { gitUrl: '', gitRef: '', gitFile: '' };
}

const [url, blobPath] = cannonfileUrlInput.split('/blob/');
const urlComponents = blobPath.split('/');
const branchName = urlComponents[0];
const filePath = urlComponents.slice(1).join('/');

return {
gitUrl: url,
gitRef: branchName,
gitFile: filePath,
};
}, [cannonfileUrlInput]);

const writeToIpfsMutation = useCannonWriteDeployToIpfs();
const gitInfo = useGitInfoFromCannonFileUrl(cannonfileUrlInput);
const partialDeployInfo = useCannonPackage(
partialDeployIpfs ? `ipfs://${partialDeployIpfs}` : '',
currentSafe?.chainId
);

const cannonDefInfo = useMergedCannonDefInfo(
gitInfo.gitUrl,
gitInfo.gitRef,
gitInfo.gitFile,
partialDeployInfo
);
const cannonDefInfo = useMergedCannonDefInfo(gitInfo, partialDeployInfo);

const hasDeployers = useMemo(() => {
return Boolean(cannonDefInfo?.def?.getDeployers()?.length);
Expand Down Expand Up @@ -210,8 +187,6 @@ export default function QueueFromGitOps() {
setPreviousPackageInput(fullPackageRef);
}, [nextCannonDeployInfo, hasDeployers]);

const writeToIpfsMutation = useCannonWriteDeployToIpfs();

useEffect(() => {
const callMutation = async () => {
if (['success'].includes(buildState.status)) {
Expand Down
9 changes: 3 additions & 6 deletions packages/website/src/hooks/cannon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { Abi, Address, createPublicClient, createTestClient, createWalletClient,
import { useChainId, usePublicClient } from 'wagmi';
// Needed to prepare mock run step with registerAction
import '@/lib/builder';
import { CannonfileGitInfo } from '@/hooks/useGitInfoFromCannonFileUrl';

type CannonTxRecord = { name: string; gas: bigint; tx: BaseTransaction };

Expand Down Expand Up @@ -563,12 +564,8 @@ function getContractsRecursive(outputs: ChainArtifacts, prefix?: string): Contra
return contracts;
}

export function useMergedCannonDefInfo(
gitUrl: string,
gitRef: string,
gitFile: string,
partialDeployInfo: ReturnType<typeof useCannonPackage>
) {
export function useMergedCannonDefInfo(gitInfo: CannonfileGitInfo, partialDeployInfo: ReturnType<typeof useCannonPackage>) {
const { gitUrl, gitRef, gitFile } = gitInfo;
const originalCannonDefInfo = useLoadCannonDefinition(gitUrl, gitRef, gitFile);

const {
Expand Down
30 changes: 30 additions & 0 deletions packages/website/src/hooks/useGitInfoFromCannonFileUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { isCannonFileURL } from '@/helpers/isCannonFileURL';

export type CannonfileGitInfo = {
gitUrl: string;
gitRef: string;
gitFile: string;
};

const EMPTY_GIT_INFO: CannonfileGitInfo = {
gitUrl: '',
gitRef: '',
gitFile: '',
};

export function useGitInfoFromCannonFileUrl(cannonfileUrlInput: string): CannonfileGitInfo {
if (!isCannonFileURL(cannonfileUrlInput) || !cannonfileUrlInput.includes('/blob/')) {
return EMPTY_GIT_INFO;
}

const [url, blobPath] = cannonfileUrlInput.split('/blob/');
const urlComponents = blobPath.split('/');
const branchName = urlComponents[0];
const filePath = urlComponents.slice(1).join('/');

return {
gitUrl: url,
gitRef: branchName,
gitFile: filePath,
};
}

0 comments on commit 38ed522

Please sign in to comment.