diff --git a/src/app/wallet/views/token_list.nim b/src/app/wallet/views/token_list.nim index 1ecc7c203b..817ac2439b 100644 --- a/src/app/wallet/views/token_list.nim +++ b/src/app/wallet/views/token_list.nim @@ -1,5 +1,5 @@ import # nim libs - tables, json + strformat, tables, json import # vendor libs NimQml @@ -21,18 +21,24 @@ type address: string const getTokenDetailsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = - let - arg = decode[GetTokenDetailsTaskArg](argEncoded) - tkn = newErc20Contract(getCurrentNetwork(), arg.address.parseAddress) - decimals = tkn.tokenDecimals() - - let output = %* { - "address": arg.address, - "name": tkn.tokenName(), - "symbol": tkn.tokenSymbol(), - "decimals": (if decimals == 0: "" else: $decimals) - } - arg.finish(output) + let arg = decode[GetTokenDetailsTaskArg](argEncoded) + try: + let + tkn = newErc20Contract(getCurrentNetwork(), arg.address.parseAddress) + decimals = tkn.tokenDecimals() + output = %* { + "address": arg.address, + "name": tkn.tokenName(), + "symbol": tkn.tokenSymbol(), + "decimals": (if decimals == 0: "" else: $decimals) + } + arg.finish(output) + except Exception as e: + let output = %* { + "address": arg.address, + "error": fmt"{e.msg}. Is this an ERC-20 or ERC-721 contract?", + } + arg.finish(output) proc getTokenDetails[T](self: T, slot: string, address: string) = let arg = GetTokenDetailsTaskArg( diff --git a/ui/app/AppLayouts/Wallet/AddCustomTokenModal.qml b/ui/app/AppLayouts/Wallet/AddCustomTokenModal.qml index 90019d96b0..627f4c024d 100644 --- a/ui/app/AppLayouts/Wallet/AddCustomTokenModal.qml +++ b/ui/app/AppLayouts/Wallet/AddCustomTokenModal.qml @@ -67,13 +67,17 @@ ModalPopup { target: walletModel.customTokenList onTokenDetailsWereResolved: { const jsonObj = JSON.parse(tokenDetails) - if(jsonObj.name === "" || jsonObj.symbol === "" || jsonObj.decimals === ""){ + if (jsonObj.error) { + validationError = jsonObj.error + return + } + if (jsonObj.name === "" && jsonObj.symbol === "" && jsonObj.decimals === "") { //% "Invalid ERC20 address" validationError = qsTrId("invalid-erc20-address") return; } - if(addressInput.text.toLowerCase() === jsonObj.address.toLowerCase()){ + if (addressInput.text.toLowerCase() === jsonObj.address.toLowerCase()) { symbolInput.text = jsonObj.symbol; decimalsInput.text = jsonObj.decimals; nameInput.text = jsonObj.name; diff --git a/ui/shared/Input.qml b/ui/shared/Input.qml index 54424248a6..3557cb8c82 100644 --- a/ui/shared/Input.qml +++ b/ui/shared/Input.qml @@ -179,7 +179,8 @@ Item { font.pixelSize: 12 height: 16 color: Style.current.danger - width: parent.width + width: inputRectangle.width + wrapMode: TextEdit.Wrap } }