-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix contract_name input * Create custom contract fn * Merging the loop solution in home * Refactoring * Fixing name typo error * Adding toast notification * Fixing newDeploy on Step3 * Parsin Record to json string * fix layout * Fixing custom Token img on contracts table * Adding useForm * Fixing deploy psp contracts * Fix typo on Routes --------- Co-authored-by: Agustín Longoni <[email protected]>
- Loading branch information
1 parent
df28515
commit c69e76a
Showing
49 changed files
with
1,151 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createContext, useContext } from 'react' | ||
|
||
interface ApiVersionContextProps { | ||
version: string | null | ||
} | ||
|
||
const ApiVersionContext = createContext<ApiVersionContextProps>({ | ||
version: null | ||
}) | ||
|
||
export const useApiVersion = () => { | ||
return useContext(ApiVersionContext) | ||
} | ||
|
||
export default ApiVersionContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
import { TokenType } from '@/domain/TokenType' | ||
import { ContractCompiledRaw } from '@/services' | ||
import { ContractType } from '@/domain/repositories/DeploymentRepository' | ||
import { ChainId } from '@/services/useink/chains' | ||
|
||
export type ContractMetadata = ContractCompiledRaw | ||
|
||
export interface UserContractDetails { | ||
userAddress: string | ||
blockchain: ChainId | ||
address: string | ||
txHash: string | undefined | ||
codeHash: string | ||
type: ContractType | ||
uuid: string | ||
name: string | ||
address: string | ||
network: ChainId | ||
codeId: string | ||
userAddress: string | ||
txHash?: string | ||
date: string | ||
type: ContractType | ||
abi?: Record<string, unknown> | ||
external: boolean // Contracts not deployed by PCW are custom and external | ||
hidden: boolean | ||
} | ||
|
||
export type ContractCompiled = Pick< | ||
export type UserContractDetailsDraft = Omit< | ||
UserContractDetails, | ||
'userAddress' | 'codeHash' | 'name' | 'name' | ||
> & { | ||
type: TokenType | ||
} | ||
'uuid' | 'external' | ||
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface OnCallbacks<I> { | ||
onStartCallback?: () => void | ||
onSuccessCallback?: (result: I) => void | ||
onErrorCallback?: (e: unknown) => void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,12 @@ | ||
import { ChainId } from '@/services/useink/chains' | ||
import { TokenType } from '../TokenType' | ||
import { UserContractDetailsDraft } from '../UserContractDetails' | ||
|
||
export type ContractType = TokenType | 'custom' | ||
export type UpdateDeployment = Partial<DeploymentItem> | ||
|
||
export interface DeploymentItem { | ||
contractName: string | ||
contractAddress: string | ||
network: ChainId | ||
codeId: string | ||
userAddress: string | ||
txHash?: string | ||
date: string | ||
contractType: ContractType | ||
externalAbi?: Record<string, unknown> | ||
hidden: boolean | ||
} | ||
export type UpdateDeployment = Partial<UserContractDetailsDraft> | ||
|
||
export interface IDeploymentsRepository<A, B> { | ||
add: (deployment: DeploymentItem) => Promise<A> | ||
findBy: (userAddress: string, networkId?: ChainId) => Promise<B> | ||
add: (deployment: UserContractDetailsDraft) => Promise<A> | ||
findBy: (userAddress: string, network?: ChainId) => Promise<B> | ||
updateBy: (deployment: UpdateDeployment) => Promise<A> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { useCallback, useState } from 'react' | ||
|
||
import { useLocalDbContext } from '@/context/LocalDbContext' | ||
import { useAddUserContracts } from '@/hooks/userContracts/useAddUserContracts' | ||
import { deploymentItemToUserContractDetails } from '@/services/transformers/toUserContractDetails' | ||
import { UserContractDetailsDraft } from '@/domain' | ||
import { OnCallbacks } from '@/domain/common/OnCallbacks' | ||
|
||
interface NewDeploymentProps extends OnCallbacks<string> { | ||
userContract: UserContractDetailsDraft | ||
} | ||
|
||
interface UseServiceAddDeployment { | ||
newDeployment: (props: NewDeploymentProps) => Promise<string | undefined> | ||
isLoading: boolean | ||
error?: string | ||
} | ||
|
||
export function useCreateDeployments(): UseServiceAddDeployment { | ||
const [isLoading, setIsLoading] = useState(false) | ||
const [error, setError] = useState<string | undefined>() | ||
const { deploymentsRepository } = useLocalDbContext() | ||
const { addUserContract } = useAddUserContracts() | ||
|
||
const newDeployment = useCallback( | ||
async ({ | ||
userContract, | ||
onSuccessCallback, | ||
onErrorCallback | ||
}: NewDeploymentProps): Promise<string | undefined> => { | ||
setError(undefined) | ||
setIsLoading(true) | ||
|
||
try { | ||
const response = await deploymentsRepository.add(userContract) | ||
if (response.error) { | ||
throw Error(response.error.message) | ||
} | ||
|
||
const newDeployId = response['data'] | ||
const userContractWithId = deploymentItemToUserContractDetails( | ||
userContract, | ||
newDeployId | ||
) | ||
addUserContract(userContractWithId) | ||
|
||
onSuccessCallback?.(newDeployId) | ||
return newDeployId | ||
} catch (error) { | ||
const _errorMsg = `An error occurred when trying to upload the deployed contract on the server` | ||
setError(_errorMsg) | ||
onErrorCallback?.(error) | ||
} finally { | ||
setIsLoading(false) | ||
} | ||
}, | ||
[addUserContract, deploymentsRepository] | ||
) | ||
|
||
return { newDeployment, isLoading, error } | ||
} |
10 changes: 5 additions & 5 deletions
10
...eployments/useListContractsDeployments.ts → src/hooks/deployments/useListDeployments.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.