feat(wallet): implement reloadWalltet feature

implemented new reloadWalltet button and call reloadAccountTokens onClicked

resolves: #13652
This commit is contained in:
belalshehab 2024-06-28 20:18:11 +03:00
parent 3e04967309
commit c501319bd0
7 changed files with 126 additions and 3 deletions

View File

@ -119,4 +119,7 @@ method resetRpcStats*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method canProfileProveOwnershipOfProvidedAddresses*(self: AccessInterface, addresses: string): bool {.base.} =
raise newException(ValueError, "No implementation available")
raise newException(ValueError, "No implementation available")
method reloadWallet*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -283,8 +283,10 @@ method load*(self: Module) =
self.setTotalCurrencyBalance()
self.notifyFilterChanged()
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args):
let args = TokensPerAccountArgs(e)
self.setTotalCurrencyBalance()
self.notifyModulesBalanceIsLoaded()
self.view.emitTokensReloaded(args.timestamp)
self.events.on(SIGNAL_TOKENS_PRICES_UPDATED) do(e:Args):
self.setTotalCurrencyBalance()
self.notifyFilterChanged()
@ -522,3 +524,6 @@ method canProfileProveOwnershipOfProvidedAddresses*(self: Module, addresses: str
if keypair.migratedToKeycard():
return false
return true
method reloadWallet*(self: Module) =
self.walletAccountService.reloadAccountTokens()

View File

@ -1,4 +1,5 @@
import NimQml, json
import times
import ./activity/controller as activityc
import ./activity/details_controller as activity_detailsc
@ -29,6 +30,7 @@ QtObject:
walletReady: bool
addressFilters: string
currentCurrency: string
lastReloadTimestamp: string
proc setup(self: View) =
self.QObject.setup
@ -266,4 +268,36 @@ QtObject:
self.delegate.resetRpcStats()
proc canProfileProveOwnershipOfProvidedAddresses*(self: View, addresses: string): bool {.slot.} =
return self.delegate.canProfileProveOwnershipOfProvidedAddresses(addresses)
return self.delegate.canProfileProveOwnershipOfProvidedAddresses(addresses)
proc reloadWallet*(self: View) {.slot.} =
self.delegate.reloadWallet()
proc formatTime(timestamp: DateTime): string =
let now = now()
let diff = now - timestamp
# Calculate daysDiff directly within the if statement
if int(diff.inDays) == 0:
return timestamp.format("hh:mm tt") & " today"
elif int(diff.inDays) == 1:
return timestamp.format("hh:mm tt") & " yesterday"
else:
return timestamp.format("MMM d hh:mm tt")
proc lastReloadTimestampChanged*(self: View) {.signal.}
proc setLastReloadTimestamp*(self: View, lastReloadTimestamp: string) =
self.lastReloadTimestamp = lastReloadTimestamp
self.lastReloadTimestampChanged()
proc getLastReloadTimestamp(self: View): string {.slot.} =
return self.lastReloadTimestamp
QtProperty[string] lastReloadTimestamp:
read = getLastReloadTimestamp
notify = lastReloadTimestampChanged
proc tokensReloaded*(self: View) {.signal.}
proc emitTokensReloaded*(self: View, timestamp: DateTime) =
self.setLastReloadTimestamp(formatTime(timestamp))
self.tokensReloaded()

View File

@ -1,8 +1,12 @@
import times
# This method will group the account assets by symbol (in case of communiy, the token address)
proc onAllTokensBuilt*(self: Service, response: string) {.slot.} =
var accountAddresses: seq[string] = @[]
var accountTokens: seq[GroupedTokenItem] = @[]
defer: self.events.emit(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT, TokensPerAccountArgs(accountAddresses:accountAddresses, accountTokens: accountTokens))
defer:
let timestamp = now()
self.events.emit(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT, TokensPerAccountArgs(accountAddresses:accountAddresses, accountTokens: accountTokens, timestamp: timestamp))
try:
let responseObj = response.parseJson
var storeResult: bool

View File

@ -72,6 +72,7 @@ type DerivedAddressesArgs* = ref object of Args
type TokensPerAccountArgs* = ref object of Args
accountAddresses*: seq[string]
accountTokens*: seq[GroupedTokenItem]
timestamp*: DateTime
type KeycardActivityArgs* = ref object of Args
success*: bool

View File

@ -14,6 +14,7 @@ import SortFilterProxyModel 0.2
import utils 1.0
import "../controls"
import "../stores"
Item {
id: root
@ -25,6 +26,7 @@ Item {
property alias headerButton: headerButton
property alias networkFilter: networkFilter
property alias reloadButton: reloadButton
signal buttonClicked()
@ -38,6 +40,8 @@ Item {
// account + balance
RowLayout {
spacing: Style.current.halfPadding
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
StatusBaseText {
objectName: "walletHeaderTitle"
Layout.alignment: Qt.AlignVCenter
@ -73,6 +77,74 @@ Item {
spacing: 16
Layout.alignment: Qt.AlignTrailing
Layout.topMargin: 5
Component.onCompleted: console.info("bTest RowLayout width, height", width, height)
Row {
// Layout.fillWidth: true
Layout.alignment: Qt.AlignRight | Qt.AlignTop
Layout.preferredHeight: 38
spacing: 8
Component.onCompleted: console.info("bTest Row width, height", width, height)
// StatusButton {
// id: visiblityButton
// // spacing: 8
// size: StatusBaseButton.Size.Small
// borderColor: Theme.palette.directColor7
// borderWidth: 1
// normalColor: Theme.palette.transparent
// hoverColor: Theme.palette.baseColor2
// icon.name: "refresh"
// icon.height: 16
// icon.width: 16
// icon.color: hovered ? Theme.palette.directColor1 : Theme.palette.baseColor1
// }
StatusButton {
id: reloadButton
size: StatusBaseButton.Size.Small
height: parent.height
width: height
borderColor: Theme.palette.directColor7
borderWidth: 1
normalColor: Theme.palette.transparent
hoverColor: Theme.palette.baseColor2
icon.name: "refresh"
icon.height: 16
icon.width: 16
icon.color: hovered ? Theme.palette.directColor1 : Theme.palette.baseColor1
tooltip.text: "Last refreshed " + RootStore.walletSectionInst.lastReloadTimestamp
Connections {
target: RootStore.walletSectionInst
function onTokensReloaded() {
console.info("btest onTokensReloaded")
reloadButton.loading = false
}
}
onClicked: {
loading = true
RootStore.reloadWallet()
}
}
// StatusButton {
// id: thirdButton
// // spacing: 8
// size: StatusBaseButton.Size.Small
// borderColor: Theme.palette.directColor7
// borderWidth: 1
// normalColor: Theme.palette.transparent
// hoverColor: Theme.palette.baseColor2
// icon.name: "refresh"
// icon.height: 16
// icon.width: 16
// icon.color: hovered ? Theme.palette.directColor1 : Theme.palette.baseColor1
// }
}
DAppsWorkflow {
Layout.alignment: Qt.AlignTop

View File

@ -558,4 +558,8 @@ QtObject {
const prefix = Constants.socialLinkPrefixesByType[Constants.socialLinkType.twitter]
return prefix + twitterHandle
}
function reloadWallet() {
walletSectionInst.reloadWallet()
}
}