Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ import ErrorHandlerProvider from './src/providers/ErrorHandler';
import Debug from 'debug';
import { wrap } from './src/utils/sentry';
import InitializeAppProvider from './src/providers/InitializeApp';
import { ErrorBoundary } from 'react-error-boundary';
import { logErrorBoundaryError } from './src/utils/exceptions';
import ErrorFallbackProvider from './src/providers/ErrorFallback';

Debug.enable(process.env.DEBUG);
console.log('DEBUG:', process.env.DEBUG);

function App() {
return (
<PaperProvider theme={theme}>
<SafeAreaProvider>
<ErrorHandlerProvider />
<InitializeAppProvider />
</SafeAreaProvider>
</PaperProvider>
<ErrorBoundary FallbackComponent={ErrorFallbackProvider} onError={logErrorBoundaryError}>
<PaperProvider theme={theme}>
<SafeAreaProvider>
<ErrorHandlerProvider />
<InitializeAppProvider />
</SafeAreaProvider>
</PaperProvider>
</ErrorBoundary>
);
}

Expand Down
4 changes: 4 additions & 0 deletions ERROR_HANDLING.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,7 @@ const MyComponent = () => {
return <div>Component Loaded</div>;
};
```

## TODO

- Go through and action: <https://chatgpt.com/share/e/675853cb-9098-8013-8cc0-f61a4ea1be06>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"pako": "^2.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-error-boundary": "^4.1.2",
"react-native": "0.74.5",
"react-native-argon2": "^2.0.1",
"react-native-autocomplete-input": "^5.4.0",
Expand Down
231 changes: 118 additions & 113 deletions src/navigation/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import SelectAsset from '../screens/SelectAssetScreen';
import OnboardingScreen from '../screens/OnboardingScreen';
import AppInstructionProvider from '../providers/AppInstruction';
import { navigationRef } from '../utils/navigate';
import { ErrorBoundary } from 'react-error-boundary';
import ErrorFallbackProvider from '../providers/ErrorFallback';
import { logErrorBoundaryError } from '../utils/exceptions';

const prefix = Linking.createURL('');

Expand Down Expand Up @@ -85,9 +88,9 @@ export type MainRouteStackParamList = {
transaction?: ITransactionRequest | null;
requestType: string;
request:
| SignClientTypes.EventArguments['session_request']
| SignClientTypes.EventArguments['session_proposal']
| null;
| SignClientTypes.EventArguments['session_request']
| SignClientTypes.EventArguments['session_proposal']
| null;
};
BottomTabs: undefined;
Assets: undefined;
Expand Down Expand Up @@ -161,134 +164,136 @@ export default function RootNavigation() {

return (
<NavigationContainer ref={navigationRef} theme={CombinedDefaultTheme} linking={linking}>
{status === UserStatus.NONE || status === UserStatus.NOT_LOGGED_IN ? (
<Stack.Navigator initialRouteName={'Splash'} screenOptions={defaultScreenOptions}>
<Stack.Screen name="Splash" options={noHeaderScreenOptions} component={MainSplashScreen} />
<Stack.Screen name="Onboarding" options={noHeaderScreenOptions} component={OnboardingScreen} />
<ErrorBoundary FallbackComponent={ErrorFallbackProvider} onError={logErrorBoundaryError}>
{status === UserStatus.NONE || status === UserStatus.NOT_LOGGED_IN ? (
<Stack.Navigator initialRouteName={'Splash'} screenOptions={defaultScreenOptions}>
<Stack.Screen name="Splash" options={noHeaderScreenOptions} component={MainSplashScreen} />
<Stack.Screen name="Onboarding" options={noHeaderScreenOptions} component={OnboardingScreen} />

<Stack.Screen
name="TermsAndCondition"
options={{ headerBackTitleVisible: false, title: 'Terms and Conditions' }}
component={TermsAndConditionScreen}
/>
<Stack.Screen
name="PrivacyAndPolicy"
options={{ headerBackTitleVisible: false, title: 'Terms and Conditions' }}
component={PrivacyAndPolicyScreen}
/>
<Stack.Screen name="Home" options={noHeaderScreenOptions} component={HomeScreen} />
<Stack.Screen
name="CreateAccountUsername"
options={{ headerBackTitleVisible: false, title: 'Create New Account' }}
component={CreateAccountUsernameScreen}
/>
<Stack.Screen
name="CreatePassphrase"
options={{ headerBackTitleVisible: false, title: 'Create New Account' }}
component={CreatePassphraseScreen}
/>
<Stack.Screen
name="Hcaptcha"
options={{ headerBackTitleVisible: false, title: 'Create New Account' }}
component={HcaptchaScreen}
/>
<Stack.Screen
name="ConfirmPassphrase"
options={{ headerBackTitleVisible: false, title: 'Create New Account' }}
component={ConfirmPassphraseScreen}
/>
<Stack.Screen
name="LoginUsername"
options={{ headerBackTitleVisible: false, title: 'Login' }}
component={LoginUsernameScreen}
/>
<Stack.Screen
name="LoginPassphrase"
options={{ headerBackTitleVisible: false, title: 'Login' }}
component={LoginPassphraseScreen}
/>
</Stack.Navigator>
) : (
<>
<NotificationsProvider />
<CommunicationProvider />
<AppInstructionProvider />
<Stack.Navigator initialRouteName={'BottomTabs'} screenOptions={defaultScreenOptions}>
<Stack.Screen
name="Drawer"
component={DrawerNavigation}
options={{ headerShown: false, title: settings.config.appName }}
name="TermsAndCondition"
options={{ headerBackTitleVisible: false, title: 'Terms and Conditions' }}
component={TermsAndConditionScreen}
/>
<Stack.Screen
name="SSO"
options={{ ...noHeaderScreenOptions, title: settings.config.appName }}
component={SSOLoginScreen}
name="PrivacyAndPolicy"
options={{ headerBackTitleVisible: false, title: 'Terms and Conditions' }}
component={PrivacyAndPolicyScreen}
/>
<Stack.Screen name="Home" options={noHeaderScreenOptions} component={HomeScreen} />
<Stack.Screen
name="ProfilePreview"
options={{ headerBackTitleVisible: false, title: 'Profile Information' }}
component={ProfilePreviewScreen}
name="CreateAccountUsername"
options={{ headerBackTitleVisible: false, title: 'Create New Account' }}
component={CreateAccountUsernameScreen}
/>
<Stack.Screen
name="SignTransaction"
options={{ headerBackTitleVisible: false, title: 'Transaction Request' }}
component={SignTransactionConsentScreen}
name="CreatePassphrase"
options={{ headerBackTitleVisible: false, title: 'Create New Account' }}
component={CreatePassphraseScreen}
/>
<Stack.Screen
name="SignTransactionSuccess"
options={{
headerBackTitleVisible: false,
title: 'Transfer',
headerBackVisible: false,
}}
component={SignTransactionConsentSuccessScreen}
name="Hcaptcha"
options={{ headerBackTitleVisible: false, title: 'Create New Account' }}
component={HcaptchaScreen}
/>
<Stack.Screen
name="WalletConnectLogin"
options={{ ...noHeaderScreenOptions, title: settings.config.appName }}
component={WalletConnectLoginScreen}
name="ConfirmPassphrase"
options={{ headerBackTitleVisible: false, title: 'Create New Account' }}
component={ConfirmPassphraseScreen}
/>
<Stack.Screen
name="CreateEthereumKey"
options={{ headerBackTitleVisible: false, title: 'Generate key' }}
component={CreateEthereumKeyScreen}
initialParams={{}}
name="LoginUsername"
options={{ headerBackTitleVisible: false, title: 'Login' }}
component={LoginUsernameScreen}
/>
<Stack.Screen
name="AssetDetail"
options={({ route }) => ({
headerBackTitleVisible: false,
title: route.params?.screenTitle || 'AssetDetail',
})}
component={AssetDetail}
/>
<Stack.Screen
name="Send"
options={({ route }) => ({
headerBackTitleVisible: false,
title: route.params?.screenTitle || 'Send',
})}
component={SendScreen}
/>
<Stack.Screen
name="Receive"
options={({ route }) => ({
headerBackTitleVisible: false,
title: route.params?.screenTitle || 'Receive',
})}
component={ReceiveScreen}
/>
<Stack.Screen
name="SelectAsset"
options={({ route }) => ({
headerBackTitleVisible: false,
title: route.params?.screenTitle || 'Select Asset',
})}
component={SelectAsset}
name="LoginPassphrase"
options={{ headerBackTitleVisible: false, title: 'Login' }}
component={LoginPassphraseScreen}
/>
</Stack.Navigator>
</>
)}
) : (
<>
<NotificationsProvider />
<CommunicationProvider />
<AppInstructionProvider />
<Stack.Navigator initialRouteName={'BottomTabs'} screenOptions={defaultScreenOptions}>
<Stack.Screen
name="Drawer"
component={DrawerNavigation}
options={{ headerShown: false, title: settings.config.appName }}
/>
<Stack.Screen
name="SSO"
options={{ ...noHeaderScreenOptions, title: settings.config.appName }}
component={SSOLoginScreen}
/>
<Stack.Screen
name="ProfilePreview"
options={{ headerBackTitleVisible: false, title: 'Profile Information' }}
component={ProfilePreviewScreen}
/>
<Stack.Screen
name="SignTransaction"
options={{ headerBackTitleVisible: false, title: 'Transaction Request' }}
component={SignTransactionConsentScreen}
/>
<Stack.Screen
name="SignTransactionSuccess"
options={{
headerBackTitleVisible: false,
title: 'Transfer',
headerBackVisible: false,
}}
component={SignTransactionConsentSuccessScreen}
/>
<Stack.Screen
name="WalletConnectLogin"
options={{ ...noHeaderScreenOptions, title: settings.config.appName }}
component={WalletConnectLoginScreen}
/>
<Stack.Screen
name="CreateEthereumKey"
options={{ headerBackTitleVisible: false, title: 'Generate key' }}
component={CreateEthereumKeyScreen}
initialParams={{}}
/>
<Stack.Screen
name="AssetDetail"
options={({ route }) => ({
headerBackTitleVisible: false,
title: route.params?.screenTitle || 'AssetDetail',
})}
component={AssetDetail}
/>
<Stack.Screen
name="Send"
options={({ route }) => ({
headerBackTitleVisible: false,
title: route.params?.screenTitle || 'Send',
})}
component={SendScreen}
/>
<Stack.Screen
name="Receive"
options={({ route }) => ({
headerBackTitleVisible: false,
title: route.params?.screenTitle || 'Receive',
})}
component={ReceiveScreen}
/>
<Stack.Screen
name="SelectAsset"
options={({ route }) => ({
headerBackTitleVisible: false,
title: route.params?.screenTitle || 'Select Asset',
})}
component={SelectAsset}
/>
</Stack.Navigator>
</>
)}
</ErrorBoundary>
</NavigationContainer>
);
}
11 changes: 11 additions & 0 deletions src/providers/ErrorFallback.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { FallbackProps } from 'react-error-boundary';

export default function ErrorFallbackProvider({ error, resetErrorBoundary }: FallbackProps) {
return (
<div role="alert">
<p>Something went wrong:</p>
<pre>{error.message}</pre>
<button onClick={resetErrorBoundary}>Try again</button>
</div>
);
}
9 changes: 9 additions & 0 deletions src/utils/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ErrorState } from '../store/errorStore';
import Debug from 'debug';
import { captureError } from './sentry';
import { serializeAny } from './strings';
import { ErrorInfo } from 'react';

const debug = Debug('tonomy-id:utils:exceptions');

Expand Down Expand Up @@ -59,3 +60,11 @@ export default function setErrorHandlers(errorStore: ErrorState) {
captureError('Native Exception Handler', new Error(errorString), 'fatal');
});
}

export function logErrorBoundaryError(error: Error, info: ErrorInfo) {
debug('ErrorBoundary Error', error, info);

// @ts-expect-error info is not a property of Error
error.info = info;
captureError('ErrorBoundary', error, 'fatal');
}
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/runtime@npm:^7.15.4, @babel/runtime@npm:^7.18.6, @babel/runtime@npm:^7.20.0, @babel/runtime@npm:^7.25.0":
"@babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.15.4, @babel/runtime@npm:^7.18.6, @babel/runtime@npm:^7.20.0, @babel/runtime@npm:^7.25.0":
version: 7.26.0
resolution: "@babel/runtime@npm:7.26.0"
dependencies:
Expand Down Expand Up @@ -17002,6 +17002,17 @@ __metadata:
languageName: node
linkType: hard

"react-error-boundary@npm:^4.1.2":
version: 4.1.2
resolution: "react-error-boundary@npm:4.1.2"
dependencies:
"@babel/runtime": "npm:^7.12.5"
peerDependencies:
react: ">=16.13.1"
checksum: 10c0/0737e5259bed40ce14eb0823b3c7b152171921f2179e604f48f3913490cdc594d6c22d43d7abb4ffb1512c832850228db07aa69d3b941db324953a5e393cb399
languageName: node
linkType: hard

"react-fast-compare@npm:^2.0.4":
version: 2.0.4
resolution: "react-fast-compare@npm:2.0.4"
Expand Down Expand Up @@ -19493,6 +19504,7 @@ __metadata:
prettier: "npm:^2.7.1"
react: "npm:18.2.0"
react-dom: "npm:18.2.0"
react-error-boundary: "npm:^4.1.2"
react-native: "npm:0.74.5"
react-native-argon2: "npm:^2.0.1"
react-native-autocomplete-input: "npm:^5.4.0"
Expand Down