feat(@desktop/wallet2): Toggle network

This commit is contained in:
Anthony Laibe 2021-09-23 16:40:05 +02:00 committed by Iuri Matias
parent 6e3ac7d5dc
commit 1cea69b331
7 changed files with 29 additions and 6 deletions

View File

@ -40,7 +40,7 @@ QtObject:
result.accountsView = newAccountsView(status)
result.collectiblesView = newCollectiblesView(status, appService)
result.settingsView = newSettingsView()
result.networksView = newNetworksView()
result.networksView = newNetworksView(status)
result.cryptoServiceController = newCryptoServiceController(status, appService)
result.savedAddressesView = newSavedAddressesView(status, appService)
result.setup

View File

@ -1,6 +1,6 @@
import NimQml, chronicles, sequtils, sugar
from status/types/network import Network, `$`
import status/[status, wallet2]
import ./network_list
logScope:
@ -8,14 +8,16 @@ logScope:
QtObject:
type NetworksView* = ref object of QObject
status: Status
allNetworks: NetworkList
enabledNetworks: NetworkList
proc setup(self: NetworksView) = self.QObject.setup
proc delete(self: NetworksView) = self.QObject.delete
proc newNetworksView*(): NetworksView =
proc newNetworksView*(status: Status): NetworksView =
new(result, delete)
result.status = status
result.allNetworks = newNetworkList()
result.enabledNetworks = newNetworkList()
result.setup
@ -35,3 +37,10 @@ QtObject:
QtProperty[QVariant] enabledNetworks:
read = getEnabledNetworks
proc toggleNetwork(self: NetworksView, chainId: int) {.slot.} =
for network in self.allNetworks.networks:
if network.chainId == chainId:
self.status.wallet2.toggleNetwork(network)
self.updateNetworks(self.status.wallet2.networks)
break

View File

@ -97,6 +97,9 @@ Item {
qrCode: walletView.store.profileModelInst.qrCode(walletView.store.selectedAccount.address)
allNetworksModel: walletView.store.walletModelV2Inst.networksView.allNetworks
enabledNetworksModel: walletView.store.walletModelV2Inst.networksView.enabledNetworks
onToggleNetwork: {
walletView.store.walletModelV2Inst.networksView.toggleNetwork(chainId)
}
onCopyText: {
walletView.store.copyText(text);
}

View File

@ -9,6 +9,7 @@ Item {
height: childrenRect.height
property var allNetworks
property var enabledNetworks
signal toggleNetwork(int chainId)
Rectangle {
id: selectRectangle
@ -65,5 +66,8 @@ Item {
x: (parent.width - width)
y: (root.height - networkFilterPanel.height)
model: root.allNetworks
onToggleNetwork: {
root.toggleNetwork(chainId)
}
}
}

View File

@ -21,6 +21,7 @@ Item {
property var enabledNetworksModel
property var allNetworksModel
signal copyText(string text)
signal toggleNetwork(int chainId)
Row {
id: accountRow
@ -78,6 +79,9 @@ Item {
anchors.right: parent.right
allNetworks: walletHeader.allNetworksModel
enabledNetworks: walletHeader.enabledNetworksModel
onToggleNetwork: {
walletHeader.toggleNetwork(chainId)
}
}
Component {

View File

@ -14,6 +14,7 @@ Popup {
height: 432
closePolicy: Popup.CloseOnEscape
property var model
signal toggleNetwork(int chainId)
background: Rectangle {
radius: Style.current.radius
@ -65,7 +66,9 @@ Popup {
anchors.verticalCenter: parent.verticalCenter
checked: model.enabled
onCheckedChanged: {
console.log("TODO: Not yet implemented")
if(checked !== model.enabled){
popup.toggleNetwork(model.chainId)
}
}
}
}

2
vendor/status-lib vendored

@ -1 +1 @@
Subproject commit c07e04e976f46edc72077b4095001afd10170a6a
Subproject commit fe7e74459ed3cb7601087db3e16931f06ed36ad0