From 3cf5f7f1b7767344bc8a1c4221666b0cd020c978 Mon Sep 17 00:00:00 2001 From: saeta-eth Date: Wed, 30 Oct 2024 17:37:29 -0300 Subject: [PATCH] fixes and improvements --- .../features/Deploy/QueueFromGitOpsPage.tsx | 98 +--- .../Deploy/TransactionDetailsPage.tsx | 20 +- .../features/Packages/CannonfileExplorer.tsx | 2 +- .../src/features/Packages/CannonfileGraph.tsx | 452 ++++++++++-------- .../src/features/Packages/Interact.tsx | 79 +-- .../Packages/PackageAccordionHelper/index.tsx | 34 +- .../features/Packages/Tabs/InteractTab.tsx | 132 ++--- .../website/src/helpers/chain-definition.ts | 4 +- packages/website/src/hooks/cannon.ts | 47 +- packages/website/src/hooks/deployer.ts | 4 +- packages/website/src/hooks/useWorker.ts | 23 - packages/website/src/lib/builder.ts | 12 +- .../src/workers/chain-definition.worker.ts | 3 +- 13 files changed, 472 insertions(+), 438 deletions(-) delete mode 100644 packages/website/src/hooks/useWorker.ts diff --git a/packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx b/packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx index 6749c235f..43910048f 100644 --- a/packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx +++ b/packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx @@ -9,7 +9,7 @@ import { useDeployerWallet } from '@/hooks/deployer'; import { useCannonPackage, useCannonWriteDeployToIpfs, - useLoadCannonDefinition, + useMergedCannonDefInfo, useCannonFindUpgradeFromUrl, CannonWriteDeployToIpfsMutationResult, useCannonBuildTmp, @@ -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, @@ -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'; @@ -90,74 +86,6 @@ const ctx: ChainBuilderContext = { overrideSettings: {}, }; -function useMergedCannonDefInfo( - gitUrl: string, - gitRef: string, - gitFile: string, - partialDeployInfo: ReturnType -) { - 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() { @@ -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); @@ -618,7 +548,7 @@ export default function QueueFromGitOps() { ); }, - [loadingDataForDeploy, disablePreviewButton, handlePreviewTxnsClick] + [loadingDataForDeploy, disablePreviewButton] ); const RenderPreviewButtonTooltip = useCallback(() => { @@ -994,7 +924,15 @@ export default function QueueFromGitOps() { {renderAlert()} - {chainId !== currentSafe?.chainId ? ( + {!isConnected ? ( + + ) : chainId !== currentSafe?.chainId ? (