From 3f71e1fe8794abc9a5b058d7fd673b21ac0dcd5d Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 4 Apr 2022 14:11:39 +0200 Subject: [PATCH] feat(@wallet): move visible token to status go --- src/app/boot/app_controller.nim | 2 +- .../wallet_section/all_tokens/controller.nim | 4 +-- .../all_tokens/io_interface.nim | 2 +- .../main/wallet_section/all_tokens/module.nim | 4 +-- .../main/wallet_section/all_tokens/view.nim | 4 +-- .../service/settings/dto/settings.nim | 17 ----------- src/app_service/service/settings/service.nim | 27 +++++++++-------- src/app_service/service/token/service.nim | 30 ++++++------------- .../service/wallet_account/service.nim | 4 +-- src/backend/backend.nim | 7 +++++ .../panels/TokenSettingsModalContent.qml | 10 +++---- .../Profile/popups/TokenSettingsModal.qml | 2 +- .../AppLayouts/Profile/stores/WalletStore.qml | 4 +-- vendor/status-go | 2 +- 14 files changed, 50 insertions(+), 69 deletions(-) diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index c6aff8bb4a..61dd8f680a 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -134,7 +134,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController = result.activityCenterService = activity_center_service.newService(statusFoundation.events, statusFoundation.threadpool, result.chatService) result.tokenService = token_service.newService( - statusFoundation.events, statusFoundation.threadpool, result.settingsService, result.networkService + statusFoundation.events, statusFoundation.threadpool, result.networkService ) result.collectibleService = collectible_service.newService(result.settingsService) result.walletAccountService = wallet_account_service.newService( diff --git a/src/app/modules/main/wallet_section/all_tokens/controller.nim b/src/app/modules/main/wallet_section/all_tokens/controller.nim index 31b2264c37..d419de0509 100644 --- a/src/app/modules/main/wallet_section/all_tokens/controller.nim +++ b/src/app/modules/main/wallet_section/all_tokens/controller.nim @@ -43,8 +43,8 @@ proc getTokens*(self: Controller): seq[token_service.TokenDto] = proc addCustomToken*(self: Controller, chainId: int, address: string, name: string, symbol: string, decimals: int) = self.tokenService.addCustomToken(chainId, address, name, symbol, decimals) -proc toggleVisible*(self: Controller, chainId: int, symbol: string) = - self.walletAccountService.toggleTokenVisible(chainId, symbol) +proc toggleVisible*(self: Controller, chainId: int, address: string) = + self.walletAccountService.toggleTokenVisible(chainId, address) proc removeCustomToken*(self: Controller, chainId: int, address: string) = self.tokenService.removeCustomToken(chainId, address) diff --git a/src/app/modules/main/wallet_section/all_tokens/io_interface.nim b/src/app/modules/main/wallet_section/all_tokens/io_interface.nim index b7a50809ea..3989192e0a 100644 --- a/src/app/modules/main/wallet_section/all_tokens/io_interface.nim +++ b/src/app/modules/main/wallet_section/all_tokens/io_interface.nim @@ -14,7 +14,7 @@ method isLoaded*(self: AccessInterface): bool {.base.} = method addCustomToken*(self: AccessInterface, chainId: int, address: string, name: string, symbol: string, decimals: int) {.base.} = raise newException(ValueError, "No implementation available") -method toggleVisible*(self: AccessInterface, chainId: int, symbol: string) {.base.} = +method toggleVisible*(self: AccessInterface, chainId: int, address: string) {.base.} = raise newException(ValueError, "No implementation available") method removeCustomToken*(self: AccessInterface, chainId: int, address: string) {.base.} = diff --git a/src/app/modules/main/wallet_section/all_tokens/module.nim b/src/app/modules/main/wallet_section/all_tokens/module.nim index 50b5bc08d5..a32a9128f5 100644 --- a/src/app/modules/main/wallet_section/all_tokens/module.nim +++ b/src/app/modules/main/wallet_section/all_tokens/module.nim @@ -77,8 +77,8 @@ method viewDidLoad*(self: Module) = method addCustomToken*(self: Module, chainId: int, address: string, name: string, symbol: string, decimals: int) = self.controller.addCustomToken(chainId, address, name, symbol, decimals) -method toggleVisible*(self: Module, chainId: int, symbol: string) = - self.controller.toggleVisible(chainId, symbol) +method toggleVisible*(self: Module, chainId: int, address: string) = + self.controller.toggleVisible(chainId, address) method removeCustomToken*(self: Module, chainId: int, address: string) = self.controller.removeCustomToken(chainId, address) diff --git a/src/app/modules/main/wallet_section/all_tokens/view.nim b/src/app/modules/main/wallet_section/all_tokens/view.nim index b3ed4ee08b..c9135b39c2 100644 --- a/src/app/modules/main/wallet_section/all_tokens/view.nim +++ b/src/app/modules/main/wallet_section/all_tokens/view.nim @@ -64,8 +64,8 @@ QtObject: proc addCustomToken(self: View, chainId: int, address: string, name: string, symbol: string, decimals: string) {.slot.} = self.delegate.addCustomToken(chainId, address, name, symbol, parseInt(decimals)) - proc toggleVisible(self: View, chainId: int, symbol: string) {.slot.} = - self.delegate.toggleVisible(chainId, symbol) + proc toggleVisible(self: View, chainId: int, address: string) {.slot.} = + self.delegate.toggleVisible(chainId, address) proc removeCustomToken(self: View, chainId: int, address: string) {.slot.} = self.delegate.removeCustomToken(chainId, address) diff --git a/src/app_service/service/settings/dto/settings.nim b/src/app_service/service/settings/dto/settings.nim index 8206787a1b..63fc3c3676 100644 --- a/src/app_service/service/settings/dto/settings.nim +++ b/src/app_service/service/settings/dto/settings.nim @@ -115,7 +115,6 @@ type telemetryServerUrl*: string fleet*: string currentUserStatus*: CurrentUserStatus - walletVisibleTokens*: Table[int, seq[string]] nodeConfig*: JsonNode wakuBloomFilterMode*: bool autoMessageEnabled*: bool @@ -155,23 +154,11 @@ proc toPinnedMailserver*(jsonObj: JsonNode): PinnedMailserver = discard jsonObj.getProp("status.test", result.statusTest) discard jsonObj.getProp("status.prod", result.statusProd) - - proc toCurrentUserStatus*(jsonObj: JsonNode): CurrentUserStatus = discard jsonObj.getProp("statusType", result.statusType) discard jsonObj.getProp("clock", result.clock) discard jsonObj.getProp("text", result.text) -proc toWalletVisibleTokens*(jsonObj: JsonNode): Table[int, seq[string]] = - for chainIdStr, tokenArr in jsonObj: - if(tokenArr.kind != JArray): - continue - - let chainId = parseInt(chainIdStr) - result[chainId] = @[] - for token in tokenArr: - result[chainId].add(token.getStr) - proc toSettingsDto*(jsonObj: JsonNode): SettingsDto = discard jsonObj.getProp(KEY_ADDRESS, result.address) discard jsonObj.getProp(KEY_CURRENCY, result.currency) @@ -221,10 +208,6 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto = if(jsonObj.getProp(KEY_CURRENT_USER_STATUS, currentUserStatusObj)): result.currentUserStatus = toCurrentUserStatus(currentUserStatusObj) - var walletVisibleTokensObj: JsonNode - if(jsonObj.getProp(KEY_WALLET_VISIBLE_TOKENS, walletVisibleTokensObj)): - result.walletVisibleTokens = toWalletVisibleTokens(walletVisibleTokensObj) - discard jsonObj.getProp(KEY_NODE_CONFIG, result.nodeConfig) discard jsonObj.getProp(KEY_WAKU_BLOOM_FILTER_MODE, result.wakuBloomFilterMode) diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index 63970fd0fe..077b95b35b 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -394,19 +394,22 @@ proc pinMailserver*(self: Service, address: string, fleet: Fleet): bool = proc unpinMailserver*(self: Service, fleet: Fleet): bool = return self.pinMailserver("", fleet) -proc getWalletVisibleTokens*(self: Service): Table[int, seq[string]] = - self.settings.walletVisibleTokens +proc isEIP1559Enabled*(self: Service, blockNumber: int): bool = + let networkId = self.getCurrentNetworkDetails().config.NetworkId + let activationBlock = case networkId: + of 3: 10499401 # Ropsten + of 4: 8897988 # Rinkeby + of 5: 5062605 # Goerli + of 1: 12965000 # Mainnet + else: -1 + if activationBlock > -1 and blockNumber >= activationBlock: + result = true + else: + result = false + self.eip1559Enabled = result -proc saveWalletVisibleTokens*(self: Service, visibleTokens: Table[int, seq[string]]): bool = - var obj = newJObject() - for chainId, tokens in visibleTokens.pairs: - obj[$chainId] = %* tokens - - if(self.saveSetting(KEY_WALLET_VISIBLE_TOKENS, obj)): - self.settings.walletVisibleTokens = visibleTokens - return true - - return false +proc isEIP1559Enabled*(self: Service): bool = + result = self.eip1559Enabled proc saveNodeConfiguration*(self: Service, value: JsonNode): bool = if(self.saveSetting(KEY_NODE_CONFIG, value)): diff --git a/src/app_service/service/token/service.nim b/src/app_service/service/token/service.nim index 25d27f9446..2b90e183b3 100644 --- a/src/app_service/service/token/service.nim +++ b/src/app_service/service/token/service.nim @@ -5,7 +5,6 @@ import web3/ethtypes from web3/conversions import `$` import ../../../backend/backend as backend -import ../settings/service as settings_service import ../network/service as network_service import ../../../app/core/eventemitter @@ -19,7 +18,6 @@ logScope: include async_tasks -const DEFAULT_VISIBLE_TOKENS = {1: @["SNT"], 3: @["STT"], 4: @["STT"]}.toTable() # Signals which may be emitted by this service: const SIGNAL_TOKEN_DETAILS_LOADED* = "tokenDetailsLoaded" const SIGNAL_TOKEN_LIST_RELOADED* = "tokenListReloaded" @@ -44,7 +42,6 @@ QtObject: type Service* = ref object of QObject events: EventEmitter threadpool: ThreadPool - settingsService: settings_service.Service networkService: network_service.Service tokens: Table[NetworkDto, seq[TokenDto]] @@ -54,39 +51,34 @@ QtObject: proc newService*( events: EventEmitter, threadpool: ThreadPool, - settingsService: settings_service.Service, networkService: network_service.Service, ): Service = new(result, delete) result.QObject.setup result.events = events result.threadpool = threadpool - result.settingsService = settingsService result.networkService = networkService result.tokens = initTable[NetworkDto, seq[TokenDto]]() proc init*(self: Service) = try: self.tokens = initTable[NetworkDto, seq[TokenDto]]() - var activeTokenSymbols = self.settingsService.getWalletVisibleTokens() let networks = self.networkService.getEnabledNetworks() + let chainIds = networks.map(n => n.chainId) + let visibleTokens = backend.getVisibleTokens(chainIds).result let responseCustomTokens = backend.getCustomTokens() for network in networks: - if not activeTokenSymbols.hasKey(network.chainId) and DEFAULT_VISIBLE_TOKENS.hasKey(network.chainId): - activeTokenSymbols[network.chainId] = DEFAULT_VISIBLE_TOKENS[network.chainId] - else: - activeTokenSymbols[network.chainId] = @[] - + let activeTokenSymbols = visibleTokens[$network.chainId].getElems().map(n => n["symbol"].getStr) let responseTokens = backend.getTokens(network.chainId) let default_tokens = map( responseTokens.result.getElems(), - proc(x: JsonNode): TokenDto = x.toTokenDto(activeTokenSymbols[network.chainId], hasIcon=true, isCustom=false) + proc(x: JsonNode): TokenDto = x.toTokenDto(activeTokenSymbols, hasIcon=true, isCustom=false) ) self.tokens[network] = concat( default_tokens, - map(responseCustomTokens.result.getElems(), proc(x: JsonNode): TokenDto = x.toTokenDto(activeTokenSymbols[network.chainId])) + map(responseCustomTokens.result.getElems(), proc(x: JsonNode): TokenDto = x.toTokenDto(activeTokenSymbols)) ).filter( proc(x: TokenDto): bool = x.chainId == network.chainId ) @@ -140,21 +132,17 @@ QtObject: self.tokens[network].add(token) self.events.emit("token/customTokenAdded", CustomTokenAdded(token: token)) - proc toggleVisible*(self: Service, chainId: int, symbol: string) = + proc toggleVisible*(self: Service, chainId: int, address: string) = + discard backend.toggleVisibleToken(chainId, address) + let network = self.networkService.getNetwork(chainId) var tokenChanged = self.tokens[network][0] for token in self.tokens[network]: - if token.symbol == symbol: + if token.addressAsString() == address: token.isVisible = not token.isVisible tokenChanged = token break - var visibleSymbols = initTable[int, seq[string]]() - for network, tokens in self.tokens.pairs: - let symbols = tokens.filter(t => t.isVisible).map(t => t.symbol) - visibleSymbols[network.chainId] = symbols - - discard self.settingsService.saveWalletVisibleTokens(visibleSymbols) self.events.emit("token/visibilityToggled", VisibilityToggled(token: tokenChanged)) proc removeCustomToken*(self: Service, chainId: int, address: string) = diff --git a/src/app_service/service/wallet_account/service.nim b/src/app_service/service/wallet_account/service.nim index 73cb683cfa..8e55c4e34e 100644 --- a/src/app_service/service/wallet_account/service.nim +++ b/src/app_service/service/wallet_account/service.nim @@ -317,8 +317,8 @@ proc updateCurrency*(self: Service, newCurrency: string) = self.refreshBalances() self.events.emit(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED, CurrencyUpdated()) -proc toggleTokenVisible*(self: Service, chainId: int, symbol: string) = - self.tokenService.toggleVisible(chainId, symbol) +proc toggleTokenVisible*(self: Service, chainId: int, address: string) = + self.tokenService.toggleVisible(chainId, address) self.refreshBalances() self.events.emit(SIGNAL_WALLET_ACCOUNT_TOKEN_VISIBILITY_UPDATED, TokenVisibilityToggled()) diff --git a/src/backend/backend.nim b/src/backend/backend.nim index 094e1530dc..e621bbb055 100644 --- a/src/backend/backend.nim +++ b/src/backend/backend.nim @@ -96,6 +96,13 @@ rpc(discoverToken, "wallet"): rpc(getPendingTransactions, "wallet"): discard +rpc(getVisibleTokens, "wallet"): + chainIds: seq[int] + +rpc(toggleVisibleToken, "wallet"): + chainId: int + address: string + rpc(fetchPrices, "wallet"): symbols: seq[string] currency: string diff --git a/ui/app/AppLayouts/Profile/panels/TokenSettingsModalContent.qml b/ui/app/AppLayouts/Profile/panels/TokenSettingsModalContent.qml index a0ba054346..c852c472a4 100644 --- a/ui/app/AppLayouts/Profile/panels/TokenSettingsModalContent.qml +++ b/ui/app/AppLayouts/Profile/panels/TokenSettingsModalContent.qml @@ -16,7 +16,7 @@ Item { property var defaultTokenList property var customTokenList - signal toggleVisibleClicked(int chainId, string symbol) + signal toggleVisibleClicked(int chainId, string address) signal removeCustomTokenTriggered(int chainId, string address) signal showTokenDetailsTriggered(int chainId, string address, string name, string symbol, string decimals) @@ -32,7 +32,7 @@ Item { components: [StatusCheckBox { id: assetCheck checked: model.isVisible - onClicked: toggleVisibleClicked(chainId, symbol) + onClicked: toggleVisibleClicked(chainId, address) }] visible: symbol && (searchBox.text == "" || name.toLowerCase().includes(searchBox.text.toLowerCase()) || symbol.toLowerCase().includes(searchBox.text.toLowerCase())) MouseArea { @@ -44,13 +44,13 @@ Item { return contextMenu.popup(mouseX, mouseY) } assetCheck.checked = !assetCheck.checked - toggleVisibleClicked(chainId, symbol) + toggleVisibleClicked(chainId, address) } StatusPopupMenu { id: contextMenu Action { - icon.source: Style.svg("make-admin") + icon.name: "admin" //% "Token details" text: qsTrId("token-details") onTriggered: { @@ -58,7 +58,7 @@ Item { } } Action { - icon.source: Style.svg("remove-from-group") + icon.name: "remove" icon.color: Style.current.red enabled: isCustom //% "Remove token" diff --git a/ui/app/AppLayouts/Profile/popups/TokenSettingsModal.qml b/ui/app/AppLayouts/Profile/popups/TokenSettingsModal.qml index 41f8eb0723..42477e7d61 100644 --- a/ui/app/AppLayouts/Profile/popups/TokenSettingsModal.qml +++ b/ui/app/AppLayouts/Profile/popups/TokenSettingsModal.qml @@ -39,7 +39,7 @@ StatusModal { customTokenList: walletStore.customTokenList onToggleVisibleClicked: { - walletStore.toggleVisible(chainId, symbol) + walletStore.toggleVisible(chainId, address) } onRemoveCustomTokenTriggered: { walletStore.removeCustomToken(chainId, address) diff --git a/ui/app/AppLayouts/Profile/stores/WalletStore.qml b/ui/app/AppLayouts/Profile/stores/WalletStore.qml index b35b2060c3..ec781db7a1 100644 --- a/ui/app/AppLayouts/Profile/stores/WalletStore.qml +++ b/ui/app/AppLayouts/Profile/stores/WalletStore.qml @@ -26,8 +26,8 @@ QtObject { return walletSectionAllTokens.addCustomToken(chainId, address, name, symbol, decimals) } - function toggleVisible(chainId, symbol) { - walletSectionAllTokens.toggleVisible(chainId, symbol) + function toggleVisible(chainId, address) { + walletSectionAllTokens.toggleVisible(chainId, address) } function removeCustomToken(chainId, address) { diff --git a/vendor/status-go b/vendor/status-go index 9fef24917a..907ba8ee5c 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 9fef24917a9c643341de200c3a4045148e9e9ab1 +Subproject commit 907ba8ee5c59922721cfcb6a1485e2bf7b8bb9e7