This repository was archived by the owner on Aug 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
70 lines (60 loc) · 1.93 KB
/
App.tsx
File metadata and controls
70 lines (60 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import './App.css'
import { useCheckSigner, useToken, useSigner, useKeypair, RequestSignatureParameters } from "@farsign/hooks";
import { makeCastAdd, getHubRpcClient, FarcasterNetwork } from "@farcaster/hub-web";
import QRCode from "react-qr-code";
import { useEffect} from 'react';
const CLIENT_NAME = "";
const APP_FID = 10626;
const MNEMONIC = "";
const HUB = "";
const DEADLINE = Math.floor(Date.now() / 1000) + 86400;// signature is valid for 1 day you might want to extend this
const params: RequestSignatureParameters = {
appFid: APP_FID,
appMnemonic: MNEMONIC,
deadline: DEADLINE,
name: CLIENT_NAME
}
const sendCast = async (encryptedSigner: any) => {
const castBody = "Getting closer and closer to something clean with my project tonight!";
const hub = getHubRpcClient(HUB);
const request = JSON.parse(localStorage.getItem("farsign-" + CLIENT_NAME)!);
const cast = (await makeCastAdd({
text: castBody,
embeds: [],
embedsDeprecated: [],
mentions: [],
mentionsPositions: [],
}, { fid: request.userFid, network: FarcasterNetwork.MAINNET }, encryptedSigner))._unsafeUnwrap();
hub.submitMessage(cast);
}
function App() {
const [keys, encryptedSigner] = useKeypair(CLIENT_NAME);
const [isConnected, setIsConnected] = useCheckSigner(CLIENT_NAME);
const [token] = useToken(CLIENT_NAME, params, keys!);
const [signer] = useSigner(CLIENT_NAME, token);
useEffect(() => {
if (typeof signer?.signerRequest == 'object') {
setIsConnected(true)
}
}, [signer])
return (
<>
<div>
{(isConnected === false) ?
<>
<QRCode value={token.deepLink}/>
<p>Sign-in with Farcaster</p>
</>
:
<>
<div className="card">
<p>{}</p>
<button onClick={() => sendCast(encryptedSigner)}>Send cast!</button>
</div>
</>
}
</div>
</>
)
}
export default App