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/fixed store cache retrieval #2358

Merged
merged 5 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 1 addition & 3 deletions PENDING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[Added] [\#2238](https://github.com/cosmos/voyager/issues/2238) Show estimaded fees @fedekunze
[Changed] Circleci config deployment job to deploy `lunie.io` and `beta.lunie.io`
[Changed] renamed to Lunie @faboweb
[Fixed] Fixed store cache retrieval on sign in @faboweb
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 6 additions & 2 deletions app/src/renderer/vuex/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ function persistState(state) {
balances: state.wallet.balances
},
delegation: {
loaded: state.delegation.loaded,
committedDelegates: state.delegation.committedDelegates,
unbondingDelegations: state.delegation.unbondingDelegations
},
Expand Down Expand Up @@ -128,7 +127,12 @@ export function getStorageKey(state) {
* @param state
* @param commit
*/
export function loadPersistedState({ state, commit }) {
export async function loadPersistedState({ state, commit, dispatch }) {
if (!state.connection.lastHeader.chain_id) {
faboweb marked this conversation as resolved.
Show resolved Hide resolved
await new Promise(resolve => setTimeout(resolve, 500))
dispatch(`loadPersistedState`)
return
}
const storageKey = getStorageKey(state)
let cachedState
try {
Expand Down
26 changes: 24 additions & 2 deletions test/unit/specs/store/store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe(`Store`, () => {
it(`should throttle updating the store cache`, async () => {
jest.useFakeTimers()

const pending = setTimeout(() => {}, 10000)
const pending = setTimeout(() => { }, 10000)
storeUpdateHandler({ type: `setWalletBalances` }, mockState, pending)

// not updating yet, as it waits if there are more updates incoming
Expand All @@ -116,7 +116,7 @@ describe(`Store`, () => {
})

it(`should not crash if the stored cache is invalid`, async () => {
jest.spyOn(console, `error`).mockImplementationOnce(() => {})
jest.spyOn(console, `error`).mockImplementationOnce(() => { })

localStorage.setItem(`store_test-net_xxx`, `xxx`)
loadPersistedState.call(
Expand All @@ -125,6 +125,28 @@ describe(`Store`, () => {
)
})

it(`should retry if network is unknown`, async () => {
const dispatch = jest.fn()
const replaceState = jest.fn()

localStorage.setItem(`store_test-net_xxx`, `xxx`)
jest.useRealTimers()
await loadPersistedState.call(
{ replaceState },
{
state: Object.assign({}, mockState, {
connection: {
lastHeader: {}
}
}),
commit: jest.fn(), dispatch
}
)

expect(dispatch).toHaveBeenCalledWith(`loadPersistedState`)
expect(replaceState).not.toHaveBeenCalled()
})

it(`get storage keys`, () => {
expect(
getStorageKey({
Expand Down