feat: limit number of collectibles to 200 to avoid explosions

This commit is contained in:
Jonathan Rainville 2020-09-25 12:52:06 -04:00 committed by Iuri Matias
parent 51e1ba6f38
commit 42102bdae4
3 changed files with 20 additions and 2 deletions

View File

@ -14,6 +14,8 @@ const STICKER* = "stickers"
const COLLECTIBLE_TYPES* = [CRYPTOKITTY, KUDO, ETHERMON, STICKER]
const MAX_TOKENS = 200
proc getTokenUri(contract: Contract, tokenId: Stuint[256]): string =
try:
let
@ -54,7 +56,7 @@ proc tokensOfOwnerByIndex(contract: Contract, address: Address): seq[int] =
result = @[]
while (true):
token = tokenOfOwnerByIndex(contract, address, index.u256)
if (token == -1 or token == 0):
if (token == -1 or token == 0 or result.len > MAX_TOKENS):
return result
result.add(token)
index = index + 1
@ -91,7 +93,8 @@ proc getCryptoKittiesBatch*(address: Address, offset: int = 0): seq[Collectible]
let limit = responseBody["limit"].getInt
let total = responseBody["total"].getInt
if (limit * (offset + 1) < total):
let currentCount = limit * (offset + 1)
if (currentCount < total and currentCount < MAX_TOKENS):
# Call the API again with oofset + 1
let nextBatch = getCryptoKittiesBatch(address, offset + 1)
return concat(cryptokitties, nextBatch)

View File

@ -29,10 +29,23 @@ Rectangle {
}
StyledText {
id: collectibleName
text: collectibleHeader.collectibleName
anchors.left: collectibleIconImage.right
anchors.leftMargin: Style.current.padding
anchors.verticalCenter: parent.verticalCenter
font.pixelSize: 17
}
StyledText {
visible: collectiblesQty >= Constants.maxTokens
text: qsTr("Maximum number of collectibles to display reached")
font.pixelSize: 17
color: Style.current.secondaryText
anchors.left: collectibleName.right
anchors.leftMargin: Style.current.padding
anchors.verticalCenter: parent.verticalCenter
}
Loader {

View File

@ -36,6 +36,8 @@ QtObject {
readonly property int pending: 6
readonly property int confirmed: 7
readonly property int maxTokens: 200
readonly property string zeroAddress: "0x0000000000000000000000000000000000000000"
readonly property var accountColors: [