feat(@desktop/wallet): Wallet Setting: New designs for edit network settings

fixes #11751
This commit is contained in:
Khushboo Mehta 2023-10-06 14:33:33 +02:00 committed by Khushboo-dev-cpp
parent 18c37fbdac
commit 601be63774
12 changed files with 58 additions and 47 deletions

View File

@ -445,7 +445,7 @@ proc connectForNotificationsOnly[T](self: Module[T]) =
self.events.on(SIGNAL_NETWORK_ENDPOINT_UPDATED) do(e: Args):
let args = NetworkEndpointUpdatedArgs(e)
self.view.showNetworkEndpointUpdated(args.networkName, args.isTest)
self.view.showNetworkEndpointUpdated(args.networkName, args.isTest, args.revertedToDefault)
self.events.on(SIGNAL_INCLUDE_WATCH_ONLY_ACCOUNTS_UPDATED) do(e: Args):
let args = SettingsBoolValueArgs(e)
@ -1490,4 +1490,4 @@ method insertMockedKeycardAction*[T](self: Module[T], cardIndex: int) =
self.keycardService.insertMockedKeycardAction(cardIndex)
method removeMockedKeycardAction*[T](self: Module[T]) =
self.keycardService.removeMockedKeycardAction()
self.keycardService.removeMockedKeycardAction()

View File

@ -59,5 +59,5 @@ proc toggleIsSepoliaEnabled*(self: Controller) =
proc fetchChainIdForUrl*(self: Controller, url: string, isMainUrl: bool) =
self.walletAccountService.fetchChainIdForUrl(url, isMainUrl)
proc updateNetworkEndPointValues*(self: Controller, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) =
self.networkService.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
proc updateNetworkEndPointValues*(self: Controller, chainId: int, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) =
self.networkService.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault)

View File

@ -31,7 +31,7 @@ method toggleIsSepoliaEnabled*(self: AccessInterface) {.base.} =
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method updateNetworkEndPointValues*(self: AccessInterface, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) {.base.} =
method updateNetworkEndPointValues*(self: AccessInterface, chainId: int, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method fetchChainIdForUrl*(self: AccessInterface, url: string, isMainUrl: bool) {.base.} =

View File

@ -104,8 +104,8 @@ method toggleIsSepoliaEnabled*(self: Module) =
self.controller.toggleIsSepoliaEnabled()
self.refreshNetworks()
method updateNetworkEndPointValues*(self: Module, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) =
self.controller.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
method updateNetworkEndPointValues*(self: Module, chainId: int, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) =
self.controller.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault)
method fetchChainIdForUrl*(self: Module, url: string, isMainUrl: bool) =
self.controller.fetchChainIdForUrl(url, isMainUrl)

View File

@ -92,8 +92,8 @@ QtObject:
proc getNetworkShortNames*(self: View, preferredNetworks: string): string {.slot.} =
return self.combinedNetworks.getNetworkShortNames(preferredNetworks, self.areTestNetworksEnabled)
proc updateNetworkEndPointValues*(self: View, chainId: int, newMainRpcInput: string, newFailoverRpcUrl: string) {.slot.} =
self.delegate.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
proc updateNetworkEndPointValues*(self: View, chainId: int, newMainRpcInput: string, newFailoverRpcUrl: string, revertToDefault: bool) {.slot.} =
self.delegate.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault)
proc fetchChainIdForUrl*(self: View, url: string, isMainUrl: bool) {.slot.} =
self.delegate.fetchChainIdForUrl(url, isMainUrl)

View File

@ -292,7 +292,7 @@ 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 showNetworkEndpointUpdated*(self: View, name: string, isTest: bool, revertedToDefault: bool) {.signal.}
proc showIncludeWatchOnlyAccountUpdated*(self: View, includeWatchOnly: bool) {.signal.}
proc showToastKeypairRemoved*(self: View, keypairName: string) {.signal.}
proc showToastKeypairsImported*(self: View, keypairName: string, keypairsCount: int, error: string) {.signal.}

View File

@ -16,6 +16,7 @@ const SIGNAL_NETWORK_ENDPOINT_UPDATED* = "networkEndPointUpdated"
type NetworkEndpointUpdatedArgs* = ref object of Args
isTest*: bool
networkName*: string
revertedToDefault*: bool
type
Service* = ref object of RootObj
@ -169,7 +170,7 @@ proc getNetworkForCollectibles*(self: Service): NetworkDto =
return self.getNetwork(Mainnet)
proc updateNetworkEndPointValues*(self: Service, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) =
proc updateNetworkEndPointValues*(self: Service, chainId: int, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) =
let network = self.getNetworkByChainId(chainId)
if network.rpcURL == newMainRpcInput and network.fallbackURL == newFailoverRpcUrl:
@ -182,4 +183,4 @@ proc updateNetworkEndPointValues*(self: Service, chainId: int, newMainRpcInput,
network.fallbackURL = newFailoverRpcUrl
if self.upsertNetwork(network):
self.events.emit(SIGNAL_NETWORK_ENDPOINT_UPDATED, NetworkEndpointUpdatedArgs(isTest: network.isTest, networkName: network.chainName))
self.events.emit(SIGNAL_NETWORK_ENDPOINT_UPDATED, NetworkEndpointUpdatedArgs(isTest: network.isTest, networkName: network.chainName, revertedToDefault: revertToDefault))

View File

@ -77,8 +77,8 @@ QtObject {
return networksModule.fetchChainIdForUrl(url, isMainUrl)
}
function updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl) {
networksModule.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
function updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault) {
networksModule.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault)
}
function updateWalletAccountPreferredChains(address, preferredChainIds) {

View File

@ -154,7 +154,7 @@ SettingsContentBase {
networksModule: root.walletStore.networksModule
onEvaluateRpcEndPoint: root.walletStore.evaluateRpcEndPoint(url, isMainUrl)
onUpdateNetworkValues: {
root.walletStore.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
root.walletStore.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault)
stackContainer.currentIndex = networksViewIndex
}
}

View File

@ -14,7 +14,7 @@ ColumnLayout {
property var network
property var networksModule
signal evaluateRpcEndPoint(string url, bool isMainUrl)
signal updateNetworkValues(int chainId, string newMainRpcInput, string newFailoverRpcUrl)
signal updateNetworkValues(int chainId, string newMainRpcInput, string newFailoverRpcUrl, bool revertToDefault)
enum EvaluationState {
UnTouched,
@ -23,6 +23,7 @@ ColumnLayout {
InvalidURL,
PingUnsuccessful,
SameAsOther,
NotSameChain,
Empty
}
@ -42,12 +43,8 @@ ColumnLayout {
})
function revertValues() {
warningCheckbox.checked = false
d.evaluationStatusMainRpc = EditNetworkForm.UnTouched
d.evaluationStatusFallBackRpc = EditNetworkForm.UnTouched
if(!!network) {
mainRpcInput.text = d.mask(network.originalRpcURL)
failoverRpcUrlInput.text = d.mask(network.originalFallbackURL)
root.updateNetworkValues(network.chainId, network.originalRpcURL, network.originalFallbackURL, true)
}
}
@ -63,6 +60,8 @@ ColumnLayout {
return qsTr("RPC successfully reached")
case EditNetworkForm.SameAsOther:
return qsTr("Main and failover JSON RPC URLs are the same")
case EditNetworkForm.NotSameChain:
return qsTr("Chain ID returned from JSON RPC doesnt match %1").arg(network.chainName)
default: return ""
}
}
@ -72,6 +71,7 @@ ColumnLayout {
case EditNetworkForm.Pending:
return Theme.palette.baseColor1
case EditNetworkForm.SameAsOther:
case EditNetworkForm.NotSameChain:
return Theme.palette.warningColor1
case EditNetworkForm.Verified:
return Theme.palette.successColor1
@ -84,6 +84,7 @@ ColumnLayout {
case EditNetworkForm.Pending:
case EditNetworkForm.Verified:
case EditNetworkForm.SameAsOther:
case EditNetworkForm.NotSameChain:
return Text.AlignLeft
default: return Text.AlignRight
}
@ -97,14 +98,15 @@ ColumnLayout {
}
}
onVisibleChanged: if(!visible) {d.revertValues()}
Connections {
target: networksModule
function onChainIdFetchedForUrl(url, chainId, success, isMainUrl) {
let status = EditNetworkForm.PingUnsuccessful
if(success) {
if((isMainUrl && url === network.fallbackURL) ||
if (network.chainId !== chainId) {
status = EditNetworkForm.NotSameChain
}
else if((isMainUrl && url === network.fallbackURL) ||
(!isMainUrl && url === network.rpcURL)) {
status = EditNetworkForm.SameAsOther
}
@ -185,14 +187,14 @@ ColumnLayout {
d.evaluationStatusMainRpc = EditNetworkForm.Empty
return
}
if (!!text && d.mask(network.originalRpcURL) === text) {
d.evaluationStatusMainRpc = EditNetworkForm.Verified
}
if(!!text && d.mask(network.originalRpcURL) !== text) {
d.evaluationStatusMainRpc = EditNetworkForm.Pending
Qt.callLater(d.evaluateRpcEndPoint, text, true);
else {
if ((d.mask(network.originalRpcURL) === text) ||
(network.rpcURL === text)) {
d.evaluationStatusMainRpc = EditNetworkForm.UnTouched
} else {
d.evaluationStatusMainRpc = EditNetworkForm.Pending
Qt.callLater(d.evaluateRpcEndPoint, text, true);
}
}
}
errorMessageCmp.horizontalAlignment: d.getErrorMessageAlignment(d.evaluationStatusMainRpc)
@ -228,14 +230,14 @@ ColumnLayout {
d.evaluationStatusFallBackRpc = EditNetworkForm.Empty
return
}
if (!!text && d.mask(network.originalFallbackURL) === text) {
d.evaluationStatusFallBackRpc = EditNetworkForm.Verified
}
if(!!text && d.mask(network.originalFallbackURL) !== text) {
d.evaluationStatusFallBackRpc = EditNetworkForm.Pending
Qt.callLater(d.evaluateRpcEndPoint, text, false);
else {
if ((d.mask(network.originalFallbackURL) === text) ||
(network.fallbackURL === text)) {
d.evaluationStatusFallBackRpc = EditNetworkForm.UnTouched
} else {
d.evaluationStatusFallBackRpc = EditNetworkForm.Pending
Qt.callLater(d.evaluateRpcEndPoint, text, false);
}
}
}
errorMessageCmp.horizontalAlignment: d.getErrorMessageAlignment(d.evaluationStatusFallBackRpc)
@ -270,6 +272,8 @@ ColumnLayout {
objectName: "editNetworkRevertButton"
text: qsTr("Revert to default")
normalColor: "transparent"
enabled: (failoverRpcUrlInput.text !== d.mask(network.originalFallbackURL)) ||
(mainRpcInput.text !== d.mask(network.originalRpcURL))
onClicked: d.revertValues()
}
StatusButton {
@ -280,7 +284,10 @@ ColumnLayout {
d.evaluationStatusFallBackRpc === EditNetworkForm.Verified ||
d.evaluationStatusMainRpc === EditNetworkForm.SameAsOther ||
d.evaluationStatusFallBackRpc === EditNetworkForm.SameAsOther ||
d.evaluationStatusFallBackRpc === EditNetworkForm.Empty
d.evaluationStatusMainRpc === EditNetworkForm.Empty ||
d.evaluationStatusFallBackRpc === EditNetworkForm.Empty ||
d.evaluationStatusMainRpc === EditNetworkForm.NotSameChain ||
d.evaluationStatusFallBackRpc === EditNetworkForm.NotSameChain
) && warningCheckbox.checked
onClicked: {
@ -293,7 +300,7 @@ ColumnLayout {
if (fallback === d.mask(network.originalFallbackURL)) {
fallback = network.originalFallbackURL
}
root.updateNetworkValues(network.chainId, main, fallback)
root.updateNetworkValues(network.chainId, main, fallback, false)
}
}
}

View File

@ -14,7 +14,7 @@ ColumnLayout {
property var combinedNetwork
signal evaluateRpcEndPoint(string url, bool isMainUrl)
signal updateNetworkValues(int chainId, string newMainRpcInput, string newFailoverRpcUrl)
signal updateNetworkValues(int chainId, string newMainRpcInput, string newFailoverRpcUrl, bool revertToDefault)
StatusTabBar {
id: editPreviwTabBar
@ -45,7 +45,7 @@ ColumnLayout {
network: !!root.combinedNetwork ? root.combinedNetwork.prod: null
networksModule: root.networksModule
onEvaluateRpcEndPoint: root.evaluateRpcEndPoint(url, isMainUrl)
onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl)
onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault)
}
}
@ -55,7 +55,7 @@ ColumnLayout {
network: !!root.combinedNetwork ? root.combinedNetwork.test: null
networksModule: root.networksModule
onEvaluateRpcEndPoint: root.evaluateRpcEndPoint(url, isMainUrl)
onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl)
onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault)
}
}
}

View File

@ -127,9 +127,12 @@ Item {
)
}
function onShowNetworkEndpointUpdated(name: string, isTest: bool) {
function onShowNetworkEndpointUpdated(name: string, isTest: bool, revertToDefault: bool) {
let mainText = revertToDefault ?
(isTest ? qsTr("Test network settings for %1 reverted to default").arg(name): qsTr("Live network settings for %1 reverted to default").arg(name)):
(isTest ? qsTr("Test network settings for %1 updated").arg(name): qsTr("Live network settings for %1 updated").arg(name))
Global.displayToastMessage(
isTest ? qsTr("Test network settings for %1 updated").arg(name): qsTr("Live network settings for %1 updated").arg(name),
mainText,
"",
"checkmark-circle",
false,