Skip to content

Commit f9fb0bd

Browse files
finish simple implementation with hard code mnemonic and password
1 parent fa06fb2 commit f9fb0bd

File tree

16 files changed

+614
-205
lines changed

16 files changed

+614
-205
lines changed

App.tsx

Lines changed: 0 additions & 154 deletions
This file was deleted.

__tests__/App.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'react-native';
66
import React from 'react';
7-
import App from '../App';
7+
import App from '../app/App';
88

99
// Note: import explicitly to use the types shiped with jest.
1010
import {it} from '@jest/globals';

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
22

33
<uses-permission android:name="android.permission.INTERNET" />
4-
4+
<uses-permission android:name="android.permission.CAMERA" />
55
<application
66
android:name=".MainApplication"
77
android:label="@string/app_name"

app/App.tsx

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Sample React Native App
3+
* https://github.com/facebook/react-native
4+
*
5+
* @format
6+
*/
7+
8+
import React, {useEffect} from 'react';
9+
// import {
10+
// SafeAreaView,
11+
// ScrollView,
12+
// StatusBar,
13+
// StyleSheet,
14+
// Text,
15+
// useColorScheme,
16+
// View,
17+
// useWindowDimensions,
18+
// } from 'react-native';
19+
20+
import HomePage from './pages/Home';
21+
import FindPage from './pages/Find';
22+
import AccountPage from './pages/Account';
23+
import QRScannerPage from './pages/QRScanner';
24+
import SignPage from './pages/Sign';
25+
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
26+
import {NavigationContainer} from '@react-navigation/native';
27+
import {createNativeStackNavigator} from '@react-navigation/native-stack';
28+
import Routes from './routes/Routes';
29+
import {loadWallet} from './wallet';
30+
31+
const Tab = createBottomTabNavigator();
32+
// const Stack = createNativeStackNavigator();
33+
34+
const FindStack = createNativeStackNavigator();
35+
const FindStackScreen = () => (
36+
<FindStack.Navigator screenOptions={{headerShown: false}}>
37+
<FindStack.Group>
38+
<FindStack.Screen name={Routes.FIND} component={FindPage} />
39+
<FindStack.Screen name={Routes.SIGN} component={SignPage} />
40+
</FindStack.Group>
41+
<FindStack.Group screenOptions={{presentation: 'modal'}}>
42+
<FindStack.Screen name={Routes.QR_SCANNER} component={QRScannerPage} />
43+
</FindStack.Group>
44+
</FindStack.Navigator>
45+
);
46+
47+
// FindStack.navigationOptions = ({navigation}) => {
48+
// let tabBarVisible = true;
49+
50+
// // let routeName = navigation.state.routes[navigation.state.index].routeName;
51+
52+
// // if (routeName == 'ProductDetails') {
53+
// // tabBarVisible = false;
54+
// // }
55+
56+
// return {
57+
// };
58+
// };
59+
60+
function App(): JSX.Element {
61+
useEffect(() => {
62+
// TODO : load wallet from storage
63+
loadWallet('j1io2u7$@081nf%@au0-,.,3151lijasfa');
64+
}, []);
65+
return (
66+
<NavigationContainer>
67+
<Tab.Navigator screenOptions={{headerShown: false}}>
68+
<Tab.Screen name="Home" component={HomePage} />
69+
<Tab.Screen name="Find" component={FindStackScreen} />
70+
<Tab.Screen name="Account" component={AccountPage} />
71+
</Tab.Navigator>
72+
</NavigationContainer>
73+
);
74+
}
75+
76+
export default App;

app/pages/Account/index.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react';
2+
import {NavigationContainer} from '@react-navigation/native';
3+
import {
4+
SafeAreaView,
5+
Text,
6+
View,
7+
StyleSheet,
8+
useWindowDimensions,
9+
} from 'react-native';
10+
import QRCode from 'react-native-qrcode-svg';
11+
import {Key, EVMWallet} from 'doom-wallet-core';
12+
const mnemonic =
13+
'farm library shuffle knee equal blush disease table deliver custom farm stereo fat level dawn book advance lamp clutch crumble gaze law bird jazz';
14+
const password = 'j1io2u7$@081nf%@au0-,.,3151lijasfa';
15+
const AccountPage = () => {
16+
const [ur, setUr] = React.useState('https://www.google.com');
17+
const {width} = useWindowDimensions();
18+
React.useEffect(() => {
19+
const wallet = new EVMWallet(Key.fromMnemonic(mnemonic, password));
20+
setUr(wallet.getConnectionUR());
21+
}, []);
22+
return (
23+
// <NavigationContainer>
24+
<SafeAreaView>
25+
<View>
26+
<Text>Account</Text>
27+
<View
28+
style={[
29+
styles.qrCodeContainer,
30+
{
31+
width: width - 40,
32+
},
33+
]}>
34+
<QRCode size={width - 40} value={ur} />
35+
</View>
36+
</View>
37+
</SafeAreaView>
38+
// </NavigationContainer>
39+
);
40+
};
41+
42+
const styles = StyleSheet.create({
43+
qrCodeContainer: {
44+
margin: 20,
45+
aspectRatio: 1,
46+
// height: 100%,
47+
},
48+
});
49+
export default AccountPage;

app/pages/Find/index.tsx

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import React, {useEffect} from 'react';
2+
import {NavigationContainer, useNavigation} from '@react-navigation/native';
3+
import {SafeAreaView, Text, View, Button} from 'react-native';
4+
import {check, request, PERMISSIONS, RESULTS} from 'react-native-permissions';
5+
import Routes from '../../routes/Routes';
6+
7+
function QRCodeButton({
8+
cameraPermission,
9+
onPress,
10+
}: {
11+
cameraPermission: string;
12+
onPress: () => void;
13+
}) {
14+
if (cameraPermission === RESULTS.GRANTED) {
15+
return <Button title="Scan QR Code" onPress={onPress} />;
16+
} else if (cameraPermission === RESULTS.DENIED) {
17+
return (
18+
<Button
19+
title="Grant Camera Permission And Scan QR Code"
20+
onPress={onPress}
21+
/>
22+
);
23+
} else {
24+
return <Text>Camera permission not granted</Text>;
25+
}
26+
}
27+
28+
const FindPage = () => {
29+
const [urText, setUrText] = React.useState<string>('');
30+
const [cameraPermission, setCameraPermission] =
31+
React.useState('not-determined');
32+
useEffect(() => {
33+
async function fetchPermission() {
34+
// TODO android
35+
const permission = await check(PERMISSIONS.IOS.CAMERA);
36+
setCameraPermission(permission);
37+
}
38+
39+
fetchPermission();
40+
}, []);
41+
const navigation = useNavigation();
42+
// const cameraPermission = await Camera.getCameraPermissionStatus()
43+
// const newCameraPermission = await Camera.requestCameraPermission()
44+
45+
const onSuccess = (ur: string) => {
46+
// setUrText(ur);
47+
navigation.navigate(Routes.SIGN, {ur});
48+
};
49+
50+
const showResult = () => {
51+
if (urText !== '') {
52+
return <Text>{urText}</Text>;
53+
} else {
54+
return null;
55+
}
56+
};
57+
58+
return (
59+
// <NavigationContainer>
60+
<SafeAreaView>
61+
<View>
62+
<Text>QR Code</Text>
63+
{showResult()}
64+
<QRCodeButton
65+
cameraPermission={cameraPermission}
66+
onPress={() => {
67+
if (cameraPermission === 'authorized') {
68+
// Navigate to QR Scanner
69+
setUrText('');
70+
navigation.navigate(Routes.QR_SCANNER, {onSuccess});
71+
} else {
72+
request(PERMISSIONS.IOS.CAMERA).then(permission => {
73+
setCameraPermission(permission);
74+
navigation.navigate(Routes.QR_SCANNER, {onSuccess});
75+
});
76+
}
77+
}}
78+
/>
79+
</View>
80+
</SafeAreaView>
81+
// </NavigationContainer>
82+
);
83+
};
84+
85+
export default FindPage;

0 commit comments

Comments
 (0)