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

Fabo/1199 improve jank at start #1216

Merged
merged 48 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
da0480b
added native menu for versions
Aug 30, 2018
e47355b
remove about from view
Aug 30, 2018
be87061
changelog
Aug 30, 2018
e3c09c6
Merge branch 'develop' into fabo/1138-show-about-menu
faboweb Aug 30, 2018
e9c2bbb
fixed tests
Aug 30, 2018
91e1ad5
linted and simplified
Aug 30, 2018
38419d8
Merge branch 'fabo/1138-show-about-menu' of https://github.com/cosmos…
Aug 30, 2018
90303bf
remove more about code
Aug 30, 2018
f4d4955
show correct voting power
Aug 30, 2018
2642e52
changelog
Aug 30, 2018
210d188
Merge remote-tracking branch 'origin/develop' into fabo/1207-fix-inco…
Aug 30, 2018
8071db3
extracted keybase and throttle updates to localstorage
Aug 30, 2018
1abce16
changelog
Aug 30, 2018
7de4e7e
Merge branch 'develop' into fabo/1199-improve-jank-at-start
faboweb Aug 30, 2018
8265ef8
fixed wallet tests
Aug 30, 2018
c7540b5
fixed tests
Aug 30, 2018
a2aed76
fixed tests
Sep 3, 2018
e154adb
added throttle tests
Sep 3, 2018
b9e59e1
removed check if state has loaded, as we are filtering mutations
Sep 3, 2018
bfd4404
updated snapshots
Sep 3, 2018
db24e64
skip loading validators at start
Sep 3, 2018
4a83535
linted
Sep 3, 2018
69285d0
fixed check for validators test
Sep 3, 2018
4d27f2c
Merge branch 'fabo/1199-improve-jank-at-start' of https://github.com/…
Sep 3, 2018
fcfae87
add in cart delegates to cache
Sep 3, 2018
75afc9c
fix moniker not showing
Sep 3, 2018
530abce
fix tests
Sep 3, 2018
37013b0
fixed page bond test
Sep 3, 2018
c189995
Merge branch 'develop' into fabo/1199-improve-jank-at-start
faboweb Sep 3, 2018
7f09233
add test for restoring committed delegations
Sep 3, 2018
305a66a
Merge branch 'fabo/1199-improve-jank-at-start' of https://github.com/…
Sep 3, 2018
74d88c6
handle issue with staking e2e tests
Sep 3, 2018
1e9b89f
fixed current atoms in pagebond not being updated right away
Sep 4, 2018
68f3b15
changelog
Sep 4, 2018
5a69633
fixed cache not restoring cart
Sep 4, 2018
6fdf2ce
increased coverage
Sep 4, 2018
8db9b3e
Merge branch 'develop' into fabo/1199-improve-jank-at-start
faboweb Sep 4, 2018
fb9bc87
fix showing undefined for bonding denom
Sep 4, 2018
b72875e
fix staked indicator
Sep 4, 2018
a46a34a
changelog
Sep 4, 2018
07b1a4a
fix wrong error showing on pagebond
Sep 4, 2018
9c317c3
changelog
Sep 4, 2018
c12de6b
removed querying for delegations after staking and relying on optimis…
Sep 4, 2018
3c1e45c
fixed bad test on pagebond
Sep 4, 2018
c6d8125
Merge branch 'fabo/1199-improve-jank-at-start' of https://github.com/…
Sep 4, 2018
07a3ade
readded updating validators after staking
Sep 4, 2018
5f46e73
fixed back pagebond snapshot
Sep 4, 2018
f35b03b
Merge branch 'develop' into fabo/1199-improve-jank-at-start
fedekunze Sep 4, 2018
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

* use correct set of seed nodes @ƒaboweb
* validator page showed incorrect voting power @faboweb
* improves poor performance at start by throttling the updates of the cached store @faboweb
* Run lint test in CI. @NodeGuy
* current atoms in PageBond still showed old atoms right after staking @ƒaboweb
* fix showing undefined for bonding denom in staking sucess message @faboweb
* fix not showing a lock (I have stake with this one) on a validator if stake is less then 1 @faboweb
* fix showing wrong error on pagebond validation @okwme

## [0.10.1] - 2018-08-29

Expand Down
1 change: 0 additions & 1 deletion app/networks

This file was deleted.

1 change: 1 addition & 0 deletions app/networks
Submodule networks added at 07c6bb
2 changes: 1 addition & 1 deletion app/src/renderer/components/staking/LiDelegate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
.li-delegate__value.status
span {{ delegateType }}
template(v-if="userCanDelegate")
.li-delegate__value.checkbox(v-if="yourVotes > 0")
.li-delegate__value.checkbox(v-if="committedDelegations[delegate.id]")
i.material-icons lock
.li-delegate__value.checkbox#remove-from-cart(v-else-if="inCart" @click='rm(delegate)')
i.material-icons check_box
Expand Down
8 changes: 4 additions & 4 deletions app/src/renderer/components/staking/PageBond.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ tm-page.page-bond(title="Staking")
:class="bondGroupClass(delta(d.atoms, d.oldAtoms))")
.bond-group__fields
.bond-bar
label.bond-bar__label(v-if="!d.delegate.revoked") {{ d.delegate.moniker }}
label.bond-bar__label.revoked(v-if="d.delegate.revoked") {{ d.delegate.moniker }}
label.bond-bar__label(v-if="!d.delegate.revoked") {{ d.delegate.description.moniker }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed monikers not showing

label.bond-bar__label.revoked(v-if="d.delegate.revoked") {{ d.delegate.description.moniker }}
label.bond-bar__revoked(v-if="d.delegate.revoked") REVOKED
.bond-bar__input
.bond-bar-old__outer
Expand Down Expand Up @@ -72,7 +72,7 @@ tm-page.page-bond(title="Staking")

tm-form-msg(:name="bondingDenom + 's'" type="required"
v-if="!$v.fields.delegates.$each[index].atoms.required")
tm-form-msg(name="bondingDenom + 's'" type="numeric"
tm-form-msg(:name="bondingDenom + 's'" type="numeric"
v-if="!$v.fields.delegates.$each[index].atoms.numeric")

.bond-group.bond-group--unbonding(
Expand Down Expand Up @@ -232,7 +232,7 @@ export default {
await this.$store.dispatch("submitDelegation", this.fields.delegates)
this.$store.commit("notify", {
title: "Successful Staking!",
body: `You have successfully staked your ${this.denom}s.`
body: `You have successfully staked your ${this.bondingDenom}s.`
})
this.$router.push("/staking")
} catch (err) {
Expand Down
4 changes: 3 additions & 1 deletion app/src/renderer/components/staking/PageStaking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export default {
"config",
"user",
"connected",
"bondingDenom"
"bondingDenom",
"keybase"
]),
address() {
return this.user.address
Expand All @@ -93,6 +94,7 @@ export default {
v.small_moniker = v.description.moniker.toLowerCase()
v.percent_of_vote = num.percent(v.voting_power / this.vpTotal)
v.your_votes = this.num.prettyInt(this.committedDelegations[v.id])
v.keybase = this.keybase[v.description.identity]
return v
})
},
Expand Down
7 changes: 5 additions & 2 deletions app/src/renderer/components/staking/PageValidator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ export default {
TmDataError
},
computed: {
...mapGetters(["delegates", "config"]),
...mapGetters(["delegates", "config", "keybase"]),
validator() {
return this.delegates.delegates.find(
let validator = this.delegates.delegates.find(
v => this.$route.params.validator === v.owner
)
if (validator)
validator.keybase = this.keybase[validator.description.identity]
return validator
},
selfBond() {
parseFloat(this.validator.tokens) -
Expand Down
1 change: 1 addition & 0 deletions app/src/renderer/vuex/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const committedDelegations = state => state.delegation.committedDelegates
export const delegates = state => state.delegates
export const shoppingCart = state => state.delegation.delegates
export const validators = state => state.validators.validators
export const keybase = state => state.keybase.identities

// govern
export const proposals = state => state.proposals
Expand Down
37 changes: 1 addition & 36 deletions app/src/renderer/vuex/modules/delegates.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import axios from "axios"

export default ({ node }) => {
const emptyState = {
delegates: [],
Expand Down Expand Up @@ -38,16 +36,6 @@ export default ({ node }) => {
}

state.delegates.push(delegate)
},
setKeybaseIdentity(
state,
{ validatorOwner, avatarUrl, profileUrl, userName }
) {
let validator = state.delegates.find(v => v.owner === validatorOwner)
if (!validator.keybase) validator.keybase = {}
validator.keybase.avatarUrl = avatarUrl
validator.keybase.profileUrl = profileUrl
validator.keybase.userName = userName
}
}

Expand All @@ -73,32 +61,9 @@ export default ({ node }) => {

commit("setDelegates", candidates)
commit("setDelegateLoading", false)
dispatch("updateValidatorAvatars")
dispatch("getKeybaseIdentities", candidates)

return state.delegates
},
async updateValidatorAvatars({ state, commit }) {
return Promise.all(
state.delegates.map(async validator => {
if (validator.description.identity && !validator.keybase) {
let urlPrefix =
"https://keybase.io/_/api/1.0/user/lookup.json?key_suffix="
let fullUrl = urlPrefix + validator.description.identity
let json = await axios.get(fullUrl)
if (json.data.status.name === "OK") {
let user = json.data.them[0]
if (user && user.pictures && user.pictures.primary) {
commit("setKeybaseIdentity", {
validatorOwner: validator.owner,
avatarUrl: user.pictures.primary.url,
userName: user.basics.username,
profileUrl: "https://keybase.io/" + user.basics.username
})
}
}
}
})
)
}
}

Expand Down
35 changes: 26 additions & 9 deletions app/src/renderer/vuex/modules/delegation.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,23 @@ export default ({ node }) => {
begin_unbondings: unbond
})

// usually I would just query the new state through the LCD but at this point we still get the old shares
dispatch("updateDelegates").then(() => {
for (let delegation of delegations) {
commit("setCommittedDelegation", {
candidateId: delegation.delegate.owner,
value: delegation.atoms
})
}
})
// (optimistic update) we update the atoms of the user before we get the new values from chain
let atomsDiff = delegations
// compare old and new delegations and diff against old atoms
.map(
delegation =>
state.committedDelegates[delegation.delegate.owner] -
delegation.atoms
)
.reduce((sum, diff) => sum + diff, 0)
commit("setAtoms", rootState.user.atoms + atomsDiff)

// we optimistically update the committed delegations
updateCommittedDelegations(delegations, commit)
// TODO usually I would just query the new state through the LCD and update the state with the result, but at this point we still get the old shares
dispatch("updateDelegates").then(() =>
updateCommittedDelegations(delegations, commit)
)
}
}

Expand All @@ -165,3 +173,12 @@ export default ({ node }) => {
actions
}
}

function updateCommittedDelegations(delegations, commit) {
for (let delegation of delegations) {
commit("setCommittedDelegation", {
candidateId: delegation.delegate.owner,
value: delegation.atoms
})
}
}
3 changes: 2 additions & 1 deletion app/src/renderer/vuex/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export default opts => ({
themes: require("./themes.js").default(opts),
user: require("./user.js").default(opts),
validators: require("./validators.js").default(opts),
wallet: require("./wallet.js").default(opts)
wallet: require("./wallet.js").default(opts),
keybase: require("./keybase.js").default(opts)
})
60 changes: 60 additions & 0 deletions app/src/renderer/vuex/modules/keybase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import axios from "axios"

export default ({}) => {
const emptyState = {
identities: {},
loading: false
}
const state = JSON.parse(JSON.stringify(emptyState))

const mutations = {
setKeybaseIdentities(state, identities) {
identities.forEach(identity => {
state.identities[identity.keybaseId] = identity
})
}
}

const actions = {
async getKeybaseIdentity({ state }, keybaseId) {
if (!/.{16}/.test(keybaseId)) return // the keybase id is not correct
if (state.identities[keybaseId]) return // we already have this identity

let urlPrefix =
"https://keybase.io/_/api/1.0/user/lookup.json?key_suffix="
let fullUrl = urlPrefix + keybaseId
let json = await axios.get(fullUrl)
if (json.data.status.name === "OK") {
let user = json.data.them[0]
if (user && user.pictures && user.pictures.primary) {
return {
keybaseId,
avatarUrl: user.pictures.primary.url,
userName: user.basics.username,
profileUrl: "https://keybase.io/" + user.basics.username
}
}
}
},
async getKeybaseIdentities({ dispatch, commit }, validators) {
return Promise.all(
validators.map(async validator => {
if (validator.description.identity) {
return dispatch(
"getKeybaseIdentity",
validator.description.identity
)
}
})
).then(identities => {
commit("setKeybaseIdentities", identities.filter(x => !!x))
})
}
}

return {
state,
actions,
mutations
}
}
6 changes: 5 additions & 1 deletion app/src/renderer/vuex/modules/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export default function({ node }) {
rootState.wallet.zoneIds.unshift(header.chain_id)
}

await dispatch("maybeUpdateValidators", header)
// updating the header is done even while the user is not logged in
Copy link
Collaborator

@jbibla jbibla Sep 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we do this / is this still true?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we bind to the "new header" events before signing in. the event would then trigger an update of the validatorset which is skipped here. This will also change when we react to the validatorset updated event.

// to prevent errors popping up from the LCD before the user is signed on, we skip updating validators before
// TODO identify why rest calls fail at this point
if (rootState.user.signedIn)
await dispatch("maybeUpdateValidators", header)
},
async reconnect({ commit }) {
if (state.stopConnecting) return
Expand Down
2 changes: 1 addition & 1 deletion app/src/renderer/vuex/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default ({ node }) => {
let { address } = await node.getKey(account)
state.address = address

commit("loadPersistedState", { password })
dispatch("loadPersistedState", { password })
commit("setModalSession", false)
dispatch("initializeWallet", address)
dispatch("loadErrorCollection", account)
Expand Down
35 changes: 8 additions & 27 deletions app/src/renderer/vuex/modules/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ export default ({ node }) => {
},
setDenoms(state, denoms) {
state.denoms = denoms
},
setTransactionTime(state, { blockHeight, blockMetaInfo }) {
state.history = state.history.map(t => {
if (t.height === blockHeight) {
// console.log("blockMetaInfo", blockMetaInfo)
t.time = blockMetaInfo && blockMetaInfo.header.time
}
return t
})
}
}

Expand Down Expand Up @@ -99,30 +90,20 @@ export default ({ node }) => {
if (!res) return

const uniqueTransactions = uniqBy(res, "hash")
commit("setWalletHistory", uniqueTransactions)

await dispatch("enrichTransactions", uniqueTransactions)
commit("setWalletHistory", uniqueTransactions)

commit("setHistoryLoading", false)
},
async enrichTransactions({ dispatch }, transactions) {
let blockHeights = []
transactions.forEach(t => {
if (!blockHeights.find(h => h === t.height)) {
blockHeights.push(t.height)
}
})
await Promise.all(
blockHeights.map(h => dispatch("queryTransactionTime", h))
transactions = await Promise.all(
transactions.map(async t => {
let blockMetaInfo = await dispatch("queryBlockInfo", t.height)
t.time = blockMetaInfo && blockMetaInfo.header.time
return t
})
)
},
async queryTransactionTime({ commit, dispatch }, blockHeight) {
let blockMetaInfo = await dispatch("queryBlockInfo", blockHeight)
// console.log(
// "received blockMetaInfo at height " + blockHeight,
// blockMetaInfo
// )
commit("setTransactionTime", { blockHeight, blockMetaInfo })
return transactions
},
async loadDenoms({ commit }) {
// read genesis.json to get default denoms
Expand Down
Loading