Skip to content

Commit

Permalink
fix(website): CAN-560
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosampler committed Sep 30, 2024
1 parent 92567c1 commit 4521b12
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 36 deletions.
97 changes: 62 additions & 35 deletions packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ import {
VStack,
} from '@chakra-ui/react';
import { useConnectModal } from '@rainbow-me/rainbowkit';
import { ChainBuilderContext, DeploymentInfo } from '@usecannon/builder';
import {
ChainBuilderContext,
DeploymentInfo,
PackageReference,
} from '@usecannon/builder';
import NextLink from 'next/link';
import { useRouter } from 'next/navigation';
import { Alert as AlertCannon } from '@/components/Alert';
Expand Down Expand Up @@ -136,6 +140,8 @@ export default function QueueFromGitOps() {
const [genericInput, setGenericInput] = useState('');
const [cannonfileUrlInput, setCannonfileUrlInput] = useState('');
const [partialDeployIpfs, setPartialDeployIpfs] = useState('');
const [prevPackageInputRef, setPrevPackageInputRef] =
useState<PackageReference | null>(null);

const [previousPackageInput, setPreviousPackageInput] = useState('');
const [pickedNonce, setPickedNonce] = useState<number | null>(null);
Expand Down Expand Up @@ -189,10 +195,8 @@ export default function QueueFromGitOps() {

const fullPackageRef = cannonDefInfo?.def?.getPackageRef(ctx) ?? null;

const hasDeployers = cannonDefInfo.def?.getDeployers()?.length ?? 0 > 0;

const onChainPrevPkgQuery = useCannonFindUpgradeFromUrl(
fullPackageRef || undefined,
prevPackageInputRef || fullPackageRef || undefined,
currentSafe?.chainId,
cannonDefInfo?.def?.getDeployers()
);
Expand All @@ -206,14 +210,22 @@ export default function QueueFromGitOps() {
currentSafe?.chainId
);

useEffect(() => {
if (previousPackageInput) {
setPrevPackageInputRef(new PackageReference(previousPackageInput));
} else {
setPrevPackageInputRef(null);
}
}, [previousPackageInput]);

useEffect(() => {
if (!cannonDefInfo?.def) return setPreviousPackageInput('');

const name = cannonDefInfo?.def.getName(ctx);
const version = 'latest';
const preset = cannonDefInfo?.def.getPreset(ctx);
setPreviousPackageInput(`${name}:${version}@${preset}`);
}, [cannonDefInfo?.def, selectedDeployType]);
}, [cannonDefInfo?.def]);

// run the build and get the list of transactions we need to run
const { buildState, doBuild, resetState } = useCannonBuildTmp(currentSafe);
Expand Down Expand Up @@ -479,17 +491,24 @@ export default function QueueFromGitOps() {

if (cannonDefInfo?.def && cannonDefInfo.def.danglingDependencies.size > 0) {
alertMessage = (
<>
The cannonfile contains invalid dependencies. Please ensure the
following references are defined:
{Array.from(cannonDefInfo.def.danglingDependencies).map(
([input, node]) => (
<Text key={`${input}:${node}`} as="span" fontFamily="monospace">
{input} in {node}
</Text>
)
)}
</>
<Flex direction="column">
<Text>
The cannonfile contains invalid dependencies. Please ensure the
following references are defined:
</Text>
<div>
{Array.from(cannonDefInfo.def.danglingDependencies).map(
(dependency) => (
<>
<Text key={dependency} as="span" fontFamily="monospace">
{dependency}
</Text>
<br />
</>
)
)}
</div>
</Flex>
);
}

Expand All @@ -503,13 +522,6 @@ export default function QueueFromGitOps() {
) : null;
};

const disablePreviewButton =
loadingDataForDeploy ||
chainId !== currentSafe?.chainId ||
!cannonDefInfo?.def ||
buildState.status === 'building' ||
buildState.status === 'success';

const cannonInfoDefinitionLoaded =
cannonfileUrlInput.length > 0 && !cannonDefInfo.error && cannonDefInfo?.def;

Expand All @@ -518,6 +530,29 @@ export default function QueueFromGitOps() {
!partialDeployInfo?.isError &&
partialDeployInfo?.pkg;

const hasDeployers = Boolean(
cannonDefInfo.def?.getDeployers()?.length ?? 0 > 0
);
const tomlRequiresPrevPackage = Boolean(
cannonfileUrlInput &&
cannonDefInfo?.def &&
!hasDeployers &&
cannonDefInfo.def.allActionNames.some((item) =>
item.startsWith('deploy.')
)
);

const disablePreviewButton =
loadingDataForDeploy ||
chainId !== currentSafe?.chainId ||
!cannonDefInfo?.def ||
buildState.status === 'building' ||
buildState.status === 'success' ||
(onChainPrevPkgQuery.isFetched &&
!prevDeployLocation &&
tomlRequiresPrevPackage &&
!previousPackageInput);

const PreviewButton = ({ message }: { message?: string }) => (
<Tooltip label={message}>
<Button
Expand Down Expand Up @@ -725,16 +760,6 @@ export default function QueueFromGitOps() {

{selectedDeployType == 'git' && (
<Flex flexDir="column" my="4">
{/* {renderCannonfileInput()} */}

{cannonDefInfo.def && !hasDeployers && (
<AlertCannon
borderless
title="No deployers found in cannonfile"
status="warning"
/>
)}

{onChainPrevPkgQuery.isFetched &&
(prevDeployLocation ? (
<AlertCannon borderless status="info">
Expand All @@ -751,7 +776,9 @@ export default function QueueFromGitOps() {
</AlertCannon>
) : (
<AlertCannon borderless status="info">
Deployment from scratch
{tomlRequiresPrevPackage
? 'We couldn\'t find a previous deployment for your cannonfile. Please, enter a value in the "Previous Package" input or modify your cannonfile to include a "deployers" key.'
: 'Deployment from scratch'}
</AlertCannon>
))}
</Flex>
Expand All @@ -770,7 +797,7 @@ export default function QueueFromGitOps() {
</FormControl>
)} */}

{(partialDeployInfo?.pkg || partialDeployInfoLoaded) && (
{(partialDeployInfoLoaded || tomlRequiresPrevPackage) && (
<FormControl mb="6">
<FormLabel>Previous Package</FormLabel>
<InputGroup>
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/hooks/cannon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ export function useCannonFindUpgradeFromUrl(packageRef?: PackageReference, chain

const onChainDataQuery = useQuery({
enabled: !!packageRef && !!chainId,
queryKey: ['cannon', 'find-upgrade-from', packageRef?.name, packageRef?.preset, chainId, deployers],
queryKey: ['cannon', 'find-upgrade-from', packageRef?.name, packageRef?.preset, packageRef?.version, chainId, deployers],
queryFn: async () => {
// eslint-disable-next-line no-console
console.log('find with deployers', deployers);
Expand Down

0 comments on commit 4521b12

Please sign in to comment.