mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-11-16 08:08:56 -05:00
add connect button
This commit is contained in:
parent
067c60ad2a
commit
a8ba2397bd
@ -6,8 +6,11 @@ import {
|
|||||||
useSignMessage,
|
useSignMessage,
|
||||||
useSignTypedData,
|
useSignTypedData,
|
||||||
useWaitForTransactionReceipt,
|
useWaitForTransactionReceipt,
|
||||||
|
useDisconnect,
|
||||||
|
useConnect,
|
||||||
} from "wagmi";
|
} from "wagmi";
|
||||||
|
|
||||||
|
import { config } from "~/components/WagmiProvider";
|
||||||
import { Button } from "~/components/ui/Button";
|
import { Button } from "~/components/ui/Button";
|
||||||
import { truncateAddress } from "~/lib/truncateAddress";
|
import { truncateAddress } from "~/lib/truncateAddress";
|
||||||
|
|
||||||
@ -17,7 +20,8 @@ export default function Demo() {
|
|||||||
const [isContextOpen, setIsContextOpen] = useState(false);
|
const [isContextOpen, setIsContextOpen] = useState(false);
|
||||||
const [txHash, setTxHash] = useState<string | null>(null);
|
const [txHash, setTxHash] = useState<string | null>(null);
|
||||||
|
|
||||||
const { address, isConnected } = useAccount();
|
const { address, addresses, isConnected } = useAccount();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
sendTransaction,
|
sendTransaction,
|
||||||
error: sendTxError,
|
error: sendTxError,
|
||||||
@ -44,6 +48,10 @@ export default function Demo() {
|
|||||||
hash: txHash as `0x${string}`,
|
hash: txHash as `0x${string}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { disconnect } = useDisconnect();
|
||||||
|
|
||||||
|
const { connect } = useConnect();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
setContext(await sdk.context);
|
setContext(await sdk.context);
|
||||||
@ -171,6 +179,24 @@ export default function Demo() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{addresses && (
|
||||||
|
<div className="my-2 text-xs">
|
||||||
|
Addresses: <pre className="inline">{JSON.stringify(addresses.length)}</pre>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="mb-4">
|
||||||
|
<Button
|
||||||
|
onClick={() =>
|
||||||
|
isConnected
|
||||||
|
? disconnect()
|
||||||
|
: connect({ connector: config.connectors[0] })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{isConnected ? "Disconnect" : "Connect"}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
{isConnected && (
|
{isConnected && (
|
||||||
<>
|
<>
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
|
|||||||
@ -41,7 +41,9 @@ export function frameConnector() {
|
|||||||
async getAccounts() {
|
async getAccounts() {
|
||||||
if (!connected) throw new Error("Not connected");
|
if (!connected) throw new Error("Not connected");
|
||||||
const provider = await this.getProvider();
|
const provider = await this.getProvider();
|
||||||
const accounts = await provider.request({ method: "eth_accounts" });
|
const accounts = await provider.request({
|
||||||
|
method: "eth_requestAccounts",
|
||||||
|
});
|
||||||
return accounts.map((x) => getAddress(x));
|
return accounts.map((x) => getAddress(x));
|
||||||
},
|
},
|
||||||
async getChainId() {
|
async getChainId() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user