-
Notifications
You must be signed in to change notification settings - Fork 100
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
Handle Node Sync in Block Explorer #587
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cbf7ef2
Added title prop to NiDataLoading
mappum a8c51df
Don't subscribe to NewBlock events unless full node is synced
mappum f10da17
Added 'Node is syncing...' dialog to PageBlocks
mappum 9e9ab28
Added test cases
mappum e7b1026
Merge branch 'develop' into matt/553-handle-node-sync
faboweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
<template lang="pug"> | ||
data-msg(icon="rotate_right" spin="true") | ||
div(slot="title") Data is loading… | ||
div(slot="title") {{ title }} | ||
div(slot="subtitle") Please wait a moment. | ||
</template> | ||
|
||
<script> | ||
import DataMsg from 'common/NiDataMsg' | ||
export default { | ||
name: 'ni-data-loading', | ||
components: { DataMsg } | ||
components: { DataMsg }, | ||
props: { | ||
title: { | ||
type: String, | ||
default: 'Data is loading…' | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ export default ({ commit, node }) => { | |
blockHeight: null, // we remember the height so we can requery the block, if querying failed | ||
blockLoading: false, | ||
subscription: false, | ||
syncing: true, | ||
blockMetas: [] | ||
} | ||
|
||
|
@@ -69,21 +70,39 @@ export default ({ commit, node }) => { | |
blockMetaInfo && state.blockMetas.push(blockMetaInfo) | ||
return blockMetaInfo | ||
}, | ||
subscribeToBlocks ({ commit }) { | ||
node.rpc.subscribe({ query: "tm.event = 'NewBlock'" }, (err, event) => { | ||
state.subscription = true | ||
subscribeToBlocks ({ state, commit, dispatch }) { | ||
// ensure we never subscribe twice | ||
if (state.subscription) return | ||
|
||
if (err) { | ||
function error (err) { | ||
state.subscription = false | ||
commit('notifyError', { title: `Error subscribing to new blocks`, body: err.message }) | ||
} | ||
|
||
node.rpc.status((err, status) => { | ||
if (err) return error(err) | ||
|
||
if (status.syncing) { | ||
// still syncing, let's try subscribing again in 30 seconds | ||
state.syncing = true | ||
state.subscription = false | ||
commit('notifyError', { title: `Error subscribing to new blocks`, body: err.message }) | ||
setTimeout(() => dispatch('subscribeToBlocks'), 30e3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 30e3? never seen that before. can't find anything on google about it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scientific notation for 30000, maybe I should do |
||
return | ||
} | ||
|
||
state.blocks.unshift(event.data.data.block) | ||
state.syncing = false | ||
|
||
if (state.blocks.length === 20) { | ||
state.blocks.pop() | ||
} | ||
node.rpc.subscribe({ query: "tm.event = 'NewBlock'" }, (err, event) => { | ||
state.subscription = true | ||
|
||
if (err) return error(err) | ||
|
||
state.blocks.unshift(event.data.data.block) | ||
|
||
if (state.blocks.length === 20) { | ||
state.blocks.pop() | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea