Skip to content

Commit

Permalink
bug fixeds
Browse files Browse the repository at this point in the history
  • Loading branch information
polstianka committed Oct 27, 2024
1 parent e8a5326 commit f951fc0
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tonapps.wallet.data.settings

import android.content.Context
import android.icu.util.Currency
import androidx.core.os.LocaleListCompat
import com.tonapps.extensions.MutableEffectFlow
import com.tonapps.extensions.clear
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.tonapps.tonkeeper.api

import android.icu.util.Currency
import com.tonapps.icu.Coins
import com.tonapps.blockchain.ton.extensions.toUserFriendly
import com.tonapps.extensions.max18
import com.tonapps.tonkeeperx.R
import com.tonapps.wallet.api.API
import com.tonapps.wallet.data.settings.SettingsRepository
import io.tonapi.models.AccountAddress
import io.tonapi.models.AccountEvent
import io.tonapi.models.Action
Expand All @@ -15,6 +18,7 @@ import io.tonapi.models.JettonPreview
import io.tonapi.models.NftItem
import io.tonapi.models.PoolImplementationType
import io.tonapi.models.TokenRates
import java.util.Locale
import kotlin.math.abs

private val nftItemPreviewSizes = arrayOf(
Expand All @@ -26,6 +30,30 @@ fun TokenRates.to(toCurrency: String, value: Float): Float {
return price.toFloat() * value
}

suspend fun API.getCurrencyCodeByCountry(settingsRepository: SettingsRepository): String {
val fromSettingsCountry = getCurrencyByCountry(settingsRepository.country)
val fromSettingsCurrency = settingsRepository.currency.code
val fromIPCountry = resolveCountry()?.let { getCurrencyByCountry(it) }
val currency = fromSettingsCountry ?: fromIPCountry ?: fromSettingsCurrency
if (currency.equals("TON", true)) {
return "USD"
}
return currency
}

private fun getCurrencyByCountry(country: String): String? {
try {
val currency = Currency.getInstance(Locale("", country)).currencyCode
if (currency.isNullOrEmpty()) {
return null
}
return currency
} catch (e: Throwable) {
return null
}
}



/*val MessageConsequences.totalFees: Long
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ data class WalletPurchaseMethodEntity(
}

private companion object {

fun replaceUrl(
url: String,
address: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.widget.AppCompatTextView
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import com.tonapps.tonkeeper.api.getCurrencyCodeByCountry
import com.tonapps.tonkeeper.core.entities.WalletPurchaseMethodEntity
import com.tonapps.tonkeeper.extensions.countryEmoji
import com.tonapps.tonkeeper.helper.BrowserHelper
Expand All @@ -17,6 +19,7 @@ import com.tonapps.wallet.api.API
import com.tonapps.wallet.data.account.entities.WalletEntity
import com.tonapps.wallet.data.purchase.entity.PurchaseMethodEntity
import com.tonapps.wallet.data.settings.SettingsRepository
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import uikit.base.BaseFragment
import uikit.extensions.applyNavBottomPadding
Expand Down Expand Up @@ -82,23 +85,28 @@ class PurchaseScreen(wallet: WalletEntity): WalletContextScreen(R.layout.fragmen
}

private fun open(method: PurchaseMethodEntity) {
val activity = requireActivity() as NavigationActivity
val methodWrapped = WalletPurchaseMethodEntity(
method = method,
wallet = screenContext.wallet,
currency = settingsRepository.currency.code,
config = api.config
)
if (viewModel.isPurchaseOpenConfirm(method)) {
confirmDialog.show(method) { showAgain ->
if (!showAgain) {
viewModel.disableConfirmDialog(screenContext.wallet, method)
lifecycleScope.launch {
val currency = api.getCurrencyCodeByCountry(settingsRepository)
val activity = requireActivity() as NavigationActivity
val methodWrapped = WalletPurchaseMethodEntity(
method = method,
wallet = screenContext.wallet,
currency = currency,
config = api.config
)
if (viewModel.isPurchaseOpenConfirm(method)) {
confirmDialog.show(method) { showAgain ->
if (!showAgain) {
viewModel.disableConfirmDialog(screenContext.wallet, method)
}
BrowserHelper.openPurchase(activity, methodWrapped)
}
} else {
BrowserHelper.openPurchase(activity, methodWrapped)
}
} else {
BrowserHelper.openPurchase(activity, methodWrapped)
}


}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.tonapps.extensions.setLocales
import com.tonapps.extensions.toUriOrNull
import com.tonapps.ledger.ton.LedgerConnectData
import com.tonapps.tonkeeper.Environment
import com.tonapps.tonkeeper.api.getCurrencyCodeByCountry
import com.tonapps.tonkeeper.core.AnalyticsHelper
import com.tonapps.tonkeeper.core.entities.WalletPurchaseMethodEntity
import com.tonapps.tonkeeper.core.history.HistoryHelper
Expand Down Expand Up @@ -449,7 +450,7 @@ class RootViewModel(
BrowserHelper.openPurchase(context, WalletPurchaseMethodEntity(
method = method,
wallet = wallet,
currency = settingsRepository.currency.code,
currency = api.getCurrencyCodeByCountry(settingsRepository),
config = api.config
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SendContactsViewModel(
private val myWalletsFlow = _myWalletsFlow.asStateFlow()

private val latestContactsFlow = flow {
emit(listOf(Item.Loading))
// emit(listOf(Item.Loading))
emitAll(getLatestContactsFlow())
}

Expand All @@ -65,10 +65,10 @@ class SendContactsViewModel(
uiItems.add(Item.Space)
}

if (savedContacts.isNotEmpty()) {
/*if (savedContacts.isNotEmpty()) {
uiItems.addAll(savedContacts)
uiItems.add(Item.Space)
}
}*/

if (latestContacts.isNotEmpty()) {
uiItems.addAll(latestContacts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_gravity="bottom"
android:layout_margin="16dp"
android:textAppearance="@style/TextAppearance.Label1"
Expand Down

0 comments on commit f951fc0

Please sign in to comment.