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 2e020b6
Show file tree
Hide file tree
Showing 9 changed files with 30 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=
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 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
8 changes: 7 additions & 1 deletion src/core/Core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ 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 { useSetGlobalError } from 'components/GlobalErrorHandler'

import { useStateSubscription } from './hooks/useStateSubscription'
import { Cover } from './components/Cover'
Expand All @@ -33,6 +35,7 @@ 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)
Expand All @@ -42,8 +45,11 @@ export const Core = () => {
await dispatch(unlockApp({ isOffline, initializeWallet })).unwrap()
} catch (err) {
console.log('ERR CORE', err)
if (err instanceof TraceError) {
setGlobalError(err.message)
}
}
}, [dispatch, isOffline, initializeWallet])
}, [dispatch, isOffline, initializeWallet, setGlobalError])

useEffect(() => {
unlockAppFn()
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 2e020b6

Please sign in to comment.