Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

US-2119: Adding Trace ID #899

Merged
merged 2 commits into from
Mar 7, 2024
Merged
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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ RIF_WALLET_KEY=RIF_WALLET
WALLETCONNECT2_PROJECT_ID=d9224e919473fd749ba8298879ce7569

USE_RELAY=true

TRACE_ID=
2 changes: 2 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ DEFAULT_CHAIN_TYPE=TESTNET

RIF_WALLET_KEY=RIF_WALLET
WALLETCONNECT2_PROJECT_ID=d9224e919473fd749ba8298879ce7569

TRACE_ID=
2 changes: 2 additions & 0 deletions .env.local.android
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ DEFAULT_CHAIN_TYPE=TESTNET

RIF_WALLET_KEY=RIF_WALLET
WALLETCONNECT2_PROJECT_ID=d9224e919473fd749ba8298879ce7569

TRACE_ID=
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ DEFAULT_CHAIN_TYPE=TESTNET

RIF_WALLET_KEY=RIF_WALLET
WALLETCONNECT2_PROJECT_ID=d9224e919473fd749ba8298879ce7569

TRACE_ID=
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The main use case of the RIF Wallet using account abstraction is to pay the gas
- Install the dependecies using yarn. This will also run the postinstall script that shims the missing packages: `yarn`
- The postinstall script runs the `rn-nodeify` package which adds packages that are native to the browser but not to react native.
- For **iOS** you need to run the additional installation steps: `cd ios` and then `pod install`
- Set the environment variable `TRACE_ID` in `.env` file to connect with backend server with an identifier, i.e. your company name.
- Run the app using the desired platform:
- `yarn ios`
- `yarn android`
Expand Down
1 change: 1 addition & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare module 'react-native-config' {
RIF_WALLET_KEY: string
WALLETCONNECT2_PROJECT_ID: string
USE_RELAY: string
TRACE_ID: string
}

export const Config: NativeConfig
Expand Down
10 changes: 6 additions & 4 deletions src/components/GlobalErrorHandler/GlobalErrorHandlerView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Clipboard from '@react-native-community/clipboard'
import React from 'react'
import { Image, StyleSheet, TouchableOpacity, View } from 'react-native'
import { useTranslation } from 'react-i18next'

import { sharedColors, sharedStyles } from 'src/shared/constants'
import { castStyle } from 'shared/utils'
Expand All @@ -19,6 +20,7 @@ const GlobalErrorHandlerView: React.FC<GlobalErrorHandlerViewType> = ({
message,
}) => {
const { handleReload, globalError } = useGlobalErrorContext()
const { t } = useTranslation()
const messageToShow: string = message || globalError || ''

const onCopyError = React.useCallback(() => {
Expand All @@ -36,10 +38,10 @@ const GlobalErrorHandlerView: React.FC<GlobalErrorHandlerViewType> = ({
<View style={styles.secondView}>
<View style={styles.textView}>
<Typography type={'h1'} style={styles.text}>
{'Oops... Something went wrong!'}
{t('global_error_title')}
</Typography>
<Typography type={'body1'} style={styles.text}>
{'We are working hard to fix it.'}
{t('global_error_subtitle')}
</Typography>
</View>
{messageToShow !== '' && (
Expand All @@ -48,7 +50,7 @@ const GlobalErrorHandlerView: React.FC<GlobalErrorHandlerViewType> = ({
type={'body2'}
color={sharedColors.white}
style={styles.errorDetailsText}>
{'error details'}
{t('global_error_details_title')}
</Typography>

<TouchableOpacity
Expand All @@ -58,7 +60,7 @@ const GlobalErrorHandlerView: React.FC<GlobalErrorHandlerViewType> = ({
type={'body3'}
color={sharedColors.white}
style={sharedStyles.flex}>
{messageToShow}
{t(messageToShow)}
</Typography>
<ContentCopyMaterialIcon color={sharedColors.white} size={25} />
</TouchableOpacity>
Expand Down
8 changes: 6 additions & 2 deletions src/core/Core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { sharedStyles } from 'shared/constants'
import { WalletConnect2Provider } from 'screens/walletConnect/WalletConnect2Context'
import { WalletContext } from 'shared/wallet'
import { useSetGlobalError } from 'components/GlobalErrorHandler'

import { useStateSubscription } from './hooks/useStateSubscription'
import { Cover } from './components/Cover'
Expand All @@ -33,17 +34,20 @@ export const Core = () => {
const dispatch = useAppDispatch()
const requests = useAppSelector(selectRequests)
const topColor = useAppSelector(selectTopColor)
const setGlobalError = useSetGlobalError()
const isOffline = useIsOffline()
const { active } = useStateSubscription()
const { wallet, initializeWallet } = useContext(WalletContext)

const unlockAppFn = useCallback(async () => {
try {
await dispatch(unlockApp({ isOffline, initializeWallet })).unwrap()
await dispatch(
unlockApp({ isOffline, initializeWallet, setGlobalError }),
).unwrap()
} catch (err) {
console.log('ERR CORE', err)
}
}, [dispatch, isOffline, initializeWallet])
}, [dispatch, isOffline, initializeWallet, setGlobalError])

useEffect(() => {
unlockAppFn()
Expand Down
5 changes: 4 additions & 1 deletion src/core/hooks/useStateSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { useAppDispatch, useAppSelector } from 'store/storeUtils'
import { SocketsEvents, socketsEvents } from 'src/subscriptions/rifSockets'
import { useWalletStateSetters } from 'shared/wallet'
import { useSetGlobalError } from 'components/GlobalErrorHandler'

import { useAppState } from './useAppState'
import { useIsOffline } from './useIsOffline'
Expand All @@ -21,6 +22,7 @@ let timer: TimeoutId
export const useStateSubscription = () => {
const { setWallet, setWalletIsDeployed, initializeWallet } =
useWalletStateSetters()
const setGlobalError = useSetGlobalError()

const dispatch = useAppDispatch()
const isOffline = useIsOffline()
Expand Down Expand Up @@ -61,7 +63,7 @@ export const useStateSubscription = () => {
previousAppState.current === 'background' &&
active
) {
dispatch(unlockApp({ isOffline, initializeWallet }))
dispatch(unlockApp({ isOffline, initializeWallet, setGlobalError }))
}
return () => {
socketsEvents.emit(SocketsEvents.DISCONNECT)
Expand All @@ -77,6 +79,7 @@ export const useStateSubscription = () => {
initializeWallet,
setWallet,
setWalletIsDeployed,
setGlobalError,
])

useEffect(() => {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ const resources = {
wallet_backup_title: 'Warning!',
wallet_backup_message:
'We have disabled the ability to take a picture of the mnemonic because it is important that you keep it private. Please write it down instead',
global_error_title: 'Oops... Something went wrong!',
global_error_subtitle: 'We are working hard to fix it.',
global_error_details_title: 'error details',
global_trace_id_error: 'Trace Id is not valid',
},
},
es: {
Expand Down
8 changes: 8 additions & 0 deletions src/redux/slices/settingsSlice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { initializeSslPinning } from 'react-native-ssl-public-key-pinning'
import { RifWalletServicesFetcher } from '@rsksmart/rif-wallet-services'
import { providers } from 'ethers'
import { RifRelayConfig } from '@rsksmart/rif-relay-light-sdk'
import Config from 'react-native-config'

import { ChainID, WalletState } from 'lib/eoaWallet'

Expand Down Expand Up @@ -228,6 +229,13 @@ export const unlockApp = createAsyncThunk<
AsyncThunkWithTypes
>('settings/unlockApp', async (payload, thunkAPI) => {
try {
if (!Config.TRACE_ID) {
sleyter93 marked this conversation as resolved.
Show resolved Hide resolved
const { setGlobalError } = payload
const errorMessage = 'global_trace_id_error'
setGlobalError(errorMessage)
return thunkAPI.rejectWithValue(errorMessage)
}

const {
persistentData: { isFirstLaunch },
settings: { chainId },
Expand Down
1 change: 1 addition & 0 deletions src/redux/slices/settingsSlice/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface UnlockAppAction {
initializeWallet: InitializeWallet
isOffline?: boolean
pinUnlocked?: boolean
setGlobalError: (value: string) => void
}

export interface SetKeysAction {
Expand Down
6 changes: 4 additions & 2 deletions src/screens/createKeys/retryLogin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import { sharedColors, sharedStyles } from 'shared/constants'
import { resetApp, unlockApp } from 'store/slices/settingsSlice'
import { useAppDispatch } from 'store/storeUtils'
import { useInitializeWallet } from 'shared/wallet'
import { useSetGlobalError } from 'components/GlobalErrorHandler'

export const RetryLogin = () => {
const initializeWallet = useInitializeWallet()
const setGlobalError = useSetGlobalError()
const dispatch = useAppDispatch()
const { t } = useTranslation()

const retryLogin = useCallback(() => {
dispatch(unlockApp({ initializeWallet }))
}, [dispatch, initializeWallet])
dispatch(unlockApp({ initializeWallet, setGlobalError }))
}, [dispatch, initializeWallet, setGlobalError])

return (
<View style={[sharedStyles.screen, sharedStyles.contentCenter]}>
Expand Down
7 changes: 6 additions & 1 deletion src/screens/pinScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
CreateKeysScreenProps,
} from 'navigation/createKeysNavigator'
import { useInitializeWallet } from 'shared/wallet'
import { useSetGlobalError } from 'components/GlobalErrorHandler'

type PIN = Array<string | null>
const defaultPin = [null, null, null, null]
Expand Down Expand Up @@ -123,6 +124,7 @@ type Props =

export const PinScreen = ({ navigation, route }: Props) => {
const initializeWallet = useInitializeWallet()
const setGlobalError = useSetGlobalError()
const insets = useSafeAreaInsets()
const isFocused = useIsFocused()
// const isVisible = useKeyboardIsVisible()
Expand Down Expand Up @@ -282,7 +284,9 @@ export const PinScreen = ({ navigation, route }: Props) => {
const handleLastDigit = useCallback(() => {
if (!isChangeRequested && isPinEqual) {
// if pin exists unlocks the app
dispatch(unlockApp({ pinUnlocked: true, initializeWallet }))
dispatch(
unlockApp({ pinUnlocked: true, initializeWallet, setGlobalError }),
)
} else if (isChangeRequested && isPinEqual) {
// if pin change requested set new pin
setTimeout(() => {
Expand All @@ -302,6 +306,7 @@ export const PinScreen = ({ navigation, route }: Props) => {
PIN,
navigation,
initializeWallet,
setGlobalError,
])

useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/subscriptions/rifSockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
RifWalletServicesSocket,
} from '@rsksmart/rif-wallet-services'
import DeviceInfo from 'react-native-device-info'
import Config from 'react-native-config'

import { ChainID } from 'lib/eoaWallet'

Expand Down Expand Up @@ -95,6 +96,7 @@ export const rifSockets = ({
chainId,
{
'User-Agent': DeviceInfo.getUserAgentSync(),
'x-trace-id': Config.TRACE_ID,
},
blockNumber,
)
Expand Down
Loading