diff --git a/android/app/src/main/java/com/avaxwallet/MainApplication.java b/android/app/src/main/java/com/avaxwallet/MainApplication.java index 3afec30435..526fc5c21d 100644 --- a/android/app/src/main/java/com/avaxwallet/MainApplication.java +++ b/android/app/src/main/java/com/avaxwallet/MainApplication.java @@ -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; @@ -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; @@ -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); diff --git a/android/gradle.properties b/android/gradle.properties index f00d1c8ada..43390d772b 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/app/screens/rpc/ConnectedDapps/ConnectedDapps.tsx b/app/screens/rpc/ConnectedDapps/ConnectedDapps.tsx index 028cbbb40f..406f29edc3 100644 --- a/app/screens/rpc/ConnectedDapps/ConnectedDapps.tsx +++ b/app/screens/rpc/ConnectedDapps/ConnectedDapps.tsx @@ -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 { @@ -51,8 +53,8 @@ const ConnectedDapps: FC = ({ goBack }) => { const { killSessions: killSessionsV1 } = useDappConnectionV1() const { killSessions: killSessionsV2 } = useDappConnectionV2() const approvedDappsV1 = useSelector(selectApprovedDApps) - const [approvedDappsV2, setApprovedDappsV2] = useState( - WalletConnectService.getSessions() + const [approvedDappsV2, setApprovedDappsV2] = useState( + [] ) const allApprovedDapps = [ @@ -69,8 +71,21 @@ const ConnectedDapps: FC = ({ 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) }, [])