Updated on 2026-08-14
This commit is contained in:
parent
e444da5a56
commit
85a7e6e1a0
1 changed files with 37 additions and 14 deletions
|
|
@ -99,17 +99,31 @@ class UserWalletManagerImpl(
|
|||
return false
|
||||
}
|
||||
|
||||
// todo check is it sync operation
|
||||
override fun addToken(currency: Currency) {
|
||||
val card = requireNotNull(appStateHolder.getActualCard()) { "card not found" }
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(currency.networkId)) { "blockchain not found" }
|
||||
val action = if (currency is NativeToken) {
|
||||
addNativeTokenToWalletAction(card, blockchain)
|
||||
} else {
|
||||
addNonNativeTokenToWalletAction(currency as NonNativeToken, card, blockchain)
|
||||
val blockchainNetwork = BlockchainNetwork(blockchain, card)
|
||||
val walletManager = appStateHolder.walletState?.getWalletManager(blockchainNetwork)
|
||||
val action = when (currency) {
|
||||
is NativeToken -> {
|
||||
if (walletManager == null) {
|
||||
addNativeTokenToWalletAction(card, blockchain, blockchainNetwork)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
is NonNativeToken -> {
|
||||
if (walletManager?.cardTokens?.contains(currency.toSdkToken()) == false) {
|
||||
addNonNativeTokenToWalletAction(currency, card, blockchain)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
action?.let {
|
||||
val mainStore = requireNotNull(appStateHolder.mainStore) { "mainStore is null" }
|
||||
mainStore.dispatchOnMain(action)
|
||||
}
|
||||
val mainStore = requireNotNull(appStateHolder.mainStore) { "mainStore is null" }
|
||||
mainStore.dispatchOnMain(action)
|
||||
}
|
||||
|
||||
override fun getWalletAddress(networkId: String): String {
|
||||
|
|
@ -143,11 +157,7 @@ class UserWalletManagerImpl(
|
|||
val extraTokensToLoadBalance = extraTokens
|
||||
.filterIsInstance<NonNativeToken>()
|
||||
.map {
|
||||
Token(
|
||||
symbol = it.symbol,
|
||||
contractAddress = it.contractAddress,
|
||||
decimals = it.decimalCount,
|
||||
)
|
||||
it.toSdkToken()
|
||||
}
|
||||
.filter {
|
||||
!walletManager.cardTokens.contains(it)
|
||||
|
|
@ -194,9 +204,12 @@ class UserWalletManagerImpl(
|
|||
)
|
||||
}
|
||||
|
||||
private fun addNativeTokenToWalletAction(card: CardDTO, blockchain: Blockchain): Action {
|
||||
private fun addNativeTokenToWalletAction(
|
||||
card: CardDTO,
|
||||
blockchain: Blockchain,
|
||||
blockchainNetwork: BlockchainNetwork,
|
||||
): Action {
|
||||
val scanResponse = requireNotNull(appStateHolder.scanResponse) { "scanResponse not found" }
|
||||
val blockchainNetwork = BlockchainNetwork(blockchain, card)
|
||||
var walletManager = appStateHolder.walletState?.getWalletManager(blockchainNetwork)
|
||||
if (walletManager == null) {
|
||||
walletManager = walletManagerFactory.makeWalletManagerForApp(
|
||||
|
|
@ -245,4 +258,14 @@ class UserWalletManagerImpl(
|
|||
companion object {
|
||||
private const val HEX_PREFIX = "0x"
|
||||
}
|
||||
}
|
||||
|
||||
private fun NonNativeToken.toSdkToken(): Token {
|
||||
return Token(
|
||||
id = this.id,
|
||||
name = this.name,
|
||||
symbol = this.symbol,
|
||||
contractAddress = this.contractAddress,
|
||||
decimals = this.decimalCount,
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue