Skip to content

Commit

Permalink
Upgrade to react-navigation 5
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjoberg committed Feb 8, 2020
1 parent 1db154d commit 44b1c1a
Show file tree
Hide file tree
Showing 49 changed files with 680 additions and 512 deletions.
12 changes: 0 additions & 12 deletions android/app/src/main/java/com/blixtwallet/LndMobile.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,18 +676,6 @@ void onFail() {
permissions.checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, checkPermissionPromise);
}

@ReactMethod
public void startLndLogObserving() {
FileObserver lndLogObserver;
File lndLog = new File(
getReactApplicationContext().getFilesDir().toString() +
"/logs/bitcoin/" +
BuildConfig.CHAIN +
"/lnd.log"
);
// TODO
}

@ReactMethod
public void getIntentStringData(Promise promise) {
String sharedText = getReactApplicationContext()
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"@react-native-community/google-signin": "^3.0.4",
"@react-native-community/masked-view": "^0.1.6",
"@react-native-community/react-native-clipboard": "^1.0.1",
"@react-navigation/bottom-tabs": "^5.0.0",
"@react-navigation/native": "^5.0.0",
"@react-navigation/stack": "^5.0.0",
"@types/sha.js": "^2.4.0",
"base64-js": "1.3.1",
"bech32": "^1.1.3",
Expand All @@ -36,27 +39,24 @@
"react-native-barcode-mask": "^1.1.0",
"react-native-blur-overlay": "1.0.7",
"react-native-build-config": "^0.3.1",
"react-native-camera": "3.16.0",
"react-native-camera": "3.17.0",
"react-native-dialogs": "1.1.0",
"react-native-document-picker": "^3.2.4",
"react-native-easy-grid": "0.2.2",
"react-native-fingerprint-scanner": "4.0.0",
"react-native-fs": "2.16.2",
"react-native-fs": "2.16.4",
"react-native-gesture-handler": "1.5.6",
"react-native-immersive": "^2.0.0",
"react-native-keychain": "4.0.5",
"react-native-linear-gradient": "2.5.6",
"react-native-push-notification": "^3.1.9",
"react-native-qrcode-svg": "6.0.3",
"react-native-reanimated": "1.7.0",
"react-native-safe-area-context": "0.6.4",
"react-native-safe-area-context": "0.7.2",
"react-native-screens": "^2.0.0-alpha.34",
"react-native-securerandom": "^1.0.0-rc.0",
"react-native-sqlite-storage": "4.1.0",
"react-native-svg": "11.0.1",
"react-navigation": "4.1.0",
"react-navigation-stack": "2.1.0",
"react-navigation-tabs": "2.7.0",
"sha.js": "^2.4.11"
},
"devDependencies": {
Expand All @@ -66,10 +66,10 @@
"@types/base64-js": "^1.2.5",
"@types/bech32": "1.1.2",
"@types/color": "3.0.1",
"@types/jest": "25.1.1",
"@types/jest": "25.1.2",
"@types/long": "4.0.1",
"@types/react": "16.9.19",
"@types/react-native": "0.61.10",
"@types/react-native": "0.61.12",
"@types/react-native-push-notification": "3.0.7",
"@types/react-native-sqlite-storage": "3.3.2",
"@types/react-test-renderer": "16.9.2",
Expand Down
14 changes: 11 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import React from "react";
import { StyleProvider } from "native-base";
import React, { useState } from "react";
import { StyleProvider, Root } from "native-base";
import { NavigationContainer } from '@react-navigation/native';
import { StoreProvider } from "easy-peasy";

import Main from "./Main";
import DEV_Commands from "./windows/InitProcess/DEV_Commands";

import getTheme from "../native-base-theme/components";
import theme from "../native-base-theme/variables/commonColor";

import store from "./state/store";

export default () => {
const [debug, setDebug] = useState(__DEV__ ? true : false);

return (
<StoreProvider store={store}>
<StyleProvider style={getTheme(theme)}>
<Main />
<NavigationContainer>
<Root>
{debug ? <DEV_Commands continueCallback={() => setDebug(false)} /> : <Main />}
</Root>
</NavigationContainer>
</StyleProvider>
</StoreProvider>
);
Expand Down
187 changes: 113 additions & 74 deletions src/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,98 +1,137 @@
import React from "react";
import { Animated, Easing } from "react-native";
import { Root } from "native-base";
import { createAppContainer, createSwitchNavigator } from "react-navigation";
import { createStackNavigator } from "react-navigation-stack";
import { createBottomTabNavigator } from "react-navigation-tabs";
import React, { useEffect, useState } from "react";
import { createStackNavigator } from "@react-navigation/stack";

import { setTopLevelNavigator } from "./utils/navigation";
import FooterNav from "./components/FooterNav";
import Overview from "./windows/Overview";
import Send from "./windows/Send";
import Receive from "./windows/Receive";
import Settings from "./windows/Settings";
import LightningInfo from "./windows/LightningInfo";
import OnChain from "./windows/OnChain";
import Init from "./windows/InitProcess/Init";
import Authentication from "./windows/InitProcess/Authentication";
import DEV_Commands from "./windows/InitProcess/DEV_Commands";
import InitLightning from "./windows/InitProcess/InitLightning";
import Welcome from "./windows/Welcome";
import LightningNodeInfo from "./windows/Settings/LightningNodeInfo";
import About from "./windows/Settings/About";
import ChannelRequest from "./windows/LNURL/ChannelRequest";
import KeysendTest from "./windows/Keysend/Test";
import GoogleDriveTestbed from "./windows/Google/GoogleDriveTestbed";

import TransactionDetails from "./windows/TransactionDetails";
import OnChainTransactionDetails from "./windows/OnChain/OnChainTransactionDetails";
import Loading from "./windows/Loading";

const MainStack = createBottomTabNavigator({
Overview,
}, {
navigationOptions: {
animationEnabled: false,
},
initialRouteName: "Overview",
tabBarComponent: FooterNav,
});
import { useStoreState, useStoreActions } from "./state/store.ts";

const StackNavigator = createStackNavigator({
Main: {
screen: MainStack,
},
TransactionDetails,
OnChainTransactionDetails,
LightningNodeInfo,
About,
Receive,
Send,
Settings,
LightningInfo,
OnChain,
ChannelRequest,
KeysendTest,
GoogleDriveTestbed
}, {
navigationOptions: {
animationEnabled: false,
const RootStack = createStackNavigator();

export type RootStackParamList = {
DEV_Commands: undefined;
Init: undefined;
Authentication: undefined;
InitLightning: undefined;

Overview: undefined;
TransactionDetails: {
rHash: string; // TODO
};
Receive: undefined;
Send: undefined;
OnChain: undefined;
Settings: undefined;
ChannelRequest: undefined;
GoogleDriveTestbed: undefined;
KeysendTest: undefined;
DeeplinkChecker: undefined;

DEV_CommandsX: undefined;
}

export default () => {
const holdOnboarding = useStoreState((store) => store.holdOnboarding);
const appReady = useStoreState((store) => store.appReady);
const walletCreated = useStoreState((store) => store.walletCreated);
const loggedIn = useStoreState((store) => store.security.loggedIn);
const initializeApp = useStoreActions((store) => store.initializeApp);
const initLightning = useStoreActions((store) => store.lightning.initialize);
const deeplinkChecker = useStoreActions((store) => store.deeplinkChecker);
const [initialRoute, setInitialRoute] = useState("Overview");

const [state, setState] =
useState<"init" | "initLightning" | "authentication" | "onboarding" | "started">("init");

useEffect(() => {
// tslint:disable-next-line
(async () => {
if (!appReady) {
await initializeApp();
}
else {
if (!walletCreated) {
setState("onboarding");
}
else if (!loggedIn) {
setState("authentication");
}
else {
console.log("else?");
if (walletCreated && !holdOnboarding) {
// setState("initLightning");
await initLightning();
if (await deeplinkChecker()) {
setInitialRoute("SendConfirmation");
}
setState("started");
}
}
}
})();
}, [appReady, loggedIn, holdOnboarding, walletCreated]);

const screenOptions = {
gestureEnabled: false,
headerShown: false,
cardStyle: {
backgroundColor: "transparent",
},
},
defaultNavigationOptions: {
animationEnabled: false,
headerShown: false,
cardStyle: {
backgroundColor: "transparent",
},
},
initialRouteName: "Main",
mode: "modal",
headerMode: "none",
});
};

const RootStack = createSwitchNavigator({
DEV_Commands,
Welcome,
Init,
Authentication,
InitLightning,
Main: { screen: StackNavigator },
}, {
navigationOptions: {
animationEnabled: false,
},
initialRouteName: __DEV__ ? "DEV_Commands" : "Init",
});
// Initialization
if (state === "init" || state === "initLightning") {
return (<Loading />);
}
if (state === "onboarding") {
return (<Welcome />);
}
if (state === "authentication") {
return (<Authentication />);
}

return (
<RootStack.Navigator initialRouteName={"Start"} screenOptions={screenOptions}>
<RootStack.Screen name="Start">{({navigation}) => {
if (initialRoute === "Overview") {
navigation.replace(initialRoute);
}
else if (initialRoute === "SendConfirmation") {
navigation.replace("Overview");
navigation.push("Send", {screen: initialRoute });
}

return null;
}}</RootStack.Screen>
<RootStack.Screen name="Overview" component={Overview} />
<RootStack.Screen name="TransactionDetails" component={TransactionDetails} />
<RootStack.Screen name="Receive" component={Receive} />
<RootStack.Screen name="Send" component={Send} />
<RootStack.Screen name="OnChain" component={OnChain} />
<RootStack.Screen name="LightningInfo" component={LightningInfo} />
<RootStack.Screen name="Settings" component={Settings} />
<RootStack.Screen name="ChannelRequest" component={ChannelRequest} />

const AppContainer = createAppContainer(RootStack);
<RootStack.Screen name="GoogleDriveTestbed" component={GoogleDriveTestbed} />
<RootStack.Screen name="KeysendTest" component={KeysendTest} />

export default () => (
<Root>
<AppContainer
ref={(navigatorRef) => setTopLevelNavigator(navigatorRef)}
/>
</Root>
);
<RootStack.Screen
name="DEV_CommandsX"
component={DEV_Commands}
/>
</RootStack.Navigator>
);
};
9 changes: 5 additions & 4 deletions src/components/BlurModal.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useEffect } from "react";
import { StyleSheet, TouchableOpacity } from "react-native";
import { View } from "react-native";
import { NavigationScreenProp } from "react-navigation";
import BlurOverlay, { closeOverlay, openOverlay } from "../Blur";
import { useNavigation } from "@react-navigation/native";

export interface ITransactionDetailsProps {
navigation: NavigationScreenProp<{}>;
children: any;
}
export default ({ navigation, children }: ITransactionDetailsProps) => {
export default ({ children }: ITransactionDetailsProps) => {
const navigation = useNavigation();

useEffect(() => {
setTimeout(() => {
openOverlay();
Expand All @@ -17,7 +18,7 @@ export default ({ navigation, children }: ITransactionDetailsProps) => {

const goBack = () => {
closeOverlay();
setTimeout(() => navigation.pop(), 0);
setTimeout(() => navigation.goBack(), 0);
};

return (
Expand Down
9 changes: 4 additions & 5 deletions src/components/FooterNav.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from "react";
import { Button, Footer, FooterTab, Icon, Text } from "native-base";
import { NavigationScreenProp } from "react-navigation";
import { useNavigation } from "@react-navigation/native";

export default () => {
const navigation = useNavigation();

export interface IFooterNavProps {
navigation: NavigationScreenProp<{}>;
}
export default ({ navigation }: IFooterNavProps) => {
return (
<Footer>
<FooterTab>
Expand Down
8 changes: 6 additions & 2 deletions src/state/Security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const security: ISecurityModel = {
actions.setLoggedIn(loginMethods.size === 0);
actions.setSeedAvailable(await getItemObject(StorageItem.seedStored) || false);
try {
actions.setFingerprintAvailable(await FingerprintScanner.isSensorAvailable() === "Fingerprint");
const sensorAvailable = await FingerprintScanner.isSensorAvailable();
actions.setFingerprintAvailable(sensorAvailable === "Biometrics");
} catch (e) {
console.log(e);
}
Expand Down Expand Up @@ -118,7 +119,10 @@ export const security: ISecurityModel = {
actions.setLoggedIn(true);
return true;
} catch (e) {
Alert.alert(e.message);
console.log(JSON.stringify(e));
if (e.name !== "UserCancel" && e.name !== "UserFallback") {
Alert.alert(e.message);
}
}
}),

Expand Down
Loading

0 comments on commit 44b1c1a

Please sign in to comment.