-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add account selector component and error printing to all examples
- Loading branch information
1 parent
3a59a72
commit 320a3e7
Showing
9 changed files
with
223 additions
and
25 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
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,27 @@ | ||
import { useWeb3 } from "../context/web3Context"; | ||
import "../css/AccountSelector.css"; | ||
|
||
export const AccountSelect = () => { | ||
const { accounts, selectAccount } = useWeb3(); | ||
|
||
if (!accounts || accounts.length === 0) { | ||
return <div>No accounts available</div>; | ||
} | ||
|
||
return ( | ||
<div className="account-select-container flex w-full gap-4 justify-center items-center"> | ||
<label htmlFor="account-selector" className="account-select-label">Select Your Account</label> | ||
<select | ||
id="account-selector" | ||
className="account-select-dropdown" | ||
onChange={(e) => selectAccount(accounts[parseInt(e.target.value)])} | ||
> | ||
{accounts.map((account, index) => ( | ||
<option value={index} key={account.address()}> | ||
Account {account.name()} : {account.address().substring(0, 6)}...{account.address().substring(account.address().length - 4)} | ||
</option> | ||
))} | ||
</select> | ||
</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
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
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,22 @@ | ||
.account-select-container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
padding: 10px; | ||
} | ||
|
||
.account-select-label { | ||
margin-bottom: 8px; | ||
font-weight: bold; | ||
} | ||
|
||
.account-select-dropdown { | ||
padding: 8px; | ||
border-radius: 4px; | ||
border: 1px solid #ccc; | ||
outline: none; | ||
width: 100%; | ||
max-width: 300px; | ||
box-shadow: 0 2px 4px rgba(0,0,0,0.1); | ||
cursor: pointer; | ||
} |
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
Oops, something went wrong.