Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(website): refactor fetch cannonfile (website-build-refactor) #1639

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
}
Loading