fix(@desktop/wallet): Display balance for all accounts (#12632)
This commit is contained in:
parent
a7058241aa
commit
8e0db2e666
|
@ -15,7 +15,7 @@ proc newController*(
|
|||
delegate: io_interface.AccessInterface,
|
||||
events: EventEmitter,
|
||||
tokenService: token_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
walletAccountService: wallet_account_service.Service
|
||||
): Controller =
|
||||
result = Controller()
|
||||
result.events = events
|
||||
|
@ -41,8 +41,8 @@ proc findTokenSymbolByAddress*(self: Controller, address: string): string =
|
|||
proc getHistoricalDataForToken*(self: Controller, symbol: string, currency: string, range: int) =
|
||||
self.tokenService.getHistoricalDataForToken(symbol, currency, range)
|
||||
|
||||
proc fetchHistoricalBalanceForTokenAsJson*(self: Controller, address: string, tokenSymbol: string, currencySymbol: string, timeIntervalEnum: int) =
|
||||
self.tokenService.fetchHistoricalBalanceForTokenAsJson(address, tokenSymbol, currencySymbol, BalanceHistoryTimeInterval(timeIntervalEnum))
|
||||
method fetchHistoricalBalanceForTokenAsJson*(self: Controller, addresses: seq[string], allAddresses: bool, tokenSymbol: string, currencySymbol: string, timeIntervalEnum: int) =
|
||||
self.tokenService.fetchHistoricalBalanceForTokenAsJson(addresses, allAddresses, tokenSymbol, currencySymbol, BalanceHistoryTimeInterval(timeIntervalEnum))
|
||||
|
||||
proc getSourcesOfTokensList*(self: Controller): var seq[SupportedSourcesItem] =
|
||||
return self.tokenService.getSourcesOfTokensList()
|
||||
|
|
|
@ -34,7 +34,7 @@ method getHistoricalDataForToken*(self: AccessInterface, symbol: string, currenc
|
|||
method tokenHistoricalDataResolved*(self: AccessInterface, tokenDetails: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method fetchHistoricalBalanceForTokenAsJson*(self: AccessInterface, address: string, tokenSymbol: string, currencySymbol: string, timeIntervalEnum: int) {.base.} =
|
||||
method fetchHistoricalBalanceForTokenAsJson*(self: AccessInterface, address: string, allAddresses: bool, tokenSymbol: string, currencySymbol: string, timeIntervalEnum: int) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method tokenBalanceHistoryDataResolved*(self: AccessInterface, balanceHistoryJson: string) {.base.} =
|
||||
|
@ -54,3 +54,6 @@ method getTokenBySymbolModelDataSource*(self: AccessInterface): TokenBySymbolMod
|
|||
# inheritance, which is not well supported in Nim.
|
||||
method viewDidLoad*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method filterChanged*(self: AccessInterface, addresses: seq[string]) =
|
||||
raise newException(ValueError, "No implementation available")
|
|
@ -18,6 +18,7 @@ type
|
|||
view: View
|
||||
controller: Controller
|
||||
moduleLoaded: bool
|
||||
addresses: seq[string]
|
||||
|
||||
proc newModule*(
|
||||
delegate: delegate_interface.AccessInterface,
|
||||
|
@ -31,6 +32,7 @@ proc newModule*(
|
|||
result.view = newView(result)
|
||||
result.controller = controller.newController(result, events, tokenService, walletAccountService)
|
||||
result.moduleLoaded = false
|
||||
result.addresses = @[]
|
||||
|
||||
method delete*(self: Module) =
|
||||
self.view.delete
|
||||
|
@ -68,8 +70,9 @@ method getHistoricalDataForToken*(self: Module, symbol: string, currency: string
|
|||
method tokenHistoricalDataResolved*(self: Module, tokenDetails: string) =
|
||||
self.view.setTokenHistoricalDataReady(tokenDetails)
|
||||
|
||||
method fetchHistoricalBalanceForTokenAsJson*(self: Module, address: string, tokenSymbol: string, currencySymbol: string, timeIntervalEnum: int) =
|
||||
self.controller.fetchHistoricalBalanceForTokenAsJson(address, tokenSymbol, currencySymbol,timeIntervalEnum)
|
||||
method fetchHistoricalBalanceForTokenAsJson*(self: Module, address: string, allAddresses: bool, tokenSymbol: string, currencySymbol: string, timeIntervalEnum: int) =
|
||||
let addresses = if allAddresses: self.addresses else: @[address]
|
||||
self.controller.fetchHistoricalBalanceForTokenAsJson(addresses, allAddresses, tokenSymbol, currencySymbol,timeIntervalEnum)
|
||||
|
||||
method tokenBalanceHistoryDataResolved*(self: Module, balanceHistoryJson: string) =
|
||||
self.view.setTokenBalanceHistoryDataReady(balanceHistoryJson)
|
||||
|
@ -99,3 +102,8 @@ method getTokenBySymbolModelDataSource*(self: Module): TokenBySymbolModelDataSou
|
|||
return (
|
||||
getTokenBySymbolList: proc(): var seq[TokenBySymbolItem] = self.getTokenBySymbolList()
|
||||
)
|
||||
|
||||
method filterChanged*(self: Module, addresses: seq[string]) =
|
||||
if addresses == self.addresses:
|
||||
return
|
||||
self.addresses = addresses
|
||||
|
|
|
@ -72,9 +72,9 @@ QtObject:
|
|||
self.setMarketHistoryIsLoading(false)
|
||||
self.tokenHistoricalDataReady(tokenDetails)
|
||||
|
||||
proc fetchHistoricalBalanceForTokenAsJson*(self: View, address: string, tokenSymbol: string, currencySymbol: string, timeIntervalEnum: int) {.slot.} =
|
||||
proc fetchHistoricalBalanceForTokenAsJson*(self: View, address: string, allAddresses: bool, tokenSymbol: string, currencySymbol: string, timeIntervalEnum: int) {.slot.} =
|
||||
self.setBalanceHistoryIsLoading(true)
|
||||
self.delegate.fetchHistoricalBalanceForTokenAsJson(address, tokenSymbol, currencySymbol, timeIntervalEnum)
|
||||
self.delegate.fetchHistoricalBalanceForTokenAsJson(address, allAddresses, tokenSymbol, currencySymbol, timeIntervalEnum)
|
||||
|
||||
proc tokenBalanceHistoryDataReady*(self: View, balanceHistoryJson: string) {.signal.}
|
||||
|
||||
|
|
|
@ -183,6 +183,7 @@ proc notifyFilterChanged(self: Module) =
|
|||
self.sendModule.filterChanged(self.filter.addresses, self.filter.chainIds)
|
||||
self.activityController.globalFilterChanged(self.filter.addresses, self.filter.allAddresses, self.filter.chainIds, self.filter.allChainsEnabled)
|
||||
self.collectiblesController.setFilterAddressesAndChains(self.filter.addresses, self.filter.chainIds)
|
||||
self.allTokensModule.filterChanged(self.filter.addresses)
|
||||
if self.filter.addresses.len > 0:
|
||||
self.view.filterChanged(self.filter.addresses[0], self.filter.allAddresses)
|
||||
|
||||
|
|
|
@ -85,7 +85,8 @@ type
|
|||
type
|
||||
GetTokenBalanceHistoryDataTaskArg = ref object of QObjectTaskArg
|
||||
chainIds: seq[int]
|
||||
address: string
|
||||
addresses: seq[string]
|
||||
allAddresses: bool
|
||||
tokenSymbol: string
|
||||
currencySymbol: string
|
||||
timeInterval: BalanceHistoryTimeInterval
|
||||
|
@ -95,11 +96,12 @@ const getTokenBalanceHistoryDataTask*: Task = proc(argEncoded: string) {.gcsafe,
|
|||
var response = %*{}
|
||||
try:
|
||||
# status-go time intervals are starting from 1
|
||||
response = backend.getBalanceHistory(arg.chainIds, arg.address, arg.tokenSymbol, arg.currencySymbol, int(arg.timeInterval) + 1).result
|
||||
response = backend.getBalanceHistory(arg.chainIds, arg.addresses, arg.tokenSymbol, arg.currencySymbol, int(arg.timeInterval) + 1).result
|
||||
|
||||
let output = %* {
|
||||
"chainIds": arg.chainIds,
|
||||
"address": arg.address,
|
||||
"addresses": arg.addresses,
|
||||
"allAddresses": arg.allAddresses,
|
||||
"tokenSymbol": arg.tokenSymbol,
|
||||
"currencySymbol": arg.currencySymbol,
|
||||
"timeInterval": int(arg.timeInterval),
|
||||
|
@ -111,7 +113,8 @@ const getTokenBalanceHistoryDataTask*: Task = proc(argEncoded: string) {.gcsafe,
|
|||
except Exception as e:
|
||||
let output = %* {
|
||||
"chainIds": arg.chainIds,
|
||||
"address": arg.address,
|
||||
"addresses": arg.addresses,
|
||||
"allAddresses": arg.allAddresses,
|
||||
"tokenSymbol": arg.tokenSymbol,
|
||||
"currencySymbol": arg.currencySymbol,
|
||||
"timeInterval": int(arg.timeInterval),
|
||||
|
|
|
@ -398,7 +398,7 @@ QtObject:
|
|||
result: response
|
||||
))
|
||||
|
||||
proc fetchHistoricalBalanceForTokenAsJson*(self: Service, address: string, tokenSymbol: string, currencySymbol: string, timeInterval: BalanceHistoryTimeInterval) =
|
||||
proc fetchHistoricalBalanceForTokenAsJson*(self: Service, addresses: seq[string], allAddresses: bool, tokenSymbol: string, currencySymbol: string, timeInterval: BalanceHistoryTimeInterval) =
|
||||
# create an empty list of chain ids
|
||||
var chainIds: seq[int] = @[]
|
||||
let networks = self.networkService.getNetworks()
|
||||
|
@ -422,7 +422,8 @@ QtObject:
|
|||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "tokenBalanceHistoryDataResolved",
|
||||
chainIds: chainIds,
|
||||
address: address,
|
||||
addresses: addresses,
|
||||
allAddresses: allAddresses,
|
||||
tokenSymbol: tokenSymbol,
|
||||
currencySymbol: currencySymbol,
|
||||
timeInterval: timeInterval
|
||||
|
|
|
@ -294,7 +294,7 @@ rpc(getName, "ens"):
|
|||
|
||||
rpc(getBalanceHistory, "wallet"):
|
||||
chainIds: seq[int]
|
||||
address: string
|
||||
addresses: seq[string]
|
||||
tokenSymbol: string
|
||||
currencySymbol: string
|
||||
timeInterval: int
|
||||
|
|
|
@ -23,6 +23,7 @@ Item {
|
|||
property var token: ({})
|
||||
property var networkConnectionStore
|
||||
/*required*/ property string address: ""
|
||||
property bool showAllAccounts: false
|
||||
property bool assetsLoading: true
|
||||
|
||||
QtObject {
|
||||
|
@ -265,8 +266,8 @@ Item {
|
|||
let selectedTimeRangeEnum = balanceStore.timeRangeStrToEnum(graphDetail.selectedTimeRange)
|
||||
|
||||
let currencySymbol = RootStore.currencyStore.currentCurrency
|
||||
if(!balanceStore.hasData(root.address, token.symbol, currencySymbol, selectedTimeRangeEnum)) {
|
||||
RootStore.fetchHistoricalBalanceForTokenAsJson(root.address, token.symbol, currencySymbol, selectedTimeRangeEnum)
|
||||
if(!balanceStore.hasData(root.address, root.showAllAccounts, token.symbol, currencySymbol, selectedTimeRangeEnum)) {
|
||||
RootStore.fetchHistoricalBalanceForTokenAsJson(root.address, root.showAllAccounts, token.symbol, currencySymbol, selectedTimeRangeEnum)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -171,6 +171,7 @@ Item {
|
|||
|
||||
assetsLoading: RootStore.assetsLoading
|
||||
address: RootStore.overview.mixedcaseAddress
|
||||
showAllAccounts: root.showAllAccounts
|
||||
|
||||
networkConnectionStore: root.networkConnectionStore
|
||||
|
||||
|
|
|
@ -244,9 +244,9 @@ QtObject {
|
|||
|
||||
property bool marketHistoryIsLoading: Global.appIsReady? walletSectionAllTokens.marketHistoryIsLoading : false
|
||||
|
||||
function fetchHistoricalBalanceForTokenAsJson(address, tokenSymbol, currencySymbol, timeIntervalEnum) {
|
||||
function fetchHistoricalBalanceForTokenAsJson(address, allAddresses, tokenSymbol, currencySymbol, timeIntervalEnum) {
|
||||
if (Global.appIsReady)
|
||||
walletSectionAllTokens.fetchHistoricalBalanceForTokenAsJson(address, tokenSymbol, currencySymbol, timeIntervalEnum)
|
||||
walletSectionAllTokens.fetchHistoricalBalanceForTokenAsJson(address, allAddresses, tokenSymbol, currencySymbol, timeIntervalEnum)
|
||||
}
|
||||
|
||||
property bool balanceHistoryIsLoading: Global.appIsReady? walletSectionAllTokens.balanceHistoryIsLoading : false
|
||||
|
|
|
@ -10,6 +10,7 @@ ChartStoreBase {
|
|||
readonly property alias address: d.address
|
||||
readonly property alias tokenSymbol: d.tokenSymbol
|
||||
readonly property alias currencySymbol: d.currencySymbol
|
||||
readonly property alias allAddresses: d.allAddresses
|
||||
|
||||
QtObject {
|
||||
id: d
|
||||
|
@ -17,17 +18,18 @@ ChartStoreBase {
|
|||
// Data identity received from backend
|
||||
property var chainIds: []
|
||||
property string address
|
||||
property bool allAddresses: false
|
||||
property string tokenSymbol
|
||||
property string currencySymbol
|
||||
}
|
||||
|
||||
function hasData(address, tokenSymbol, currencySymbol, timeRangeEnum) {
|
||||
return address === d.address && tokenSymbol === d.tokenSymbol && currencySymbol === d.currencySymbol
|
||||
function hasData(address, allAddresses, tokenSymbol, currencySymbol, timeRangeEnum) {
|
||||
return address === d.address && allAddresses === d.allAddresses && tokenSymbol === d.tokenSymbol && currencySymbol === d.currencySymbol
|
||||
&& root.dataRange[root.timeRangeEnumToTimeIndex(timeRangeEnum)][root.timeRangeEnumToStr(timeRangeEnum)].length > 0
|
||||
}
|
||||
|
||||
/// \arg timeRange: of type ChartStoreBase.TimeRange
|
||||
function setData(address, tokenSymbol, currencySymbol, timeRange, timeRangeData, balanceData) {
|
||||
function setData(address, allAddresses, tokenSymbol, currencySymbol, timeRange, timeRangeData, balanceData) {
|
||||
switch(timeRange) {
|
||||
case ChartStoreBase.TimeRange.Weekly:
|
||||
root.weeklyData = balanceData
|
||||
|
@ -55,15 +57,16 @@ ChartStoreBase {
|
|||
}
|
||||
|
||||
d.address = address
|
||||
d.allAddresses = allAddresses
|
||||
d.tokenSymbol = tokenSymbol
|
||||
d.currencySymbol = currencySymbol
|
||||
|
||||
root.newDataReady(address, tokenSymbol, currencySymbol, timeRange)
|
||||
}
|
||||
|
||||
function resetAllData(address, tokenSymbol, currencySymbol) {
|
||||
function resetAllData(address, allAddresses, tokenSymbol, currencySymbol) {
|
||||
for (let tR = ChartStoreBase.TimeRange.Weekly; tR <= ChartStoreBase.TimeRange.All; tR++) {
|
||||
root.setData(address, tokenSymbol, currencySymbol, tR, [], [])
|
||||
root.setData(address, allAddresses, tokenSymbol, currencySymbol, tR, [], [])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,8 +81,14 @@ ChartStoreBase {
|
|||
return
|
||||
}
|
||||
|
||||
if(d.address != response.address || d.tokenSymbol != response.tokenSymbol || d.currencySymbol != response.currencySymbol) {
|
||||
root.resetAllData(response.address, response.tokenSymbol, response.currencySymbol)
|
||||
if (!response.allAddresses && response.addresses.length > 0) {
|
||||
response.address = response.addresses[0]
|
||||
} else {
|
||||
response.address = ""
|
||||
}
|
||||
|
||||
if(d.allAddresses != response.allAddresses || d.address != response.address || d.tokenSymbol != response.tokenSymbol || d.currencySymbol != response.currencySymbol) {
|
||||
root.resetAllData(response.address, response.allAddresses, response.tokenSymbol, response.currencySymbol)
|
||||
}
|
||||
|
||||
if(typeof response.historicalData === "undefined" || response.historicalData === null || response.historicalData.length == 0) {
|
||||
|
@ -93,7 +102,7 @@ ChartStoreBase {
|
|||
tmpDataValues.push({ x: new Date(dataEntry.time * 1000), y: dataEntry.value })
|
||||
}
|
||||
|
||||
root.setData(response.address, response.tokenSymbol, response.currencySymbol, response.timeInterval, [], tmpDataValues)
|
||||
root.setData(response.address, response.allAddresses, response.tokenSymbol, response.currencySymbol, response.timeInterval, [], tmpDataValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 472e4bdb7761e9e05204dd0f74b1a5f138e8138c
|
||||
Subproject commit 078ead7876c0545a6c2ddb2ec25a30f937d160d9
|
Loading…
Reference in New Issue