diff --git a/src/domain/UserContractDetails.ts b/src/domain/UserContractDetails.ts index 3c3ab550..49160dd7 100644 --- a/src/domain/UserContractDetails.ts +++ b/src/domain/UserContractDetails.ts @@ -16,7 +16,8 @@ export interface UserContractDetails { date: string type: ContractType abi?: Record - external: boolean // Contracts not deployed by PCW are custom and external + // TODO + external: boolean // Represents a contract that has not been aggregated by the connected wallet accounts. hidden: boolean } diff --git a/src/domain/repositories/DeploymentRepository.ts b/src/domain/repositories/DeploymentRepository.ts index 4c6b094a..1fadc438 100644 --- a/src/domain/repositories/DeploymentRepository.ts +++ b/src/domain/repositories/DeploymentRepository.ts @@ -1,12 +1,16 @@ import { ChainId } from '@/services/useink/chains' import { TokenType } from '../TokenType' -import { UserContractDetailsDraft } from '../UserContractDetails' +import { + UserContractDetails, + UserContractDetailsDraft +} from '../UserContractDetails' -export type ContractType = TokenType | 'custom' +export type ContractType = TokenType | 'custom' // custom contracts are generally deployed outside the PCW export type UpdateDeployment = Partial export interface IDeploymentsRepository { add: (deployment: UserContractDetailsDraft) => Promise findBy: (userAddress: string, network?: ChainId) => Promise updateBy: (deployment: UpdateDeployment) => Promise + get(uuid: string): Promise } diff --git a/src/hooks/userContracts/useFindUserContract.ts b/src/hooks/userContracts/useFindUserContract.ts index 6113bb3f..113abb3e 100644 --- a/src/hooks/userContracts/useFindUserContract.ts +++ b/src/hooks/userContracts/useFindUserContract.ts @@ -1,6 +1,6 @@ import { useLocalDbContext } from '@/context/LocalDbContext' import { UserContractDetails } from '@/domain' -import { useEffect, useState } from 'react' +import { useCallback, useEffect, useState } from 'react' interface UseFindUserContract { userContract: UserContractDetails | undefined @@ -14,15 +14,30 @@ export function useFindUserContract(uuid: string): UseFindUserContract { >() const [isLoading, setIsLoading] = useState(false) const [requested, setRequested] = useState(false) - const { userContractsRepository, apiCompileContractRepository } = - useLocalDbContext() + const { + userContractsRepository, + apiCompileContractRepository, + apiDeploymentsRepository + } = useLocalDbContext() + + const getUserContract = useCallback( + async (uuid: UserContractDetails['uuid']) => { + let knownUserContract = await userContractsRepository.get(uuid) + + if (!knownUserContract) { + knownUserContract = await apiDeploymentsRepository.get(uuid) + } + + return knownUserContract + }, + [apiDeploymentsRepository, userContractsRepository] + ) useEffect(() => { if (!uuid) return setIsLoading(true) - userContractsRepository - .get(uuid) + getUserContract(uuid) .then(async response => { if (response && !response?.abi) { const compiled = await apiCompileContractRepository.search( @@ -36,7 +51,12 @@ export function useFindUserContract(uuid: string): UseFindUserContract { setRequested(true) }) .finally(() => setIsLoading(false)) - }, [apiCompileContractRepository, userContractsRepository, uuid]) + }, [ + apiCompileContractRepository, + getUserContract, + userContractsRepository, + uuid + ]) return { userContract, isLoading, requested } } diff --git a/src/pages/contract-detail/index.tsx b/src/pages/contract-detail/index.tsx index d42b057d..11794146 100644 --- a/src/pages/contract-detail/index.tsx +++ b/src/pages/contract-detail/index.tsx @@ -1,11 +1,9 @@ import { ContractDetailSkeleton } from '@/view/CustomContracts/detail/SkeletonContractDetail' import MainContainer from '@/view/layout/MainContainer' import ContractDetail from '@/view/ContractDetailView' -import { useModalBehaviour } from '@/hooks/useModalBehaviour' import { useRouter } from 'next/router' import { useFindUserContract } from '@/hooks/userContracts/useFindUserContract' import { useHasMounted } from '@/hooks/useHasMounted' -import { useDownloadMetadata } from '@/view/components/ContractsTable/useDownloadMetadata' export default function CustomContractDetailPage() { const router = useRouter() @@ -13,8 +11,6 @@ export default function CustomContractDetailPage() { const { userContract, requested, isLoading } = useFindUserContract( uuid as string ) - const { onDownloadSource } = useDownloadMetadata(userContract) - const modalBehaviour = useModalBehaviour() const hasMounted = useHasMounted() if (!userContract || !hasMounted || isLoading) { @@ -28,13 +24,7 @@ export default function CustomContractDetailPage() { return ( - {userContract && ( - - )} + {userContract && } ) } diff --git a/src/view/ContractDetailView/ContractInteractionForm./ReadMethodsForm.tsx b/src/view/ContractDetailView/ContractInteractionForm/ReadMethodsForm.tsx similarity index 98% rename from src/view/ContractDetailView/ContractInteractionForm./ReadMethodsForm.tsx rename to src/view/ContractDetailView/ContractInteractionForm/ReadMethodsForm.tsx index 061bdda3..8d6d72ad 100644 --- a/src/view/ContractDetailView/ContractInteractionForm./ReadMethodsForm.tsx +++ b/src/view/ContractDetailView/ContractInteractionForm/ReadMethodsForm.tsx @@ -28,9 +28,10 @@ export function ReadMethodsForm({ const [outcome, setOutcome] = useState('') useEffect(() => { + if (!expanded) return caller.send(inputData) // eslint-disable-next-line react-hooks/exhaustive-deps - }, [inputData]) + }, [inputData, expanded]) useEffect(() => { if (caller.result?.ok) { diff --git a/src/view/ContractDetailView/ContractInteractionForm./WriteMethodsForm.tsx b/src/view/ContractDetailView/ContractInteractionForm/WriteMethodsForm.tsx similarity index 100% rename from src/view/ContractDetailView/ContractInteractionForm./WriteMethodsForm.tsx rename to src/view/ContractDetailView/ContractInteractionForm/WriteMethodsForm.tsx diff --git a/src/view/ContractDetailView/ContractInteractionForm./index.tsx b/src/view/ContractDetailView/ContractInteractionForm/index.tsx similarity index 100% rename from src/view/ContractDetailView/ContractInteractionForm./index.tsx rename to src/view/ContractDetailView/ContractInteractionForm/index.tsx diff --git a/src/view/ContractDetailView/ContractInteractionForm./styled.ts b/src/view/ContractDetailView/ContractInteractionForm/styled.ts similarity index 100% rename from src/view/ContractDetailView/ContractInteractionForm./styled.ts rename to src/view/ContractDetailView/ContractInteractionForm/styled.ts diff --git a/src/view/ContractDetailView/ContractsTabInteraction.tsx b/src/view/ContractDetailView/ContractsTabInteraction.tsx index 5f304c95..34fbe06c 100644 --- a/src/view/ContractDetailView/ContractsTabInteraction.tsx +++ b/src/view/ContractDetailView/ContractsTabInteraction.tsx @@ -10,7 +10,7 @@ import { import { useContractPromiseFromSource } from '@/hooks/useContractPromise' import { FallbackSpinner } from '@/components/FallbackSpinner' import { ContractPromise, Registry } from '@/services/substrate/types' -import { ContractInteractionForm } from './ContractInteractionForm.' +import { ContractInteractionForm } from './ContractInteractionForm' const types: ContractTabType[] = ['Read Contract', 'Write Contract'] const groupedIndex: Record = { diff --git a/src/view/ContractDetailView/index.tsx b/src/view/ContractDetailView/index.tsx index b7a1dd5c..9ac81219 100644 --- a/src/view/ContractDetailView/index.tsx +++ b/src/view/ContractDetailView/index.tsx @@ -8,7 +8,6 @@ import ShareIcon from '@mui/icons-material/Share' import DownloadIcon from '@mui/icons-material/Download' import { getChain } from '@/constants/chains' import NetworkBadge from '@/view/components/NetworkBadge' -import { UseModalBehaviour } from '@/hooks/useModalBehaviour' import { UserContractDetails, UserContractDetailsWithAbi } from '@/domain' import { isoDate, @@ -31,19 +30,15 @@ import CancelIcon from '@mui/icons-material/Cancel' import { UpdateDeployment } from '@/domain/repositories/DeploymentRepository' import { useUpdateUserContracts } from '@/hooks/userContracts/useUpdateUserContracts' -import { UserContractTableItem } from '@/domain/wizard/ContractTableItem' +import { useDownloadMetadata } from '@/components/ContractsTable/useDownloadMetadata' + interface Props { - modalBehaviour: UseModalBehaviour userContract: UserContractDetails - onDownloadSource: (contract: UserContractTableItem) => void } interface AbiSource { source: { language: string } } -export default function ContractDetail({ - userContract, - onDownloadSource -}: Props): JSX.Element { +export default function ContractDetail({ userContract }: Props): JSX.Element { const [openShareModal, setOpenShareModal] = React.useState(false) const url = getUserContractUrl(userContract) const { accountConnected } = useNetworkAccountsContext() @@ -57,6 +52,7 @@ export default function ContractDetail({ const anyInvalidField: boolean = Object.values(formData).some( field => (field.required && !field.value) || field.error !== null ) + const { onDownloadSource } = useDownloadMetadata(userContract) const handleUpdateContractName = () => { const updatedContract: UpdateDeployment = { @@ -253,7 +249,7 @@ export default function ContractDetail({ - Deployed by + Added by {''} {truncateAddress(userContract.userAddress, 4)} diff --git a/src/view/ContractDetailsInteraction/index.tsx b/src/view/ContractDetailsInteraction/index.tsx deleted file mode 100644 index b43f555f..00000000 --- a/src/view/ContractDetailsInteraction/index.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import { Box, Typography } from '@mui/material' -import React from 'react' -import { UserContractDetails } from '@/domain' -import BasicTabs from '@/components/Tabs' -import SimpleAccordion from '@/components/Accordion' - -type ContractTabType = 'Read Contract' | 'Write Contract' -const types: ContractTabType[] = ['Read Contract', 'Write Contract'] - -interface Props { - userContract: UserContractDetails -} - -export function ContractDetailsInteraction({ userContract }: Props) { - const [type, setType] = React.useState(types[0]) - const isReadContract = type === 'Read Contract' - - const handleChange = (newValue: number) => { - setType(types[newValue]) - } - - return ( - <> - - - <> - {/* {type} */} - {isReadContract ? ( - <> - - Learn more about your contract 🔁 - - - Let'start to work with your contract displaying each - method. - - - ) : ( - <> - - Interact with your contract 🔁 - - - Let's start to work with your contract doing different - querys. - - - )} - {/* */} - - - - - ) -}