Updated on 2026-08-14
This commit is contained in:
parent
fec81d0697
commit
25d39f9f0b
11 changed files with 81 additions and 71 deletions
|
|
@ -84,7 +84,6 @@ class IntentHandler {
|
|||
val successUri = Uri.parse(ExchangeUrlBuilder.SUCCESS_URL)
|
||||
if (data.host == successUri.host && data.authority == successUri.authority) {
|
||||
val currency = store.state.walletState.selectedCurrency ?: return
|
||||
|
||||
val currencyType = AnalyticsParam.CurrencyType.Currency(currency)
|
||||
Analytics.send(Token.Bought(currencyType))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,11 @@ class TradeCryptoMiddleware {
|
|||
|
||||
private fun openSwap() {
|
||||
val currency = store.state.walletState.selectedWalletData?.currency?.toSwapCurrency()
|
||||
val bundle = bundleOf(SwapFragment.CURRENCY_BUNDLE_KEY to Json.encodeToString(currency))
|
||||
val bundle =
|
||||
bundleOf(
|
||||
SwapFragment.CURRENCY_BUNDLE_KEY to Json.encodeToString(currency),
|
||||
SwapFragment.DERIVATION_PATH to store.state.walletState.selectedWalletData?.currency?.derivationPath
|
||||
)
|
||||
store.dispatchOnMain(NavigationAction.NavigateTo(screen = AppScreen.Swap, bundle = bundle))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,9 +48,10 @@ class TransactionManagerImpl(
|
|||
gasLimit: Int,
|
||||
destinationAddress: String,
|
||||
dataToSign: String,
|
||||
derivationPath: String?,
|
||||
): SendTxResult {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
val walletManager = getActualWalletManager(blockchain)
|
||||
val walletManager = getActualWalletManager(blockchain, derivationPath)
|
||||
walletManager.update()
|
||||
val amount = Amount(value = BigDecimal.ZERO, blockchain = blockchain)
|
||||
return sendTransactionInternal(
|
||||
|
|
@ -73,9 +74,10 @@ class TransactionManagerImpl(
|
|||
dataToSign: String,
|
||||
isSwap: Boolean,
|
||||
currencyToSend: Currency,
|
||||
derivationPath: String?,
|
||||
): SendTxResult {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
val walletManager = getActualWalletManager(blockchain)
|
||||
val walletManager = getActualWalletManager(blockchain, derivationPath)
|
||||
walletManager.update()
|
||||
val amount = if (isSwap) {
|
||||
createAmountForSwap(amountToSend, currencyToSend, blockchain)
|
||||
|
|
@ -129,9 +131,9 @@ class TransactionManagerImpl(
|
|||
return Blockchain.fromNetworkId(networkId)?.decimals() ?: error("blockchain not found")
|
||||
}
|
||||
|
||||
override suspend fun updateWalletManager(networkId: String) {
|
||||
override suspend fun updateWalletManager(networkId: String, derivationPath: String?) {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
getActualWalletManager(blockchain).update()
|
||||
getActualWalletManager(blockchain, derivationPath).update()
|
||||
}
|
||||
|
||||
override fun calculateFee(networkId: String, gasPrice: String, estimatedGas: Int): BigDecimal {
|
||||
|
|
@ -147,9 +149,10 @@ class TransactionManagerImpl(
|
|||
currencyToSend: Currency,
|
||||
destinationAddress: String,
|
||||
data: String?,
|
||||
derivationPath: String?,
|
||||
): ProxyFee {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
val walletManager = getActualWalletManager(blockchain)
|
||||
val walletManager = getActualWalletManager(blockchain, derivationPath)
|
||||
if (walletManager is EthereumWalletManager) {
|
||||
val gasLimit = getGasLimit(
|
||||
evmWalletManager = walletManager,
|
||||
|
|
@ -293,19 +296,10 @@ class TransactionManagerImpl(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getActualWalletManager(blockchain: Blockchain): WalletManager {
|
||||
val card = appStateHolder.getActualCard()
|
||||
if (card != null) {
|
||||
val blockchainNetwork = BlockchainNetwork(blockchain, card)
|
||||
val walletManager = appStateHolder.walletState?.getWalletManager(blockchainNetwork)
|
||||
if (walletManager != null) {
|
||||
return walletManager
|
||||
} else {
|
||||
error("no wallet manager found")
|
||||
}
|
||||
} else {
|
||||
error("card not found")
|
||||
}
|
||||
private fun getActualWalletManager(blockchain: Blockchain, derivationPath: String?): WalletManager {
|
||||
val blockchainNetwork = BlockchainNetwork(blockchain, derivationPath, emptyList())
|
||||
val walletManager = appStateHolder.walletState?.getWalletManager(blockchainNetwork)
|
||||
return requireNotNull(walletManager) { "no wallet manager found" }
|
||||
}
|
||||
|
||||
private fun createExtras(
|
||||
|
|
|
|||
|
|
@ -85,23 +85,17 @@ class UserWalletManagerImpl(
|
|||
?: ""
|
||||
}
|
||||
|
||||
override suspend fun isTokenAdded(currency: Currency): Boolean {
|
||||
val card = requireNotNull(appStateHolder.getActualCard()) { "card is null" }
|
||||
override suspend fun isTokenAdded(currency: Currency, derivationPath: String?): Boolean {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(currency.networkId)) { "blockchain not found" }
|
||||
val blockchainNetwork = BlockchainNetwork(blockchain, card)
|
||||
val walletManager = appStateHolder.walletState?.getWalletManager(blockchainNetwork)
|
||||
if (walletManager != null) {
|
||||
return walletManager.cardTokens.any {
|
||||
it.id == currency.id
|
||||
}
|
||||
val walletManager = getActualWalletManager(blockchain, derivationPath)
|
||||
return walletManager.cardTokens.any {
|
||||
it.id == currency.id
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override suspend fun addToken(currency: Currency) {
|
||||
val card = requireNotNull(appStateHolder.getActualCard()) { "card not found" }
|
||||
override suspend fun addToken(currency: Currency, derivationPath: String?) {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(currency.networkId)) { "blockchain not found" }
|
||||
val blockchainNetwork = BlockchainNetwork(blockchain, card)
|
||||
val blockchainNetwork = BlockchainNetwork(blockchain, derivationPath, emptyList())
|
||||
|
||||
val selectedUserWallet = userWalletsListManager.selectedUserWalletSync.guard {
|
||||
Timber.e("Unable to add token, no user wallet selected")
|
||||
|
|
@ -113,34 +107,27 @@ class UserWalletManagerImpl(
|
|||
)
|
||||
}
|
||||
|
||||
override fun getWalletAddress(networkId: String): String {
|
||||
override fun getWalletAddress(networkId: String, derivationPath: String?): String {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
val card = requireNotNull(appStateHolder.getActualCard()) { "card not found" }
|
||||
val blockchainNetwork = BlockchainNetwork(blockchain, card)
|
||||
val walletManager = appStateHolder.walletState?.getWalletManager(blockchainNetwork)
|
||||
if (walletManager != null) {
|
||||
return walletManager.wallet.address
|
||||
} else {
|
||||
error("no wallet manager found")
|
||||
}
|
||||
val walletManager = getActualWalletManager(blockchain, derivationPath)
|
||||
return walletManager.wallet.address
|
||||
}
|
||||
|
||||
override fun getLastTransactionHash(networkId: String): String? {
|
||||
override fun getLastTransactionHash(networkId: String, derivationPath: String?): String? {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
val card = requireNotNull(appStateHolder.getActualCard()) { "card not found" }
|
||||
val blockchainNetwork = BlockchainNetwork(blockchain, card)
|
||||
val walletManager = appStateHolder.walletState?.getWalletManager(blockchainNetwork)
|
||||
return walletManager?.wallet?.recentTransactions
|
||||
?.lastOrNull { it.hash?.isNotEmpty() == true }
|
||||
val walletManager = getActualWalletManager(blockchain, derivationPath)
|
||||
return walletManager.wallet.recentTransactions
|
||||
.lastOrNull { it.hash?.isNotEmpty() == true }
|
||||
?.hash?.let { HEX_PREFIX + it }
|
||||
}
|
||||
|
||||
override suspend fun getCurrentWalletTokensBalance(
|
||||
networkId: String,
|
||||
extraTokens: List<Currency>,
|
||||
derivationPath: String?,
|
||||
): Map<String, ProxyAmount> {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
val walletManager = getActualWalletManager(blockchain)
|
||||
val walletManager = getActualWalletManager(blockchain, derivationPath)
|
||||
|
||||
// workaround for get balance for tokens that doesn't exist in wallet
|
||||
val extraTokensToLoadBalance = extraTokens
|
||||
|
|
@ -165,9 +152,9 @@ class UserWalletManagerImpl(
|
|||
return balances
|
||||
}
|
||||
|
||||
override fun getNativeTokenBalance(networkId: String): ProxyAmount? {
|
||||
override fun getNativeTokenBalance(networkId: String, derivationPath: String?): ProxyAmount? {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
val walletManager = getActualWalletManager(blockchain)
|
||||
val walletManager = getActualWalletManager(blockchain, derivationPath)
|
||||
return walletManager.wallet.amounts.firstNotNullOfOrNull {
|
||||
it.takeIf { it.key is AmountType.Coin }
|
||||
}?.value?.let {
|
||||
|
|
@ -198,9 +185,8 @@ class UserWalletManagerImpl(
|
|||
appStateHolder.mainStore?.dispatchOnMain(WalletAction.LoadData.Refresh)
|
||||
}
|
||||
|
||||
private fun getActualWalletManager(blockchain: Blockchain): WalletManager {
|
||||
val card = requireNotNull(appStateHolder.getActualCard()) { "card not found" }
|
||||
val blockchainNetwork = BlockchainNetwork(blockchain, card)
|
||||
private fun getActualWalletManager(blockchain: Blockchain, derivationPath: String?): WalletManager {
|
||||
val blockchainNetwork = BlockchainNetwork(blockchain, derivationPath, emptyList())
|
||||
return requireNotNull(appStateHolder.walletState?.getWalletManager(blockchainNetwork)) {
|
||||
"No wallet manager found"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue