generated from shuding/nextra-docs-template
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from sei-protocol/feat/btns-quick-start
feat: incorporate user input components in quickstart guide
- Loading branch information
Showing
4 changed files
with
217 additions
and
4,052 deletions.
There are no files selected for viewing
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,55 @@ | ||
import React, { useState } from 'react'; | ||
import styles from '../../styles/SeiTraceSearch.module.css'; | ||
|
||
const SeiTraceSearch = () => { | ||
const [address, setAddress] = useState(''); | ||
const [error, setError] = useState(''); | ||
|
||
const isValidAddress = (addr: string) => { | ||
// Accept addresses starting with 'sei' or '0x' and of reasonable length | ||
const seiPattern = /^sei[a-z0-9]{8,}$/i; | ||
const evmPattern = /^0x[a-fA-F0-9]{40}$/; | ||
return seiPattern.test(addr) || evmPattern.test(addr); | ||
}; | ||
|
||
const getSeiTraceUrl = (addr: string) => { | ||
const chainParam = '?chain=pacific-1'; | ||
// For all addresses, use '/address/' path | ||
return `https://seitrace.com/address/${addr}${chainParam}`; | ||
}; | ||
|
||
const handleSubmit = (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
const trimmedAddress = address.trim(); | ||
if (trimmedAddress) { | ||
if (isValidAddress(trimmedAddress)) { | ||
const url = getSeiTraceUrl(trimmedAddress); | ||
window.open(url, '_blank'); | ||
setError(''); | ||
} else { | ||
setError('Please enter a valid Sei or EVM address.'); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit} className={styles.form}> | ||
<div className={styles.inputContainer}> | ||
<input | ||
id="addressInput" | ||
type="text" | ||
placeholder="Enter address" | ||
value={address} | ||
onChange={(e) => setAddress(e.target.value)} | ||
className={`${styles.input} ${error ? styles.error : ''}`} | ||
/> | ||
<button type="submit" className={styles.button}> | ||
View on SEITRACE | ||
</button> | ||
</div> | ||
{error && <div className={styles.errorMessage}>{error}</div>} | ||
</form> | ||
); | ||
}; | ||
|
||
export default SeiTraceSearch; |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
.form { | ||
margin-top: 1rem; | ||
} | ||
|
||
.label { | ||
color: #ddd; | ||
font-size: 1rem; | ||
} | ||
|
||
.inputContainer { | ||
display: flex; | ||
margin-top: 0.5rem; | ||
} | ||
|
||
.input { | ||
flex: 1; | ||
padding: 0.75rem 1rem; | ||
font-size: 1rem; | ||
border: none; | ||
border-radius: 25px 0 0 25px; | ||
background-color: #1a1a1a; | ||
color: #fff; | ||
outline: none; | ||
transition: background-color 0.3s; | ||
} | ||
|
||
.input::placeholder { | ||
color: #666; | ||
} | ||
|
||
.input.error { | ||
background-color: #2a1a1a; | ||
box-shadow: inset 0 0 0 2px #e74c3c; | ||
} | ||
|
||
.input:not(.error) { | ||
box-shadow: inset 0 0 0 2px #333; | ||
} | ||
|
||
.button { | ||
padding: 0 1.5rem; | ||
font-size: 1rem; | ||
border: none; | ||
border-radius: 0 25px 25px 0; | ||
background-color: #1a1a1a; | ||
color: #fff; | ||
cursor: pointer; | ||
transition: background-color 0.3s; | ||
box-shadow: inset 0 0 0 2px #333; | ||
} | ||
|
||
.button:hover { | ||
background-color: #333; | ||
} | ||
|
||
.errorMessage { | ||
color: #e74c3c; | ||
margin-top: 0.5rem; | ||
font-size: 0.9rem; | ||
} | ||
|
Oops, something went wrong.