From 11820d040043a62d03eec115deeabc269096cb30 Mon Sep 17 00:00:00 2001 From: Khushboo Mehta Date: Mon, 7 Aug 2023 20:47:16 +0200 Subject: [PATCH] feat(@desktop/wallet): Wallet settings - Notification after each action fixes #11719 --- src/app/modules/main/module.nim | 8 ++++++ .../wallet/accounts/module.nim | 12 +++++---- .../wallet/networks/controller.nim | 3 +++ .../profile_section/wallet/networks/view.nim | 2 +- src/app/modules/main/view.nim | 2 ++ src/app_service/service/network/service.nim | 26 ++++++++++++++----- src/app_service/service/settings/service.nim | 5 +++- .../AppLayouts/Profile/stores/WalletStore.qml | 26 +++++++++++++++++++ .../AppLayouts/Profile/views/WalletView.qml | 5 +++- .../Profile/views/wallet/EditNetworkView.qml | 15 ++++++----- .../Profile/views/wallet/NetworksView.qml | 4 +-- ui/app/mainui/AppMain.qml | 25 ++++++++++++++++-- vendor/status-go | 2 +- 13 files changed, 110 insertions(+), 25 deletions(-) diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 227422aa32..8958c7e101 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -394,6 +394,14 @@ proc connectForNotificationsOnly[T](self: Module[T]) = let args = KeypairArgs(e) self.view.showToastKeypairRenamed(args.oldKeypairName, args.keypair.name) + self.events.on(SIGNAL_NETWORK_ENDPOINT_UPDATED) do(e: Args): + let args = NetworkEndpointUpdatedArgs(e) + self.view.showNetworkEndpointUpdated(args.networkName, args.isTest) + + self.events.on(SIGNAL_INCLUDE_WATCH_ONLY_ACCOUNTS_UPDATED) do(e: Args): + let args = SettingsBoolValueArgs(e) + self.view.showIncludeWatchOnlyAccountUpdated(args.value) + method load*[T]( self: Module[T], events: EventEmitter, diff --git a/src/app/modules/main/profile_section/wallet/accounts/module.nim b/src/app/modules/main/profile_section/wallet/accounts/module.nim index 5be0e4376a..d5d193d2e3 100644 --- a/src/app/modules/main/profile_section/wallet/accounts/module.nim +++ b/src/app/modules/main/profile_section/wallet/accounts/module.nim @@ -75,11 +75,13 @@ method createKeypairItems*(self: Module, walletAccounts: seq[WalletAccountDto], var keyPairItems = keypairs.buildKeyPairsList(self.controller.getKeypairs(), excludeAlreadyMigratedPairs = false, excludePrivateKeyKeypairs = false, self.controller.areTestNetworksEnabled()) - var item = newKeyPairItem() - item.setIcon("show") - item.setPairType(KeyPairType.WatchOnly.int) - item.setAccounts(walletAccounts.filter(a => a.walletType == WalletTypeWatch).map(x => self.convertWalletAccountDtoToKeyPairAccountItem(x))) - keyPairItems.add(item) + var watchOnlyAccounts = walletAccounts.filter(a => a.walletType == WalletTypeWatch).map(x => self.convertWalletAccountDtoToKeyPairAccountItem(x)) + if watchOnlyAccounts.len > 0: + var item = newKeyPairItem() + item.setIcon("show") + item.setPairType(KeyPairType.WatchOnly.int) + item.setAccounts(watchOnlyAccounts) + keyPairItems.add(item) for address, tokens in accountsTokens.pairs: let balance = currencyAmountToItem(tokens.map(t => t.getCurrencyBalance(enabledChainIds, currency)).foldl(a + b, 0.0),currencyFormat) diff --git a/src/app/modules/main/profile_section/wallet/networks/controller.nim b/src/app/modules/main/profile_section/wallet/networks/controller.nim index 2ec8116c17..6f26c75ba6 100644 --- a/src/app/modules/main/profile_section/wallet/networks/controller.nim +++ b/src/app/modules/main/profile_section/wallet/networks/controller.nim @@ -38,6 +38,9 @@ proc init*(self: Controller) = let args = ChainIdForUrlArgs(e) self.delegate.chainIdFetchedForUrl(args.url, args.chainId, args.success) + self.events.on(SIGNAL_NETWORK_ENDPOINT_UPDATED) do(e: Args): + self.delegate.refreshNetworks() + proc getNetworks*(self: Controller): seq[CombinedNetworkDto] = return self.networkService.getCombinedNetworks() diff --git a/src/app/modules/main/profile_section/wallet/networks/view.nim b/src/app/modules/main/profile_section/wallet/networks/view.nim index a90b8676a3..1f17891861 100644 --- a/src/app/modules/main/profile_section/wallet/networks/view.nim +++ b/src/app/modules/main/profile_section/wallet/networks/view.nim @@ -73,7 +73,7 @@ QtObject: proc getNetworkShortNames*(self: View, preferredNetworks: string): string {.slot.} = return self.combinedNetworks.getNetworkShortNames(preferredNetworks, self.areTestNetworksEnabled) - proc updateNetworkEndPointValues*(self: View, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) = + proc updateNetworkEndPointValues*(self: View, chainId: int, newMainRpcInput: string, newFailoverRpcUrl: string) {.slot.} = self.delegate.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl) proc fetchChainIdForUrl*(self: View, url: string) {.slot.} = diff --git a/src/app/modules/main/view.nim b/src/app/modules/main/view.nim index 753c789c6d..0428914d6b 100644 --- a/src/app/modules/main/view.nim +++ b/src/app/modules/main/view.nim @@ -274,3 +274,5 @@ QtObject: ## Signals for in app (ephemeral) notifications proc showToastAccountAdded*(self: View, name: string) {.signal.} proc showToastKeypairRenamed*(self: View, oldName: string, newName: string) {.signal.} + proc showNetworkEndpointUpdated*(self: View, name: string, isTest: bool) {.signal.} + proc showIncludeWatchOnlyAccountUpdated*(self: View, includeWatchOnly: bool) {.signal.} diff --git a/src/app_service/service/network/service.nim b/src/app_service/service/network/service.nim index 767824b270..628195d506 100644 --- a/src/app_service/service/network/service.nim +++ b/src/app_service/service/network/service.nim @@ -11,6 +11,12 @@ export dto, types logScope: topics = "network-service" +const SIGNAL_NETWORK_ENDPOINT_UPDATED* = "networkEndPointUpdated" + +type NetworkEndpointUpdatedArgs* = ref object of Args + isTest*: bool + networkName*: string + type Service* = ref object of RootObj events: EventEmitter @@ -57,8 +63,8 @@ proc getNetworks*(self: Service): seq[NetworkDto] = else: result.add(network.prod) -proc upsertNetwork*(self: Service, network: NetworkDto) = - discard backend.addEthereumChain(backend.Network( +proc upsertNetwork*(self: Service, network: NetworkDto): bool = + let response = backend.addEthereumChain(backend.Network( chainId: network.chainId, nativeCurrencyDecimals: network.nativeCurrencyDecimals, layer: network.layer, @@ -76,6 +82,7 @@ proc upsertNetwork*(self: Service, network: NetworkDto) = relatedChainID: network.relatedChainID, )) self.dirty.store(true) + return response.error == nil proc deleteNetwork*(self: Service, network: NetworkDto) = discard backend.deleteEthereumChain(network.chainId) @@ -89,6 +96,13 @@ proc getNetwork*(self: Service, chainId: int): NetworkDto = if chainId == net.chainId: return net +proc getNetworkByChainId*(self: Service, chainId: int): NetworkDto = + for network in self.fetchNetworks(): + if chainId == network.prod.chainId: + return network.prod + elif chainId == network.test.chainId: + return network.test + proc getNetwork*(self: Service, networkType: NetworkType): NetworkDto = let testNetworksEnabled = self.settingsService.areTestNetworksEnabled() for network in self.fetchNetworks(): @@ -108,7 +122,7 @@ proc setNetworksState*(self: Service, chainIds: seq[int], enabled: bool) = continue network.enabled = enabled - self.upsertNetwork(network) + discard self.upsertNetwork(network) proc getChainIdForEns*(self: Service): int = if self.settingsService.areTestNetworksEnabled(): @@ -141,7 +155,7 @@ proc getNetworkForCollectibles*(self: Service): NetworkDto = return self.getNetwork(Mainnet) proc updateNetworkEndPointValues*(self: Service, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) = - let network = self.getNetwork(chainId) + let network = self.getNetworkByChainId(chainId) if network.rpcURL == newMainRpcInput and network.fallbackURL == newFailoverRpcUrl: return @@ -152,5 +166,5 @@ proc updateNetworkEndPointValues*(self: Service, chainId: int, newMainRpcInput, if network.fallbackURL != newFailoverRpcUrl: network.fallbackURL = newFailoverRpcUrl - self.upsertNetwork(network) - + if self.upsertNetwork(network): + self.events.emit(SIGNAL_NETWORK_ENDPOINT_UPDATED, NetworkEndpointUpdatedArgs(isTest: network.isTest, networkName: network.chainName)) diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index e26906fdc1..efaba0496c 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -47,6 +47,9 @@ type SettingProfilePictureArgs* = ref object of Args value*: int + SettingsBoolValueArgs* = ref object of Args + value*: bool + QtObject: type Service* = ref object of QObject events: EventEmitter @@ -974,4 +977,4 @@ QtObject: let newValue = not self.settings.includeWatchOnlyAccount if(self.saveSetting(INCLUDE_WATCH_ONLY_ACCOUNT, newValue)): self.settings.includeWatchOnlyAccount = newValue - self.events.emit(SIGNAL_INCLUDE_WATCH_ONLY_ACCOUNTS_UPDATED, Args()) + self.events.emit(SIGNAL_INCLUDE_WATCH_ONLY_ACCOUNTS_UPDATED, SettingsBoolValueArgs(value: newValue)) diff --git a/ui/app/AppLayouts/Profile/stores/WalletStore.qml b/ui/app/AppLayouts/Profile/stores/WalletStore.qml index 27416f6360..24c9312d3a 100644 --- a/ui/app/AppLayouts/Profile/stores/WalletStore.qml +++ b/ui/app/AppLayouts/Profile/stores/WalletStore.qml @@ -108,4 +108,30 @@ QtObject { function copyToClipboard(textToCopy) { globalUtils.copyToClipboard(textToCopy) } + + function getNetworkData(combinedNetwork) { + return { + prod: {chainId: combinedNetwork.prod.chainId, + layer: combinedNetwork.prod.layer, + chainName: combinedNetwork.prod.chainName, + iconUrl: combinedNetwork.prod.iconUrl, + shortName: combinedNetwork.prod.shortName, + chainColor: combinedNetwork.prod.chainColor, + rpcURL: combinedNetwork.prod.rpcURL, + fallbackURL: combinedNetwork.prod.fallbackURL, + blockExplorerURL: combinedNetwork.prod.blockExplorerURL, + nativeCurrencySymbol: combinedNetwork.prod.nativeCurrencySymbol}, + test: {chainId: combinedNetwork.test.chainId, + layer: combinedNetwork.test.layer, + chainName: combinedNetwork.test.chainName, + iconUrl: combinedNetwork.test.iconUrl, + shortName: combinedNetwork.test.shortName, + chainColor: combinedNetwork.test.chainColor, + rpcURL: combinedNetwork.test.rpcURL, + fallbackURL: combinedNetwork.test.fallbackURL, + blockExplorerURL: combinedNetwork.test.blockExplorerURL, + nativeCurrencySymbol: combinedNetwork.test.nativeCurrencySymbol}, + layer: combinedNetwork.layer + } + } } diff --git a/ui/app/AppLayouts/Profile/views/WalletView.qml b/ui/app/AppLayouts/Profile/views/WalletView.qml index 72c8849c99..35b2ec7c1d 100644 --- a/ui/app/AppLayouts/Profile/views/WalletView.qml +++ b/ui/app/AppLayouts/Profile/views/WalletView.qml @@ -145,7 +145,10 @@ SettingsContentBase { Layout.fillWidth: true networksModule: root.walletStore.networksModule onEvaluateRpcEndPoint: root.walletStore.evaluateRpcEndPoint(url) - onUpdateNetworkValues: root.walletStore.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl) + onUpdateNetworkValues: { + root.walletStore.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl) + stackContainer.currentIndex = networksViewIndex + } } AccountOrderView { diff --git a/ui/app/AppLayouts/Profile/views/wallet/EditNetworkView.qml b/ui/app/AppLayouts/Profile/views/wallet/EditNetworkView.qml index dcd0f9c30d..7b23c07021 100644 --- a/ui/app/AppLayouts/Profile/views/wallet/EditNetworkView.qml +++ b/ui/app/AppLayouts/Profile/views/wallet/EditNetworkView.qml @@ -28,22 +28,25 @@ ColumnLayout { } } - StackLayout { - id: stackLayout - Layout.preferredHeight: currentIndex === 0 ? editLiveNetwork.height: editTestNetwork.height + Loader { Layout.fillWidth: true - currentIndex: editPreviwTabBar.currentIndex + active: root.visible + sourceComponent: editPreviwTabBar.currentIndex === 0 ? editLiveNetwork: editTestNetwork + } + Component { + id: editLiveNetwork EditNetworkForm { - id: editLiveNetwork network: !!root.combinedNetwork ? root.combinedNetwork.prod: null networksModule: root.networksModule onEvaluateRpcEndPoint: root.evaluateRpcEndPoint(url) onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl) } + } + Component { + id: editTestNetwork EditNetworkForm { - id: editTestNetwork network: !!root.combinedNetwork ? root.combinedNetwork.test: null networksModule: root.networksModule onEvaluateRpcEndPoint: root.evaluateRpcEndPoint(url) diff --git a/ui/app/AppLayouts/Profile/views/wallet/NetworksView.qml b/ui/app/AppLayouts/Profile/views/wallet/NetworksView.qml index 564e2d44aa..10bd81c46f 100644 --- a/ui/app/AppLayouts/Profile/views/wallet/NetworksView.qml +++ b/ui/app/AppLayouts/Profile/views/wallet/NetworksView.qml @@ -42,7 +42,7 @@ Item { delegate: WalletNetworkDelegate { network: areTestNetworksEnabled ? model.test: model.prod areTestNetworksEnabled: walletStore.areTestNetworksEnabled - onClicked: editNetwork(model) + onClicked: editNetwork(walletStore.getNetworkData(model)) } } @@ -70,7 +70,7 @@ Item { delegate: WalletNetworkDelegate { network: areTestNetworksEnabled ? model.test: model.prod areTestNetworksEnabled: walletStore.areTestNetworksEnabled - onClicked: editNetwork(model) + onClicked: editNetwork(walletStore.getNetworkData(model)) } } diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index 1b35472688..2d389474d1 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -99,7 +99,7 @@ Item { Global.displayToastMessage( qsTr("\"%1\" successfuly added").arg(name), "", - "check-circle", + "checkmark-circle", false, Constants.ephemeralNotificationType.success, "" @@ -110,12 +110,33 @@ Item { Global.displayToastMessage( qsTr("You successfully renamed your keypair\nfrom \"%1\" to \"%2\"").arg(oldName).arg(newName), "", - "check-circle", + "checkmark-circle", false, Constants.ephemeralNotificationType.success, "" ) } + + function onShowNetworkEndpointUpdated(name: string, isTest: bool) { + Global.displayToastMessage( + isTest ? qsTr("Test network settings for %1 updated").arg(name): qsTr("Live network settings for %1 updated").arg(name), + "", + "checkmark-circle", + false, + Constants.ephemeralNotificationType.success, + "" + ) + } + + function onShowIncludeWatchOnlyAccountUpdated(includeWatchOnly: bool) { + Global.displayToastMessage( + includeWatchOnly ? qsTr("Your wallet’s total balance will now include balances of watched addresses") : qsTr("Your wallet’s total balance will not include balances of watched addresses") , + "", + "checkmark-circle", + false, + Constants.ephemeralNotificationType.success, + "") + } } QtObject { diff --git a/vendor/status-go b/vendor/status-go index 1f510eae70..a63e417f9f 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 1f510eae70f00c6daab8eed7395b7fbf4332755e +Subproject commit a63e417f9f6c779300f35b51998770742f5e363f