feat(@wallet): token list global updated at

fixes #13269
This commit is contained in:
Anthony Laibe 2024-02-01 13:01:07 +01:00 committed by Anthony Laibe
parent fa75cf7b9b
commit 1634109971
13 changed files with 39 additions and 21 deletions

View File

@ -63,6 +63,9 @@ proc getTokenBySymbolList*(self: Controller): var seq[TokenBySymbolItem] =
proc getTokenDetails*(self: Controller, symbol: string): TokenDetailsItem =
return self.tokenService.getTokenDetails(symbol)
proc getTokenListUpdatedAt*(self: Controller): int64 =
return self.tokenService.getTokenListUpdatedAt()
proc getMarketValuesBySymbol*(self: Controller, symbol: string): TokenMarketValuesItem =
return self.tokenService.getMarketValuesBySymbol(symbol)

View File

@ -53,6 +53,7 @@ method load*(self: Module) =
self.view.modelsAboutToUpdate()
self.events.on(SIGNAL_TOKENS_LIST_UPDATED) do(e: Args):
self.view.modelsUpdated()
self.view.setTokenListUpdatedAt(self.controller.getTokenListUpdatedAt())
self.events.on(SIGNAL_TOKENS_DETAILS_ABOUT_TO_BE_UPDATED) do(e: Args):
self.view.tokensDetailsAboutToUpdate()
self.events.on(SIGNAL_TOKENS_DETAILS_UPDATED) do(e: Args):

View File

@ -8,6 +8,8 @@ QtObject:
delegate: io_interface.AccessInterface
marketHistoryIsLoading: bool
balanceHistoryIsLoading: bool
tokenListUpdatedAt: int64
# This contains the different sources for the tokens list
# ex. uniswap list, status tokens list
sourcesOfTokensModel: SourcesOfTokensModel
@ -51,6 +53,16 @@ QtObject:
read = getMarketHistoryIsLoading
notify = marketHistoryIsLoadingChanged
proc tokenListUpdatedAtChanged*(self: View) {.signal.}
proc getTokenListUpdatedAt(self: View): QVariant {.slot.} =
return newQVariant(self.tokenListUpdatedAt)
proc setTokenListUpdatedAt*(self: View, updatedAt: int64) =
self.tokenListUpdatedAt = updatedAt
self.tokenListUpdatedAtChanged()
QtProperty[QVariant] tokenListUpdatedAt:
read = getTokenListUpdatedAt
notify = tokenListUpdatedAtChanged
proc balanceHistoryIsLoadingChanged*(self: View) {.signal.}
proc getBalanceHistoryIsLoading(self: View): QVariant {.slot.} =
return newQVariant(self.balanceHistoryIsLoading)

View File

@ -70,15 +70,17 @@ proc newTokenDto*(
type TokenSourceDto* = ref object of RootObj
name* {.serializedFieldName("name").}: string
tokens* {.serializedFieldName("tokens").}: seq[TokenDto]
updatedAt* {.serializedFieldName("updatedAt").}: int64
source* {.serializedFieldName("source").}: string
version* {.serializedFieldName("version").}: string
type TokenListDto* = ref object of RootObj
updatedAt* {.serializedFieldName("updatedAt").}: int64
data* {.serializedFieldName("data").}: seq[TokenSourceDto]
proc `$`*(self: TokenSourceDto): string =
result = fmt"""TokenSourceDto[
name: {self.name},
tokens: {self.tokens},
updatedAt: {self.updatedAt},
source: {self.source},
version: {self.version}
]"""

View File

@ -84,6 +84,7 @@ QtObject:
tokensMarketDetailsLoading: bool
hasMarketDetailsCache: bool
hasPriceValuesCache: bool
tokenListUpdatedAt: int64
proc getCurrency*(self: Service): string
proc updateCachedTokenPrice(self: Service, crypto: string, fiat: string, price: float64)
@ -202,6 +203,9 @@ QtObject:
let errDesription = e.msg
error "error: ", errDesription
proc getTokenListUpdatedAt*(self: Service): int64 =
return self.tokenListUpdatedAt
proc fetchTokensPrices(self: Service, symbols: seq[string]) =
self.tokensPricesLoading = true
defer: self.events.emit(SIGNAL_TOKENS_PRICES_ABOUT_TO_BE_UPDATED, Args())
@ -254,16 +258,21 @@ QtObject:
if not errorString.isEmptyOrWhitespace:
raise newException(Exception, "Error getting supported tokens list: " & errorString)
let sourcesList = if tokensResult.isNil or tokensResult.kind == JNull: @[]
else: Json.decode($tokensResult, seq[TokenSourceDto], allowUnknownFields = true)
if tokensResult.isNil or tokensResult.kind == JNull:
raise newException(Exception, "Error in response of getting supported tokens list")
let tokenList = Json.decode($tokensResult, TokenListDto, allowUnknownFields = true)
self.tokenListUpdatedAt = tokenList.updatedAt
let supportedNetworkChains = self.networkService.getAllNetworkChainIds()
var flatTokensList: Table[string, TokenItem] = initTable[string, TokenItem]()
var tokenBySymbolList: Table[string, TokenBySymbolItem] = initTable[string, TokenBySymbolItem]()
var tokenSymbols: seq[string] = @[]
for s in sourcesList:
let newSource = SupportedSourcesItem(name: s.name, updatedAt: s.updatedAt, source: s.source, version: s.version, tokensCount: s.tokens.len)
for s in tokenList.data:
let newSource = SupportedSourcesItem(name: s.name, source: s.source, version: s.version, tokensCount: s.tokens.len)
self.sourcesOfTokensList.add(newSource)
for token in s.tokens:

View File

@ -63,7 +63,6 @@ SplitView {
required property string name
required property string image
required property string source
required property int updatedAt
required property string version
required property int tokensCount
@ -77,7 +76,6 @@ SplitView {
sourceName: delegate.name
sourceImage: delegate.image
sourceUrl: delegate.source
sourceUpdatedAt: delegate.updatedAt
sourceVersion: delegate.version
tokensCount: delegate.tokensCount

View File

@ -13,7 +13,6 @@ ListModel {
{
key: root.uniswap,
name: "Uniswap Labs Default",
updatedAt: 1695720962,
source: "https://gateway.ipfs.io/ipns/tokens.uniswap.org",
version: "11.6.0",
tokensCount: 731,
@ -22,7 +21,6 @@ ListModel {
{
key: root.status,
name: "Status Token List",
updatedAt: 1661506562,
source: "https://status.im/",
version: "11.6.0",
tokensCount: 250,

View File

@ -90,7 +90,6 @@ StatusListView {
sourceName: delegate.name
sourceImage: delegate.image
sourceUrl: delegate.source
sourceUpdatedAt: delegate.updatedAt
sourceVersion: delegate.version
tokensCount: delegate.tokensCount

View File

@ -19,7 +19,6 @@ StatusDialog {
required property string sourceName
required property string sourceImage
required property string sourceUrl
required property int sourceUpdatedAt
required property string sourceVersion
required property int tokensCount
required property var tokensListModel // Expected roles: name, symbol, image, chainName, explorerUrl, isTest
@ -147,13 +146,6 @@ StatusDialog {
title: qsTr("Version")
text: root.sourceVersion
}
CustomTextBlock {
title: qsTr("Automatically updates")
text: qsTr("Last updated %n day(s) ago",
"",
LocaleUtils.daysBetween(root.sourceUpdatedAt * 1000, Date.now()))
}
}
component CustomHeaderDelegate: RowLayout {

View File

@ -309,6 +309,7 @@ SettingsContentBase {
implicitHeight: root.availableHeight
Layout.fillWidth: true
tokenListUpdatedAt: tokensStore.tokenListUpdatedAt
sourcesOfTokensModel: tokensStore.sourcesOfTokensModel
tokensListModel: tokensStore.extendedFlatTokensModel
baseWalletAssetsModel: RootStore.walletAssetsStore.groupedAccountAssetsModel

View File

@ -20,6 +20,7 @@ import AppLayouts.Wallet.panels 1.0
Item {
id: root
required property double tokenListUpdatedAt
required property var sourcesOfTokensModel // Expected roles: key, name, updatedAt, source, version, tokensCount, image
required property var tokensListModel // Expected roles: name, symbol, image, chainName, explorerUrl
@ -267,7 +268,7 @@ Item {
}
StatusBaseText {
Layout.alignment: Qt.AlignRight
text: qsTr("Last updated %1 @%2").arg(LocaleUtils.formatDate(root.sourcesOfTokensModel.get(0).updatedAt * 1000)).arg(LocaleUtils.formatTime(root.sourcesOfTokensModel.get(0).updatedAt, Locale.ShortFormat))
text: qsTr("Last updated %1 @%2").arg(LocaleUtils.formatDate(root.tokenListUpdatedAt * 1000)).arg(LocaleUtils.formatTime(root.tokenListUpdatedAt, Locale.ShortFormat))
color: Style.current.darkGrey
}
}

View File

@ -12,6 +12,8 @@ QtObject {
readonly property var _allTokensModule: !!walletSectionAllTokens ? walletSectionAllTokens : null
readonly property var _networksModule: !!networksModule ? networksModule : null
readonly property double tokenListUpdatedAt: root._allTokensModule.tokenListUpdatedAt
/* This contains the different sources for the tokens list
ex. uniswap list, status tokens list */
readonly property var sourcesOfTokensModel: SortFilterProxyModel {

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 812910f087e0451cc702d2590cec3953bb8c3d14
Subproject commit 9c131edfaa47ab38fe25048a7116dc4c54336336