Skip to content

Commit

Permalink
CP-5843: Fix App Crash on Connected Sites (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
atn4z7 authored Jul 6, 2023
1 parent 2ac9e64 commit a8b883a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
18 changes: 18 additions & 0 deletions android/app/src/main/java/com/avaxwallet/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Application;
import android.content.Context;
import android.database.CursorWindow;

import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
Expand All @@ -13,6 +14,7 @@
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers;
import com.facebook.soloader.SoLoader;

import java.lang.reflect.Field;
import java.util.List;

import io.csie.kudo.reactnative.v8.executor.V8ExecutorFactory;
Expand Down Expand Up @@ -61,6 +63,22 @@ public ReactNativeHost getReactNativeHost() {
@Override
public void onCreate() {
super.onCreate();

// Temp workaround for data not getting persisted on Android
// https://github.com/rt2zz/redux-persist/issues/199
// https://github.com/rt2zz/redux-persist/issues/960
// Basically, retrieving data from AsyncStorage is limited by a size of a WindowCursor
// which is a buffer used to read data from SQLite (what AsyncStorage uses)
// Currently it's size is around 2 MB. This means that the single item read at one time cannot be larger than 2 MB.
// Here we are increasing it to 10 MB to get around this issue
try {
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
field.setAccessible(true);
field.set(null, 10 * 1024 * 1024); // 10MB
} catch (Exception e) {
e.printStackTrace();
}

// If you opted-in for the New Architecture, we enable the TurboModule system
ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
SoLoader.init(this, /* native exopackage */ false);
Expand Down
6 changes: 5 additions & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
newArchEnabled=false

# https://github.com/software-mansion/react-native-reanimated/issues/3292
android.disableAutomaticComponentCreation=true
android.disableAutomaticComponentCreation=true

# Async Storage has a 6 MB size limit on Android by default
# here we increase it to 10 MB to accommodate our app
AsyncStorage_db_size_in_MB=10
21 changes: 18 additions & 3 deletions app/screens/rpc/ConnectedDapps/ConnectedDapps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { useDappConnectionV1 } from 'hooks/useDappConnectionV1'
import { useDeeplink } from 'contexts/DeeplinkContext/DeeplinkContext'
import { DeepLinkOrigin } from 'contexts/DeeplinkContext/types'
import { WalletConnectVersions } from 'store/walletConnectV2'
import { SessionTypes } from '@walletconnect/types'
import Logger from 'utils/Logger'
import { Dapp } from './types'
import { DappItem } from './DappItem'
interface Props {
Expand All @@ -51,8 +53,8 @@ const ConnectedDapps: FC<Props> = ({ goBack }) => {
const { killSessions: killSessionsV1 } = useDappConnectionV1()
const { killSessions: killSessionsV2 } = useDappConnectionV2()
const approvedDappsV1 = useSelector(selectApprovedDApps)
const [approvedDappsV2, setApprovedDappsV2] = useState(
WalletConnectService.getSessions()
const [approvedDappsV2, setApprovedDappsV2] = useState<SessionTypes.Struct[]>(
[]
)

const allApprovedDapps = [
Expand All @@ -69,8 +71,21 @@ const ConnectedDapps: FC<Props> = ({ goBack }) => {
]

useEffect(() => {
const getSessions = () => {
try {
const sessions = WalletConnectService.getSessions()
setApprovedDappsV2(sessions)
} catch (err) {
Logger.error('failed to get sessions', err)
}
}

// immediately fetch sessions onMounting
// then do it periodically while on this screen
getSessions()

const id = setInterval(() => {
setApprovedDappsV2(WalletConnectService.getSessions())
getSessions()
}, GET_DAPPS_V2_INTERVAL)
return () => clearInterval(id)
}, [])
Expand Down

0 comments on commit a8b883a

Please sign in to comment.