Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/WC - handling lost connections in wallet connect #16580

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/app/modules/main/network_connection/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ QtObject:
case website:
of BLOCKCHAINS:
self.blockchainNetworkConnection.updateValues(completelyDown, connectionState, chainIds, lastCheckedAt)
self.blockchainNetworkConnectionChanged()
of COLLECTIBLES:
self.collectiblesNetworkConnection.updateValues(completelyDown, connectionState, chainIds, lastCheckedAt)
self.collectiblesNetworkConnectionChanged()
of MARKET:
self.marketValuesNetworkConnection.updateValues(completelyDown, connectionState, chainIds, lastCheckedAt)
self.marketValuesNetworkConnectionChanged()
self.networkConnectionStatusUpdate(website, completelyDown, connectionState, chainIds, float(lastCheckedAt))

10 changes: 10 additions & 0 deletions storybook/pages/DAppsWorkflowPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Item {
accountsModel: wcService.validAccounts
networksModel: wcService.flatNetworks
sessionRequestsModel: wcService.sessionRequestsModel
enabled: wcService.isServiceOnline

//formatBigNumber: (number, symbol, noSymbolOption) => wcService.walletRootStore.currencyStore.formatBigNumber(number, symbol, noSymbolOption)

Expand Down Expand Up @@ -200,6 +201,13 @@ Item {
}
}

StatusBaseText { text: "Networks Down" }

NetworkFilter {
id: networkFilter
flatNetworks: walletConnectService.walletRootStore.filteredFlatModel
}

// spacer
ColumnLayout {}

Expand Down Expand Up @@ -337,6 +345,8 @@ Item {
projectId: projectIdText.projectId
}

blockchainNetworksDown: networkFilter.selection

store: SharedStores.DAppsStore {
signal dappsListReceived(string dappsJson)
signal userAuthenticated(string topic, string id, string password, string pin)
Expand Down
132 changes: 132 additions & 0 deletions storybook/qmlTests/tests/tst_ChainsAvailabilityWatchdog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import QtQuick 2.15

import QtTest 1.15

import AppLayouts.Wallet.helpers 1.0

Item {
id: root

width: 600
height: 400

Component {
id: chainsAvailabilityWatchdogComponent
ChainsAvailabilityWatchdog {
id: chainsAvailabilityWatchdog
readonly property SignalSpy chainOnlineChangedSpy: SignalSpy { target: chainsAvailabilityWatchdog; signalName: "chainOnlineChanged" }
networksModel: ListModel {
ListElement {
chainId: 1
isOnline: true
}
ListElement {
chainId: 2
isOnline: true
}
}
}
}

TestCase {
id: chainsAvailabilityWatchdogTest
name: "ChainsAvailabilityWatchdog"

property ChainsAvailabilityWatchdog componentUnderTest: null

function init() {
componentUnderTest = chainsAvailabilityWatchdogComponent.createObject(root)
componentUnderTest.chainOnlineChangedSpy.clear()
}

function test_initAllOnline() {
tryVerify(() => componentUnderTest.allOnline)
tryVerify(() => !componentUnderTest.allOffline)
}

function test_chainOnlineChanged() {
componentUnderTest.networksModel.setProperty(0, "isOnline", false)

tryVerify(() => !componentUnderTest.allOnline)
tryVerify(() => !componentUnderTest.allOffline)
compare(componentUnderTest.chainOnlineChangedSpy.count, 1)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[0][0], 1)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[0][1], false)
}

function test_allOffline() {
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
componentUnderTest.networksModel.setProperty(1, "isOnline", false)

tryVerify(() => !componentUnderTest.allOnline)
tryVerify(() => componentUnderTest.allOffline)

compare(componentUnderTest.chainOnlineChangedSpy.count, 2)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[0][0], 1)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[0][1], false)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[1][0], 2)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[1][1], false)
}

function test_emptyModel() {
componentUnderTest.networksModel.clear()

tryVerify(() => !componentUnderTest.allOnline)
tryVerify(() => componentUnderTest.allOffline)
}

function test_modelChanges() {
tryVerify(() => componentUnderTest.allOnline)
tryVerify(() => !componentUnderTest.allOffline)

componentUnderTest.networksModel.append({ chainId: 3, isOnline: false })

compare(componentUnderTest.allOnline, false)
compare(componentUnderTest.allOffline, false)
compare(componentUnderTest.chainOnlineChangedSpy.count, 1)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[0][0], 3)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[0][1], false)
}

function test_modelChanges2() {
tryVerify(() => componentUnderTest.allOnline)
tryVerify(() => !componentUnderTest.allOffline)

componentUnderTest.networksModel.append({ chainId: 3, isOnline: true })

compare(componentUnderTest.allOnline, true)
compare(componentUnderTest.allOffline, false)
compare(componentUnderTest.chainOnlineChangedSpy.count, 1)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[0][0], 3)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[0][1], true)
}

function test_modelChangesWhileOffline() {
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
componentUnderTest.networksModel.setProperty(1, "isOnline", false)

tryVerify(() => !componentUnderTest.allOnline)
tryVerify(() => componentUnderTest.allOffline)

componentUnderTest.networksModel.append({ chainId: 3, isOnline: false })

compare(componentUnderTest.allOnline, false)
compare(componentUnderTest.allOffline, true)
compare(componentUnderTest.chainOnlineChangedSpy.count, 3)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[0][0], 1)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[0][1], false)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[1][0], 2)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[1][1], false)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[2][0], 3)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[2][1], false)

componentUnderTest.networksModel.setProperty(2, "isOnline", true)

tryVerify(() => !componentUnderTest.allOnline)
tryVerify(() => !componentUnderTest.allOffline)
compare(componentUnderTest.chainOnlineChangedSpy.count, 4)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[3][0], 3)
compare(componentUnderTest.chainOnlineChangedSpy.signalArguments[3][1], true)
}
}
}
Loading