fix(wallet) sending community tokens doesn't work
The contract address is not resolved for the community tokens because of symbol usage to identify assets. The symbol is not resolved by `getTokenBySymbolByTokensKey`. This fix changes from using symbol to always using assetKey to identify the token for all non-native and non-collectibles transfers. Closes #14074
This commit is contained in:
parent
fd964337a8
commit
65791a8e87
|
@ -368,11 +368,14 @@ QtObject:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.sendTransactionSentSignal(from_addr, to_addr, uuid, @[], RpcResponse[JsonNode](), fmt"Error sending token transfer transaction: {e.msg}")
|
self.sendTransactionSentSignal(from_addr, to_addr, uuid, @[], RpcResponse[JsonNode](), fmt"Error sending token transfer transaction: {e.msg}")
|
||||||
|
|
||||||
|
# in case of collectibles transfer, assetKey is used to get the contract address and token id
|
||||||
|
# in case of asset transfer, asset is valid and used to get the asset symbol and contract address
|
||||||
proc transferToken(
|
proc transferToken(
|
||||||
self: Service,
|
self: Service,
|
||||||
from_addr: string,
|
from_addr: string,
|
||||||
to_addr: string,
|
to_addr: string,
|
||||||
tokenSymbol: string,
|
assetKey: string,
|
||||||
|
asset: TokenBySymbolItem,
|
||||||
uuid: string,
|
uuid: string,
|
||||||
routes: seq[TransactionPathDto],
|
routes: seq[TransactionPathDto],
|
||||||
password: string,
|
password: string,
|
||||||
|
@ -387,30 +390,38 @@ QtObject:
|
||||||
mtCommand = MultiTransactionCommandDto(
|
mtCommand = MultiTransactionCommandDto(
|
||||||
fromAddress: from_addr,
|
fromAddress: from_addr,
|
||||||
toAddress: to_addr,
|
toAddress: to_addr,
|
||||||
fromAsset: tokenSymbol,
|
fromAsset: if not asset.isNil: asset.symbol else: assetKey,
|
||||||
toAsset: tokenSymbol,
|
toAsset: if not asset.isNil: asset.symbol else: assetKey,
|
||||||
multiTxType: transactions.MultiTransactionType.MultiTransactionSend,
|
multiTxType: transactions.MultiTransactionType.MultiTransactionSend,
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.isCollectiblesTransfer(sendType):
|
# if collectibles transfer ...
|
||||||
let contract_tokenId = mtCommand.toAsset.split(":")
|
if asset.isNil:
|
||||||
|
let contract_tokenId = assetKey.split(":")
|
||||||
if contract_tokenId.len == 2:
|
if contract_tokenId.len == 2:
|
||||||
toContractAddress = parseAddress(contract_tokenId[0])
|
toContractAddress = parseAddress(contract_tokenId[0])
|
||||||
mtCommand.fromAsset = contract_tokenId[1]
|
mtCommand.fromAsset = contract_tokenId[1]
|
||||||
mtCommand.toAsset = contract_tokenId[1]
|
mtCommand.toAsset = contract_tokenId[1]
|
||||||
|
else:
|
||||||
|
error "Invalid assetKey for collectibles transfer", assetKey=assetKey
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for route in routes:
|
for route in routes:
|
||||||
var txData = TransactionDataDto()
|
var txData = TransactionDataDto()
|
||||||
var gasFees: string = ""
|
var gasFees: string = ""
|
||||||
|
|
||||||
if not self.isCollectiblesTransfer(sendType):
|
# If not collectible ...
|
||||||
let token = self.tokenService.getTokenBySymbolByTokensKey(mtCommand.toAsset)
|
if not asset.isNil:
|
||||||
if token != nil:
|
var foundAddress = false
|
||||||
for addressPerChain in token.addressPerChainId:
|
for addressPerChain in asset.addressPerChainId:
|
||||||
if addressPerChain.chainId == route.toNetwork.chainId:
|
if addressPerChain.chainId == route.toNetwork.chainId:
|
||||||
toContractAddress = parseAddress(addressPerChain.address)
|
toContractAddress = parseAddress(addressPerChain.address)
|
||||||
break
|
foundAddress = true
|
||||||
|
break
|
||||||
|
if not foundAddress:
|
||||||
|
error "Contract address not found for asset", assetKey=assetKey
|
||||||
|
return
|
||||||
|
|
||||||
if not route.gasFees.eip1559Enabled:
|
if not route.gasFees.eip1559Enabled:
|
||||||
gasFees = $route.gasFees.gasPrice
|
gasFees = $route.gasFees.gasPrice
|
||||||
|
@ -471,27 +482,25 @@ QtObject:
|
||||||
finalPassword = common_utils.hashPassword(password)
|
finalPassword = common_utils.hashPassword(password)
|
||||||
try:
|
try:
|
||||||
var chainID = 0
|
var chainID = 0
|
||||||
var isEthTx = false
|
|
||||||
|
|
||||||
if(selectedRoutes.len > 0):
|
if(selectedRoutes.len > 0):
|
||||||
chainID = selectedRoutes[0].fromNetwork.chainID
|
chainID = selectedRoutes[0].fromNetwork.chainID
|
||||||
|
|
||||||
var tokenSymbol = ""
|
# asset == nil means transferToken is executed for a collectibles transfer
|
||||||
if self.isCollectiblesTransfer(sendType):
|
var asset: TokenBySymbolItem
|
||||||
tokenSymbol = assetKey
|
if not self.isCollectiblesTransfer(sendType):
|
||||||
else:
|
asset = self.tokenService.getTokenBySymbolByTokensKey(assetKey)
|
||||||
let token = self.tokenService.getTokenBySymbolByTokensKey(assetKey)
|
if not asset.isNil:
|
||||||
if token != nil:
|
let network = self.networkService.getNetworkByChainId(chainID)
|
||||||
tokenSymbol = token.symbol
|
if not network.isNil and network.nativeCurrencySymbol == asset.symbol:
|
||||||
|
self.transferEth(fromAddr, toAddr, asset.symbol, uuid, selectedRoutes, finalPassword)
|
||||||
|
return
|
||||||
|
# else continue with asset transfer
|
||||||
|
else:
|
||||||
|
error "Asset not found for", assetKey=assetKey
|
||||||
|
return
|
||||||
|
|
||||||
let network = self.networkService.getNetworkByChainId(chainID)
|
self.transferToken(fromAddr, toAddr, assetKey, asset, uuid, selectedRoutes, finalPassword, sendType, tokenName, isOwnerToken)
|
||||||
if not network.isNil and network.nativeCurrencySymbol == tokenSymbol:
|
|
||||||
isEthTx = true
|
|
||||||
|
|
||||||
if(isEthTx):
|
|
||||||
self.transferEth(fromAddr, toAddr, tokenSymbol, uuid, selectedRoutes, finalPassword)
|
|
||||||
else:
|
|
||||||
self.transferToken(fromAddr, toAddr, tokenSymbol, uuid, selectedRoutes, finalPassword, sendType, tokenName, isOwnerToken)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.events.emit(SIGNAL_TRANSACTION_SENT, TransactionSentArgs(chainId: 0, txHash: "", uuid: uuid, error: fmt"Error sending token transfer transaction: {e.msg}"))
|
self.events.emit(SIGNAL_TRANSACTION_SENT, TransactionSentArgs(chainId: 0, txHash: "", uuid: uuid, error: fmt"Error sending token transfer transaction: {e.msg}"))
|
||||||
|
|
Loading…
Reference in New Issue