1- import React , { useState , useId , useRef , useEffect } from 'react'
1+ import React , { useState , useRef , useEffect } from 'react'
22import { Tooltip } from './Tooltip'
33import { InputField } from './InputField'
44import { ToolsSecondaryButton } from './ToolsSecondaryButton'
@@ -20,11 +20,10 @@ interface ToolsWalletAddressProps {
2020}
2121
2222export const ToolsWalletAddress = ( { toolName } : ToolsWalletAddressProps ) => {
23- const snap = useSnapshot ( toolState )
23+ const snap = useSnapshot ( toolState , { sync : true } )
2424 const uiActions = useUIActions ( )
2525 const [ error , setError ] = useState < ElementErrors > ( )
2626 const [ isLoading , setIsLoading ] = useState ( false )
27- const generatedId = useId ( )
2827 const inputRef = useRef < HTMLInputElement > ( null )
2928
3029 useEffect ( ( ) => {
@@ -98,6 +97,9 @@ export const ToolsWalletAddress = ({ toolName }: ToolsWalletAddressProps) => {
9897 if ( snap . walletConnectStep !== 'unfilled' ) {
9998 toolActions . setConnectWalletStep ( 'unfilled' )
10099 }
100+ if ( error ) {
101+ setError ( undefined )
102+ }
101103 }
102104
103105 const handleSubmit = ( e : React . FormEvent < HTMLFormElement > ) => {
@@ -107,55 +109,50 @@ export const ToolsWalletAddress = ({ toolName }: ToolsWalletAddressProps) => {
107109 }
108110 }
109111
110- const renderStatusMessage = ( ) => {
112+ const getStatusMessage = ( ) : {
113+ message : string
114+ type : 'error' | 'success' | 'info'
115+ } => {
111116 if ( snap . walletConnectStep === 'error' ) {
112- return (
113- < p className = "w-full text-style-small-standard !text-red-600" >
114- You have not connected your wallet address yet.
115- </ p >
116- )
117+ return {
118+ message : 'You have not connected your wallet address yet.' ,
119+ type : 'error'
120+ }
117121 }
118-
119122 if ( ! snap . isWalletConnected ) {
120- return (
121- < p className = "w-full text-style-small-standard" >
122- If you're connecting your wallet address for the first time,
123- you'll start with the default configuration.
124- < br />
125- You can then customize and save your config as needed.
126- </ p >
127- )
123+ return {
124+ message :
125+ "If you're connecting your wallet address for the first time, you'll start with the default configuration. You can then customize and save your config as needed." ,
126+ type : 'info'
127+ }
128128 }
129-
130129 if ( ! snap . hasRemoteConfigs ) {
131- return (
132- < p className = "w-full text-style-small-standard !text-text-success" >
133- There are no custom edits for the { toolName } correlated to this wallet
134- address but you can start customizing when you want.
135- </ p >
136- )
130+ return {
131+ message : `There are no custom edits for the ${ toolName } correlated to this wallet address but you can start customizing when you want.` ,
132+ type : 'success'
133+ }
137134 }
138135
139- return (
140- < p className = "w-full text-style-small-standard !text-text-success" >
141- We've loaded your configuration.
142- < br />
143- Feel free to keep customizing your { toolName } to fit your style.
144- </ p >
145- )
136+ return {
137+ message : `We've loaded your configuration. Feel free to keep customizing your ${ toolName } to fit your style.` ,
138+ type : 'success'
139+ }
146140 }
141+
142+ const statusMessage = getStatusMessage ( )
147143 return (
148144 < form
149145 onSubmit = { handleSubmit }
150146 className = { cx (
151147 'flex flex-col xl:flex-row xl:items-start gap-2xl p-md bg-white rounded-lg' ,
152148 snap . walletConnectStep === 'error' && 'border border-red-600'
153149 ) }
154- aria-labelledby = { generatedId }
155150 >
156- < div className = "flex flex-col items-start gap-md w-full xl:flex-1 xl:grow" >
151+ < div className = "items-start gap-md w-full xl:flex-1 xl:grow" >
157152 < div className = "inline-flex items-center gap-xs" >
158- < Heading5 id = { generatedId } > Wallet address</ Heading5 >
153+ < Heading5 htmlFor = "wallet-address-url" as = "label" >
154+ Wallet address
155+ </ Heading5 >
159156 < Tooltip >
160157 Your wallet is required in order for us to save this components
161158 configuration for you, link it to the original author, and verify
@@ -164,11 +161,7 @@ export const ToolsWalletAddress = ({ toolName }: ToolsWalletAddressProps) => {
164161 behalf.
165162 </ Tooltip >
166163 </ div >
167-
168- < div
169- id = "wallet-address-input"
170- className = "flex items-start gap-3 w-full"
171- >
164+ < div className = "flex items-start gap-3 w-full pt-md" >
172165 < div className = "flex-1 min-w-0 h-12" >
173166 < InputField
174167 ref = { inputRef }
@@ -178,11 +171,11 @@ export const ToolsWalletAddress = ({ toolName }: ToolsWalletAddressProps) => {
178171 ? undefined
179172 : 'https://walletprovider.com/MyWallet'
180173 }
181- defaultValue = { snap . walletAddress }
182- onBlur = { handleWalletAddressChange }
174+ value = { snap . walletAddress }
175+ onChange = { handleWalletAddressChange }
183176 disabled = { snap . isWalletConnected }
177+ readOnly = { isLoading }
184178 error = { error ?. fieldErrors . walletAddress }
185- aria-labelledby = { generatedId }
186179 />
187180 </ div >
188181 { snap . isWalletConnected && (
@@ -200,16 +193,25 @@ export const ToolsWalletAddress = ({ toolName }: ToolsWalletAddressProps) => {
200193 </ div >
201194 </ div >
202195
203- < div
204- id = "wallet-address-message"
205- className = "flex flex-col w-full xl:max-w-[490px] items-start gap-xs xl:flex-1 xl:grow"
206- >
207- { renderStatusMessage ( ) }
196+ < div className = "flex flex-col w-full xl:max-w-[490px] items-start gap-xs xl:flex-1 xl:grow" >
197+ < span
198+ id = "wallet-status"
199+ role = { statusMessage . type === 'error' ? 'alert' : 'status' }
200+ className = { cx (
201+ 'w-full text-style-small-standard' ,
202+ statusMessage . type === 'error' && '!text-red-600' ,
203+ statusMessage . type === 'success' && '!text-text-success'
204+ ) }
205+ >
206+ { statusMessage . message }
207+ </ span >
208+
208209 { ! snap . isWalletConnected && (
209210 < ToolsSecondaryButton
210211 type = "submit"
211212 className = "xl:w-[143px]"
212213 disabled = { isLoading }
214+ aria-busy = { isLoading }
213215 >
214216 < div className = "flex items-center justify-center gap-2" >
215217 { isLoading && < SVGSpinner className = "w-4 h-4" /> }
0 commit comments