feat(@desktop/settings): Added advanced token settings (#13128)
This commit is contained in:
parent
9da47c5294
commit
a975e55271
|
@ -5,6 +5,7 @@ import ./io_interface
|
|||
import app/core/eventemitter
|
||||
import app_service/service/token/service as token_service
|
||||
import app_service/service/wallet_account/service as wallet_account_service
|
||||
import app/modules/shared_models/currency_amount
|
||||
import app_service/service/currency/dto
|
||||
import app_service/service/settings/service as settings_service
|
||||
|
||||
|
@ -95,5 +96,24 @@ proc getTokenPreferencesJson*(self: Controller): string =
|
|||
proc getTokenGroupByCommunity*(self: Controller): bool =
|
||||
return self.settingsService.tokenGroupByCommunity()
|
||||
|
||||
proc toggleTokenGroupByCommunity*(self: Controller) =
|
||||
discard self.settingsService.toggleTokenGroupByCommunity()
|
||||
proc toggleTokenGroupByCommunity*(self: Controller): bool =
|
||||
return self.settingsService.toggleTokenGroupByCommunity()
|
||||
|
||||
proc getShowCommunityAssetWhenSendingTokens*(self: Controller): bool =
|
||||
return self.settingsService.showCommunityAssetWhenSendingTokens()
|
||||
|
||||
proc toggleShowCommunityAssetWhenSendingTokens*(self: Controller): bool =
|
||||
return self.settingsService.toggleShowCommunityAssetWhenSendingTokens()
|
||||
|
||||
proc getDisplayAssetsBelowBalance*(self: Controller): bool =
|
||||
return self.settingsService.displayAssetsBelowBalance()
|
||||
|
||||
proc toggleDisplayAssetsBelowBalance*(self: Controller): bool =
|
||||
return self.settingsService.toggleDisplayAssetsBelowBalance()
|
||||
|
||||
proc getDisplayAssetsBelowBalanceThreshold*(self: Controller): CurrencyAmount =
|
||||
let amount = float64(self.settingsService.displayAssetsBelowBalanceThreshold())
|
||||
return newCurrencyAmount(amount, self.tokenService.getCurrency(), 9, true)
|
||||
|
||||
proc setDisplayAssetsBelowBalanceThreshold*(self: Controller, threshold: int64): bool =
|
||||
return self.settingsService.setDisplayAssetsBelowBalanceThreshold(threshold)
|
|
@ -1,5 +1,6 @@
|
|||
import app_service/service/token/service_items
|
||||
import app_service/service/currency/dto
|
||||
import app/modules/shared_models/currency_amount
|
||||
|
||||
type
|
||||
SourcesOfTokensModelDataSource* = tuple[
|
||||
|
@ -84,5 +85,23 @@ method filterChanged*(self: AccessInterface, addresses: seq[string]) =
|
|||
method getTokenGroupByCommunity*(self: AccessInterface): bool =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method toggleTokenGroupByCommunity*(self: AccessInterface) =
|
||||
method toggleTokenGroupByCommunity*(self: AccessInterface): bool =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getShowCommunityAssetWhenSendingTokens*(self: AccessInterface): bool =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method toggleShowCommunityAssetWhenSendingTokens*(self: AccessInterface): bool =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getDisplayAssetsBelowBalance*(self: AccessInterface): bool =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method toggleDisplayAssetsBelowBalance*(self: AccessInterface): bool =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getDisplayAssetsBelowBalanceThreshold*(self: AccessInterface): CurrencyAmount =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method setDisplayAssetsBelowBalanceThreshold*(self: AccessInterface, threshold: int64): bool =
|
||||
raise newException(ValueError, "No implementation available")
|
|
@ -5,6 +5,7 @@ import ../io_interface as delegate_interface
|
|||
|
||||
import app/global/global_singleton
|
||||
import app/core/eventemitter
|
||||
import app/modules/shared_models/currency_amount
|
||||
import app_service/service/token/service as token_service
|
||||
import app_service/service/wallet_account/service as wallet_account_service
|
||||
import app_service/service/token/dto
|
||||
|
@ -146,5 +147,23 @@ method getTokenPreferencesJson*(self: Module): string =
|
|||
method getTokenGroupByCommunity*(self: Module): bool =
|
||||
return self.controller.getTokenGroupByCommunity()
|
||||
|
||||
method toggleTokenGroupByCommunity*(self: Module) =
|
||||
self.controller.toggleTokenGroupByCommunity()
|
||||
method toggleTokenGroupByCommunity*(self: Module): bool =
|
||||
return self.controller.toggleTokenGroupByCommunity()
|
||||
|
||||
method getShowCommunityAssetWhenSendingTokens*(self: Module): bool =
|
||||
return self.controller.getShowCommunityAssetWhenSendingTokens()
|
||||
|
||||
method toggleShowCommunityAssetWhenSendingTokens*(self: Module): bool =
|
||||
return self.controller.toggleShowCommunityAssetWhenSendingTokens()
|
||||
|
||||
method getDisplayAssetsBelowBalance*(self: Module): bool =
|
||||
return self.controller.getDisplayAssetsBelowBalance()
|
||||
|
||||
method toggleDisplayAssetsBelowBalance*(self: Module): bool =
|
||||
return self.controller.toggleDisplayAssetsBelowBalance()
|
||||
|
||||
method getDisplayAssetsBelowBalanceThreshold*(self: Module): CurrencyAmount =
|
||||
return self.controller.getDisplayAssetsBelowBalanceThreshold()
|
||||
|
||||
method setDisplayAssetsBelowBalanceThreshold*(self: Module, threshold: int64): bool =
|
||||
return self.controller.setDisplayAssetsBelowBalanceThreshold(threshold)
|
|
@ -1,4 +1,4 @@
|
|||
import NimQml, sequtils, strutils
|
||||
import NimQml, sequtils, strutils, chronicles
|
||||
|
||||
import ./io_interface, ./sources_of_tokens_model, ./flat_tokens_model, ./token_by_symbol_model
|
||||
|
||||
|
@ -158,6 +158,53 @@ QtObject:
|
|||
read = getTokenGroupByCommunity
|
||||
notify = tokenGroupByCommunityChanged
|
||||
|
||||
proc toggleTokenGroupByCommunity*(self: View) {.slot.} =
|
||||
self.delegate.toggleTokenGroupByCommunity()
|
||||
self.tokenGroupByCommunityChanged()
|
||||
proc toggleTokenGroupByCommunity*(self: View): bool {.slot.} =
|
||||
if not self.delegate.toggleTokenGroupByCommunity():
|
||||
error "Failed to toggle tokenGroupByCommunity"
|
||||
return
|
||||
self.tokenGroupByCommunityChanged()
|
||||
|
||||
proc showCommunityAssetWhenSendingTokensChanged*(self: View) {.signal.}
|
||||
|
||||
proc getShowCommunityAssetWhenSendingTokens(self: View): bool {.slot.} =
|
||||
return self.delegate.getShowCommunityAssetWhenSendingTokens()
|
||||
|
||||
QtProperty[bool] showCommunityAssetWhenSendingTokens:
|
||||
read = getShowCommunityAssetWhenSendingTokens
|
||||
notify = showCommunityAssetWhenSendingTokensChanged
|
||||
|
||||
proc toggleShowCommunityAssetWhenSendingTokens*(self: View) {.slot.} =
|
||||
if not self.delegate.toggleShowCommunityAssetWhenSendingTokens():
|
||||
error "Failed to toggle showCommunityAssetWhenSendingTokens"
|
||||
return
|
||||
self.showCommunityAssetWhenSendingTokensChanged()
|
||||
|
||||
proc displayAssetsBelowBalanceChanged*(self: View) {.signal.}
|
||||
|
||||
proc getDisplayAssetsBelowBalance(self: View): bool {.slot.} =
|
||||
return self.delegate.getDisplayAssetsBelowBalance()
|
||||
|
||||
QtProperty[bool] displayAssetsBelowBalance:
|
||||
read = getDisplayAssetsBelowBalance
|
||||
notify = displayAssetsBelowBalanceChanged
|
||||
|
||||
proc toggleDisplayAssetsBelowBalance*(self: View) {.slot.} =
|
||||
if not self.delegate.toggleDisplayAssetsBelowBalance():
|
||||
error "Failed to toggle displayAssetsBelowBalance"
|
||||
return
|
||||
self.displayAssetsBelowBalanceChanged()
|
||||
|
||||
proc displayAssetsBelowBalanceThresholdChanged*(self: View) {.signal.}
|
||||
|
||||
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()):
|
||||
error "Failed to set displayAssetsBelowBalanceThreshold"
|
||||
return
|
||||
self.displayAssetsBelowBalanceThresholdChanged()
|
||||
|
||||
QtProperty[QVariant] displayAssetsBelowBalanceThreshold:
|
||||
read = getDisplayAssetsBelowBalanceThreshold
|
||||
notify = displayAssetsBelowBalanceThresholdChanged
|
|
@ -46,6 +46,9 @@ const KEY_BIO* = "bio"
|
|||
const KEY_TEST_NETWORKS_ENABLED* = "test-networks-enabled?"
|
||||
const KEY_IS_SEPOLIA_ENABLED* = "is-sepolia-enabled?"
|
||||
const KEY_TOKEN_GROUP_BY_COMMUNITY* = "token-group-by-community?"
|
||||
const KEY_SHOW_COMMUNITY_ASSET_WHEN_SENDING_TOKENS* = "show-community-asset-when-sending-tokens?"
|
||||
const KEY_DISPLAY_ASSETS_BELOW_BALANCE* = "display-assets-below-balance?"
|
||||
const KEY_DISPLAY_ASSETS_BELOW_BALANCE_THRESHOLD* = "display-assets-below-balance-threshold"
|
||||
const PROFILE_MIGRATION_NEEDED* = "profile-migration-needed"
|
||||
const KEY_URL_UNFURLING_MODE* = "url-unfurling-mode"
|
||||
|
||||
|
@ -154,6 +157,9 @@ type
|
|||
profileMigrationNeeded*: bool
|
||||
isSepoliaEnabled*: bool
|
||||
tokenGroupByCommunity*: bool
|
||||
showCommunityAssetWhenSendingTokens*: bool
|
||||
displayAssetsBelowBalance*: bool
|
||||
displayAssetsBelowBalanceThreshold*: int64
|
||||
urlUnfurlingMode*: UrlUnfurlingMode
|
||||
|
||||
|
||||
|
@ -212,6 +218,9 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
|
|||
discard jsonObj.getProp(KEY_TEST_NETWORKS_ENABLED, result.testNetworksEnabled)
|
||||
discard jsonObj.getProp(KEY_IS_SEPOLIA_ENABLED, result.isSepoliaEnabled)
|
||||
discard jsonObj.getProp(KEY_TOKEN_GROUP_BY_COMMUNITY, result.tokenGroupByCommunity)
|
||||
discard jsonObj.getProp(KEY_SHOW_COMMUNITY_ASSET_WHEN_SENDING_TOKENS, result.showCommunityAssetWhenSendingTokens)
|
||||
discard jsonObj.getProp(KEY_DISPLAY_ASSETS_BELOW_BALANCE, result.displayAssetsBelowBalance)
|
||||
discard jsonObj.getProp(KEY_DISPLAY_ASSETS_BELOW_BALANCE_THRESHOLD, result.displayAssetsBelowBalanceThreshold)
|
||||
discard jsonObj.getProp(PROFILE_MIGRATION_NEEDED, result.profileMigrationNeeded)
|
||||
|
||||
var urlUnfurlingMode: int
|
||||
|
|
|
@ -143,7 +143,7 @@ QtObject:
|
|||
discard self.getNotificationMessagePreview()
|
||||
|
||||
|
||||
proc saveSetting(self: Service, attribute: string, value: string | JsonNode | bool | int): bool =
|
||||
proc saveSetting(self: Service, attribute: string, value: string | JsonNode | bool | int | int64): bool =
|
||||
try:
|
||||
let response = status_settings.saveSettings(attribute, value)
|
||||
if(not response.error.isNil):
|
||||
|
@ -508,6 +508,35 @@ QtObject:
|
|||
return true
|
||||
return false
|
||||
|
||||
proc showCommunityAssetWhenSendingTokens*(self: Service): bool =
|
||||
return self.settings.showCommunityAssetWhenSendingTokens
|
||||
|
||||
proc toggleShowCommunityAssetWhenSendingTokens*(self: Service): bool =
|
||||
let newValue = not self.settings.showCommunityAssetWhenSendingTokens
|
||||
if(self.saveSetting(KEY_SHOW_COMMUNITY_ASSET_WHEN_SENDING_TOKENS, newValue)):
|
||||
self.settings.showCommunityAssetWhenSendingTokens = newValue
|
||||
return true
|
||||
return false
|
||||
|
||||
proc displayAssetsBelowBalance*(self: Service): bool =
|
||||
return self.settings.displayAssetsBelowBalance
|
||||
|
||||
proc toggleDisplayAssetsBelowBalance*(self: Service): bool =
|
||||
let newValue = not self.settings.displayAssetsBelowBalance
|
||||
if(self.saveSetting(KEY_DISPLAY_ASSETS_BELOW_BALANCE, newValue)):
|
||||
self.settings.displayAssetsBelowBalance = newValue
|
||||
return true
|
||||
return false
|
||||
|
||||
proc displayAssetsBelowBalanceThreshold*(self: Service): int64 =
|
||||
return self.settings.displayAssetsBelowBalanceThreshold
|
||||
|
||||
proc setDisplayAssetsBelowBalanceThreshold*(self: Service, value: int64): bool =
|
||||
if(self.saveSetting(KEY_DISPLAY_ASSETS_BELOW_BALANCE_THRESHOLD, value)):
|
||||
self.settings.displayAssetsBelowBalanceThreshold = value
|
||||
return true
|
||||
return false
|
||||
|
||||
proc urlUnfurlingMode*(self: Service): UrlUnfurlingMode =
|
||||
return self.settings.urlUnfurlingMode
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ export response_type
|
|||
proc getSettings*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
return core.callPrivateRPC("settings_getSettings")
|
||||
|
||||
proc saveSettings*(key: string, value: string | JsonNode | bool | int): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
proc saveSettings*(key: string, value: string | JsonNode | bool | int | int64): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [key, value]
|
||||
result = core.callPrivateRPC("settings_saveSetting", payload)
|
||||
|
||||
|
|
Loading…
Reference in New Issue