-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: components to get parameters of contract
- Loading branch information
Showing
9 changed files
with
140 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.param, .add-remove-container { | ||
display: flex; | ||
justify-content: space-between; | ||
margin-top: 0.5rem; | ||
} | ||
|
||
.add-button, .remove-button { | ||
width: 47%; | ||
} | ||
|
||
.param-textfield { | ||
width: 70%; | ||
} | ||
|
||
.param-dropdown { | ||
width: 25%; | ||
} |
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,37 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import { IDeployForm } from '@/types'; | ||
import { ArgTypes } from '@/enums.ts'; | ||
|
||
const useDeployParams = () => { | ||
const form = useFormContext<IDeployForm>(); | ||
const [paramsCount, setParamsCount] = useState(0); | ||
|
||
const addParam = () => { | ||
setParamsCount(paramsCount + 1); | ||
}; | ||
|
||
const removeParam = () => { | ||
if (paramsCount === 0) return; | ||
setParamsCount(paramsCount - 1); | ||
}; | ||
|
||
useEffect(() => { | ||
form.resetField('params'); | ||
for (let i = 0; i < paramsCount; i++) { | ||
form.setValue(`params.${i}` as const, { | ||
value: '', | ||
type: Object.getOwnPropertyNames(ArgTypes).filter((value) => !isNaN(Number(value)))[0], | ||
}); | ||
} | ||
}, [paramsCount]); | ||
|
||
return { | ||
form, | ||
paramsCount, | ||
addParam, | ||
removeParam, | ||
}; | ||
}; | ||
|
||
export default useDeployParams; |
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,48 @@ | ||
import './DeployParams.css'; | ||
import { VSCodeButton, VSCodeDropdown, VSCodeOption, VSCodeTextField } from '@vscode/webview-ui-toolkit/react'; | ||
import useDeployParams from '@components/DeployParams/DeployParams.logic.ts'; | ||
import { ArgTypes } from '@/enums.ts'; | ||
|
||
const DeployParams = () => { | ||
const logic = useDeployParams(); | ||
|
||
return ( | ||
<div> | ||
<div className="add-remove-container"> | ||
<VSCodeButton className="add-button" onClick={logic.addParam}> | ||
Add param | ||
</VSCodeButton> | ||
<VSCodeButton className="remove-button" onClick={logic.removeParam}> | ||
Remove param | ||
</VSCodeButton> | ||
</div> | ||
{logic.paramsCount > 0 && | ||
Array.from({ length: logic.paramsCount }).map((_, index) => { | ||
return ( | ||
<div key={index}> | ||
<label htmlFor="param">Param {index + 1}:</label> | ||
<div className="param"> | ||
<VSCodeTextField | ||
className="param-textfield" | ||
{...logic.form.register(`params.${index}.value` as const)} | ||
/> | ||
<VSCodeDropdown className="param-dropdown" {...logic.form.register(`params.${index}.type` as const)}> | ||
{Object.getOwnPropertyNames(ArgTypes) | ||
.filter((value) => isNaN(Number(value))) | ||
.map((argType, index) => { | ||
return ( | ||
<VSCodeOption key={argType} value={index.toString()}> | ||
{argType} | ||
</VSCodeOption> | ||
); | ||
})} | ||
</VSCodeDropdown> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default DeployParams; |
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,18 @@ | ||
export enum ArgTypes { | ||
STRING = 0, | ||
BOOL = 1, | ||
U8 = 2, | ||
U32 = 3, | ||
U64 = 4, | ||
I128 = 5, | ||
U128 = 6, | ||
U256 = 7, | ||
I32 = 8, | ||
I64 = 9, | ||
F32 = 10, | ||
F64 = 11, | ||
ARRAY = 12, | ||
UINT8ARRAY = 13, | ||
SERIALIZABLE = 14, | ||
SERIALIZABLE_OBJECT_ARRAY = 15, | ||
} |
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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { ArgTypes } from '@/enums.ts'; | ||
|
||
export type VSCode = any; | ||
|
||
export interface IParam { | ||
type: ArgTypes; | ||
value: any; | ||
} | ||
|
||
export interface IDeployForm { | ||
environmentId: string; | ||
contractId: string; | ||
walletId: string; | ||
fees: number; | ||
value: number; | ||
params: any[]; | ||
params: Param[]; | ||
} |
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