Skip to content

Commit

Permalink
fix(HW-642): fix rtl support (#2084)
Browse files Browse the repository at this point in the history
Co-authored-by: iGroza <[email protected]>
  • Loading branch information
iGroza and iGroza authored Aug 30, 2024
1 parent bd1bc41 commit 69efe4c
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 31 deletions.
2 changes: 2 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ dependencies {
implementation('com.danikula:videocache:2.7.1')
implementation("org.slf4j:slf4j-api:2.0.9")

implementation 'com.jakewharton:process-phoenix:3.0.0'
implementation 'com.facebook.soloader:soloader:0.10.4+'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "com.facebook.react:react-android"
Expand All @@ -206,6 +207,7 @@ dependencies {
implementation 'com.android.installreferrer:installreferrer:2.2'

implementation project(':react-native-fs')
implementation project(':react-native-restart')

testImplementation platform("org.junit:junit-bom:5.9.1")
testImplementation "org.junit.jupiter:junit-jupiter:5.9.1"
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/java/com/haqq/wallet/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MainActivity : ReactActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
SplashScreen.show(this, true)
val sharedI18nUtilInstance: I18nUtil = I18nUtil.getInstance()
sharedI18nUtilInstance.allowRTL(getApplicationContext(),true)
sharedI18nUtilInstance.allowRTL(this, sharedI18nUtilInstance.isRTL(this))
super.onCreate(null)
}

Expand Down
16 changes: 14 additions & 2 deletions android/app/src/main/java/com/haqq/wallet/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.haqq.wallet

import android.app.Application
import android.content.Context
import android.os.Build
import com.facebook.react.*
import com.facebook.react.config.ReactFeatureFlags
import com.haqq.wallet.haptic.HapticPackage
Expand All @@ -13,8 +14,11 @@ import com.haqq.wallet.MainApplication
import com.haqq.wallet.toast.ToastPackage
import java.lang.reflect.InvocationTargetException
import android.webkit.WebView;
import androidx.annotation.RequiresApi
import com.facebook.react.modules.i18nmanager.I18nUtil
import com.haqq.wallet.appnativeconfig.AppNativeConfigPackage
import com.haqq.wallet.apputils.AppUtilsPackage
import com.jakewharton.processphoenix.ProcessPhoenix

class MainApplication : Application(), ReactApplication {
private val mReactNativeHost: ReactNativeHost = object : ReactNativeHost(this) {
Expand Down Expand Up @@ -51,12 +55,20 @@ class MainApplication : Application(), ReactApplication {

override fun onCreate() {
super.onCreate()
// To check if your application is inside the Phoenix process to skip initialization in onCreate:
if (ProcessPhoenix.isPhoenixProcess(this)) {
return;
}
// If you opted-in for the New Architecture, we enable the TurboModule system
ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WebView.setDataDirectorySuffix("haqqwebview")
}

if (BuildConfig.DEBUG) {
WebView.setWebContentsDebuggingEnabled(true);
}
WebView.setWebContentsDebuggingEnabled(true);
}

SoLoader.init(this, /* native exopackage */false)
initializeFlipper(this, reactNativeHost.reactInstanceManager)
Expand Down
4 changes: 4 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ rootProject.name = 'haqq'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')

include ':react-native-fs'
project(':react-native-fs').projectDir = new File(settingsDir, '../node_modules/react-native-fs/android')

include ':react-native-restart'
project(':react-native-restart').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-restart/android')

if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") {
include(":ReactAndroid")
project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid')
Expand Down
36 changes: 16 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/**
* @format
*/
import './global';
import '@ethersproject/shims';
import '@walletconnect/react-native-compat';
import {AppRegistry, I18nManager, LogBox} from 'react-native';
import {AppRegistry, LogBox} from 'react-native';
import './global';

import Config from 'react-native-config';
import {app} from '@app/contexts';
import {DEBUG_VARS} from '@app/debug-vars';
import {enableBatchedStateUpdates} from '@app/hooks/batched-set-state';
import {EventTracker} from '@app/services/event-tracker';
import {MarketingEvents} from '@app/types';
import {IS_IOS} from '@app/variables/common';
import {JsonRpcProvider} from '@ethersproject/providers';
import messaging from '@react-native-firebase/messaging';
import * as Sentry from '@sentry/react-native';
import {ethers} from 'ethers';
import Config from 'react-native-config';
import {enableFreeze, enableScreens} from 'react-native-screens';
import {name as appName} from './app.json';
import {App} from './src/app';
import './src/event-actions';
import {Jailbreak} from './src/jailbreak';
import messaging from '@react-native-firebase/messaging';
import {IS_IOS} from '@app/variables/common';
import {DEBUG_VARS} from '@app/debug-vars';
import {enableFreeze, enableScreens} from 'react-native-screens';
import {enableBatchedStateUpdates} from '@app/hooks/batched-set-state';
import {EventTracker} from '@app/services/event-tracker';
import {MarketingEvents} from '@app/types';
import {app} from '@app/contexts';
import {ethers} from 'ethers';

if (!global.BigInt) {
const BigInt = require('big-integer');
Expand All @@ -37,12 +37,6 @@ enableBatchedStateUpdates();

LogBox.ignoreLogs(["The 'navigation' object hasn't been initialized"]);

// try {
// const isRTLEnabled = true;
// I18nManager.allowRTL(isRTLEnabled);
// I18nManager.swapLeftAndRightInRTL(isRTLEnabled);
// } catch (e) {}

if (__DEV__ && IS_IOS) {
messaging().setAPNSToken('dev-apns-token', 'sandbox');
}
Expand Down Expand Up @@ -99,9 +93,11 @@ JsonRpcProvider.prototype.send = async function (method, params) {
let parsedAddressFrom = 'unknown';
try {
const hexString = params[0].replace(/^0x/, '');
parsedAddressFrom = ethers.utils.parseTransaction(Buffer.from(hexString, 'hex'))?.from;
parsedAddressFrom = ethers.utils.parseTransaction(
Buffer.from(hexString, 'hex'),
)?.from;
} catch (e) {}

const eventParams = {
type: 'EVM',
network: app.provider.name,
Expand Down
2 changes: 1 addition & 1 deletion ios/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AppDelegate: RCTAppDelegate {
FirebaseApp.configure()
let app = super.application(application, didFinishLaunchingWithOptions: launchOptions);
RNSplashScreen.show();
RCTI18nUtil().allowRTL(true);
RCTI18nUtil().allowRTL(RCTI18nUtil().isRTLAllowed());
return app;
}

Expand Down
11 changes: 11 additions & 0 deletions patches/react-native-restart+0.0.27.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/node_modules/react-native-restart/android/build.gradle b/node_modules/react-native-restart/android/build.gradle
index 7eaecbc..7dfced8 100644
--- a/node_modules/react-native-restart/android/build.gradle
+++ b/node_modules/react-native-restart/android/build.gradle
@@ -117,5 +117,5 @@ repositories {

dependencies {
api 'com.facebook.react:react-native:+'
- implementation 'com.jakewharton:process-phoenix:2.1.2'
+ implementation 'com.jakewharton:process-phoenix:3.0.0'
}
17 changes: 13 additions & 4 deletions src/services/backend/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,18 @@ export class Backend {
}

async providers() {
const response = await fetch(`${this.getRemoteUrl()}provider`, {
headers: Backend.headers,
});
return await getHttpResponse<NetworkProviderResponse>(response);
try {
const response = await fetch(`${this.getRemoteUrl()}provider`, {
headers: Backend.headers,
});
return await getHttpResponse<NetworkProviderResponse>(response);
} catch (error: unknown) {
if (error instanceof Error) {
Logger.error('Error fetching providers:', error.message);
} else {
Logger.error('Unknown error occurred while fetching providers');
}
throw error;
}
}
}
15 changes: 12 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-bitwise */
import {formatNumberWithSubscriptZeros} from '@haqq/format-number-with-subscript-zeros/src';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {SessionTypes} from '@walletconnect/types';
import {
differenceInDays,
Expand Down Expand Up @@ -1061,15 +1062,23 @@ export function isSupportedCosmosTxForRender(
return false;
}

export const setRTL = (lang: AppLanguage) => {
export const IS_RTL_ENABLED_KEY = 'is_rtl_enabled';
export const setRTL = async (lang: AppLanguage) => {
const isRTL = RTL_LANGUAGES.includes(lang);

const isRTLenabled =
(await AsyncStorage.getItem(IS_RTL_ENABLED_KEY)) === 'true';

I18nManager.allowRTL(isRTL);
I18nManager.forceRTL(isRTL);
I18nManager.swapLeftAndRightInRTL(isRTL);

if (isRTL !== I18nManager.isRTL) {
await AsyncStorage.setItem(IS_RTL_ENABLED_KEY, isRTL.toString());

if (isRTL !== isRTLenabled) {
RNRestart.restart();
}
};

const hexRegExp = /^(0[xX])?[0-9A-Fa-f]+$/;
export function isValidHex(hexString: string) {
return hexRegExp.test(hexString);
Expand Down

0 comments on commit 69efe4c

Please sign in to comment.