-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add wallet address search form
Adds a Search Wallet form component - with validation, without any search logic.
- Loading branch information
1 parent
f6ac757
commit f985410
Showing
6 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import { Header } from './Header'; | ||
import { WalletPage } from './WalletPage'; | ||
|
||
function App() { | ||
return <Header />; | ||
return ( | ||
<> | ||
<Header /> | ||
<WalletPage /> | ||
</> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { FieldError, useForm } from 'react-hook-form'; | ||
import { SearchCriteria } from './api/types'; | ||
|
||
type Props = { | ||
onSearch: (search: SearchCriteria) => void; | ||
}; | ||
|
||
export function SearchWalletForm({ onSearch }: Props) { | ||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors, isSubmitting }, | ||
} = useForm<SearchCriteria>(); | ||
|
||
const fieldStyle = 'flex flex-col mb-2'; | ||
function getEditorStyle(fieldError: FieldError | undefined) { | ||
return fieldError ? 'border-red-500' : 'border-slate-300'; | ||
} | ||
return ( | ||
<form noValidate className="border-b py-4" onSubmit={handleSubmit(onSearch)}> | ||
<div className={fieldStyle}> | ||
<label htmlFor="address">Wallet Address</label> | ||
<input | ||
type="text" | ||
id="address" | ||
{...register('address', { required: 'You must enter a wallet address' })} | ||
className={getEditorStyle(errors.address)} | ||
/> | ||
<ValidationError fieldError={errors.address} /> | ||
</div> | ||
<div className={fieldStyle}> | ||
<button | ||
type="submit" | ||
disabled={isSubmitting} | ||
className="mt-2 h-10 px-6 font-semibold bg-slate-700 text-white self-start" | ||
> | ||
Search | ||
</button> | ||
</div> | ||
</form> | ||
); | ||
} | ||
|
||
function ValidationError({ fieldError }: { fieldError: FieldError | undefined }) { | ||
if (!fieldError) { | ||
return null; | ||
} | ||
return ( | ||
<div role="alert" className="text-red-500 text-xs mt-1"> | ||
{fieldError.message} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useState } from 'react'; | ||
import { SearchCriteria } from './api/types'; | ||
import { SearchWalletForm } from './SearchWalletForm'; | ||
|
||
export function WalletPage() { | ||
const [searchCriteria, setSearchCriteria] = useState<SearchCriteria | undefined>(); | ||
|
||
function handleSearch(search: SearchCriteria) { | ||
setSearchCriteria(search); | ||
} | ||
|
||
return ( | ||
<main className="max-w-xs ml-auto mr-auto"> | ||
<SearchWalletForm onSearch={handleSearch} /> | ||
<div>Wallet balance and last ten transactions will be here.</div> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type SearchCriteria = { | ||
address: string; | ||
}; |