feat(@desktop/tokens): Handle community ID and community token image (#12980)

This commit is contained in:
Cuteivist 2023-12-20 11:31:02 +01:00 committed by GitHub
parent 6ab6e4a26e
commit 3b162e0541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 4 deletions

View File

@ -103,6 +103,10 @@ proc walletTokenToItem*(
marketValues.change24hour, marketValues.change24hour,
currencyAmountToItem(marketValues.price, currencyFormat), currencyAmountToItem(marketValues.price, currencyFormat),
t.decimals, t.decimals,
t.image,
t.communityId,
t.communityName,
t.communityImage,
loading = false loading = false
) )

View File

@ -27,6 +27,10 @@ type
change24hour: float64 change24hour: float64
currencyPrice: CurrencyAmount currencyPrice: CurrencyAmount
decimals: int decimals: int
image: string
communityId: string
communityName: string
communityImage: string
loading: bool loading: bool
proc initItem*( proc initItem*(
@ -49,6 +53,10 @@ proc initItem*(
change24hour: float64, change24hour: float64,
currencyPrice: CurrencyAmount, currencyPrice: CurrencyAmount,
decimals: int, decimals: int,
image: string,
communityId: string,
communityName: string,
communityImage: string,
loading: bool = false loading: bool = false
): Item = ): Item =
result.name = name result.name = name
@ -73,6 +81,10 @@ proc initItem*(
result.change24hour = change24hour result.change24hour = change24hour
result.currencyPrice = currencyPrice result.currencyPrice = currencyPrice
result.decimals = decimals result.decimals = decimals
result.image = image
result.communityId = communityId
result.communityName = communityName
result.communityImage = communityImage
result.loading = loading result.loading = loading
proc `$`*(self: Item): string = proc `$`*(self: Item): string =
@ -97,6 +109,10 @@ proc `$`*(self: Item): string =
change24hour: {self.change24hour}, change24hour: {self.change24hour},
currencyPrice: {self.currencyPrice}, currencyPrice: {self.currencyPrice},
decimals: {self.decimals}, decimals: {self.decimals},
image: {self.image},
communityId: {self.communityId},
communityName: {self.communityName},
communityImage: {self.communityImage},
loading: {self.loading}, loading: {self.loading},
]""" ]"""
@ -123,6 +139,10 @@ proc initLoadingItem*(): Item =
change24hour = 0, change24hour = 0,
currencyPrice = newCurrencyAmount(), currencyPrice = newCurrencyAmount(),
decimals = 0, decimals = 0,
image = "",
communityId = "",
communityName = "",
communityImage = "",
loading = true loading = true
) )
@ -189,5 +209,17 @@ proc getCurrencyPrice*(self: Item): CurrencyAmount =
proc getDecimals*(self: Item): int = proc getDecimals*(self: Item): int =
return self.decimals return self.decimals
proc getImage*(self: Item): string =
return self.image
proc getCommunityId*(self: Item): string =
return self.communityId
proc getCommunityName*(self: Item): string =
return self.communityName
proc getCommunityImage*(self: Item): string =
return self.communityImage
proc getLoading*(self: Item): bool = proc getLoading*(self: Item): bool =
return self.loading return self.loading

View File

@ -26,6 +26,10 @@ type
Change24hour Change24hour
CurrencyPrice CurrencyPrice
Decimals Decimals
CommunityId
CommunityName
CommunityImage
ImageUrl
Loading Loading
QtObject: QtObject:
@ -83,6 +87,10 @@ QtObject:
ModelRole.Change24hour.int:"change24hour", ModelRole.Change24hour.int:"change24hour",
ModelRole.CurrencyPrice.int:"currencyPrice", ModelRole.CurrencyPrice.int:"currencyPrice",
ModelRole.Decimals.int:"decimals", ModelRole.Decimals.int:"decimals",
ModelRole.CommunityId.int:"communityId",
ModelRole.CommunityName.int:"communityName",
ModelRole.CommunityImage.int:"communityImage",
ModelRole.ImageUrl.int:"imageUrl",
ModelRole.Loading.int:"loading", ModelRole.Loading.int:"loading",
}.toTable }.toTable
@ -139,6 +147,14 @@ QtObject:
result = newQVariant(item.getCurrencyPrice()) result = newQVariant(item.getCurrencyPrice())
of ModelRole.Decimals: of ModelRole.Decimals:
result = newQVariant(item.getDecimals()) result = newQVariant(item.getDecimals())
of ModelRole.CommunityId:
result = newQVariant(item.getCommunityId())
of ModelRole.CommunityName:
result = newQVariant(item.getCommunityName())
of ModelRole.CommunityImage:
result = newQVariant(item.getCommunityImage())
of ModelRole.ImageUrl:
result = newQVariant(item.getImage())
of ModelRole.Loading: of ModelRole.Loading:
result = newQVariant(item.getLoading()) result = newQVariant(item.getLoading())
@ -167,6 +183,10 @@ QtObject:
of "change24hour": result = $item.getChange24hour() of "change24hour": result = $item.getChange24hour()
of "currencyPrice": result = $item.getCurrencyPrice() of "currencyPrice": result = $item.getCurrencyPrice()
of "decimals": result = $item.getDecimals() of "decimals": result = $item.getDecimals()
of "communityId": result = $item.getCommunityId()
of "communityName": result = $item.getCommunityName()
of "communityImage": result = $item.getCommunityImage()
of "ImageUrl": result = $item.getImage()
of "loading": result = $item.getLoading() of "loading": result = $item.getLoading()
proc setItems*(self: Model, items: seq[Item]) = proc setItems*(self: Model, items: seq[Item]) =

View File

@ -21,6 +21,7 @@ type
decimals* {.serializedFieldName("decimals").}: int decimals* {.serializedFieldName("decimals").}: int
chainID* {.serializedFieldName("chainId").}: int chainID* {.serializedFieldName("chainId").}: int
communityID* {.serializedFieldName("communityId").}: string communityID* {.serializedFieldName("communityId").}: string
image* {.serializedFieldName("image").}: string
proc `$`*(self: TokenDto): string = proc `$`*(self: TokenDto): string =
result = fmt"""TokenDto[ result = fmt"""TokenDto[
@ -29,7 +30,8 @@ proc `$`*(self: TokenDto): string =
symbol: {self.symbol}, symbol: {self.symbol},
decimals: {self.decimals}, decimals: {self.decimals},
chainID: {self.chainID}, chainID: {self.chainID},
communityID: {self.communityID} communityID: {self.communityID},
image: {self.image}
]""" ]"""
# TODO: Remove after https://github.com/status-im/status-desktop/issues/12513 # TODO: Remove after https://github.com/status-im/status-desktop/issues/12513
@ -39,7 +41,8 @@ proc newTokenDto*(
symbol: string, symbol: string,
decimals: int, decimals: int,
chainId: int, chainId: int,
communityId: string = "" communityId: string = "",
image: string = ""
): TokenDto = ): TokenDto =
return TokenDto( return TokenDto(
address: address, address: address,
@ -47,7 +50,8 @@ proc newTokenDto*(
symbol: symbol, symbol: symbol,
decimals: decimals, decimals: decimals,
chainId: chainId, chainId: chainId,
communityId: communityId communityId: communityId,
image: image
) )
type TokenSourceDto* = ref object of RootObj type TokenSourceDto* = ref object of RootObj

View File

@ -27,6 +27,10 @@ type
assetWebsiteUrl*: string assetWebsiteUrl*: string
builtOn*: string builtOn*: string
marketValuesPerCurrency*: Table[string, TokenMarketValuesDto] marketValuesPerCurrency*: Table[string, TokenMarketValuesDto]
image*: string
communityId*: string
communityName*: string
communityImage*: string
proc newTokenMarketValuesDto*( proc newTokenMarketValuesDto*(
marketCap: float64, marketCap: float64,
@ -72,6 +76,13 @@ proc toWalletTokenDto*(jsonObj: JsonNode): WalletTokenDto =
discard jsonObj.getProp("description", result.description) discard jsonObj.getProp("description", result.description)
discard jsonObj.getProp("assetWebsiteUrl", result.assetWebsiteUrl) discard jsonObj.getProp("assetWebsiteUrl", result.assetWebsiteUrl)
discard jsonObj.getProp("builtOn", result.builtOn) discard jsonObj.getProp("builtOn", result.builtOn)
discard jsonObj.getProp("image", result.image)
var communityDataObj: JsonNode
if(jsonObj.getProp("community_data", communityDataObj)):
discard communityDataObj.getProp("id", result.communityId)
discard communityDataObj.getProp("name", result.communityName)
discard communityDataObj.getProp("image", result.communityImage)
var marketValuesPerCurrencyObj: JsonNode var marketValuesPerCurrencyObj: JsonNode
if(jsonObj.getProp("marketValuesPerCurrency", marketValuesPerCurrencyObj)): if(jsonObj.getProp("marketValuesPerCurrency", marketValuesPerCurrencyObj)):
@ -105,6 +116,10 @@ proc `$`*(self: WalletTokenDto): string =
description: {self.description}, description: {self.description},
assetWebsiteUrl: {self.assetWebsiteUrl}, assetWebsiteUrl: {self.assetWebsiteUrl},
builtOn: {self.builtOn}, builtOn: {self.builtOn},
image: {self.image},
communityId: {self.communityId},
communityName: {self.communityName},
communityImage: {self.communityImage},
balancesPerChain: balancesPerChain:
""" """
for chain, balance in self.balancesPerChain: for chain, balance in self.balancesPerChain:
@ -131,6 +146,10 @@ proc copyToken*(self: WalletTokenDto): WalletTokenDto =
result.description = self.description result.description = self.description
result.assetWebsiteUrl = self.assetWebsiteUrl result.assetWebsiteUrl = self.assetWebsiteUrl
result.builtOn = self.builtOn result.builtOn = self.builtOn
result.image = self.image
result.communityId = self.communityId
result.communityName = self.communityName
result.communityImage = self.communityImage
result.balancesPerChain = initTable[int, BalanceDto]() result.balancesPerChain = initTable[int, BalanceDto]()
for chainId, balanceDto in self.balancesPerChain: for chainId, balanceDto in self.balancesPerChain:

View File

@ -37,7 +37,15 @@ StatusListItem {
property string errorTooltipText_2 property string errorTooltipText_2
readonly property bool isCommunityToken: !!modelData && !!modelData.communityId readonly property bool isCommunityToken: !!modelData && !!modelData.communityId
readonly property string symbolUrl: !!modelData && modelData.symbol ? Constants.tokenIcon(modelData.symbol, false) : "" readonly property string symbolUrl: {
if (!modelData)
return ""
if (modelData.imageUrl)
return modelData.imageUrl
if (modelData.symbol)
return Constants.tokenIcon(modelData.symbol, false)
return ""
}
readonly property string upDownTriangle: { readonly property string upDownTriangle: {
if (!modelData) if (!modelData)
return "" return ""