diff --git a/app/src/main/java/com/brainwallet/data/model/Fee.kt b/app/src/main/java/com/brainwallet/data/model/Fee.kt index 0ea99667..b1d086ae 100644 --- a/app/src/main/java/com/brainwallet/data/model/Fee.kt +++ b/app/src/main/java/com/brainwallet/data/model/Fee.kt @@ -8,8 +8,6 @@ import com.brainwallet.tools.manager.FeeManager.LUXURY import com.brainwallet.tools.manager.FeeManager.REGULAR import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlin.math.ceil -import kotlin.math.round @Serializable data class Fee( @@ -22,23 +20,31 @@ data class Fee( @JvmField @SerialName("fee_per_kb_economy") var economy: Long, + var timestamp: Long ) { companion object { - //from legacy - // this is the default that matches the mobile-api if the server is unavailable - private const val defaultEconomyFeePerKB: Long = - 2500L // From legacy minimum. default min is 1000 as Litecoin Core version v0.17.1 + /** + * Default value for economy fee rate per kilobyte. + * Used as a fallback when fee rate cannot be determined dynamically. + * + * Previous value: 2500L (2.5 satoshis per byte). From legacy minimum. default min is 1000 as Litecoin Core version v0.17.1 + * Updated economy to 8000L (8 satoshis per byte) on 2023-11-16 (same as iOS) + */ + private const val defaultEconomyFeePerKB: Long = 8000L private const val defaultRegularFeePerKB: Long = 25000L private const val defaultLuxuryFeePerKB: Long = 66746L private const val defaultTimestamp: Long = 1583015199122L -// {"fee_per_kb":5289,"fee_per_kb_economy":2645,"fee_per_kb_luxury":10578} - + /** + * currently we are using this static [Default] for our fee + * maybe we need to update core if we need dynamic fee? + */ @JvmStatic val Default = Fee( defaultLuxuryFeePerKB, defaultRegularFeePerKB, defaultEconomyFeePerKB, + defaultTimestamp ) } } @@ -80,4 +86,9 @@ fun FeeOption.getFiatFormatted(currencyEntity: CurrencyEntity): String { val fiatValue = getFiat(currencyEntity) val formatted = String.format("%.3f", fiatValue) return "${currencyEntity.symbol}$formatted" +} + +fun List.getSelectedIndex(selectedFeeType: String): Int { + return indexOfFirst { it.type == selectedFeeType }.takeIf { it >= 0 } + ?: 2 //2 -> index of top, since we have [low,medium,top] } \ No newline at end of file diff --git a/app/src/main/java/com/brainwallet/data/repository/LtcRepository.kt b/app/src/main/java/com/brainwallet/data/repository/LtcRepository.kt index 365bbc0d..962602f7 100644 --- a/app/src/main/java/com/brainwallet/data/repository/LtcRepository.kt +++ b/app/src/main/java/com/brainwallet/data/repository/LtcRepository.kt @@ -54,17 +54,13 @@ interface LtcRepository { } - override suspend fun fetchFeePerKb(): Fee { - return sharedPreferences.fetchWithCache( - key = PREF_KEY_NETWORK_FEE_PER_KB, - cachedAtKey = PREF_KEY_NETWORK_FEE_PER_KB_CACHED_AT, - cacheTimeMs = 6 * 60 * 60 * 1000, - fetchData = { - remoteApiSource.getFeePerKb() - }, - defaultValue = Fee.Default - ) - } + /** + * for now we just using [Fee.Default] + * will move to [RemoteApiSource.getFeePerKb] after fix the calculation when we do send + * + * maybe need updaete core if we need to use dynamic fee? + */ + override suspend fun fetchFeePerKb(): Fee = Fee.Default //using static fee override suspend fun fetchLimits(baseCurrencyCode: String): MoonpayCurrencyLimit { return sharedPreferences.fetchWithCache( diff --git a/app/src/main/java/com/brainwallet/data/repository/SettingRepository.kt b/app/src/main/java/com/brainwallet/data/repository/SettingRepository.kt index 2e4b3388..3f217918 100644 --- a/app/src/main/java/com/brainwallet/data/repository/SettingRepository.kt +++ b/app/src/main/java/com/brainwallet/data/repository/SettingRepository.kt @@ -5,6 +5,7 @@ import androidx.core.content.edit import com.brainwallet.data.model.AppSetting import com.brainwallet.data.model.CurrencyEntity import com.brainwallet.data.model.Language +import com.brainwallet.tools.manager.FeeManager import com.brainwallet.tools.sqlite.CurrencyDataSource import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow @@ -36,6 +37,10 @@ interface SettingRepository { fun toggleDarkMode(isDarkMode: Boolean) + fun putSelectedFeeType(feeType: String) + + fun getSelectedFeeType(): String + class Impl( private val sharedPreferences: SharedPreferences, private val currencyDataSource: CurrencyDataSource @@ -77,6 +82,17 @@ interface SettingRepository { _state.update { it.copy(isDarkMode = isDarkMode) } } + override fun putSelectedFeeType(feeType: String) { + sharedPreferences.edit { + putString(KEY_SELECTED_FEE_TYPE, feeType) + } + } + + override fun getSelectedFeeType(): String = + sharedPreferences.getString(KEY_SELECTED_FEE_TYPE, FeeManager.REGULAR) + ?: FeeManager.REGULAR + + private fun load(): AppSetting { return AppSetting( isDarkMode = sharedPreferences.getBoolean(KEY_IS_DARK_MODE, true), @@ -100,5 +116,6 @@ interface SettingRepository { const val KEY_IS_DARK_MODE = "is_dark_mode" const val KEY_LANGUAGE_CODE = "language_code" const val KEY_FIAT_CURRENCY_CODE = "fiat_currency_code" + const val KEY_SELECTED_FEE_TYPE = "selected_fee_type" } } \ No newline at end of file diff --git a/app/src/main/java/com/brainwallet/presenter/fragments/FragmentSend.kt b/app/src/main/java/com/brainwallet/presenter/fragments/FragmentSend.kt index 9b47690e..83d08dcb 100644 --- a/app/src/main/java/com/brainwallet/presenter/fragments/FragmentSend.kt +++ b/app/src/main/java/com/brainwallet/presenter/fragments/FragmentSend.kt @@ -135,6 +135,9 @@ class FragmentSend : Fragment() { updateText() + //update fee + BRWalletManager.getInstance().setFeePerKb(FeeManager.getInstance().currentFeeValue) + return rootView } @@ -496,7 +499,6 @@ class FragmentSend : Fragment() { override fun onStop() { super.onStop() - FeeManager.getInstance().resetFeeType() } override fun onResume() { @@ -611,9 +613,22 @@ class FragmentSend : Fragment() { } Timber.d("timber: updateText: currentAmountInLitoshis %d", currentAmountInLitoshis) + // Service Fee depending on ISOSymbol + var serviceFee = Utils.tieredOpsFee(activity, currentAmountInLitoshis) + val serviceFeeForISOSymbol = + BRExchange.getAmountFromLitoshis(activity, selectedISOSymbol, BigDecimal(serviceFee)) + .setScale(scaleValue, RoundingMode.HALF_UP) + val formattedServiceFee = BRCurrency.getFormattedCurrencyString( + activity, + selectedISOSymbol, + serviceFeeForISOSymbol + ) + + val totalAmountToCalculateFees = currentAmountInLitoshis + serviceFee + // Network Fee depending on ISOSymbol - var networkFee = if (currentAmountInLitoshis > 0) { - BRWalletManager.getInstance().feeForTransactionAmount(currentAmountInLitoshis) + var networkFee = if (totalAmountToCalculateFees > 0) { + BRWalletManager.getInstance().feeForTransactionAmount(totalAmountToCalculateFees) } else { 0 } //Amount is zero so network fee is also zero @@ -626,17 +641,6 @@ class FragmentSend : Fragment() { networkFeeForISOSymbol ) - // Service Fee depending on ISOSymbol - var serviceFee = Utils.tieredOpsFee(activity, currentAmountInLitoshis) - val serviceFeeForISOSymbol = - BRExchange.getAmountFromLitoshis(activity, selectedISOSymbol, BigDecimal(serviceFee)) - .setScale(scaleValue, RoundingMode.HALF_UP) - val formattedServiceFee = BRCurrency.getFormattedCurrencyString( - activity, - selectedISOSymbol, - serviceFeeForISOSymbol - ) - // Total Fees depending on ISOSymbol val totalFees = networkFee + serviceFee val totalFeeForISOSymbol = diff --git a/app/src/main/java/com/brainwallet/tools/manager/FeeManager.java b/app/src/main/java/com/brainwallet/tools/manager/FeeManager.java index f9457baa..bf927976 100644 --- a/app/src/main/java/com/brainwallet/tools/manager/FeeManager.java +++ b/app/src/main/java/com/brainwallet/tools/manager/FeeManager.java @@ -4,9 +4,10 @@ import androidx.annotation.StringDef; +import com.brainwallet.data.model.Fee; import com.brainwallet.data.repository.LtcRepository; +import com.brainwallet.data.repository.SettingRepository; import com.brainwallet.tools.threads.BRExecutor; -import com.brainwallet.data.model.Fee; import org.koin.java.KoinJavaComponent; @@ -14,7 +15,6 @@ import java.lang.annotation.RetentionPolicy; //we are still using this, maybe in the future will deprecate? -@Deprecated public final class FeeManager { @@ -56,8 +56,24 @@ public boolean isLuxuryFee() { public static final String REGULAR = "regular";//medium public static final String ECONOMY = "economy";//low - public void setFees(long luxuryFee, long regularFee, long economyFee) { - currentFeeOptions = new Fee(luxuryFee, regularFee, economyFee); + public void setFees(Fee fee) { + currentFeeOptions = fee; + } + + public long getCurrentFeeValue() { + SettingRepository settingRepository = KoinJavaComponent.get(SettingRepository.class); + String feeType = settingRepository.getSelectedFeeType(); + + switch (feeType) { + case LUXURY: + return currentFeeOptions.luxury; + case REGULAR: + return currentFeeOptions.regular; + case ECONOMY: + return currentFeeOptions.economy; + default: + return currentFeeOptions.regular; // Default to regular fee + } } public static void updateFeePerKb(Context app) { @@ -66,8 +82,7 @@ public static void updateFeePerKb(Context app) { (coroutineScope, continuation) -> ltcRepository.fetchFeePerKb(continuation) ).whenComplete((fee, throwable) -> { - //legacy logic - FeeManager.getInstance().setFees(fee.luxury, fee.regular, fee.economy); + FeeManager.getInstance().setFees(fee); BRSharedPrefs.putFeeTime(app, System.currentTimeMillis()); //store the time of the last successful fee fetch }); } diff --git a/app/src/main/java/com/brainwallet/tools/manager/PromptManager.java b/app/src/main/java/com/brainwallet/tools/manager/PromptManager.java index e6c9a029..a716d7f7 100644 --- a/app/src/main/java/com/brainwallet/tools/manager/PromptManager.java +++ b/app/src/main/java/com/brainwallet/tools/manager/PromptManager.java @@ -9,6 +9,7 @@ import android.content.Intent; import android.view.View; +import com.brainwallet.presenter.activities.settings.SyncBlockchainActivity; import com.brainwallet.tools.security.BRKeyStore; import com.brainwallet.tools.threads.BRExecutor; import com.brainwallet.R; @@ -88,6 +89,7 @@ public void run() { BRSharedPrefs.putStartHeight(app, 0); BRPeerManager.getInstance().rescan(); BRSharedPrefs.putScanRecommended(app, false); + BRSharedPrefs.putAllowSpend(app, false); } }); } diff --git a/app/src/main/java/com/brainwallet/tools/util/BRConstants.java b/app/src/main/java/com/brainwallet/tools/util/BRConstants.java index 7c989533..bd8f810b 100644 --- a/app/src/main/java/com/brainwallet/tools/util/BRConstants.java +++ b/app/src/main/java/com/brainwallet/tools/util/BRConstants.java @@ -129,7 +129,6 @@ private BRConstants() { public static final String _20201118_DTGS = "did_tap_get_support"; public static final String _20200217_DUWP = "did_unlock_with_pin"; public static final String _20200217_DUWB = "did_unlock_with_biometrics"; - public static final String _20200301_DUDFPK = "did_use_default_fee_per_kb"; public static final String _20201121_SIL = "started_IFPS_lookup"; public static final String _20201121_DRIA = "did_resolve_IPFS_address"; public static final String _20201121_FRIA = "failed_resolve_IPFS_address"; @@ -137,6 +136,7 @@ private BRConstants() { public static final String _20230407_DCS = "did_complete_sync"; public static final String _20250303_DSTU = "did_skip_top_up"; + public static final String _20250517_WCINFO = "wallet_callback_info"; ///Dev: These events not yet used public static final String _20200207_DTHB = "did_tap_header_balance"; @@ -170,7 +170,6 @@ private BRConstants() { _20201118_DTGS, _20200217_DUWP, _20200217_DUWB, - _20200301_DUDFPK, _20201121_SIL, _20201121_DRIA, _20201121_FRIA, @@ -187,7 +186,8 @@ private BRConstants() { _20241006_UCR, _HOME_OPEN, _20250222_PAC, - _20250303_DSTU + _20250303_DSTU, + _20250517_WCINFO }) public @interface Event { } diff --git a/app/src/main/java/com/brainwallet/tools/util/BRExchange.java b/app/src/main/java/com/brainwallet/tools/util/BRExchange.java index 52b6df6b..c199b115 100644 --- a/app/src/main/java/com/brainwallet/tools/util/BRExchange.java +++ b/app/src/main/java/com/brainwallet/tools/util/BRExchange.java @@ -102,11 +102,17 @@ public static BigDecimal getLitoshisFromAmount(Context app, String iso, BigDecim if (iso.equalsIgnoreCase("LTC")) { result = BRExchange.getLitoshisForLitecoin(app, amount); } else { - //multiply by 100 because core function localAmount accepts the smallest amount e.g. cents CurrencyEntity ent = CurrencyDataSource.getInstance(app).getCurrencyByIso(iso); if (ent == null) return new BigDecimal(0); - BigDecimal rate = new BigDecimal(ent.rate).multiply(new BigDecimal(100)); - result = new BigDecimal(BRWalletManager.getInstance().bitcoinAmount(amount.multiply(new BigDecimal(100)).longValue(), rate.doubleValue())); + + // Get the exchange rate + BigDecimal rate = new BigDecimal(ent.rate); + + result = amount.divide(rate, 8, BRConstants.ROUNDING_MODE) + .multiply(new BigDecimal("100000000")); + + // Round to a whole number of litoshis + result = result.setScale(0, BRConstants.ROUNDING_MODE); } return result; } diff --git a/app/src/main/java/com/brainwallet/tools/util/Utils.java b/app/src/main/java/com/brainwallet/tools/util/Utils.java index 8e7e6062..fb03d0c3 100644 --- a/app/src/main/java/com/brainwallet/tools/util/Utils.java +++ b/app/src/main/java/com/brainwallet/tools/util/Utils.java @@ -267,38 +267,29 @@ else if (name == ServiceItems.CLIENTCODE) { } /// Description: 1715876807 public static long tieredOpsFee(Context app, long sendAmount) { - - double doubleRate = 83.000; - double sendAmountDouble = new Double(String.valueOf(sendAmount)); - String usIso = Currency.getInstance(new Locale("en", "US")).getCurrencyCode(); - CurrencyEntity currency = CurrencyDataSource.getInstance(app).getCurrencyByIso(usIso); - if (currency != null) { - doubleRate = currency.rate; + if (sendAmount < 1_398_000) { + return 69900; } - double usdInLTC = sendAmountDouble * doubleRate / 100_000_000.0; - usdInLTC = Math.floor(usdInLTC * 100) / 100; - - if (isBetween(usdInLTC, 0.00, 20.00)) { - double lowRate = usdInLTC * 0.01; - return (long) ((lowRate / doubleRate) * 100_000_000.0); + else if (sendAmount < 6_991_000) { + return 111_910; + } + else if (sendAmount < 27_965_000) { + return 279_700; } - else if (isBetween(usdInLTC, 20.00, 50.00)) { - return (long) ((0.30 / doubleRate) * 100_000_000.0); + else if (sendAmount < 139_820_000) { + return 699_540; } - else if (isBetween(usdInLTC, 50.00, 100.00)) { - return (long) ((1.00 / doubleRate) * 100_000_000.0); - } - else if (isBetween(usdInLTC, 100.00, 500.00)) { - return (long) ((2.00 / doubleRate) * 100_000_000.0); + else if (sendAmount < 279_653_600) { + return 1_049_300; } - else if (isBetween(usdInLTC, 500.00, 1000.00)) { - return (long) ((2.50 / doubleRate) * 100_000_000.0); + else if (sendAmount < 699_220_000) { + return 1_398_800; } - else if ( usdInLTC > 1000.00) { - return (long) ((3.00 / doubleRate) * 100_000_000.0); + else if (sendAmount < 1_398_440_000) { + return 2_797_600; } else { - return (long) ((3.00 / doubleRate) * 100_000_000.0); + return 2_797_600; } } private static boolean isBetween(double x, double lower, double upper) { diff --git a/app/src/main/java/com/brainwallet/ui/screens/home/SettingsEvent.kt b/app/src/main/java/com/brainwallet/ui/screens/home/SettingsEvent.kt index 48e0750a..61a8ced4 100644 --- a/app/src/main/java/com/brainwallet/ui/screens/home/SettingsEvent.kt +++ b/app/src/main/java/com/brainwallet/ui/screens/home/SettingsEvent.kt @@ -8,6 +8,7 @@ sealed class SettingsEvent { val shareAnalyticsDataEnabled: Boolean = false, val lastSyncMetadata: String? = null, ) : SettingsEvent() + object OnSecurityUpdatePinClick : SettingsEvent() object OnSecuritySeedPhraseClick : SettingsEvent() object OnSecurityShareAnalyticsDataClick : SettingsEvent() @@ -20,4 +21,5 @@ sealed class SettingsEvent { object OnFiatSelectorDismiss : SettingsEvent() data class OnFiatChange(val currency: CurrencyEntity) : SettingsEvent() object OnBlockchainSyncClick : SettingsEvent() + data class OnFeeTypeChange(val feeType: String) : SettingsEvent() } \ No newline at end of file diff --git a/app/src/main/java/com/brainwallet/ui/screens/home/SettingsState.kt b/app/src/main/java/com/brainwallet/ui/screens/home/SettingsState.kt index 60a209bd..d0336bff 100644 --- a/app/src/main/java/com/brainwallet/ui/screens/home/SettingsState.kt +++ b/app/src/main/java/com/brainwallet/ui/screens/home/SettingsState.kt @@ -5,6 +5,7 @@ import com.brainwallet.data.model.Fee import com.brainwallet.data.model.FeeOption import com.brainwallet.data.model.Language import com.brainwallet.data.model.toFeeOptions +import com.brainwallet.tools.manager.FeeManager data class SettingsState( val darkMode: Boolean = true, @@ -20,4 +21,5 @@ data class SettingsState( val shareAnalyticsDataEnabled: Boolean = false, val lastSyncMetadata: String? = null, val currentFeeOptions: List = Fee.Default.toFeeOptions(), + val selectedFeeType: String = FeeManager.LUXURY ) \ No newline at end of file diff --git a/app/src/main/java/com/brainwallet/ui/screens/home/SettingsViewModel.kt b/app/src/main/java/com/brainwallet/ui/screens/home/SettingsViewModel.kt index 8859d395..738af4be 100644 --- a/app/src/main/java/com/brainwallet/ui/screens/home/SettingsViewModel.kt +++ b/app/src/main/java/com/brainwallet/ui/screens/home/SettingsViewModel.kt @@ -8,8 +8,10 @@ import com.brainwallet.data.model.Language import com.brainwallet.data.model.toFeeOptions import com.brainwallet.data.repository.LtcRepository import com.brainwallet.data.repository.SettingRepository +import com.brainwallet.tools.manager.FeeManager import com.brainwallet.ui.BrainwalletViewModel import com.brainwallet.util.EventBus +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow @@ -47,6 +49,25 @@ class SettingsViewModel( AppSetting() ) + init { + viewModelScope.launch { + while (true) { + /** + * need update fee options every 4s, since we are fetching every 4s + * pls check at + * - [CurrencyUpdateWorker] + * - [LtcRepository.fetchRates] + * - [LtcRepository.fetchFeePerKb] + */ + + _state.update { + it.copy(currentFeeOptions = FeeManager.getInstance().currentFeeOptions.toFeeOptions()) + } + delay(4000) + } + } + } + override fun onEvent(event: SettingsEvent) { when (event) { is SettingsEvent.OnLoad -> viewModelScope.launch { @@ -54,7 +75,7 @@ class SettingsViewModel( it.copy( shareAnalyticsDataEnabled = event.shareAnalyticsDataEnabled, lastSyncMetadata = event.lastSyncMetadata, - currentFeeOptions = ltcRepository.fetchFeePerKb().toFeeOptions() + selectedFeeType = settingRepository.getSelectedFeeType() ) } } @@ -143,6 +164,11 @@ class SettingsViewModel( EventBus.emit(EventBus.Event.Message(LEGACY_EFFECT_ON_SHARE_ANALYTICS_DATA_TOGGLE)) } + + is SettingsEvent.OnFeeTypeChange -> _state.update { + settingRepository.putSelectedFeeType(event.feeType) + it.copy(selectedFeeType = event.feeType) + } } } diff --git a/app/src/main/java/com/brainwallet/ui/screens/home/composable/HomeSettingDrawerSheet.kt b/app/src/main/java/com/brainwallet/ui/screens/home/composable/HomeSettingDrawerSheet.kt index 1daa4b33..b3559014 100644 --- a/app/src/main/java/com/brainwallet/ui/screens/home/composable/HomeSettingDrawerSheet.kt +++ b/app/src/main/java/com/brainwallet/ui/screens/home/composable/HomeSettingDrawerSheet.kt @@ -135,6 +135,7 @@ fun HomeSettingDrawerSheet( .fillMaxSize() .wrapContentHeight(), selectedCurrency = state.selectedCurrency, + selectedFeeType = state.selectedFeeType, feeOptions = state.currentFeeOptions, onEvent = { viewModel.onEvent(it) diff --git a/app/src/main/java/com/brainwallet/ui/screens/home/composable/settingsrows/LitecoinBlockchainDetail.kt b/app/src/main/java/com/brainwallet/ui/screens/home/composable/settingsrows/LitecoinBlockchainDetail.kt index 138ab31c..f964e418 100644 --- a/app/src/main/java/com/brainwallet/ui/screens/home/composable/settingsrows/LitecoinBlockchainDetail.kt +++ b/app/src/main/java/com/brainwallet/ui/screens/home/composable/settingsrows/LitecoinBlockchainDetail.kt @@ -14,10 +14,6 @@ import androidx.compose.material3.SegmentedButtonDefaults import androidx.compose.material3.SingleChoiceSegmentedButtonRow import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableIntStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource @@ -26,24 +22,21 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.brainwallet.R import com.brainwallet.data.model.CurrencyEntity -import com.brainwallet.data.model.Fee import com.brainwallet.data.model.FeeOption import com.brainwallet.data.model.getFiatFormatted -import com.brainwallet.data.model.toFeeOptions -import com.brainwallet.tools.manager.FeeManager +import com.brainwallet.data.model.getSelectedIndex import com.brainwallet.ui.screens.home.SettingsEvent import com.brainwallet.ui.theme.BrainwalletTheme -import com.brainwallet.wallet.BRWalletManager //TODO @Composable fun LitecoinBlockchainDetail( modifier: Modifier = Modifier, selectedCurrency: CurrencyEntity, + selectedFeeType: String, feeOptions: List, onEvent: (SettingsEvent) -> Unit, ) { - var feeOptionsState by remember { mutableIntStateOf(2) } //2 -> index of top, since we have [low,medium,top] /// Layout values val contentHeight = 60 @@ -81,12 +74,9 @@ fun LitecoinBlockchainDetail( NetworkFeeSelector( selectedCurrency = selectedCurrency, feeOptions = feeOptions, - selectedIndex = feeOptionsState + selectedIndex = feeOptions.getSelectedIndex(selectedFeeType) ) { newSelectedIndex -> - feeOptionsState = newSelectedIndex - - //just update inside BRWalletManager.setFeePerKb - BRWalletManager.getInstance().setFeePerKb(feeOptions[newSelectedIndex].feePerKb) + onEvent.invoke(SettingsEvent.OnFeeTypeChange(feeOptions[newSelectedIndex].type)) } } diff --git a/app/src/main/java/com/brainwallet/wallet/BRWalletManager.java b/app/src/main/java/com/brainwallet/wallet/BRWalletManager.java index 507a5125..59aaed33 100644 --- a/app/src/main/java/com/brainwallet/wallet/BRWalletManager.java +++ b/app/src/main/java/com/brainwallet/wallet/BRWalletManager.java @@ -9,6 +9,7 @@ import android.media.MediaPlayer; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.os.Bundle; import android.os.Handler; import android.os.NetworkOnMainThreadException; import android.os.SystemClock; @@ -334,6 +335,14 @@ public void onClick(DialogInterface dialog, int which) { */ public static void publishCallback(final String message, final int error, byte[] txHash) { Timber.d("timber: publishCallback: " + message + ", err:" + error + ", txHash: " + Arrays.toString(txHash)); + + Bundle params = new Bundle(); + params.putString("function", "BRWalletManager.publishCallback"); + params.putString("message", message); + params.putInt("error", error); + params.putString("txHash", Arrays.toString(txHash)); + AnalyticsManager.logCustomEventWithParams(BRConstants._20250517_WCINFO, params); + final Context app = BrainwalletApp.getBreadContext(); BRExecutor.getInstance().forMainThreadTasks().execute(new Runnable() { @Override @@ -440,6 +449,7 @@ public static void onTxDeleted(String hash, int notifyUser, final int recommendR final Context ctx = BrainwalletApp.getBreadContext(); if (ctx != null) { BRSharedPrefs.putScanRecommended(ctx, true); + TransactionDataSource.getInstance(ctx).deleteTxByHash(hash); } else { Timber.i("timber: onTxDeleted: Failed! ctx is null"); } @@ -513,11 +523,8 @@ public void initWallet(final Context ctx) { m.createWallet(transactionsCount, pubkeyEncoded); String firstAddress = BRWalletManager.getFirstAddress(pubkeyEncoded); BRSharedPrefs.putFirstAddress(ctx, firstAddress); - FeeManager feeManager = FeeManager.getInstance(); - if (feeManager.isLuxuryFee()) { - FeeManager.updateFeePerKb(ctx); - BRWalletManager.getInstance().setFeePerKb(feeManager.currentFeeOptions.luxury); - } + //set fee here + BRWalletManager.getInstance().setFeePerKb(FeeManager.getInstance().getCurrentFeeValue()); } if (!pm.isCreated()) { diff --git a/app/src/test/java/com/brainwallet/tools/database/DatabaseTests.kt b/app/src/test/java/com/brainwallet/tools/database/DatabaseTests.kt index 9a3a7d4f..3b8821d0 100644 --- a/app/src/test/java/com/brainwallet/tools/database/DatabaseTests.kt +++ b/app/src/test/java/com/brainwallet/tools/database/DatabaseTests.kt @@ -68,7 +68,6 @@ class DatabaseTests { // Assert.assertSame(BRConstants._20201118_DTGS,"did_tap_get_support"); // Assert.assertSame(BRConstants._20200217_DUWP,"did_unlock_with_pin"); // Assert.assertSame(BRConstants._20200217_DUWB,"did_unlock_with_biometrics"); -// Assert.assertSame(BRConstants._20200301_DUDFPK,"did_use_default_fee_per_kb"); // Assert.assertSame(BRConstants._20201121_SIL,"started_IFPS_lookup"); // Assert.assertSame(BRConstants._20201121_DRIA,"did_resolve_IPFS_address"); // Assert.assertSame(BRConstants._20201121_FRIA,"failed_resolve_IPFS_address"); diff --git a/app/src/test/java/com/brainwallet/tools/util/BRConstantsTest.kt b/app/src/test/java/com/brainwallet/tools/util/BRConstantsTest.kt index 82eabe93..5779b8df 100644 --- a/app/src/test/java/com/brainwallet/tools/util/BRConstantsTest.kt +++ b/app/src/test/java/com/brainwallet/tools/util/BRConstantsTest.kt @@ -43,7 +43,6 @@ class BRConstantsTest { assertSame(BRConstants._20201118_DTGS,"did_tap_get_support"); assertSame(BRConstants._20200217_DUWP,"did_unlock_with_pin"); assertSame(BRConstants._20200217_DUWB,"did_unlock_with_biometrics"); - assertSame(BRConstants._20200301_DUDFPK,"did_use_default_fee_per_kb"); assertSame(BRConstants._20201121_SIL,"started_IFPS_lookup"); assertSame(BRConstants._20201121_DRIA,"did_resolve_IPFS_address"); assertSame(BRConstants._20201121_FRIA,"failed_resolve_IPFS_address"); @@ -128,7 +127,6 @@ class BRConstantsTest { // Assert.assertSame(BRConstants._20201118_DTGS,"did_tap_get_support"); // Assert.assertSame(BRConstants._20200217_DUWP,"did_unlock_with_pin"); // Assert.assertSame(BRConstants._20200217_DUWB,"did_unlock_with_biometrics"); -// Assert.assertSame(BRConstants._20200301_DUDFPK,"did_use_default_fee_per_kb"); // Assert.assertSame(BRConstants._20201121_SIL,"started_IFPS_lookup"); // Assert.assertSame(BRConstants._20201121_DRIA,"did_resolve_IPFS_address"); // Assert.assertSame(BRConstants._20201121_FRIA,"failed_resolve_IPFS_address");