|
| 1 | +import "./global"; |
| 2 | +import React from "react"; |
| 3 | +import { |
| 4 | + StyleSheet, |
| 5 | + View, |
| 6 | + TouchableOpacity, |
| 7 | + Button, |
| 8 | + AppState |
| 9 | +} from "react-native"; |
| 10 | +import { StackNavigator } from "react-navigation"; |
| 11 | +import { Ionicons } from "@expo/vector-icons"; |
| 12 | +import Expo from "expo"; |
| 13 | +import { reaction } from "mobx"; |
| 14 | +import { observer } from "mobx-react"; |
| 15 | +import { Home, Send, Deposit, Payment, Settings, New } from "./src/screens"; |
| 16 | +import { Loader } from "./src/components"; |
| 17 | +import store from "./src/store"; |
| 18 | + |
| 19 | +const Stack = StackNavigator( |
| 20 | + { |
| 21 | + Home: { |
| 22 | + screen: Home |
| 23 | + }, |
| 24 | + Send: { |
| 25 | + screen: Send |
| 26 | + }, |
| 27 | + Deposit: { |
| 28 | + screen: Deposit |
| 29 | + }, |
| 30 | + Payment: { |
| 31 | + screen: Payment |
| 32 | + }, |
| 33 | + Settings: { |
| 34 | + screen: Settings |
| 35 | + }, |
| 36 | + New: { |
| 37 | + screen: New |
| 38 | + } |
| 39 | + }, |
| 40 | + { |
| 41 | + navigationOptions: ({ navigation }) => ({ |
| 42 | + headerStyle: { |
| 43 | + backgroundColor: "white" |
| 44 | + }, |
| 45 | + headerLeft: ( |
| 46 | + <TouchableOpacity |
| 47 | + activeOpacity={0.5} |
| 48 | + style={{ |
| 49 | + padding: 15 |
| 50 | + }} |
| 51 | + onPress={() => navigation.goBack()} |
| 52 | + > |
| 53 | + <Ionicons name="ios-close" size={40} color="#222" /> |
| 54 | + </TouchableOpacity> |
| 55 | + ), |
| 56 | + gesturesEnabled: false, |
| 57 | + headerTitleStyle: { |
| 58 | + fontFamily: "ClearSans", |
| 59 | + marginTop: -2 |
| 60 | + } |
| 61 | + }), |
| 62 | + mode: "modal" |
| 63 | + } |
| 64 | +); |
| 65 | + |
| 66 | +@observer |
| 67 | +export default class App extends React.Component { |
| 68 | + state = { |
| 69 | + authenticated: false, |
| 70 | + appState: AppState.currentState |
| 71 | + }; |
| 72 | + |
| 73 | + componentDidMount() { |
| 74 | + reaction( |
| 75 | + () => store.appReady, |
| 76 | + () => { |
| 77 | + if (store.touchIdEnabled) { |
| 78 | + this.authenticateWithFingerprint(); |
| 79 | + } else { |
| 80 | + this.setState({ authenticated: true }); |
| 81 | + } |
| 82 | + } |
| 83 | + ); |
| 84 | + |
| 85 | + AppState.addEventListener("change", this._handleAppStateChange); |
| 86 | + } |
| 87 | + |
| 88 | + _handleAppStateChange = nextAppState => { |
| 89 | + if (!store.touchIdEnabled) return; |
| 90 | + |
| 91 | + if (nextAppState === "background") { |
| 92 | + this.setState({ authenticated: false, appState: nextAppState }); |
| 93 | + return; |
| 94 | + } else if ( |
| 95 | + this.state.appState === "background" && |
| 96 | + nextAppState === "active" |
| 97 | + ) { |
| 98 | + this.setState({ appState: nextAppState }); |
| 99 | + this.authenticateWithFingerprint(); |
| 100 | + } |
| 101 | + }; |
| 102 | + |
| 103 | + authenticateWithFingerprint = () => { |
| 104 | + Expo.Fingerprint.authenticateAsync( |
| 105 | + "Unlock Stellar Wallet with Touch ID" |
| 106 | + ).then(({ success, error }) => { |
| 107 | + if (success) { |
| 108 | + this.setState({ authenticated: true }); |
| 109 | + } |
| 110 | + }); |
| 111 | + }; |
| 112 | + |
| 113 | + render() { |
| 114 | + if (!store.appReady) return <Loader />; |
| 115 | + |
| 116 | + return ( |
| 117 | + <View style={styles.container}> |
| 118 | + <Stack /> |
| 119 | + {store.touchIdEnabled && |
| 120 | + !this.state.authenticated && ( |
| 121 | + <View style={[StyleSheet.absoluteFill, styles.lockedContainer]}> |
| 122 | + <Button |
| 123 | + title="Unlock with Touch ID" |
| 124 | + onPress={this.authenticateWithFingerprint} |
| 125 | + /> |
| 126 | + </View> |
| 127 | + )} |
| 128 | + </View> |
| 129 | + ); |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +const styles = StyleSheet.create({ |
| 134 | + container: { |
| 135 | + flex: 1, |
| 136 | + backgroundColor: "white" |
| 137 | + }, |
| 138 | + lockedContainer: { |
| 139 | + backgroundColor: "white", |
| 140 | + alignItems: "center", |
| 141 | + justifyContent: "center" |
| 142 | + } |
| 143 | +}); |
0 commit comments