Skip to content

Commit d92688e

Browse files
US-2029 RIF Wallet - Socket error - [TypeError: Cannot set property 'cache' of undefined] (#810)
* chore: upgrade @rsksmart/rif-wallet-services * refactor: update usage of rifSockets in the app * lint: fix unused errors
1 parent b6b862e commit d92688e

File tree

7 files changed

+27
-42
lines changed

7 files changed

+27
-42
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@rsksmart/rif-wallet-bitcoin": "^1.2.0",
4040
"@rsksmart/rif-wallet-core": "^1.0.2",
4141
"@rsksmart/rif-wallet-eip681": "1.0.1",
42-
"@rsksmart/rif-wallet-services": "^1.0.8",
42+
"@rsksmart/rif-wallet-services": "^1.1.0",
4343
"@rsksmart/rif-wallet-token": "^1.0.1",
4444
"@rsksmart/rlogin-dpath": "^1.0.1",
4545
"@rsksmart/rns-resolver.js": "^1.0.1",

src/redux/slices/settingsSlice/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const createWallet = createAsyncThunk<
138138

139139
// connect to sockets
140140
rifSockets({
141-
wallet: kms.rifWallet,
141+
address: kms.rifWallet.smartWalletAddress,
142142
fetcher: fetcherInstance,
143143
dispatch: thunkAPI.dispatch,
144144
setGlobalError: thunkAPI.rejectWithValue,
@@ -259,7 +259,7 @@ export const unlockApp = createAsyncThunk<
259259

260260
// connect to sockets
261261
rifSockets({
262-
wallet: rifWallet,
262+
address: rifWallet.smartWalletAddress,
263263
fetcher: fetcherInstance,
264264
dispatch: thunkAPI.dispatch,
265265
setGlobalError: thunkAPI.rejectWithValue,

src/screens/activity/ActivityScreen.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { EnhancedResult } from '@rsksmart/rif-wallet-abi-enhancer'
2-
import { RIFWallet } from '@rsksmart/rif-wallet-core'
32
import { IApiTransaction } from '@rsksmart/rif-wallet-services'
43
import { ethers } from 'ethers'
54
import { useContext, useEffect } from 'react'
@@ -21,6 +20,7 @@ import {
2120
} from 'store/slices/transactionsSlice/selectors'
2221
import { useAppDispatch, useAppSelector } from 'store/storeUtils'
2322
import { WalletContext } from 'shared/wallet'
23+
import { ChainTypesByIdType } from 'src/shared/constants/chainConstants'
2424

2525
import { ActivityBasicRow } from './ActivityRow'
2626

@@ -116,10 +116,9 @@ const styles = StyleSheet.create({
116116

117117
export const enhanceTransactionInput = async (
118118
transaction: IApiTransaction,
119-
wallet: RIFWallet,
119+
chainId: ChainTypesByIdType,
120120
): Promise<EnhancedResult | null> => {
121121
try {
122-
const chainId = await wallet.getChainId()
123122
const enhancedTx = await abiEnhancer.enhance(chainId, {
124123
from: transaction.from.toLowerCase(),
125124
to: transaction.to.toLowerCase(),

src/subscriptions/onSocketChangeEmitted.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IApiTransaction } from '@rsksmart/rif-wallet-services'
2-
import { EnhancedResult } from '@rsksmart/rif-wallet-abi-enhancer'
2+
import { EnhancedResult, IAbiEnhancer } from '@rsksmart/rif-wallet-abi-enhancer'
33

44
import { resetSocketState } from 'store/shared/actions/resetSocketState'
55
import { addOrUpdateBalances } from 'store/slices/balancesSlice'
@@ -16,19 +16,21 @@ import { AppDispatch } from 'store/index'
1616
import { ChainTypesByIdType } from 'shared/constants/chainConstants'
1717
import { getCurrentChainId } from 'storage/ChainStorage'
1818

19-
import { AbiWallet, Action } from './types'
19+
import { Action } from './types'
2020

21-
interface OnNewTransactionEventEmittedArgs extends AbiWallet {
21+
interface OnNewTransactionEventEmittedArgs {
2222
dispatch: AppDispatch
2323
payload: IApiTransaction
2424
usdPrices: UsdPricesState
2525
chainId: ChainTypesByIdType
26+
abiEnhancer: IAbiEnhancer
2627
}
2728

28-
interface OnSocketChangeEmittedArgs extends AbiWallet {
29+
interface OnSocketChangeEmittedArgs {
2930
dispatch: AppDispatch
3031
usdPrices: UsdPricesState
3132
chainId: ChainTypesByIdType
33+
abiEnhancer: IAbiEnhancer
3234
}
3335

3436
const onNewTransactionEventEmitted = async ({
@@ -67,13 +69,7 @@ const onNewTransactionEventEmitted = async ({
6769
}
6870

6971
export const onSocketChangeEmitted =
70-
({
71-
dispatch,
72-
abiEnhancer,
73-
wallet,
74-
usdPrices,
75-
chainId,
76-
}: OnSocketChangeEmittedArgs) =>
72+
({ dispatch, abiEnhancer, usdPrices, chainId }: OnSocketChangeEmittedArgs) =>
7773
(action: Action) => {
7874
// Temporal patch to avoid dispatching events if current chainId does not match
7975
// @TODO find root cause of why the rifSockets is emitting an outdated event
@@ -92,7 +88,6 @@ export const onSocketChangeEmitted =
9288
case 'newTransaction':
9389
onNewTransactionEventEmitted({
9490
abiEnhancer,
95-
wallet,
9691
dispatch,
9792
payload,
9893
usdPrices,

src/subscriptions/rifSockets.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import EventEmitter from 'eventemitter3'
2-
import { RIFWallet } from '@rsksmart/rif-wallet-core'
32
import {
43
ITokenWithBalance,
54
RifWalletServicesFetcher,
65
RifWalletServicesSocket,
76
} from '@rsksmart/rif-wallet-services'
8-
import { Options, setInternetCredentials } from 'react-native-keychain'
97
import DeviceInfo from 'react-native-device-info'
108

119
import { resetSocketState } from 'store/shared/actions/resetSocketState'
@@ -35,12 +33,12 @@ export enum SocketsEvents {
3533
}
3634

3735
interface RifSockets {
38-
wallet: RIFWallet
36+
address: string
37+
chainId: ChainTypesByIdType
3938
setGlobalError: (err: string) => void
4039
dispatch: AppDispatch
4140
usdPrices: UsdPricesState
4241
fetcher: RifWalletServicesFetcher
43-
chainId: ChainTypesByIdType
4442
balances: Record<string, TokenBalanceObject>
4543
}
4644

@@ -52,25 +50,21 @@ const onSocketInit = (
5250
}
5351

5452
export const rifSockets = ({
55-
wallet,
53+
address,
54+
chainId,
5655
fetcher,
5756
dispatch,
5857
setGlobalError,
5958
usdPrices,
60-
chainId,
6159
balances,
6260
}: RifSockets) => {
6361
const onChange = onSocketChangeEmitted({
6462
dispatch,
6563
abiEnhancer,
66-
wallet,
6764
usdPrices,
6865
chainId,
6966
})
70-
const rifWalletServicesSocket = new RifWalletServicesSocket<
71-
Options,
72-
ReturnType<typeof setInternetCredentials>
73-
>(
67+
const rifWalletServicesSocket = new RifWalletServicesSocket(
7468
getWalletSetting(SETTINGS.RIF_WALLET_SERVICE_URL, chainTypesById[chainId]),
7569
abiEnhancer,
7670
{
@@ -79,10 +73,11 @@ export const rifSockets = ({
7973
SETTINGS.RIF_WALLET_KEY,
8074
chainTypesById[chainId],
8175
),
76+
// @TODO: make sure that the chainId type is more specific in lib
8277
onEnhanceTransaction: enhanceTransactionInput,
8378
onFilterOutRepeatedTransactions: filterEnhancedTransactions,
84-
onBeforeInit: (encryptionKey, currentInstance) => {
85-
currentInstance.cache = new MMKVStorage('txs', encryptionKey)
79+
onBeforeInit: currentInstance => {
80+
currentInstance.cache = new MMKVStorage('txs')
8681
},
8782
},
8883
{
@@ -116,7 +111,9 @@ export const rifSockets = ({
116111
)
117112
rifWalletServicesSocket.on('change', onChange)
118113
rifWalletServicesSocket
119-
.connect(wallet, fetcher, { 'User-Agent': DeviceInfo.getUserAgentSync() })
114+
.connect(address, chainId, fetcher, {
115+
'User-Agent': DeviceInfo.getUserAgentSync(),
116+
})
120117
.catch(err => {
121118
if (err instanceof Error) {
122119
setGlobalError(err.message)

src/subscriptions/types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
ITokenWithBalance,
55
} from '@rsksmart/rif-wallet-services'
66
import { IAbiEnhancer, EnhancedResult } from '@rsksmart/rif-wallet-abi-enhancer'
7-
import { RIFWallet } from '@rsksmart/rif-wallet-core'
87

98
export interface IPrice {
109
price: number
@@ -85,8 +84,3 @@ export interface TransactionsServerResponseWithActivityTransactions
8584
extends TransactionsServerResponse {
8685
activityTransactions: IActivityTransaction[]
8786
}
88-
89-
export interface AbiWallet {
90-
abiEnhancer: IAbiEnhancer
91-
wallet: RIFWallet
92-
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,10 +2131,10 @@
21312131
dependencies:
21322132
"@rsksmart/rsk-utils" "^1.1.0"
21332133

2134-
"@rsksmart/rif-wallet-services@^1.0.8":
2135-
version "1.0.8"
2136-
resolved "https://registry.yarnpkg.com/@rsksmart/rif-wallet-services/-/rif-wallet-services-1.0.8.tgz#d4b9099c0c931c295dbac357d1a35f383700028f"
2137-
integrity sha512-sKXNT3PU6eDYKSBZxV1vLOA/N/lOYavGjw4Q12dWCjyT3xv7uQtAKIB+njYTyK0HxaKfKcR0+Agq/4KIdiAZ/w==
2134+
"@rsksmart/rif-wallet-services@^1.1.0":
2135+
version "1.1.0"
2136+
resolved "https://registry.yarnpkg.com/@rsksmart/rif-wallet-services/-/rif-wallet-services-1.1.0.tgz#5d981fcfc1d4015d41e1b11c293363bdd117246a"
2137+
integrity sha512-DHiW0j+MNrxzBKCgW6mSheiD7H38K4OIv2a0WSopXd/B4vswiOHY3zyZghmajNKqqzT87yD9AE0/+y8fHpu0RA==
21382138
dependencies:
21392139
"@ethersproject/contracts" "^5.7.0"
21402140
"@rsksmart/rif-wallet-abi-enhancer" "*"

0 commit comments

Comments
 (0)