Skip to content

Commit

Permalink
Adding contract_type field on the API
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypalacios committed Oct 3, 2023
1 parent bbc4d69 commit a50dec3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
24 changes: 4 additions & 20 deletions src/domain/UserContractDetails.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TokenType } from '@/domain/TokenType'
import { ContractCompiledRaw } from '@/infrastructure'
import { ContractType } from '@/domain/repositories/DeploymentRepository'

export type ContractMetadata = ContractCompiledRaw

Expand All @@ -9,11 +10,11 @@ export interface UserContractDetails {
address: string
txHash: string
codeHash: string
type?: TokenType
type: ContractType
name: string
abi?: Record<string, unknown>
date: string
external: boolean
abi?: Record<string, unknown>
external: boolean // Contracts not deployed by PCW are custom and external
}

export type ContractCompiled = Pick<
Expand All @@ -22,20 +23,3 @@ export type ContractCompiled = Pick<
> & {
type: TokenType
}

// export type ContractDeployed = Required<ContractDetails> & {
// status: 'deployed'
// }
// export type UserContracts = ContractCompiled | ContractDeployed

// export function isContractCompiled(
// contract: UserContracts
// ): contract is ContractCompiled {
// return contract.status === 'compiled'
// }

// export function isContractDeployed(
// contract: UserContracts
// ): contract is ContractDeployed {
// return contract.status === 'deployed'
// }
6 changes: 4 additions & 2 deletions src/domain/repositories/DeploymentRepository.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { ChainId } from '@/infrastructure/useink/chains'
import { TokenType } from '../TokenType'

// TODO implement on API
type ContractType = TokenType | 'custom'
export type ContractType = TokenType | 'custom'

export interface DeploymentItem {
contractName: TokenType
contractAddress: string
network: ChainId
codeId: string
userAddress: string
txHash?: string
date: string
contractType: ContractType
externalAbi?: Record<string, unknown>
}

export interface IDeploymentsRepository<A, B> {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/deployments/useCreateContractsDeployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { useCallback, useState } from 'react'
import { DeploymentItem } from '@/domain/repositories/DeploymentRepository'
import { useLocalDbContext } from '@/context/LocalDbContext'

interface UseAddDeployment {
interface UseServiceAddDeployment {
newDeployment: (deployment: DeploymentItem) => Promise<string | undefined>
isLoading: boolean
error?: string
}

export function useCreateContractDeployments(): UseAddDeployment {
export function useCreateContractDeployments(): UseServiceAddDeployment {
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState<string | undefined>()
const { deploymentsRepository } = useLocalDbContext()
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useDeployContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export const useDeployContract = (): ReturnValue & {
codeHash: code_id,
name: tokenType,
abi: metadataAbi.json,
type: tokenType,
date: new Date().toISOString(),
external: false
}
Expand Down
18 changes: 16 additions & 2 deletions src/infrastructure/backendApi/ApiDeploymentRepository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BackendApiConfig } from '@/constants/config'
import {
ContractType,
DeploymentItem,
IDeploymentsRepository
} from '@/domain/repositories/DeploymentRepository'
Expand All @@ -13,7 +14,10 @@ interface DeploymentRaw {
network: ChainId
code_id: string
user_address: string
tx_hash?: string
date: string
contract_type: ContractType
external_abi?: string
}

export type IApiDeploymentRepository = IDeploymentsRepository<
Expand All @@ -28,7 +32,12 @@ function adaptDeployment(deploymentRaw: DeploymentRaw): DeploymentItem {
network: deploymentRaw.network,
codeId: deploymentRaw.code_id,
userAddress: deploymentRaw.user_address,
date: deploymentRaw.date
txHash: deploymentRaw.tx_hash,
date: deploymentRaw.date,
contractType: deploymentRaw.contract_type,
externalAbi: deploymentRaw.external_abi
? JSON.parse(deploymentRaw.external_abi)
: undefined
}
}

Expand All @@ -46,7 +55,12 @@ export class ApiDeploymentRepository implements IApiDeploymentRepository {
network: deployment.network,
code_id: deployment.codeId,
user_address: deployment.userAddress,
date: deployment.date
tx_hash: deployment.txHash,
date: deployment.date,
contract_type: deployment.contractType,
...(deployment.externalAbi && {
external_abi: deployment.externalAbi
})
})
}
)
Expand Down
8 changes: 5 additions & 3 deletions src/view/wizardView/Step3Deploy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ export default function Step3Deploy({
blockchain: networkConnected,
successCallback: userContractsDetail => {
newDeployment({
userAddress: accountConnected.address,
contractName: userContractsDetail.name as TokenType,
codeId: userContractsDetail.codeHash,
contractAddress: userContractsDetail.address,
network: userContractsDetail.blockchain as ChainId,
date: userContractsDetail.date
codeId: userContractsDetail.codeHash,
userAddress: accountConnected.address,
txHash: userContractsDetail.txHash,
date: userContractsDetail.date,
contractType: userContractsDetail.type
})
addUserContract(userContractsDetail)
}
Expand Down

0 comments on commit a50dec3

Please sign in to comment.