-
Notifications
You must be signed in to change notification settings - Fork 0
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
Init wagmi and connect wallet functionality #17
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createPublicClient, http, publicActions, walletActions, getContract } from 'viem'; | ||
import { foundry } from 'viem/chains'; | ||
import WordleABI from '../abis/WordleABI.json'; | ||
import ERC20ABI from '../abis/ERC20ABI.json'; | ||
|
||
// Public client | ||
export const publicClient = createPublicClient({ | ||
chain: foundry, | ||
transport: http(), | ||
}); | ||
|
||
// Wordle3 Contract | ||
export const publicWordle = getContract({ | ||
address: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0', | ||
abi: WordleABI, | ||
client: publicClient, | ||
}); | ||
|
||
// Wordle Token contract | ||
export const publicWdt = getContract({ | ||
address: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512', | ||
abi: ERC20ABI, | ||
client: publicClient, | ||
}); |
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,50 @@ | ||
import React from 'react' | ||
import { useConnect } from 'wagmi' | ||
import { useAccount, useDisconnect, useEnsAvatar, useEnsName } from 'wagmi' | ||
|
||
|
||
/** | ||
* Account component that displays connected account and passes on | ||
* the address to the parent component for interaction. | ||
*/ | ||
function Account({onAddressChange}) { | ||
const { address } = useAccount() | ||
const { disconnect } = useDisconnect() | ||
const { data: ensName } = useEnsName({ address }) | ||
const { data: ensAvatar } = useEnsAvatar({ name: ensName! }) | ||
|
||
if (address) onAddressChange(address); | ||
|
||
return ( | ||
<div> | ||
{ensAvatar && <img alt="ENS Avatar" src={ensAvatar} />} | ||
{address && <div>{ensName ? `${ensName} (${address})` : address}</div>} | ||
<button onClick={() => disconnect()}>Disconnect</button> | ||
</div> | ||
) | ||
} | ||
|
||
/** | ||
* Account component that displays available wallet connectors | ||
* Connectors are also pulled from ../../wagmi.config.ts | ||
*/ | ||
function WalletOptions() { | ||
const { connectors, connect } = useConnect() | ||
|
||
return connectors.map((connector) => ( | ||
<button key={connector.uid} onClick={() => connect({ connector })}> | ||
{connector.name} | ||
</button> | ||
)) | ||
} | ||
|
||
/** | ||
* Wrapper for the login user flow. | ||
* Receives onAddressChange from parent component to lift the address | ||
* for smart contract operations | ||
*/ | ||
export function ConnectWallet({onAddressChange}) { | ||
const { isConnected } = useAccount() | ||
if (isConnected) return <Account onAddressChange={onAddressChange} /> | ||
return <WalletOptions /> | ||
} |
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,15 @@ | ||
import { http, createConfig } from 'wagmi' | ||
import { anvil } from 'wagmi/chains' | ||
import { injected, metaMask, safe } from 'wagmi/connectors' | ||
|
||
export const wagmiConfig = createConfig({ | ||
chains: [anvil], | ||
transports: { | ||
[anvil.id]: http(), | ||
}, | ||
connectors: [ | ||
injected(), | ||
metaMask(), | ||
safe(), | ||
] | ||
}) |
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.
added these for the time being, but more can be added later. wagmi also auto-detects wallets.