feat(@desktop/wallet): Provide QProperties for token management (#12929)
This commit is contained in:
parent
fbe6cc95d1
commit
635bf7e582
|
@ -49,11 +49,11 @@ QtObject:
|
|||
|
||||
proc isSepoliaEnabledChanged*(self: View) {.signal.}
|
||||
|
||||
proc getIsSepoliaEnalbled(self: View): bool {.slot.} =
|
||||
proc getIsSepoliaEnabled(self: View): bool {.slot.} =
|
||||
return self.isSepoliaEnabled
|
||||
|
||||
QtProperty[bool] isSepoliaEnabled:
|
||||
read = getIsSepoliaEnalbled
|
||||
read = getIsSepoliaEnabled
|
||||
notify = isSepoliaEnabledChanged
|
||||
|
||||
proc setIsSepoliaEnabled*(self: View, isSepoliaEnabled: bool) =
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import json
|
||||
|
||||
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_service/service/currency/dto
|
||||
import app_service/service/settings/service as settings_service
|
||||
|
||||
type
|
||||
Controller* = ref object of RootObj
|
||||
|
@ -11,18 +14,21 @@ type
|
|||
events: EventEmitter
|
||||
tokenService: token_service.Service
|
||||
walletAccountService: wallet_account_service.Service
|
||||
settingsService: settings_service.Service
|
||||
|
||||
proc newController*(
|
||||
delegate: io_interface.AccessInterface,
|
||||
events: EventEmitter,
|
||||
tokenService: token_service.Service,
|
||||
walletAccountService: wallet_account_service.Service
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
settingsService: settings_service.Service
|
||||
): Controller =
|
||||
result = Controller()
|
||||
result.events = events
|
||||
result.delegate = delegate
|
||||
result.tokenService = tokenService
|
||||
result.walletAccountService = walletAccountService
|
||||
result.settingsService = settingsService
|
||||
|
||||
proc delete*(self: Controller) =
|
||||
discard
|
||||
|
@ -74,3 +80,18 @@ proc getTokensDetailsLoading*(self: Controller): bool =
|
|||
|
||||
proc getTokensMarketValuesLoading*(self: Controller): bool =
|
||||
self.tokenService.getTokensMarketValuesLoading()
|
||||
|
||||
proc updateTokenPreferences*(self: Controller, tokenPreferencesJson: string) =
|
||||
self.tokenService.updateTokenPreferences(tokenPreferencesJson)
|
||||
|
||||
proc getTokenPreferencesJson*(self: Controller): string =
|
||||
let data = self.tokenService.getTokenPreferences()
|
||||
if data.isNil:
|
||||
return "[]"
|
||||
return $data
|
||||
|
||||
proc getTokenGroupByCommunity*(self: Controller): bool =
|
||||
return self.settingsService.tokenGroupByCommunity()
|
||||
|
||||
proc toggleTokenGroupByCommunity*(self: Controller) =
|
||||
discard self.settingsService.toggleTokenGroupByCommunity()
|
|
@ -65,6 +65,12 @@ method getTokenBySymbolModelDataSource*(self: AccessInterface): TokenBySymbolMod
|
|||
method getTokenMarketValuesDataSource*(self: AccessInterface): TokenMarketValuesDataSource {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method updateTokenPreferences*(self: AccessInterface, tokenPreferencesJson: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getTokenPreferencesJson*(self: AccessInterface): string {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
# View Delegate Interface
|
||||
# Delegate for the view must be declared here due to use of QtObject and multi
|
||||
# inheritance, which is not well supported in Nim.
|
||||
|
@ -72,4 +78,10 @@ method viewDidLoad*(self: AccessInterface) {.base.} =
|
|||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method filterChanged*(self: AccessInterface, addresses: seq[string]) =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getTokenGroupByCommunity*(self: AccessInterface): bool =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method toggleTokenGroupByCommunity*(self: AccessInterface) =
|
||||
raise newException(ValueError, "No implementation available")
|
|
@ -9,7 +9,7 @@ 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
|
||||
import app_service/service/currency/service
|
||||
import app_service/service/settings/service
|
||||
import app_service/service/settings/service as settings_service
|
||||
|
||||
export io_interface
|
||||
|
||||
|
@ -27,12 +27,13 @@ proc newModule*(
|
|||
events: EventEmitter,
|
||||
tokenService: token_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
settingsService: settings_service.Service
|
||||
): Module =
|
||||
result = Module()
|
||||
result.delegate = delegate
|
||||
result.events = events
|
||||
result.view = newView(result)
|
||||
result.controller = controller.newController(result, events, tokenService, walletAccountService)
|
||||
result.controller = controller.newController(result, events, tokenService, walletAccountService, settingsService)
|
||||
result.moduleLoaded = false
|
||||
result.addresses = @[]
|
||||
|
||||
|
@ -59,6 +60,9 @@ method load*(self: Module) =
|
|||
self.view.tokensMarketValuesUpdated()
|
||||
self.events.on(SIGNAL_TOKENS_PRICES_UPDATED) do(e: Args):
|
||||
self.view.tokensMarketValuesUpdated()
|
||||
self.events.on(SIGNAL_TOKEN_PREFERENCES_UPDATED) do(e: Args):
|
||||
let args = ResultArgs(e)
|
||||
self.view.tokenPreferencesUpdated(args.success)
|
||||
|
||||
self.events.on(SIGNAL_CURRENCY_FORMATS_UPDATED) do(e:Args):
|
||||
self.view.currencyFormatsUpdated()
|
||||
|
@ -127,3 +131,15 @@ method filterChanged*(self: Module, addresses: seq[string]) =
|
|||
if addresses == self.addresses:
|
||||
return
|
||||
self.addresses = addresses
|
||||
|
||||
method updateTokenPreferences*(self: Module, tokenPreferencesJson: string) {.slot.} =
|
||||
self.controller.updateTokenPreferences(tokenPreferencesJson)
|
||||
|
||||
method getTokenPreferencesJson*(self: Module): string =
|
||||
return self.controller.getTokenPreferencesJson()
|
||||
|
||||
method getTokenGroupByCommunity*(self: Module): bool =
|
||||
return self.controller.getTokenGroupByCommunity()
|
||||
|
||||
method toggleTokenGroupByCommunity*(self: Module) =
|
||||
self.controller.toggleTokenGroupByCommunity()
|
|
@ -128,3 +128,28 @@ QtObject:
|
|||
proc currencyFormatsUpdated*(self: View) =
|
||||
self.flatTokensModel.currencyFormatsUpdated()
|
||||
self.tokensBySymbolModel.currencyFormatsUpdated()
|
||||
|
||||
proc tokenPreferencesUpdated*(self: View, result: bool) {.signal.}
|
||||
|
||||
proc updateTokenPreferences*(self: View, tokenPreferencesJson: string) {.slot.} =
|
||||
self.delegate.updateTokenPreferences(tokenPreferencesJson)
|
||||
|
||||
proc getTokenPreferencesJson(self: View): QVariant {.slot.} =
|
||||
let preferences = self.delegate.getTokenPreferencesJson()
|
||||
return newQVariant(preferences)
|
||||
|
||||
QtProperty[QVariant] tokenPreferencesJson:
|
||||
read = getTokenPreferencesJson
|
||||
|
||||
proc tokenGroupByCommunityChanged*(self: View) {.signal.}
|
||||
|
||||
proc getTokenGroupByCommunity(self: View): bool {.slot.} =
|
||||
return self.delegate.getTokenGroupByCommunity()
|
||||
|
||||
QtProperty[bool] tokenGroupByCommunity:
|
||||
read = getTokenGroupByCommunity
|
||||
notify = tokenGroupByCommunityChanged
|
||||
|
||||
proc toggleTokenGroupByCommunity*(self: View) {.slot.} =
|
||||
self.delegate.toggleTokenGroupByCommunity()
|
||||
self.tokenGroupByCommunityChanged()
|
|
@ -116,7 +116,7 @@ proc newModule*(
|
|||
result.controller = newController(result, settingsService, walletAccountService, currencyService, networkService)
|
||||
|
||||
result.accountsModule = accounts_module.newModule(result, events, walletAccountService, networkService, currencyService)
|
||||
result.allTokensModule = all_tokens_module.newModule(result, events, tokenService, walletAccountService)
|
||||
result.allTokensModule = all_tokens_module.newModule(result, events, tokenService, walletAccountService, settingsService)
|
||||
result.assetsModule = assets_module.newModule(result, events, walletAccountService, networkService, tokenService,
|
||||
currencyService)
|
||||
result.sendModule = send_module.newModule(result, events, walletAccountService, networkService, currencyService,
|
||||
|
|
|
@ -45,6 +45,7 @@ const KEY_DISPLAY_NAME* = "display-name"
|
|||
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 PROFILE_MIGRATION_NEEDED* = "profile-migration-needed"
|
||||
const KEY_URL_UNFURLING_MODE* = "url-unfurling-mode"
|
||||
|
||||
|
@ -152,6 +153,7 @@ type
|
|||
notificationsMessagePreview*: int
|
||||
profileMigrationNeeded*: bool
|
||||
isSepoliaEnabled*: bool
|
||||
tokenGroupByCommunity*: bool
|
||||
urlUnfurlingMode*: UrlUnfurlingMode
|
||||
|
||||
|
||||
|
@ -209,6 +211,7 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
|
|||
discard jsonObj.getProp(KEY_GIF_FAVORITES, result.gifFavorites)
|
||||
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(PROFILE_MIGRATION_NEEDED, result.profileMigrationNeeded)
|
||||
|
||||
var urlUnfurlingMode: int
|
||||
|
|
|
@ -498,6 +498,16 @@ QtObject:
|
|||
return true
|
||||
return false
|
||||
|
||||
proc tokenGroupByCommunity*(self: Service): bool =
|
||||
return self.settings.tokenGroupByCommunity
|
||||
|
||||
proc toggleTokenGroupByCommunity*(self: Service): bool =
|
||||
let newValue = not self.settings.tokenGroupByCommunity
|
||||
if(self.saveSetting(KEY_TOKEN_GROUP_BY_COMMUNITY, newValue)):
|
||||
self.settings.tokenGroupByCommunity = newValue
|
||||
return true
|
||||
return false
|
||||
|
||||
proc urlUnfurlingMode*(self: Service): UrlUnfurlingMode =
|
||||
return self.settings.urlUnfurlingMode
|
||||
|
||||
|
|
|
@ -38,6 +38,11 @@ const SIGNAL_TOKENS_LIST_ABOUT_TO_BE_UPDATED* = "tokensListAboutToBeUpdated"
|
|||
const SIGNAL_TOKENS_DETAILS_UPDATED* = "tokensDetailsUpdated"
|
||||
const SIGNAL_TOKENS_MARKET_VALUES_UPDATED* = "tokensMarketValuesUpdated"
|
||||
const SIGNAL_TOKENS_PRICES_UPDATED* = "tokensPricesValuesUpdated"
|
||||
const SIGNAL_TOKEN_PREFERENCES_UPDATED* = "tokenPreferencesUpdated"
|
||||
|
||||
type
|
||||
ResultArgs* = ref object of Args
|
||||
success*: bool
|
||||
|
||||
type
|
||||
TokenHistoricalDataArgs* = ref object of Args
|
||||
|
@ -604,3 +609,30 @@ QtObject:
|
|||
)
|
||||
self.threadpool.start(arg)
|
||||
return
|
||||
|
||||
proc getTokenPreferences*(self: Service): JsonNode =
|
||||
try:
|
||||
let response = backend.getTokenPreferences()
|
||||
if not response.error.isNil:
|
||||
error "status-go error", procName="getTokenPreferences", errCode=response.error.code, errDesription=response.error.message
|
||||
return
|
||||
return response.result
|
||||
except Exception as e:
|
||||
error "error: ", procName="getTokenPreferences", errName=e.name, errDesription=e.msg
|
||||
|
||||
proc updateTokenPreferences*(self: Service, tokenPreferencesJson: string) =
|
||||
var updated = false
|
||||
try:
|
||||
let preferencesJson = parseJson(tokenPreferencesJson)
|
||||
var tokenPreferences: seq[TokenPreferences]
|
||||
if preferencesJson.kind == JArray:
|
||||
for preferences in preferencesJson:
|
||||
add(tokenPreferences, fromJson(preferences, TokenPreferences))
|
||||
let response = backend.updateTokenPreferences(tokenPreferences)
|
||||
if not response.error.isNil:
|
||||
raise newException(CatchableError, response.error.message)
|
||||
updated = true
|
||||
except Exception as e:
|
||||
error "error: ", procName="updateTokenPreferences", errName=e.name, errDesription=e.msg
|
||||
|
||||
self.events.emit(SIGNAL_TOKEN_PREFERENCES_UPDATED, ResultArgs(success: updated))
|
||||
|
|
|
@ -63,6 +63,21 @@ type
|
|||
activityTypes* {.serializedFieldName("activityTypes").}: seq[int]
|
||||
readType* {.serializedFieldName("readType").}: int
|
||||
|
||||
TokenPreferences* = ref object of RootObj
|
||||
key* {.serializedFieldName("key").}: string
|
||||
position* {.serializedFieldName("position").}: int
|
||||
groupPosition* {.serializedFieldName("groupPosition").}: int
|
||||
visible* {.serializedFieldName("visible").}: bool
|
||||
communityId* {.serializedFieldName("communityId").}: string
|
||||
|
||||
proc fromJson*(t: JsonNode, T: typedesc[TokenPreferences]): TokenPreferences {.inline.} =
|
||||
result = TokenPreferences()
|
||||
discard t.getProp("key", result.key)
|
||||
discard t.getProp("position", result.position)
|
||||
discard t.getProp("groupPosition", result.groupPosition)
|
||||
discard t.getProp("visible", result.visible)
|
||||
discard t.getProp("communityId", result.communityId)
|
||||
|
||||
rpc(clientVersion, "web3"):
|
||||
discard
|
||||
|
||||
|
@ -270,6 +285,12 @@ rpc(moveWalletAccount, "accounts"):
|
|||
fromPosition: int
|
||||
toPosition: int
|
||||
|
||||
rpc(updateTokenPreferences, "accounts"):
|
||||
preferences: seq[TokenPreferences]
|
||||
|
||||
rpc(getTokenPreferences, "accounts"):
|
||||
discard
|
||||
|
||||
rpc(updateKeypairName, "accounts"):
|
||||
keyUid: string
|
||||
name: string
|
||||
|
|
Loading…
Reference in New Issue