Skip to content

Commit

Permalink
fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
saeta-eth committed Oct 30, 2024
1 parent ee2f213 commit 3cf5f7f
Show file tree
Hide file tree
Showing 13 changed files with 472 additions and 438 deletions.
98 changes: 18 additions & 80 deletions packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useDeployerWallet } from '@/hooks/deployer';
import {
useCannonPackage,
useCannonWriteDeployToIpfs,
useLoadCannonDefinition,
useMergedCannonDefInfo,
useCannonFindUpgradeFromUrl,
CannonWriteDeployToIpfsMutationResult,
useCannonBuildTmp,
Expand Down Expand Up @@ -46,12 +46,10 @@ import {
ChainBuilderContext,
DeploymentInfo,
PackageReference,
RawChainDefinition,
} from '@usecannon/builder';
import NextLink from 'next/link';
import { useRouter } from 'next/navigation';
import { Alert as AlertCannon } from '@/components/Alert';
import { useQuery } from '@tanstack/react-query';
import React, { useEffect, useMemo, useState, useCallback } from 'react';
import {
encodeAbiParameters,
Expand All @@ -67,9 +65,7 @@ import pkg from '../../../package.json';
import NoncePicker from './NoncePicker';
import { TransactionDisplay } from './TransactionDisplay';
import 'react-diff-view/style/index.css';
import { ChainDefinition } from '@usecannon/builder/dist/src';
import { extractIpfsHash } from '@/helpers/ipfs';
import { getChainDefinitionFromWorker } from '@/helpers/chain-definition';

const EMPTY_IPFS_MISC_URL =
'ipfs://QmeSt2mnJKE8qmRhLyYbHQQxDKpsFbcWnw5e7JF4xVbN6k';
Expand All @@ -90,74 +86,6 @@ const ctx: ChainBuilderContext = {
overrideSettings: {},
};

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

const {
data: workerDef,
error: workerError,
isLoading,
} = useQuery({
queryKey: [
'worker-def',
gitUrl,
gitRef,
gitFile,
partialDeployInfo?.ipfsQuery.data?.deployInfo,
],
queryFn: async () => {
if (
!partialDeployInfo?.ipfsQuery.data?.deployInfo &&
!originalCannonDefInfo.def
) {
return null;
}

const deployInfo =
partialDeployInfo?.ipfsQuery.data?.deployInfo?.def ||
originalCannonDefInfo.def;

try {
if (deployInfo) {
return await getChainDefinitionFromWorker(
deployInfo as RawChainDefinition
);
}
} catch (e) {
// fallback to non-worker execution if worker fails
return new ChainDefinition(deployInfo as RawChainDefinition);
}
return null;
},
enabled: Boolean(
partialDeployInfo?.ipfsQuery.data?.deployInfo || originalCannonDefInfo.def
),
});

return useMemo(() => {
const isError = originalCannonDefInfo.isError || !!workerError;
const isFetching = originalCannonDefInfo.isFetching || isLoading;
const error = workerError || originalCannonDefInfo.error;

return {
isLoading,
isFetching,
isError,
error,
def: workerDef!,
};
}, [originalCannonDefInfo, workerDef, workerError, isLoading]);
}

type DeployType = 'git' | 'partial';

export default function QueueFromGitOps() {
Expand Down Expand Up @@ -250,13 +178,15 @@ export default function QueueFromGitOps() {
}, [previousPackageInput]);

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

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

// run the build and get the list of transactions we need to run
const { buildState, doBuild, resetState } = useCannonBuildTmp(currentSafe);
Expand Down Expand Up @@ -618,7 +548,7 @@ export default function QueueFromGitOps() {
</Tooltip>
);
},
[loadingDataForDeploy, disablePreviewButton, handlePreviewTxnsClick]
[loadingDataForDeploy, disablePreviewButton]
);

const RenderPreviewButtonTooltip = useCallback(() => {
Expand Down Expand Up @@ -994,7 +924,15 @@ export default function QueueFromGitOps() {

{renderAlert()}

{chainId !== currentSafe?.chainId ? (
{!isConnected ? (
<Button
width="100%"
colorScheme="teal"
onClick={() => openConnectModal && openConnectModal()}
>
Connect wallet
</Button>
) : chainId !== currentSafe?.chainId ? (
<Button
width="100%"
colorScheme="teal"
Expand Down
20 changes: 18 additions & 2 deletions packages/website/src/features/Deploy/TransactionDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { TransactionDisplay } from './TransactionDisplay';
import { TransactionStepper } from './TransactionStepper';
import 'react-diff-view/style/index.css';
import { ChainDefinition } from '@usecannon/builder';
import { getChainDefinitionFromWorker } from '@/helpers/chain-definition';

const AdditionalSignaturesText = ({ amount }: { amount: number }) => (
<Text fontWeight="bold" mt="3">
Expand Down Expand Up @@ -95,6 +96,7 @@ function TransactionDetailsPage() {
const [expandDiff, setExpandDiff] = useState<boolean>(false);
const [executionTxnHash, setExecutionTxnHash] = useState<Hash | null>(null);
const accountAlreadyConnected = useRef(account.isConnected);
const [chainDefinition, setChainDefinition] = useState<ChainDefinition>();

const safe: SafeDefinition = useMemo(
() => ({
Expand Down Expand Up @@ -231,23 +233,37 @@ function TransactionDetailsPage() {
gitFile ?? ''
);

useEffect(() => {
const getChainDef = async () => {
if (!cannonDefInfo.def) return;

const chainDefition = await getChainDefinitionFromWorker(
cannonDefInfo.def
);
setChainDefinition(chainDefition);
};

void getChainDef();
}, [cannonDefInfo.def]);

const buildInfo = useCannonBuild(
safe,
new ChainDefinition(cannonDefInfo.def!),
chainDefinition,
prevCannonDeployInfo.ipfsQuery.data?.deployInfo
);

useEffect(() => {
if (
!safe ||
!cannonDefInfo.def ||
!chainDefinition ||
!prevCannonDeployInfo.ipfsQuery.data?.deployInfo
)
return;
buildInfo.doBuild();
}, [
!isTransactionExecuted &&
(!prevDeployGitHash || prevCannonDeployInfo.ipfsQuery.isFetched),
chainDefinition,
]);

// compare proposed build info with expected transaction batch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const CannonfileExplorer: FC<{
flex="1"
direction="column"
>
<CannonfileGraph deploymentInfo={deploymentInfo} />
<CannonfileGraph deploymentDefinition={deploymentInfo.def} />
</Flex>
<Container
maxW="container.lg"
Expand Down
Loading

0 comments on commit 3cf5f7f

Please sign in to comment.