-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
87 lines (77 loc) · 2.38 KB
/
App.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import React, { useEffect, useState } from "react";
import { ActivityIndicator, SafeAreaView, Text, View } from "react-native";
import Toast from "react-native-toast-message";
import { toastConfig } from "./src/config/toastConfig";
import { capsule } from "./src/clients/capsule";
import { LoginStep } from "./src/components/LoginStep";
import { UseWalletStep } from "./src/components/UseWalletStep";
function App(): React.JSX.Element {
const [step, setStep] = useState(1);
const [isInitializing, setIsInitializing] = useState(false);
const [isCreatingWallet, setIsCreatingWallet] = useState(false);
const isLoading = isInitializing || isCreatingWallet;
const goToSecondStep = () => {
setStep(2);
};
const onLogout = () => {
setStep(1);
};
useEffect(() => {
const init = async () => {
try {
setIsInitializing(true);
// Initialize Capsule before proceeding to the app
await capsule.init();
if (await capsule.isSessionActive()) {
goToSecondStep();
}
} catch (e) {
console.error("Init Error: ", e);
} finally {
setIsInitializing(false);
}
};
init();
}, []);
return (
<>
<SafeAreaView style={{ flex: 1 }}>
<View style={{ backgroundColor: "black", flex: 1, padding: 24 }}>
<Text style={{ textAlign: "center", color: "white", fontSize: 24 }}>
Capsule{"\n"}Expo Sample App
</Text>
{isLoading ? (
<View style={{ flex: 1, justifyContent: "center" }}>
<ActivityIndicator size="large" color="white" />
{isCreatingWallet && (
<Text
style={{
textAlign: "center",
color: "white",
fontSize: 18,
paddingTop: 8,
}}
>
Creating Wallet...
</Text>
)}
</View>
) : (
<>
{step === 1 ? (
<LoginStep
goToNextStep={goToSecondStep}
setIsCreatingWallet={setIsCreatingWallet}
/>
) : (
<UseWalletStep onLogout={onLogout} />
)}
</>
)}
</View>
</SafeAreaView>
<Toast config={toastConfig} />
</>
);
}
export default App;