-
Notifications
You must be signed in to change notification settings - Fork 0
/
privy.tsx
47 lines (42 loc) · 1.37 KB
/
privy.tsx
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
import { Button, View, TextInput } from "react-native";
import { useEmbeddedWallet, useLoginWithSMS, usePrivy } from "@privy-io/expo";
import { useEffect, useRef, useState } from "react";
export default function Privy() {
const [code, setCode] = useState("");
const embeddedWallet = useEmbeddedWallet();
const { user: privyUser, isReady: privyReady, logout } = usePrivy();
const { sendCode, loginWithCode } = useLoginWithSMS();
const creatingEmbeddedWallet = useRef(false);
console.log({ embedded: embeddedWallet.status, privyUser: !!privyUser });
useEffect(() => {
const createWallet = async () => {
if (
privyUser &&
embeddedWallet.status === "not-created" &&
privyReady &&
!creatingEmbeddedWallet.current
) {
creatingEmbeddedWallet.current = true;
console.log("creating embedded wallet !!!");
await embeddedWallet.create();
}
};
createWallet();
}, [embeddedWallet, privyReady, privyUser]);
return (
<View>
<Button
onPress={() => sendCode({ phone: "+33661183357" })}
title="Get code"
/>
<TextInput
value={code}
onChangeText={setCode}
placeholder="Code"
inputMode="numeric"
/>
<Button onPress={() => loginWithCode({ code })} title="Send code" />
<Button onPress={logout} title="Logout" />
</View>
);
}