Skip to content

Commit

Permalink
Merge pull request #787 from cosmos/fabo/777-fix-blocks-after-switch
Browse files Browse the repository at this point in the history
Fabo/777 fix blocks not showing after switching the network
  • Loading branch information
nylira authored Jun 5, 2018
2 parents 518e5cb + ad4d5a1 commit f6e3c60
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]


### Changes

* Disabled error reporting in development @faboweb
Expand All @@ -16,6 +15,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

* Persisting e2e failure screenshots as artifact on circleci @faboweb

### Fixed

* Blocks not updating in block explorer when switching network @faboweb

## [0.6.2] - 2018-05-23

### Added
Expand Down
2 changes: 2 additions & 0 deletions app/src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ async function main() {
})

firstStart = false
} else {
store.dispatch("reconnected")
}
})

Expand Down
2 changes: 2 additions & 0 deletions app/src/renderer/vuex/modules/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default ({ commit, node }) => {
if (state.blockLoading) {
dispatch("getBlock", state.blockHeight)
}
//on a reconnect we assume, that the rpc connector changed, so we can safely resubscribe to blocks
state.subscription = false
dispatch("subscribeToBlocks")
},
async getBlock({ state, commit, dispatch }, height) {
Expand Down
10 changes: 7 additions & 3 deletions app/src/renderer/vuex/modules/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export default function({ node }) {
}

const actions = {
reconnected({ commit, dispatch }) {
dispatch("rpcSubscribe")
},
setLastHeader({ state, rootState, dispatch }, header) {
state.lastHeader = header

Expand Down Expand Up @@ -137,6 +134,10 @@ export default function({ node }) {
async setMockedConnector({ state, dispatch, commit }, mocked) {
state.mocked = mocked

// IDEA let's have an event 'networkSwitched' and bundle those action under this one
// remove blocks from block explorer as it should not show blocks of another network
commit("setBlocks", [])

// disable updates from the live node
node.rpcDisconnect()

Expand All @@ -150,6 +151,9 @@ export default function({ node }) {
// if we run a mocked version only, we don't want the lcd to run in the meantime
ipcRenderer.send("stop-lcd")

// we need to trigger this event for the mocked mode as it is usually triggered by the "connected" event from the main thread
dispatch("rpcSubscribe")

// the mocked node is automatically connected
dispatch("reconnected")
} else {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/specs/store/node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,16 @@ describe("Module: Node", () => {
expect(store.state.config.modals.session.state).toBe("loading")
expect(store.state.user.signedIn).toBe(false)
})

it("should reset blocks in explorer if switched mocked mode", () => {
store.state.blockchain.blocks = [
{
x: "y"
}
]

store.dispatch("setMockedConnector", true)

expect(store.state.blockchain.blocks).toEqual([])
})
})

0 comments on commit f6e3c60

Please sign in to comment.