Skip to content

Commit

Permalink
feat: resolved bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
RutvikGhaskataEalf committed Nov 27, 2024
1 parent fcacf93 commit ea23bb8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/aelf-smartcontract-viewer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aelf-smartcontract-viewer",
"version": "1.1.0",
"version": "1.1.1",
"type": "module",
"main": "dist/aelf-smartcontract-viewer.js",
"types": "dist/aelf-smartcontract-viewer.umd.cjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@

.contract-view-container.dark .ant-collapse-content {
border-color: #eee5 !important;
}
}

.contract-view-container.dark .accordion-item h2{
background-color: #fff1;
border-radius: 7px 7px 0 0;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useMemo } from "react";
import React, { useState, useMemo, useEffect } from "react";
import { Divider, Input, Button } from "@nextui-org/react";
import { useForm } from "react-hook-form";
import { IWalletInfo } from "aelf-sdk/types/wallet";
Expand Down Expand Up @@ -43,24 +43,32 @@ const FormItem: React.FC<FormItemProps> = ({
wallet,
disabled,
}) => {
const { handleSubmit, control, watch, setValue } = useForm();
const { handleSubmit, control, watch, setValue } = useForm({});
const [response, setResponse] = useState<any>(null);
const [loading, setLoading] = useState<boolean>(false);
const [isSubmittable, setIsSubmittable] = useState(false);

const values = watch();
const isSubmittable = useMemo(
() => Object.values(values).every((item) => item || item === 0),
[values]
);

useEffect(() => {
if (Object.values(values).every((item) => item || item === 0)) {
setIsSubmittable(true);
} else {
setIsSubmittable(false);
}
}, [values]);

const handleContractCall = async (data: any, isWrite: boolean) => {
setLoading(true);
console.log("isWrite", isWrite, (Object.keys(data).length && data) || {});
try {
const result = isWrite
? await contract[name](data)
: await contract[name].call(data || {});
? await contract[name](Object.keys(data).length && (data || {}))
: await contract[name].call(Object.keys(data).length && (data || {}));
console.log("result", result);
setResponse(result || { data: null });
} catch (e: any) {
console.log("error", e);
setResponse(e instanceof Error ? formatError(e) : e);
} finally {
setLoading(false);
Expand All @@ -79,9 +87,11 @@ const FormItem: React.FC<FormItemProps> = ({
{ele.type === "int64" ? (
<ValueFormItem
data={ele}
inputValue={values[ele.name]}
type={ele.type}
setFieldValue={setValue}
disabled={disabled}
props={{ ...control.register(ele.name) }}
/>
) : (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ interface ValueFormItemProps {
data: IInputItem;
setFieldValue: (key: string, value: string) => void;
type: string;
inputValue: string | number;
disabled: boolean;
props?: React.InputHTMLAttributes<HTMLInputElement>;
}

const ValueFormItem: React.FC<ValueFormItemProps> = ({
data,
inputValue,
setFieldValue,
type,
disabled,
Expand Down Expand Up @@ -157,6 +159,8 @@ const ValueFormItem: React.FC<ValueFormItemProps> = ({
type="text"
radius="none"
// @ts-ignore
value={inputValue}
// @ts-ignore
size="sm"
className="border-[1px] my-2"
disabled={disabled}
Expand Down
2 changes: 1 addition & 1 deletion packages/aelf-smartcontract-viewer/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ContractView } from "./component/contract-view/index";
createRoot(document.getElementById("root")!).render(
<StrictMode>
<ContractView
address="2vojXfVXL3iaKTwJue4sEa5fpbhcdrscDHw81SnCtCdWLu4JFs"
address="2tGSfUSPzPAfJR6sj6mQYV349ryrsg6VmuW2SQ3dfv8D5wUXNc"
rpcUrl="https://tdvw-test-node.aelf.io" // i.e = https://explorer-test-side02.aelf.io/chain
contractName="Smart Contract"
/>
Expand Down

0 comments on commit ea23bb8

Please sign in to comment.