@@ -12,12 +12,15 @@ export function NewWalletPage() {
1212 const [ confirm , setConfirm ] = useState ( "" ) ;
1313 const [ message , setMessage ] = useState < string | null > ( null ) ;
1414 const [ variant , setVariant ] = useState < NotificationVariant > ( "error" ) ;
15+ const [ submitting , setSubmitting ] = useState ( false ) ;
1516
1617 const navigate = useNavigate ( ) ;
1718
1819 const handleSubmit = async ( ) => {
1920 // Simple custom rules – adjust as needed
2021 if ( ! name . trim ( ) ) return setMessage ( "Wallet name is required." ) ;
22+ // spaces should be underscores
23+ const walletName : string = name . trim ( ) . replace ( / \s + / g, "_" ) ;
2124
2225 const isStrong = await invoke < boolean > ( "check_password_complexity" , { password : pw } ) ;
2326 if ( ! isStrong ) return setMessage ( `Passwords Must Contain The Following:
@@ -27,10 +30,14 @@ export function NewWalletPage() {
2730 Number: Requires At Least One Digit.
2831 Special Character: Requires At Least One Special Symbol.` ) ;
2932 if ( pw !== confirm ) return setMessage ( "Passwords do not match." ) ;
33+
34+ setSubmitting ( true ) ;
35+ let success = false ;
3036 try {
31- await invoke ( "create_new_wallet" , { walletName : name , password : pw } ) ;
37+ await invoke ( "create_new_wallet" , { walletName : walletName , password : pw } ) ;
3238 const walletExists = await invoke < WalletExistsResult > ( "check_if_wallet_exists" ) ;
3339 if ( walletExists ) {
40+ success = true ;
3441 setMessage ( `Wallet Was Created!` ) ;
3542 setVariant ( 'success' ) ;
3643 setTimeout ( ( ) => navigate ( "/wallet/" ) , 2718 ) ;
@@ -41,6 +48,8 @@ export function NewWalletPage() {
4148 }
4249 } catch ( e : any ) {
4350 setMessage ( e as string ) ;
51+ } finally {
52+ if ( ! success ) setSubmitting ( false ) ;
4453 }
4554 } ;
4655
@@ -50,10 +59,10 @@ export function NewWalletPage() {
5059
5160 < ShowNotification message = { message } setMessage = { setMessage } variant = { variant } />
5261
53- < TextField label = "Wallet name" value = { name } onChange = { ( e ) => setName ( e . target . value ) } />
62+ < TextField label = "Wallet name" value = { name } onChange = { ( e ) => setName ( e . target . value ) } disabled = { submitting } />
5463
55- < PasswordField label = "Password" value = { pw } onChange = { setPw } />
56- < PasswordField label = "Confirm password" value = { confirm } onChange = { setConfirm } />
64+ < PasswordField label = "Password" value = { pw } onChange = { setPw } disabled = { submitting } />
65+ < PasswordField label = "Confirm password" value = { confirm } onChange = { setConfirm } disabled = { submitting } />
5766
5867 < div className = "flex items-center justify-between" >
5968 < button onClick = { ( ) => navigate ( "/" ) } className = "rounded px-3 py-2 text-sm underline" >
@@ -63,7 +72,7 @@ export function NewWalletPage() {
6372 < button
6473 onClick = { handleSubmit }
6574 className = "rounded bg-blue-600 px-4 py-2 text-sm text-white disabled:opacity-50"
66- disabled = { ! name || ! pw || ! confirm }
75+ disabled = { submitting || ! name || ! pw || ! confirm }
6776 >
6877 Create
6978 </ button >
0 commit comments