|
1 | 1 | import { StatusBar } from "expo-status-bar";
|
2 |
| -import { Button, Modal, StyleSheet, Text, TextInput, View } from "react-native"; |
3 |
| -import { useRouter } from "expo-router"; |
| 2 | +import { StyleSheet, View } from "react-native"; |
| 3 | +import { useRouter, Stack } from "expo-router"; |
4 | 4 | import { useState } from "react";
|
5 | 5 | import { useFacade } from "@/data/facades";
|
| 6 | +import { |
| 7 | + Layout, |
| 8 | + Text, |
| 9 | + Card, |
| 10 | + Button, |
| 11 | + Input, |
| 12 | + Modal, |
| 13 | + Spinner, |
| 14 | +} from "@ui-kitten/components"; |
| 15 | + |
| 16 | +const LoadingIndicator = () => ( |
| 17 | + <View style={styles.loadingContainer}> |
| 18 | + <Spinner size="small" status="basic" /> |
| 19 | + </View> |
| 20 | +); |
6 | 21 |
|
7 | 22 | export default function ImportEncoded() {
|
8 | 23 | const router = useRouter();
|
9 |
| - |
10 | 24 | const [modalVisible, setModalVisible] = useState(false);
|
11 | 25 | const [accountName, setAccountName] = useState("Account Name");
|
12 | 26 | const [encodedAccount, setEncodedAccount] = useState("");
|
13 | 27 |
|
14 | 28 | const facade = useFacade();
|
15 |
| - |
16 | 29 | const importAccount = facade.importAccount.useMutation();
|
17 | 30 |
|
18 | 31 | return (
|
19 |
| - <View style={styles.container}> |
20 |
| - <Modal visible={modalVisible} animationType="slide"> |
21 |
| - <View style={styles.container}> |
22 |
| - <Text>Account Imported!</Text> |
23 |
| - <Text> |
24 |
| - Before you start managing your digital assets, we need to scan the |
25 |
| - blockchain. This may take some time. |
| 32 | + <> |
| 33 | + <Stack.Screen |
| 34 | + options={{ |
| 35 | + headerTitle: "Account Import", |
| 36 | + headerBackTitle: "Back", |
| 37 | + }} |
| 38 | + /> |
| 39 | + |
| 40 | + <Layout style={styles.container} level="1"> |
| 41 | + <Modal |
| 42 | + visible={modalVisible} |
| 43 | + backdropStyle={styles.backdrop} |
| 44 | + onBackdropPress={() => setModalVisible(false)} |
| 45 | + > |
| 46 | + <Card disabled style={styles.modalCard}> |
| 47 | + <Text category="h6" style={styles.modalTitle}> |
| 48 | + Account Imported! |
| 49 | + </Text> |
| 50 | + <Text style={styles.modalText} appearance="hint"> |
| 51 | + Before you start managing your digital assets, we need to scan the |
| 52 | + blockchain. This may take some time. |
| 53 | + </Text> |
| 54 | + <Button |
| 55 | + onPress={async () => { |
| 56 | + router.dismissAll(); |
| 57 | + setModalVisible(false); |
| 58 | + }} |
| 59 | + style={styles.modalButton} |
| 60 | + > |
| 61 | + Let's go! |
| 62 | + </Button> |
| 63 | + </Card> |
| 64 | + </Modal> |
| 65 | + |
| 66 | + <Card disabled style={styles.card}> |
| 67 | + <Text category="h6" style={styles.title}> |
| 68 | + Encoded Key Import |
| 69 | + </Text> |
| 70 | + |
| 71 | + <Text appearance="hint" style={styles.description}> |
| 72 | + Paste the complete string into the provided text field below. |
26 | 73 | </Text>
|
| 74 | + |
| 75 | + <Input |
| 76 | + label="Account Name" |
| 77 | + placeholder="Enter account name" |
| 78 | + value={accountName} |
| 79 | + onChangeText={setAccountName} |
| 80 | + style={styles.input} |
| 81 | + size="large" |
| 82 | + /> |
| 83 | + |
| 84 | + <Input |
| 85 | + label="Encoded Key" |
| 86 | + placeholder="Paste your encoded key here" |
| 87 | + value={encodedAccount} |
| 88 | + onChangeText={setEncodedAccount} |
| 89 | + style={styles.input} |
| 90 | + size="large" |
| 91 | + multiline |
| 92 | + textStyle={styles.encodedInput} |
| 93 | + /> |
| 94 | + |
27 | 95 | <Button
|
28 |
| - title="Let's go!" |
| 96 | + style={styles.button} |
| 97 | + size="large" |
29 | 98 | onPress={async () => {
|
30 |
| - router.dismissAll(); |
31 |
| - setModalVisible(false); |
| 99 | + await importAccount.mutateAsync({ |
| 100 | + account: encodedAccount, |
| 101 | + name: accountName, |
| 102 | + }); |
| 103 | + setModalVisible(true); |
32 | 104 | }}
|
33 |
| - /> |
34 |
| - </View> |
35 |
| - </Modal> |
36 |
| - <Text>Paste the complete string into the provided text field below.</Text> |
37 |
| - <TextInput |
38 |
| - placeholder="Account Name" |
39 |
| - value={accountName} |
40 |
| - onChangeText={setAccountName} |
41 |
| - /> |
42 |
| - <TextInput |
43 |
| - placeholder="Encoded Key" |
44 |
| - value={encodedAccount} |
45 |
| - onChangeText={setEncodedAccount} |
46 |
| - /> |
47 |
| - <Button |
48 |
| - title="Continue" |
49 |
| - onPress={async () => { |
50 |
| - await importAccount.mutateAsync({ |
51 |
| - account: encodedAccount, |
52 |
| - name: accountName, |
53 |
| - }); |
54 |
| - setModalVisible(true); |
55 |
| - }} |
56 |
| - /> |
57 |
| - <StatusBar style="auto" /> |
58 |
| - </View> |
| 105 | + accessoryLeft={ |
| 106 | + importAccount.isPending ? LoadingIndicator : undefined |
| 107 | + } |
| 108 | + disabled={ |
| 109 | + importAccount.isPending || !encodedAccount || !accountName |
| 110 | + } |
| 111 | + > |
| 112 | + {importAccount.isPending ? "Importing..." : "Import Account"} |
| 113 | + </Button> |
| 114 | + </Card> |
| 115 | + |
| 116 | + <StatusBar style="auto" /> |
| 117 | + </Layout> |
| 118 | + </> |
59 | 119 | );
|
60 | 120 | }
|
61 | 121 |
|
62 | 122 | const styles = StyleSheet.create({
|
63 | 123 | container: {
|
64 | 124 | flex: 1,
|
65 |
| - backgroundColor: "#fff", |
66 |
| - alignItems: "center", |
| 125 | + padding: 16, |
| 126 | + }, |
| 127 | + card: { |
| 128 | + marginVertical: 8, |
| 129 | + borderRadius: 12, |
| 130 | + }, |
| 131 | + title: { |
| 132 | + textAlign: "center", |
| 133 | + marginBottom: 8, |
| 134 | + }, |
| 135 | + description: { |
| 136 | + textAlign: "center", |
| 137 | + marginBottom: 24, |
| 138 | + }, |
| 139 | + input: { |
| 140 | + marginBottom: 16, |
| 141 | + }, |
| 142 | + encodedInput: { |
| 143 | + minHeight: 80, |
| 144 | + textAlignVertical: "top", |
| 145 | + }, |
| 146 | + button: { |
| 147 | + marginTop: 8, |
| 148 | + }, |
| 149 | + backdrop: { |
| 150 | + backgroundColor: "rgba(0, 0, 0, 0.5)", |
| 151 | + }, |
| 152 | + modalCard: { |
| 153 | + borderRadius: 12, |
| 154 | + margin: 24, |
| 155 | + padding: 16, |
| 156 | + }, |
| 157 | + modalTitle: { |
| 158 | + textAlign: "center", |
| 159 | + marginVertical: 16, |
| 160 | + }, |
| 161 | + modalText: { |
| 162 | + textAlign: "center", |
| 163 | + marginBottom: 24, |
| 164 | + }, |
| 165 | + modalButton: { |
| 166 | + marginTop: 8, |
| 167 | + }, |
| 168 | + loadingContainer: { |
67 | 169 | justifyContent: "center",
|
| 170 | + alignItems: "center", |
68 | 171 | },
|
69 | 172 | });
|
0 commit comments