-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
components: add ConnectWalletButton, AddressView #10
Open
caffeinum
wants to merge
10
commits into
main
Choose a base branch
from
feature/components
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e16092c
add ui components
caffeinum 7387734
v0.3.2-beta
caffeinum dc84b56
v0.3.2-beta1
caffeinum c945306
v0.3.2-beta2
caffeinum 32c5f4e
v0.3.2-beta3
caffeinum 7cdcd6c
update examples
caffeinum fff6061
refactor ConnectWallet as ProfileView
caffeinum 623f96f
profileview: fix styling
caffeinum ff80146
fix use same color
caffeinum 9adef2d
v0.3.2-beta4
caffeinum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,28 @@ | ||
import React from "react" | ||
import { useWeb3 } from "../" | ||
|
||
type Props = { | ||
isShort?: boolean | ||
} | ||
|
||
/** | ||
* AddressView is used to display the current address. | ||
* It should be used inside Web3Provider so that it picks up address | ||
* @param isShort - If true, the address is displayed in short format: 0xff...abcd | ||
* @returns {JSX.Element} | ||
*/ | ||
export const AddressView = ({ isShort = true }: Props): JSX.Element => { | ||
const { address } = useWeb3() | ||
|
||
if (!address) return null | ||
theshadowagent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// TODO: parse ENS here | ||
|
||
return <> | ||
{isShort ? `${address.slice(0, 4)}...${address.slice(-4)}` : address} | ||
</> | ||
|
||
// return <div>{address ? `Connected to ${address}` : 'Not connected'}</div> | ||
} | ||
|
||
export default AddressView |
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,45 @@ | ||
import React, { useState } from "react" | ||
import { useWeb3 } from "@3rdweb/hooks" | ||
|
||
import ConnectWeb3Modal from "./ConnectWeb3Modal" | ||
|
||
type ButtonProps = { text: string, onClick: () => void } | ||
|
||
type Props = { | ||
autoOpen: boolean | ||
showDisconnect?: boolean | ||
renderButton?: (props: ButtonProps) => JSX.Element | ||
} | ||
|
||
/** | ||
* ConnectWallet | ||
* @param param0 - autoOpen - If true, the modal will be opened on page load | ||
* @param param0 - showDisconnect - If true, a button will be shown to disconnect | ||
* @param param0 - renderButton - If provided, you can control how a button is rendered | ||
* @returns {JSX.Element} | ||
*/ | ||
export const ConnectWallet = ({ autoOpen = false, showDisconnect = false, renderButton }: Props): JSX.Element => { | ||
|
||
const [open, setOpen] = useState(autoOpen) | ||
|
||
const { address, disconnectWallet } = useWeb3() | ||
|
||
return <> | ||
<ConnectWeb3Modal open={open} setOpen={setOpen} /> | ||
|
||
{!address && ( | ||
renderButton | ||
? renderButton({ text: "Connect Wallet", onClick: () => setOpen(true) }) | ||
: <button onClick={() => setOpen(true)}>Connect Wallet</button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use |
||
)} | ||
|
||
{showDisconnect && address && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
renderButton | ||
? renderButton({ text: "Disconnect Wallet", onClick: () => disconnectWallet() }) | ||
: <button onClick={() => disconnectWallet()}>Disconnect Wallet</button> | ||
)} | ||
|
||
</> | ||
} | ||
|
||
export default ConnectWallet |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to style
<AddressView />
? Consider wrapping in @mui<Box />
and passing styling props:sx
,style
,className