Skip to content

Commit

Permalink
use actual formState instead of self mantained state
Browse files Browse the repository at this point in the history
  • Loading branch information
peetzweg committed Feb 2, 2024
1 parent d623968 commit b753f5f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions frontend/src/components/web3/greeter-contract-interactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const GreeterContractInteractions: FC = () => {
const { typedContract } = useRegisteredTypedContract(ContractIds.Greeter, GreeterContract)
const [greeterMessage, setGreeterMessage] = useState<string>()
const [fetchIsLoading, setFetchIsLoading] = useState<boolean>()
const [updateIsLoading, setUpdateIsLoading] = useState<boolean>()
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
})
Expand Down Expand Up @@ -72,8 +71,6 @@ export const GreeterContractInteractions: FC = () => {
return
}

// Send transaction
setUpdateIsLoading(true)
try {
await contractTxWithToast(api, activeAccount.address, contract, 'setMessage', {}, [
newMessage,
Expand All @@ -82,7 +79,6 @@ export const GreeterContractInteractions: FC = () => {
} catch (e) {
console.error(e)
} finally {
setUpdateIsLoading(false)
fetchGreeting()
}
}
Expand Down Expand Up @@ -121,12 +117,12 @@ export const GreeterContractInteractions: FC = () => {
<FormLabel className="text-base">Update Greeting</FormLabel>
<FormControl>
<div className="flex gap-2">
<Input disabled={updateIsLoading} {...register('newMessage')} />
<Input disabled={form.formState.isSubmitting} {...register('newMessage')} />
<Button
type="submit"
className="bg-primary font-bold"
disabled={fetchIsLoading || updateIsLoading}
isLoading={updateIsLoading}
disabled={fetchIsLoading || form.formState.isSubmitting}
isLoading={form.formState.isSubmitting}
>
Submit
</Button>
Expand Down

0 comments on commit b753f5f

Please sign in to comment.