feat(@desktop/settings): Integrate token advanced settings with backend (#13487)

This commit is contained in:
Cuteivist 2024-02-19 13:09:07 +01:00 committed by GitHub
parent 01095e0208
commit 2e6af7aa51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 128 additions and 34 deletions

View File

@ -16,6 +16,7 @@ type
tokenService: token_service.Service
walletAccountService: wallet_account_service.Service
settingsService: settings_service.Service
displayAssetsBelowBalanceThreshold: CurrencyAmount
proc newController*(
delegate: io_interface.AccessInterface,
@ -113,7 +114,8 @@ proc toggleDisplayAssetsBelowBalance*(self: Controller): bool =
proc getDisplayAssetsBelowBalanceThreshold*(self: Controller): CurrencyAmount =
let amount = float64(self.settingsService.displayAssetsBelowBalanceThreshold())
return newCurrencyAmount(amount, self.tokenService.getCurrency(), 9, true)
self.displayAssetsBelowBalanceThreshold = newCurrencyAmount(amount, self.tokenService.getCurrency(), 9, true)
return self.displayAssetsBelowBalanceThreshold
proc setDisplayAssetsBelowBalanceThreshold*(self: Controller, threshold: int64): bool =
return self.settingsService.setDisplayAssetsBelowBalanceThreshold(threshold)

View File

@ -203,8 +203,8 @@ QtObject:
proc getDisplayAssetsBelowBalanceThreshold(self: View): QVariant {.slot.} =
return newQVariant(self.delegate.getDisplayAssetsBelowBalanceThreshold())
proc setDisplayAssetsBelowBalanceThreshold(self: View, threshold: QVariant) {.slot.} =
if not self.delegate.setDisplayAssetsBelowBalanceThreshold(threshold.int64Val()):
proc setDisplayAssetsBelowBalanceThreshold(self: View, threshold: int) {.slot.} =
if not self.delegate.setDisplayAssetsBelowBalanceThreshold(int64(threshold)):
error "Failed to set displayAssetsBelowBalanceThreshold"
return
self.displayAssetsBelowBalanceThresholdChanged()

View File

@ -58,19 +58,24 @@ SettingsContentBase {
}
dirty: manageTokensView.dirty
ignoreDirty: stackContainer.currentIndex === manageTokensViewIndex
ignoreDirty: stackContainer.currentIndex === manageTokensViewIndex && !manageTokensView.advancedTabVisible
saveChangesButtonEnabled: dirty
toast.type: SettingsDirtyToastMessage.Type.Info
toast.cancelButtonVisible: false
toast.saveForLaterButtonVisible: dirty
toast.saveChangesText: qsTr("Apply to my Wallet")
toast.changesDetectedText: qsTr("New custom sort order created")
toast.cancelButtonVisible: manageTokensView.advancedTabVisible
toast.saveForLaterButtonVisible: !manageTokensView.advancedTabVisible
toast.saveChangesText: manageTokensView.advancedTabVisible ? toast.defaultSaveChangesText : qsTr("Apply to my Wallet")
toast.changesDetectedText: manageTokensView.advancedTabVisible ? toast.defaultChangesDetectedText : qsTr("New custom sort order created")
onSaveForLaterClicked: {
manageTokensView.saveChanges()
}
onSaveChangesClicked: {
if (manageTokensView.advancedTabVisible) {
// Save changes only when tab is active
manageTokensView.saveChanges()
return
}
let sectionLink = "%1/%2/".arg(Constants.appSection.wallet).arg(WalletLayout.LeftPanelSelection.AllAddresses)
@ -313,6 +318,7 @@ SettingsContentBase {
implicitHeight: root.availableHeight
Layout.fillWidth: true
tokensStore: root.tokensStore
tokenListUpdatedAt: tokensStore.tokenListUpdatedAt
assetsController: root.assetsStore.assetsController
collectiblesController: root.collectiblesStore.collectiblesController

View File

@ -16,10 +16,14 @@ import utils 1.0
import AppLayouts.Profile.panels 1.0
import AppLayouts.Wallet.panels 1.0
import AppLayouts.Wallet.stores 1.0
Item {
id: root
required property TokensStore tokensStore
required property double tokenListUpdatedAt
required property var assetsController
required property var collectiblesController
@ -35,22 +39,17 @@ Item {
property alias currentIndex: tabBar.currentIndex
readonly property bool dirty: {
if (!loader.item)
return false
if (tabBar.currentIndex > d.hiddenTabIndex)
return false
// FIXME take advanced settings into account here too (#13178)
return loader.item && loader.item.dirty
}
readonly property bool dirty: !!loader.item && loader.item.dirty
readonly property bool advancedTabVisible: tabBar.currentIndex === d.advancedTabIndex
function saveChanges() {
if (tabBar.currentIndex > d.hiddenTabIndex)
return
// FIXME save advanced settings (#13178)
loader.item.saveSettings()
}
function resetChanges() {
loader.item.resetChanges()
}
QtObject {
id: d
@ -147,7 +146,34 @@ Item {
Component {
id: advancedTab
ColumnLayout {
id: advancedTabColumn
id: advancedSettings
function saveSettings() {
if (showCommunityAssetsSwitch.checked !== root.tokensStore.showCommunityAssetsInSend)
root.tokensStore.toggleShowCommunityAssetsInSend()
if (displayThresholdSwitch.checked !== root.tokensStore.displayAssetsBelowBalance)
root.tokensStore.toggleDisplayAssetsBelowBalance()
const rawAmount = currencyAmount.value * Math.pow(10, thresholdCurrency.displayDecimals)
if (rawAmount !== thresholdCurrency.amount) {
root.tokensStore.setDisplayAssetsBelowBalanceThreshold(rawAmount)
}
dirty = false
}
function resetChanges() {
showCommunityAssetsSwitch.checked = root.tokensStore.showCommunityAssetsInSend
displayThresholdSwitch.checked = root.tokensStore.displayAssetsBelowBalance
currencyAmount.value = getDisplayThresholdAmount()
dirty = false
}
function getDisplayThresholdAmount() {
return thresholdCurrency.amount / Math.pow(10, thresholdCurrency.displayDecimals)
}
property bool dirty: false
property var thresholdCurrency: root.tokensStore.getDisplayAssetsBelowBalanceThresholdCurrency()
spacing: 8
StatusListItem {
@ -157,9 +183,13 @@ Item {
components: [
StatusSwitch {
id: showCommunityAssetsSwitch
checked: true // FIXME integrate with backend (#13178)
checked: root.tokensStore.showCommunityAssetsInSend
onCheckedChanged: {
// FIXME integrate with backend (#13178)
if (!advancedSettings.dirty && checked === root.tokensStore.showCommunityAssetsInSend) {
// Skipping initial value
return
}
advancedSettings.dirty = true
}
}
]
@ -176,15 +206,27 @@ Item {
components: [
CurrencyAmountInput {
id: currencyAmount
enabled: displayThresholdSwitch.checked
currencySymbol: SharedStores.RootStore.currencyStore.currentCurrency
value: 0.10 // FIXME integrate with backend (#13178)
value: advancedSettings.getDisplayThresholdAmount()
onValueChanged: {
if (!advancedSettings.dirty && advancedSettings.getDisplayThresholdAmount() === value) {
// Skipping initial value
return
}
advancedSettings.dirty = true
}
},
StatusSwitch {
id: displayThresholdSwitch
checked: false // FIXME integrate with backend (#13178)
checked: root.tokensStore.displayAssetsBelowBalance
onCheckedChanged: {
// FIXME integrate with backend (#13178)
if (!advancedSettings.dirty && checked === root.tokensStore.displayAssetsBelowBalance) {
// Skipping initial value
return
}
advancedSettings.dirty = true
}
}
]

View File

@ -103,6 +103,37 @@ QtObject {
// Property and methods below are used to apply advanced token management settings to the SendModal
readonly property bool showCommunityAssetsInSend: root._allTokensModule.showCommunityAssetWhenSendingTokens
readonly property bool balanceThresholdEnabled: root._allTokensModule.displayAssetsBelowBalance
readonly property real balanceThresholdAmount: root._allTokensModule.displayAssetsBelowBalanceThreshold
readonly property bool displayAssetsBelowBalance: root._allTokensModule.displayAssetsBelowBalance
signal displayAssetsBelowBalanceThresholdChanged()
function getDisplayAssetsBelowBalanceThresholdCurrency() {
return root._allTokensModule.displayAssetsBelowBalanceThreshold
}
function getDisplayAssetsBelowBalanceThresholdDisplayAmount() {
const thresholdCurrency = getDisplayAssetsBelowBalanceThresholdCurrency()
return thresholdCurrency.amount / Math.pow(10, thresholdCurrency.displayDecimals)
}
function setDisplayAssetsBelowBalanceThreshold(rawValue) {
// rawValue - raw amount (multiplied by displayDecimals)`
root._allTokensModule.setDisplayAssetsBelowBalanceThreshold(rawValue)
}
function toggleShowCommunityAssetsInSend() {
root._allTokensModule.toggleShowCommunityAssetWhenSendingTokens()
}
function toggleDisplayAssetsBelowBalance() {
root._allTokensModule.toggleDisplayAssetsBelowBalance()
}
readonly property Connections allTokensConnections: Connections {
target: root._allTokensModule
function onDisplayAssetsBelowBalanceThresholdChanged() {
root.displayAssetsBelowBalanceThresholdChanged()
}
}
}

View File

@ -24,6 +24,11 @@ Rectangle {
property alias cancelChangesText: cancelChangesButton.text
property alias changesDetectedText: changesDetectedTextItem.text
readonly property string defaultChangesDetectedText: qsTr("Changes detected")
readonly property string defaultSaveChangesText: qsTr("Save changes")
readonly property string defaultSaveForLaterText: qsTr("Save for later")
readonly property string defaultCancelChangesText: qsTr("Cancel")
property Flickable flickable: null
enum Type {
@ -123,12 +128,12 @@ Rectangle {
padding: 8
horizontalAlignment: Text.AlignHCenter
color: Theme.palette.directColor1
text: qsTr("Changes detected")
text: root.defaultChangesDetectedText
}
StatusButton {
id: cancelChangesButton
text: qsTr("Cancel")
text: root.defaultCancelChangesText
enabled: root.active
visible: root.cancelButtonVisible
type: StatusBaseButton.Type.Danger
@ -137,7 +142,7 @@ Rectangle {
StatusFlatButton {
id: saveForLaterButton
text: qsTr("Save for later")
text: root.defaultSaveForLaterText
enabled: root.active && root.saveChangesButtonEnabled
visible: root.saveForLaterButtonVisible
onClicked: root.saveForLaterClicked()
@ -147,7 +152,7 @@ Rectangle {
id: saveChangesButton
objectName: "settingsDirtyToastMessageSaveButton"
buttonType: DisabledTooltipButton.Normal
text: qsTr("Save changes")
text: root.defaultSaveChangesText
enabled: root.active && root.saveChangesButtonEnabled
interactive: root.active && root.saveChangesButtonEnabled
onClicked: root.saveChangesClicked()

View File

@ -272,8 +272,16 @@ QtObject {
}
}
readonly property Connections tokensStoreConnections: Connections {
target: tokensStore
function onDisplayAssetsBelowBalanceThresholdChanged() {
processedAssetsModel.displayAssetsBelowBalanceThresholdAmount = tokensStore.getDisplayAssetsBelowBalanceThresholdDisplayAmount()
}
}
// Model prepared to provide filtered and sorted assets as per the advanced Settings in token management
property var processedAssetsModel: SortFilterProxyModel {
property real displayAssetsBelowBalanceThresholdAmount: tokensStore.getDisplayAssetsBelowBalanceThresholdDisplayAmount()
sourceModel: __assetsWithFilteredBalances
proxyRoles: [
FastExpressionRole {
@ -317,10 +325,10 @@ QtObject {
expression: {
if (model.isCommunityAsset)
return true
return model.currentCurrencyBalance > tokensStore.balanceThresholdAmount
return model.currentCurrencyBalance > processedAssetsModel.displayAssetsBelowBalanceThresholdAmount
}
expectedRoles: ["isCommunityAsset", "currentCurrencyBalance"]
enabled: tokensStore.balanceThresholdEnabled
enabled: tokensStore.displayAssetsBelowBalance
}
]
sorters: RoleSorter {