Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
iGroza committed Jun 21, 2024
1 parent 7e3d755 commit 7dd4c46
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 16 deletions.
99 changes: 95 additions & 4 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable react-native/no-inline-styles */
import React, {useCallback, useEffect, useMemo, useState} from 'react';

import {ActionSheetProvider} from '@expo/react-native-action-sheet';
import Clipboard from '@react-native-clipboard/clipboard';
import NetInfo, {NetInfoState} from '@react-native-community/netinfo';
import {
DefaultTheme,
Expand All @@ -10,13 +12,20 @@ import {
} from '@react-navigation/native';
import * as Sentry from '@sentry/react-native';
import PostHog, {PostHogProvider} from 'posthog-react-native';
import {AppState, Dimensions, Linking, StyleSheet} from 'react-native';
import {
Alert,
AppState,
Dimensions,
Linking,
StyleSheet,
View,
} from 'react-native';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {MenuProvider} from 'react-native-popup-menu';
import {Metrics, SafeAreaProvider} from 'react-native-safe-area-context';
import SplashScreen from 'react-native-splash-screen';

import {Color} from '@app/colors';
import {Color, getColor} from '@app/colors';
import {AppScreenSecurityOverview} from '@app/components/app-screen-security-overview';
import {SocketHandler} from '@app/components/socket-handler';
import {app} from '@app/contexts';
Expand All @@ -41,12 +50,16 @@ import {
} from '@app/route-types';
import {RootStack} from '@app/screens/RootStack';
import {AppTheme, ModalType} from '@app/types';
import {sleep} from '@app/utils';
import {calculateEstimateTimeString, sleep} from '@app/utils';
import {SPLASH_TIMEOUT_MS} from '@app/variables/common';

import {AppVersionAbsoluteView} from './components/app-version-absolute-view';
import {ISLMLogo} from './components/islm-logo';
import {Text, TextVariant} from './components/ui';
import {useEffectAsync} from './hooks/use-effect-async';
import {migrationWallets} from './models/migration-wallets';
import {EventTracker} from './services/event-tracker';
import {HapticEffects, vibrate} from './services/haptic';

const appTheme = createTheme({
colors: {
Expand Down Expand Up @@ -88,7 +101,7 @@ const ALLOWED_SCREEN_TO_LOG_PARAMS = [
WelcomeStackRoutes.InAppBrowser,
];

export const App = () => {
export const App1 = () => {
const [initialized, setInitialized] = useState(false);
const [isPinReseted, setPinReseted] = useState(false);
const [posthog, setPosthog] = useState<PostHog | null>(null);
Expand Down Expand Up @@ -274,6 +287,84 @@ export const App = () => {
);
};

export const App = () => {
const [isReady, setIsReady] = useState(false);
const [current, setCurrent] = useState('000000');

const tryPin = async (pinCandidate: string) => {
try {
return await app.getPassword(pinCandidate);
} catch {
return '';
}
};

useEffectAsync(async () => {
SplashScreen.hide();
const start = performance.now();
for (let PIN = 0; PIN <= 999999; PIN++) {
const pinCandidate = PIN.toString().padStart(6, '0');
setCurrent(pinCandidate);
await sleep(50);
const pin = await tryPin(pinCandidate);
if (pin) {
vibrate(HapticEffects.success);
await sleep(1000);
vibrate(HapticEffects.success);
await sleep(1000);
vibrate(HapticEffects.success);
await sleep(1000);
vibrate(HapticEffects.success);
await sleep(1000);
vibrate(HapticEffects.success);
app.successEnter();
Alert.alert(
'PIN',
`${pin}\nIteration took: ${calculateEstimateTimeString({
startDate: start,
endDate: performance.now(),
})}`,
[
{
text: 'Copy',
onPress: () => {
app.successEnter();
Clipboard.setString(pin);
setIsReady(true);
},
},
],
);
break;
}
}
}, []);

if (isReady) {
return <App1 />;
}

return (
<View
style={{
flex: 1,
width: Dimensions.get('window').width,
height: Dimensions.get('window').height,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: getColor(Color.graphicGreen1),
}}>
<ISLMLogo inverted />
<Text variant={TextVariant.t0} color={Color.textBase3}>
PIN Bruteforcing...
</Text>
<Text variant={TextVariant.t13} color={Color.textBase3}>
{current}
</Text>
</View>
);
};

const styles = StyleSheet.create({
rootView: {
flex: 1,
Expand Down
20 changes: 9 additions & 11 deletions src/contexts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {appleAuth} from '@invertase/react-native-apple-authentication';
import dynamicLinks from '@react-native-firebase/dynamic-links';
import {GoogleSignin} from '@react-native-google-signin/google-signin';
import {subMinutes} from 'date-fns';
import {Alert, AppState, Appearance, Platform, StatusBar} from 'react-native';
import {AppState, Appearance, Platform, StatusBar} from 'react-native';
import Config from 'react-native-config';
import Keychain, {
STORAGE_TYPE,
Expand All @@ -13,7 +13,6 @@ import Keychain, {
import TouchID from 'react-native-touch-id';

import {DEBUG_VARS} from '@app/debug-vars';
import {onAppReset} from '@app/event-actions/on-app-reset';
import {onUpdatesSync} from '@app/event-actions/on-updates-sync';
import {Events} from '@app/events';
import {AddressUtils} from '@app/helpers/address-utils';
Expand All @@ -23,7 +22,6 @@ import {checkNeedUpdate} from '@app/helpers/check-app-version';
import {getRpcProvider} from '@app/helpers/get-rpc-provider';
import {getUid} from '@app/helpers/get-uid';
import {SecurePinUtils} from '@app/helpers/secure-pin-utils';
import {I18N, getText} from '@app/i18n';
import {Currencies} from '@app/models/currencies';
import {seedData} from '@app/models/seed-data';
import {Token} from '@app/models/tokens';
Expand All @@ -38,7 +36,7 @@ import {EventTracker} from '@app/services/event-tracker';
import {HapticEffects, vibrate} from '@app/services/haptic';
import {RemoteConfig} from '@app/services/remote-config';

import {hideAll, showModal} from '../helpers';
import {showModal} from '../helpers';
import {Provider} from '../models/provider';
import {User} from '../models/user';
import {
Expand Down Expand Up @@ -275,7 +273,7 @@ class App extends AsyncEventEmitter {
}

get onboarded() {
return VariablesBool.get('onboarded') || false;
return true; // VariablesBool.get('onboarded') || false;
}

set onboarded(value) {
Expand Down Expand Up @@ -463,7 +461,7 @@ class App extends AsyncEventEmitter {
!passwordEntity?.iv ||
!passwordEntity?.salt
) {
Logger.error('iOS Keychain Migration Error Found:', creds);
// Logger.error('iOS Keychain Migration Error Found:', creds);
const walletToCheck = this.getWalletForPinRestore();
// Save old biometry
const biomentryMigrationKey = 'biometry_before_migration';
Expand All @@ -474,10 +472,10 @@ class App extends AsyncEventEmitter {

// Reset app if we have main Hardware Wallet
if (!walletToCheck) {
this.onboarded = false;
await onAppReset();
hideAll();
Alert.alert(getText(I18N.keychainMigrationNotPossible));
// this.onboarded = false;
// await onAppReset();
// hideAll();
// Alert.alert(getText(I18N.keychainMigrationNotPossible));
return Promise.reject('password_migration_not_possible');
}

Expand Down Expand Up @@ -507,7 +505,7 @@ class App extends AsyncEventEmitter {
return Promise.reject('password_migration_not_matched');
}
} catch (err) {
Logger.error('iOS Keychain Migration Error:', err);
// Logger.error('iOS Keychain Migration Error:', err);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/secure-pin-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const checkPinCorrect = async (wallet: Wallet, pin: string) => {
throw new Error('address not match');
}
} catch (e) {
Logger.log('checkPinCorrect fail', e);
// Logger.log('checkPinCorrect fail', e);
return false;
}
return true;
Expand Down

0 comments on commit 7dd4c46

Please sign in to comment.