fix: capture RpcExceptions generated by stickers that would not allow login
This commit is contained in:
parent
74a38c671d
commit
4fae0eb100
|
@ -9,6 +9,9 @@ import ../signals/types as signal_types
|
||||||
import ens
|
import ens
|
||||||
import eth/common/eth_types
|
import eth/common/eth_types
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "chat-model"
|
||||||
|
|
||||||
type
|
type
|
||||||
ChatUpdateArgs* = ref object of Args
|
ChatUpdateArgs* = ref object of Args
|
||||||
chats*: seq[Chat]
|
chats*: seq[Chat]
|
||||||
|
@ -99,12 +102,16 @@ proc getPurchasedStickerPacks*(self: ChatModel, address: EthAddress): seq[int] =
|
||||||
if self.purchasedStickerPacks != @[]:
|
if self.purchasedStickerPacks != @[]:
|
||||||
return self.purchasedStickerPacks
|
return self.purchasedStickerPacks
|
||||||
|
|
||||||
var balance = status_stickers.getBalance(address)
|
try:
|
||||||
# balance = 2 # hardcode to test support of purchased sticker packs, because buying sticker packs is proving very difficult on testnet
|
var balance = status_stickers.getBalance(address)
|
||||||
var tokenIds = toSeq[0..<balance].map(idx => status_stickers.tokenOfOwnerByIndex(address, idx))
|
# balance = 2 # hardcode to test support of purchased sticker packs, because buying sticker packs is proving very difficult on testnet
|
||||||
# tokenIds = @[1, 2] # hardcode to test support of purchased sticker packs
|
var tokenIds = toSeq[0..<balance].map(idx => status_stickers.tokenOfOwnerByIndex(address, idx))
|
||||||
self.purchasedStickerPacks = tokenIds.map(tokenId => status_stickers.getPackIdFromTokenId(tokenId))
|
# tokenIds = @[1, 2] # hardcode to test support of purchased sticker packs
|
||||||
result = self.purchasedStickerPacks
|
self.purchasedStickerPacks = tokenIds.map(tokenId => status_stickers.getPackIdFromTokenId(tokenId))
|
||||||
|
result = self.purchasedStickerPacks
|
||||||
|
except RpcException:
|
||||||
|
error "Error in getPurchasedStickerPacks", message = getCurrentExceptionMsg()
|
||||||
|
result = @[]
|
||||||
|
|
||||||
proc getInstalledStickerPacks*(self: ChatModel): Table[int, StickerPack] =
|
proc getInstalledStickerPacks*(self: ChatModel): Table[int, StickerPack] =
|
||||||
if self.installedStickerPacks != initTable[int, StickerPack]():
|
if self.installedStickerPacks != initTable[int, StickerPack]():
|
||||||
|
@ -117,14 +124,18 @@ proc getAvailableStickerPacks*(self: ChatModel): Table[int, StickerPack] =
|
||||||
if self.availableStickerPacks != initTable[int, StickerPack]():
|
if self.availableStickerPacks != initTable[int, StickerPack]():
|
||||||
return self.availableStickerPacks
|
return self.availableStickerPacks
|
||||||
|
|
||||||
let numPacks = status_stickers.getPackCount()
|
try:
|
||||||
for i in 0..<numPacks:
|
let numPacks = status_stickers.getPackCount()
|
||||||
try:
|
for i in 0..<numPacks:
|
||||||
let stickerPack = status_stickers.getPackData(i)
|
try:
|
||||||
self.availableStickerPacks[stickerPack.id] = stickerPack
|
let stickerPack = status_stickers.getPackData(i)
|
||||||
except:
|
self.availableStickerPacks[stickerPack.id] = stickerPack
|
||||||
continue
|
except:
|
||||||
result = self.availableStickerPacks
|
continue
|
||||||
|
result = self.availableStickerPacks
|
||||||
|
except RpcException:
|
||||||
|
error "Error in getAvailableStickerPacks", message = getCurrentExceptionMsg()
|
||||||
|
result = initTable[int, StickerPack]()
|
||||||
|
|
||||||
proc getRecentStickers*(self: ChatModel): seq[Sticker] =
|
proc getRecentStickers*(self: ChatModel): seq[Sticker] =
|
||||||
result = status_stickers.getRecentStickers()
|
result = status_stickers.getRecentStickers()
|
||||||
|
|
|
@ -65,8 +65,8 @@ proc getBalance*(address: EthAddress): int =
|
||||||
|
|
||||||
let responseStr = status.callPrivateRPC("eth_call", payload)
|
let responseStr = status.callPrivateRPC("eth_call", payload)
|
||||||
let response = Json.decode(responseStr, RpcResponse)
|
let response = Json.decode(responseStr, RpcResponse)
|
||||||
if response.error != "":
|
if not response.error.isNil:
|
||||||
raise newException(RpcException, "Error getting stickers balance: " & response.error)
|
raise newException(RpcException, "Error getting stickers balance: " & response.error.message)
|
||||||
if response.result == "0x":
|
if response.result == "0x":
|
||||||
return 0
|
return 0
|
||||||
result = fromHex[int](response.result)
|
result = fromHex[int](response.result)
|
||||||
|
@ -81,8 +81,8 @@ proc getPackCount*(): int =
|
||||||
|
|
||||||
let responseStr = status.callPrivateRPC("eth_call", payload)
|
let responseStr = status.callPrivateRPC("eth_call", payload)
|
||||||
let response = Json.decode(responseStr, RpcResponse)
|
let response = Json.decode(responseStr, RpcResponse)
|
||||||
if response.error != "":
|
if not response.error.isNil:
|
||||||
raise newException(RpcException, "Error getting stickers balance: " & response.error)
|
raise newException(RpcException, "Error getting stickers balance: " & response.error.message)
|
||||||
if response.result == "0x":
|
if response.result == "0x":
|
||||||
return 0
|
return 0
|
||||||
result = fromHex[int](response.result)
|
result = fromHex[int](response.result)
|
||||||
|
@ -97,8 +97,8 @@ proc getPackData*(id: int): StickerPack =
|
||||||
}, "latest"]
|
}, "latest"]
|
||||||
let responseStr = status.callPrivateRPC("eth_call", payload)
|
let responseStr = status.callPrivateRPC("eth_call", payload)
|
||||||
let response = Json.decode(responseStr, RpcResponse)
|
let response = Json.decode(responseStr, RpcResponse)
|
||||||
if response.error != "":
|
if not response.error.isNil:
|
||||||
raise newException(RpcException, "Error getting sticker pack data: " & response.error)
|
raise newException(RpcException, "Error getting sticker pack data: " & response.error.message)
|
||||||
|
|
||||||
let packData = contracts.decodeContractResponse[PackData](response.result)
|
let packData = contracts.decodeContractResponse[PackData](response.result)
|
||||||
|
|
||||||
|
@ -136,8 +136,8 @@ proc buyPack*(packId: int, address: EthAddress, price: Stuint[256], password: st
|
||||||
|
|
||||||
let responseStr = status.sendTransaction($payload, password)
|
let responseStr = status.sendTransaction($payload, password)
|
||||||
let response = Json.decode(responseStr, RpcResponse)
|
let response = Json.decode(responseStr, RpcResponse)
|
||||||
if response.error != "":
|
if not response.error.isNil:
|
||||||
raise newException(RpcException, "Error getting stickers balance: " & response.error)
|
raise newException(RpcException, "Error getting stickers balance: " & response.error.message)
|
||||||
result = response.result # should be a tx receipt
|
result = response.result # should be a tx receipt
|
||||||
|
|
||||||
proc tokenOfOwnerByIndex*(address: EthAddress, idx: int): int =
|
proc tokenOfOwnerByIndex*(address: EthAddress, idx: int): int =
|
||||||
|
@ -149,8 +149,8 @@ proc tokenOfOwnerByIndex*(address: EthAddress, idx: int): int =
|
||||||
|
|
||||||
let responseStr = status.callPrivateRPC("eth_call", payload)
|
let responseStr = status.callPrivateRPC("eth_call", payload)
|
||||||
let response = Json.decode(responseStr, RpcResponse)
|
let response = Json.decode(responseStr, RpcResponse)
|
||||||
if response.error != "":
|
if not response.error.isNil:
|
||||||
raise newException(RpcException, "Error getting owned tokens: " & response.error)
|
raise newException(RpcException, "Error getting owned tokens: " & response.error.message)
|
||||||
if response.result == "0x":
|
if response.result == "0x":
|
||||||
return 0
|
return 0
|
||||||
result = fromHex[int](response.result)
|
result = fromHex[int](response.result)
|
||||||
|
@ -164,8 +164,8 @@ proc getPackIdFromTokenId*(tokenId: int): int =
|
||||||
|
|
||||||
let responseStr = status.callPrivateRPC("eth_call", payload)
|
let responseStr = status.callPrivateRPC("eth_call", payload)
|
||||||
let response = Json.decode(responseStr, RpcResponse)
|
let response = Json.decode(responseStr, RpcResponse)
|
||||||
if response.error != "":
|
if not response.error.isNil:
|
||||||
raise newException(RpcException, "Error getting pack id from token id: " & response.error)
|
raise newException(RpcException, "Error getting pack id from token id: " & response.error.message)
|
||||||
if response.result == "0x":
|
if response.result == "0x":
|
||||||
return 0
|
return 0
|
||||||
result = fromHex[int](response.result)
|
result = fromHex[int](response.result)
|
||||||
|
|
|
@ -57,12 +57,16 @@ type
|
||||||
keyUid*: string
|
keyUid*: string
|
||||||
photoPath*: string
|
photoPath*: string
|
||||||
|
|
||||||
|
type RpcError* = ref object
|
||||||
|
code*: int
|
||||||
|
message*: string
|
||||||
|
|
||||||
type
|
type
|
||||||
RpcResponse* = ref object
|
RpcResponse* = ref object
|
||||||
jsonrpc*: string
|
jsonrpc*: string
|
||||||
result*: string
|
result*: string
|
||||||
id*: int
|
id*: int
|
||||||
error*: string
|
error*: RpcError
|
||||||
|
|
||||||
proc toAccount*(account: GeneratedAccount): Account =
|
proc toAccount*(account: GeneratedAccount): Account =
|
||||||
result = Account(name: account.name, photoPath: account.photoPath, keyUid: account.address)
|
result = Account(name: account.name, photoPath: account.photoPath, keyUid: account.address)
|
||||||
|
|
Loading…
Reference in New Issue