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
e787dce368
commit
36d8a33935
|
@ -371,11 +371,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,
|
||||||
|
@ -390,30 +393,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)
|
||||||
|
foundAddress = true
|
||||||
break
|
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
|
||||||
|
@ -474,27 +485,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):
|
||||||
|
asset = self.tokenService.getTokenBySymbolByTokensKey(assetKey)
|
||||||
|
if not asset.isNil:
|
||||||
|
let network = self.networkService.getNetworkByChainId(chainID)
|
||||||
|
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:
|
else:
|
||||||
let token = self.tokenService.getTokenBySymbolByTokensKey(assetKey)
|
error "Asset not found for", assetKey=assetKey
|
||||||
if token != nil:
|
return
|
||||||
tokenSymbol = token.symbol
|
|
||||||
|
|
||||||
let network = self.networkService.getNetwork(chainID)
|
self.transferToken(fromAddr, toAddr, assetKey, asset, uuid, selectedRoutes, finalPassword, sendType, tokenName, isOwnerToken)
|
||||||
if 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