1- "use client" ;
2-
31// @refresh reset
4- import { useReducer , useState } from "react" ;
2+ import { useMemo , useReducer , useState } from "react" ;
53import dynamic from "next/dynamic" ;
6- import { ContractReadMethods } from "./ContractReadMethods" ;
74import { Address , Balance } from "~~/components/scaffold-stark" ;
85import {
96 useDeployedContractInfo ,
@@ -17,12 +14,12 @@ import {
1714import { ContractVariables } from "./ContractVariables" ;
1815import { ClassHash } from "~~/components/scaffold-stark/ClassHash" ;
1916
20- const ContractWriteMethods = dynamic (
21- ( ) =>
22- import ( "./ContractWriteMethods" ) . then ( ( mod ) => mod . ContractWriteMethods ) ,
23- {
24- loading : ( ) => < p > Loading Write Methods... </ p > ,
25- } ,
17+ const ContractWriteMethods = dynamic ( ( ) =>
18+ import ( "./ContractWriteMethods" ) . then ( ( mod ) => mod . ContractWriteMethods ) ,
19+ ) ;
20+
21+ const ContractReadMethods = dynamic ( ( ) =>
22+ import ( "./ContractReadMethods" ) . then ( ( mod ) => mod . ContractReadMethods ) ,
2623) ;
2724
2825type ContractUIProps = {
@@ -54,6 +51,17 @@ export const ContractUI = ({
5451 { id : "write" , label : "Write" } ,
5552 ] ;
5653
54+ const tabContent = useMemo ( ( ) => {
55+ return activeTab === "write" ? (
56+ < ContractWriteMethods
57+ deployedContractData = { deployedContractData }
58+ onChange = { triggerRefreshDisplayVariables }
59+ />
60+ ) : (
61+ < ContractReadMethods deployedContractData = { deployedContractData } />
62+ ) ;
63+ } , [ activeTab , deployedContractData , triggerRefreshDisplayVariables ] ) ;
64+
5765 if ( status === ContractCodeStatus . NOT_FOUND ) {
5866 return (
5967 < p className = "text-3xl mt-14" >
@@ -81,7 +89,7 @@ export const ContractUI = ({
8189 < span className = "font-bold text-sm" > Balance:</ span >
8290 < Balance
8391 address = { deployedContractData . address }
84- className = "px-0 h-1.5 min-h-[0.375rem] text-network"
92+ className = "px-0 h-1.5 min-h-1.5 text-network"
8593 />
8694 </ div >
8795 </ div >
@@ -102,13 +110,13 @@ export const ContractUI = ({
102110 </ div >
103111
104112 < div className = "col-span-1 lg:col-span-2 flex flex-col gap-6" >
105- < div className = "tabs tabs-boxed border border-[#8A45FC] rounded-[5px] bg-transparent" >
113+ < div className = "tabs tabs-box border border-[#8A45FC] rounded-[5px] bg-transparent" >
106114 { tabs . map ( ( tab ) => (
107115 < a
108116 key = { tab . id }
109- className = { `tab h-10 ${
117+ className = { `tab h-10 w-1/2 ${
110118 activeTab === tab . id
111- ? "tab-active ! bg-[#8A45FC] ! rounded-[5px] ! text-white"
119+ ? "tab-active bg-[#8A45FC]! rounded-[5px]! text-white! w-1/2 "
112120 : ""
113121 } `}
114122 onClick = { ( ) => setActiveTab ( tab . id ) }
@@ -119,19 +127,7 @@ export const ContractUI = ({
119127 </ div >
120128 < div className = "z-10" >
121129 < div className = "rounded-[5px] border border-[#8A45FC] flex flex-col relative bg-component" >
122- < div className = "p-5 divide-y divide-secondary" >
123- { activeTab === "read" && (
124- < ContractReadMethods
125- deployedContractData = { deployedContractData }
126- />
127- ) }
128- { activeTab === "write" && (
129- < ContractWriteMethods
130- deployedContractData = { deployedContractData }
131- onChange = { triggerRefreshDisplayVariables }
132- />
133- ) }
134- </ div >
130+ < div className = "p-5 divide-y divide-secondary" > { tabContent } </ div >
135131 { deployedContractLoading && (
136132 < div className = "absolute inset-0 rounded-[5px] bg-white/20 z-10" >
137133 < div className = "animate-spin h-4 w-4 border-2 border-purple-500 border-t-transparent rounded-full absolute top-4 right-4" />
0 commit comments