feat(@desktop/wallet): Wallet settings - Notification after each action

fixes #11719
This commit is contained in:
Khushboo Mehta 2023-08-07 20:47:16 +02:00 committed by Khushboo-dev-cpp
parent a06cd4b8a5
commit 11820d0400
13 changed files with 110 additions and 25 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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()

View File

@ -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.} =

View File

@ -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.}

View File

@ -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))

View File

@ -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))

View File

@ -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
}
}
}

View File

@ -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 {

View File

@ -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)

View File

@ -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))
}
}

View File

@ -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 wallets total balance will now include balances of watched addresses") : qsTr("Your wallets total balance will not include balances of watched addresses") ,
"",
"checkmark-circle",
false,
Constants.ephemeralNotificationType.success,
"")
}
}
QtObject {

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 1f510eae70f00c6daab8eed7395b7fbf4332755e
Subproject commit a63e417f9f6c779300f35b51998770742f5e363f