Skip to content

Commit

Permalink
adding trace id into headers and validate is it set
Browse files Browse the repository at this point in the history
  • Loading branch information
sleyter93 committed Mar 1, 2024
1 parent 01a4449 commit 60d4820
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 1 deletion.
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=IOVLABS
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=IOVLABS
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=IOVLABS
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=IOVLABS
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
9 changes: 8 additions & 1 deletion src/core/Core.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useContext, useEffect } from 'react'
import { useCallback, useContext, useEffect, useState } from 'react'
import { StatusBar, View } from 'react-native'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import {
Expand All @@ -21,6 +21,7 @@ import {
import { sharedStyles } from 'shared/constants'
import { WalletConnect2Provider } from 'screens/walletConnect/WalletConnect2Context'
import { WalletContext } from 'shared/wallet'
import { TraceError } from 'store/slices/settingsSlice/types'

import { useStateSubscription } from './hooks/useStateSubscription'
import { Cover } from './components/Cover'
Expand All @@ -30,6 +31,7 @@ export const navigationContainerRef =
createNavigationContainerRef<RootTabsParamsList>()

export const Core = () => {
const [, setError] = useState()
const dispatch = useAppDispatch()
const requests = useAppSelector(selectRequests)
const topColor = useAppSelector(selectTopColor)
Expand All @@ -42,6 +44,11 @@ export const Core = () => {
await dispatch(unlockApp({ isOffline, initializeWallet })).unwrap()
} catch (err) {
console.log('ERR CORE', err)
if (err instanceof TraceError) {
setError(() => {
throw err
})
}
}
}, [dispatch, isOffline, initializeWallet])

Expand Down
6 changes: 6 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 @@ -45,6 +46,7 @@ import {
CreateFirstWalletAction,
OnRequestAction,
SettingsSlice,
TraceError,
UnlockAppAction,
} from './types'
import { UsdPricesState } from '../usdPricesSlice'
Expand Down Expand Up @@ -228,6 +230,10 @@ export const unlockApp = createAsyncThunk<
AsyncThunkWithTypes
>('settings/unlockApp', async (payload, thunkAPI) => {
try {
if (!Config.TRACE_ID) {
return thunkAPI.rejectWithValue(new TraceError('Trace Id is not valid'))
}

const {
persistentData: { isFirstLaunch },
settings: { chainId },
Expand Down
6 changes: 6 additions & 0 deletions src/redux/slices/settingsSlice/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ export interface SettingsSlice {
bitcoin: Bitcoin | null
usedBitcoinAddresses: { [key: string]: string }
}

export class TraceError extends Error {
constructor(message: string) {
super(message)
}
}
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

0 comments on commit 60d4820

Please sign in to comment.