From 4246c82cd3889b2bd5bb991924c8daece85446bd Mon Sep 17 00:00:00 2001 From: Daniel Beal Date: Thu, 31 Oct 2024 11:52:12 +0900 Subject: [PATCH] button cannot be disabled without a reason component so annoying lol --- packages/website/src/components/Button.tsx | 21 +++ .../features/Deploy/QueueFromGitOpsPage.tsx | 138 +++++++++--------- 2 files changed, 90 insertions(+), 69 deletions(-) create mode 100644 packages/website/src/components/Button.tsx diff --git a/packages/website/src/components/Button.tsx b/packages/website/src/components/Button.tsx new file mode 100644 index 000000000..dde3c7df6 --- /dev/null +++ b/packages/website/src/components/Button.tsx @@ -0,0 +1,21 @@ +import { ReactNode } from 'react'; +import { + Button as ChakraButton, + ButtonProps as ChakraButtonProps, + Tooltip, +} from '@chakra-ui/react'; + +type Props = { + disabledReason?: string | false; + children?: ReactNode; +} & Omit; + +export function Button({ children, disabledReason, ...rest }: Props) { + return ( + + + {children} + + + ); +} diff --git a/packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx b/packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx index 52ce8c23d..0e68f0d04 100644 --- a/packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx +++ b/packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx @@ -22,7 +22,6 @@ import { Alert, AlertIcon, Box, - Button, Code, Container, Flex, @@ -50,6 +49,7 @@ import { import NextLink from 'next/link'; import { useRouter } from 'next/navigation'; import { Alert as AlertCannon } from '@/components/Alert'; +import { Button as ButtonCannon } from '@/components/Button'; import React, { useEffect, useMemo, useState } from 'react'; import { encodeAbiParameters, @@ -553,31 +553,33 @@ export default function QueueFromGitOps() { ) ); - const disablePreviewButton = - loadingDataForDeploy || - chainId !== currentSafe?.chainId || - !cannonDefInfo?.def || - buildState.status === 'building' || - buildState.status === 'success' || + const previewDisabledReason: string = + (loadingDataForDeploy && 'Loading package data...') || + (chainId !== currentSafe?.chainId && 'Wallet Chain ID is incorrect') || + (!cannonDefInfo?.def && 'Cannon chain definition could not be loaded') || + (buildState.status === 'building' && 'Simulation in progress...') || + (buildState.status === 'success' && 'Build is complete') || (onChainPrevPkgQuery.isFetched && !prevDeployLocation && tomlRequiresPrevPackage && - !previousPackageInput) || - !canTomlBeDeployedUsingWebsite; + !previousPackageInput && + 'Loading previous package data...') || + (!canTomlBeDeployedUsingWebsite && + 'Package is not deployable with website (see alert)') || + ''; + // TODO: clean up, disabled reason handling is kind of wierd here const PreviewButton = ({ message }: { message?: string }) => ( - - - + + {loadingDataForDeploy + ? 'Loading required data...' + : 'Preview Transactions to Queue'} + ); function renderCannonFileInput() { @@ -876,7 +878,7 @@ export default function QueueFromGitOps() { {renderAlertMessage()} {chainId !== currentSafe?.chainId ? ( - + ) : ( )} @@ -943,7 +945,7 @@ export default function QueueFromGitOps() { the button below. - + ) : deployer.executionProgress.length < deployer.queuedTransactions.length ? ( @@ -1040,55 +1042,53 @@ export default function QueueFromGitOps() { {stager.execConditionFailed && (buildState.result?.safeSteps.length || 0) > 0 ? ( - - - - ) : null} - - - + {stager.signing ? ( + <> + Currently Signing + + + ) : ( + 'Queue & Sign' + )} + + ) : null} + { + execTxn.writeContract(stager.executeTxnConfig!, { + onSuccess: () => { + router.push(links.DEPLOY); + + toast({ + title: 'You successfully executed the transaction.', + status: 'success', + duration: 5000, + isClosable: true, + }); + }, + }); + }} + > + Execute + )}