Merge pull request #8425 from BlueWallet/ref-cleanup-andr-build
REF: cleanup and andr build fix
This commit is contained in:
commit
c4fefbd7f8
@ -107,9 +107,6 @@ android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// Caution! In production, you need to generate your own keystore file.
|
||||
// see https://reactnative.dev/docs/signed-apk-android.
|
||||
signingConfig signingConfigs.debug
|
||||
minifyEnabled enableProguardInReleaseBuilds
|
||||
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
|
||||
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
|
||||
|
||||
@ -1,210 +0,0 @@
|
||||
package io.bluewallet.bluewallet
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import com.bugsnag.android.Bugsnag
|
||||
import com.facebook.react.PackageList
|
||||
import com.facebook.react.ReactApplication
|
||||
import com.facebook.react.ReactHost
|
||||
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
|
||||
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
|
||||
import com.facebook.react.modules.i18nmanager.I18nUtil
|
||||
import io.bluewallet.bluewallet.components.segmentedcontrol.CustomSegmentedControlPackage
|
||||
|
||||
class MainApplication : Application(), ReactApplication {
|
||||
|
||||
private lateinit var sharedPref: SharedPreferences
|
||||
private val themeChangeReceiver = ThemeChangeReceiver()
|
||||
private val preferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { prefs, key ->
|
||||
if (key == "preferredCurrency") {
|
||||
prefs.edit().remove("previous_price").apply()
|
||||
|
||||
// Update BitcoinPrice widgets
|
||||
WidgetUpdateWorker.scheduleWork(this)
|
||||
|
||||
// Immediately refresh Market widgets
|
||||
MarketWidget.refreshAllWidgetsImmediately(this)
|
||||
} else if (key == "force_dark_mode") {
|
||||
// Theme setting changed, update all widgets
|
||||
ThemeHelper.updateAllWidgets(this)
|
||||
} else if (key == "donottrack") {
|
||||
// Handle Do Not Track changes similar to iOS
|
||||
val isEnabled = prefs.getString("donottrack", "0") == "1"
|
||||
Log.d("MainApplication", "Do Not Track changed to: $isEnabled")
|
||||
|
||||
if (isEnabled) {
|
||||
// Set deviceUIDCopy to "Disabled"
|
||||
prefs.edit()
|
||||
.putString("deviceUIDCopy", "Disabled")
|
||||
.apply()
|
||||
Log.d("MainApplication", "Do Not Track enabled - set deviceUIDCopy to 'Disabled'")
|
||||
} else {
|
||||
// Re-initialize device UID
|
||||
initializeDeviceUID()
|
||||
}
|
||||
} else if (key == "deviceUID") {
|
||||
// When deviceUID changes, update deviceUIDCopy
|
||||
val isDoNotTrackEnabled = prefs.getString("donottrack", "0") == "1"
|
||||
if (!isDoNotTrackEnabled) {
|
||||
val deviceUID = prefs.getString("deviceUID", null)
|
||||
if (deviceUID != null) {
|
||||
prefs.edit()
|
||||
.putString("deviceUIDCopy", deviceUID)
|
||||
.apply()
|
||||
Log.d("MainApplication", "deviceUID changed, synced to deviceUIDCopy: $deviceUID")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val reactHost: ReactHost by lazy {
|
||||
getDefaultReactHost(
|
||||
context = applicationContext,
|
||||
packageList = PackageList(this).packages.apply {
|
||||
// Packages that cannot be autolinked yet can be added manually here, for example:
|
||||
// add(MyReactNativePackage())
|
||||
add(CustomSegmentedControlPackage())
|
||||
add(SettingsPackage())
|
||||
},
|
||||
useDevSupport = BuildConfig.DEBUG,
|
||||
jsMainModulePath = "index",
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
sharedPref = getSharedPreferences("group.io.bluewallet.bluewallet", Context.MODE_PRIVATE)
|
||||
|
||||
// Handle clearFilesOnLaunch before registering listeners
|
||||
clearFilesIfNeeded()
|
||||
|
||||
sharedPref.registerOnSharedPreferenceChangeListener(preferenceChangeListener)
|
||||
|
||||
// Register the theme change receiver
|
||||
registerReceiver(themeChangeReceiver, IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED))
|
||||
|
||||
val sharedI18nUtilInstance = I18nUtil.getInstance()
|
||||
sharedI18nUtilInstance.allowRTL(applicationContext, true)
|
||||
loadReactNative(this)
|
||||
|
||||
initializeDeviceUID()
|
||||
initializeBugsnag()
|
||||
}
|
||||
|
||||
override fun onTerminate() {
|
||||
super.onTerminate()
|
||||
sharedPref.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener)
|
||||
|
||||
// Unregister the theme change receiver
|
||||
try {
|
||||
unregisterReceiver(themeChangeReceiver)
|
||||
} catch (e: Exception) {
|
||||
Log.e("MainApplication", "Error unregistering theme receiver", e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initializeBugsnag() {
|
||||
val isDoNotTrackEnabled = sharedPref.getString("donottrack", "0")
|
||||
if (isDoNotTrackEnabled != "1") {
|
||||
Bugsnag.start(this)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize device UID similar to iOS implementation
|
||||
* Uses the same Android ID as react-native-device-info's getUniqueId()
|
||||
*/
|
||||
private fun initializeDeviceUID() {
|
||||
val isDoNotTrackEnabled = sharedPref.getString("donottrack", "0") == "1"
|
||||
|
||||
if (isDoNotTrackEnabled) {
|
||||
val currentCopy = sharedPref.getString("deviceUIDCopy", "")
|
||||
if (currentCopy != "Disabled") {
|
||||
sharedPref.edit()
|
||||
.putString("deviceUIDCopy", "Disabled")
|
||||
.apply()
|
||||
Log.d("MainApplication", "Do Not Track enabled - set deviceUIDCopy to 'Disabled'")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Get the Android ID (same as react-native-device-info's getUniqueId())
|
||||
val deviceUID = try {
|
||||
android.provider.Settings.Secure.getString(
|
||||
contentResolver,
|
||||
android.provider.Settings.Secure.ANDROID_ID
|
||||
) ?: "unknown"
|
||||
} catch (e: Exception) {
|
||||
Log.e("MainApplication", "Error getting Android ID", e)
|
||||
"unknown"
|
||||
}
|
||||
|
||||
// Store in deviceUID for consistency
|
||||
sharedPref.edit()
|
||||
.putString("deviceUID", deviceUID)
|
||||
.apply()
|
||||
|
||||
// Copy deviceUID to deviceUIDCopy (for Settings compatibility)
|
||||
val currentCopy = sharedPref.getString("deviceUIDCopy", "")
|
||||
if (deviceUID != currentCopy) {
|
||||
sharedPref.edit()
|
||||
.putString("deviceUIDCopy", deviceUID)
|
||||
.apply()
|
||||
Log.d("MainApplication", "Synced deviceUID to deviceUIDCopy: $deviceUID")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear files if clearFilesOnLaunch is enabled
|
||||
* Similar to iOS implementation
|
||||
*/
|
||||
private fun clearFilesIfNeeded() {
|
||||
val shouldClear = sharedPref.getBoolean("clearFilesOnLaunch", false)
|
||||
|
||||
if (shouldClear) {
|
||||
try {
|
||||
// Clear cache directory
|
||||
cacheDir?.let { clearDirectory(it) }
|
||||
|
||||
// Clear files directory
|
||||
filesDir?.let { clearDirectory(it) }
|
||||
|
||||
// Clear external cache directory
|
||||
externalCacheDir?.let { clearDirectory(it) }
|
||||
|
||||
// Reset the flag and set a flag to show alert
|
||||
sharedPref.edit()
|
||||
.putBoolean("clearFilesOnLaunch", false)
|
||||
.putBoolean("shouldShowCacheClearedAlert", true)
|
||||
.apply()
|
||||
|
||||
Log.d("MainApplication", "Cache and files cleared on launch")
|
||||
} catch (e: Exception) {
|
||||
Log.e("MainApplication", "Error clearing files", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively clear all files in a directory
|
||||
*/
|
||||
private fun clearDirectory(dir: java.io.File) {
|
||||
if (!dir.exists()) return
|
||||
|
||||
dir.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory) {
|
||||
clearDirectory(file)
|
||||
}
|
||||
try {
|
||||
file.delete()
|
||||
Log.d("MainApplication", "Deleted: ${file.absolutePath}")
|
||||
} catch (e: Exception) {
|
||||
Log.e("MainApplication", "Error deleting file: ${file.absolutePath}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -246,7 +246,6 @@ export default function PaymentCodesList() {
|
||||
const onAddContactPress = async () => {
|
||||
try {
|
||||
const newPc = await prompt(loc.bip47.add_contact, loc.bip47.provide_payment_code, true, 'plain-text');
|
||||
console.log('newPc', newPc);
|
||||
if (!newPc) return;
|
||||
|
||||
await _addContact(newPc);
|
||||
@ -264,17 +263,14 @@ export default function PaymentCodesList() {
|
||||
if (counterpartyMetadata[newPc]?.hidden) {
|
||||
// contact already present, just need to unhide it
|
||||
counterpartyMetadata[newPc].hidden = false;
|
||||
console.log('unhiding contact', newPc);
|
||||
await saveToDisk();
|
||||
setReload(Math.random());
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('adding contact', newPc);
|
||||
const cl = new ContactList();
|
||||
|
||||
if (cl.isAddressValid(newPc)) {
|
||||
console.log('contact is valid', newPc);
|
||||
// this is not a payment code but a regular onchain address. pretending its a payment code and adding it
|
||||
foundWallet.addBIP47Receiver(newPc);
|
||||
await saveToDisk();
|
||||
@ -283,13 +279,11 @@ export default function PaymentCodesList() {
|
||||
}
|
||||
|
||||
if (!cl.isPaymentCodeValid(newPc)) {
|
||||
console.log('!cl.isPaymentCodeValid');
|
||||
presentAlert({ message: loc.bip47.invalid_pc });
|
||||
return;
|
||||
}
|
||||
|
||||
if (cl.isBip352PaymentCodeValid(newPc)) {
|
||||
console.log('isBip352PaymentCodeValid', newPc);
|
||||
// ok its a SilentPayments code, notification tx is not needed, just add it to recipients:
|
||||
foundWallet.addBIP47Receiver(newPc);
|
||||
await saveToDisk();
|
||||
@ -299,14 +293,11 @@ export default function PaymentCodesList() {
|
||||
|
||||
setIsLoading(true);
|
||||
|
||||
console.log('1');
|
||||
const notificationTx = foundWallet.getBIP47NotificationTransaction(newPc);
|
||||
console.log('2');
|
||||
|
||||
if (notificationTx && notificationTx.confirmations > 0) {
|
||||
// we previously sent notification transaction to him, so just need to add him to internals
|
||||
foundWallet.addBIP47Receiver(newPc);
|
||||
console.log('syncBip47ReceiversAddresses...', newPc);
|
||||
await foundWallet.syncBip47ReceiversAddresses(newPc); // so we can unwrap and save all his possible addresses
|
||||
// (for a case if already have txs with him, we will now be able to label them on tx list)
|
||||
await saveToDisk();
|
||||
|
||||
@ -401,8 +401,6 @@ describe('BlueWallet UI Tests - import BIP84 wallet', () => {
|
||||
await element(by.text('Imported HD SegWit (BIP84 Bech32 Native)')).tap();
|
||||
await element(by.id('WalletDetails')).tap();
|
||||
|
||||
// await detox.REPL(); // <---------------------------------------------
|
||||
|
||||
// switch on BIP47 slider if its not switched
|
||||
if (!(await getSwitchValue('BIP47Switch'))) {
|
||||
await expect(element(by.text('Contacts'))).not.toBeVisible();
|
||||
|
||||
@ -35,6 +35,8 @@ else
|
||||
GRADLE_ARCH_ARGS+=("-PreactNativeArchitectures=${ARCHITECTURES}")
|
||||
(cd android && ./gradlew assembleRelease assembleReleaseAndroidTest -DtestBuildType=release "${GRADLE_ARCH_ARGS[@]}")
|
||||
RELEASE_APK=./android/app/build/outputs/apk/release/app-release.apk
|
||||
UNSIGNED_RELEASE_APK=./android/app/build/outputs/apk/release/app-release-unsigned.apk
|
||||
mv "$UNSIGNED_RELEASE_APK" "$RELEASE_APK"
|
||||
TEST_APK=./android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk
|
||||
fi
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user