From d1d6044db2337ec910310f02e5d87945488ac62c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Iv=C3=A1n=20Vieitez=20Parra?= <3857362+corrideat@users.noreply.github.com> Date: Thu, 2 May 2024 15:01:07 +0000 Subject: [PATCH] WIP --- frontend/controller/actions/identity.js | 5 ++--- frontend/views/components/tabs/TabWrapper.vue | 1 + shared/domains/chelonia/chelonia.js | 4 ++-- shared/domains/chelonia/internals.js | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/controller/actions/identity.js b/frontend/controller/actions/identity.js index 4fe0a8240c..8a34f120d3 100644 --- a/frontend/controller/actions/identity.js +++ b/frontend/controller/actions/identity.js @@ -318,8 +318,6 @@ export default (sbp('sbp/selectors/register', { const contractIDs = Object.create(null) // login can be called when no settings are saved (e.g. from Signup.vue) if (cheloniaState) { - // The retrieved local data might need to be completed in case it was originally saved - // under an older version of the app where fewer/other Vuex modules were implemented. Object.assign(sbp('chelonia/rootState'), cheloniaState) console.error('@@@@SET CHELONIA STATE[identity.js]', { cRS: sbp('chelonia/rootState'), cheloniaState, stateC: JSON.parse(JSON.stringify(state)), state }) sbp('chelonia/pubsub/update') // resubscribe to contracts since we replaced the state @@ -523,8 +521,9 @@ export default (sbp('sbp/selectors/register', { // we could avoid waiting on these 2nd layer of actions) await sbp('okTurtles.eventQueue/queueEvent', 'encrypted-action', () => {}) // See comment below for 'gi.db/settings/delete' - sbp('state/vuex/state').cheloniaState = sbp('chelonia/rootState') + await sbp('okTurtles.eventQueue/queueEvent', 'CHELONIA_STATE', () => {}) await sbp('gi.db/settings/delete', 'CHELONIA_STATE') + sbp('state/vuex/state').cheloniaState = sbp('chelonia/rootState') await sbp('state/vuex/save') // If there is a state encryption key in the app settings, remove it diff --git a/frontend/views/components/tabs/TabWrapper.vue b/frontend/views/components/tabs/TabWrapper.vue index 9bd1eac9c5..d30b902f55 100644 --- a/frontend/views/components/tabs/TabWrapper.vue +++ b/frontend/views/components/tabs/TabWrapper.vue @@ -121,6 +121,7 @@ export default ({ // The action could be asynchronous, so we wrap it in a try-catch block try { await sbp(tabItem.action) + console.error('@@@@tabClick-CLOSING', tabItem) this.$emit('close') } catch (e) { console.error(`Error on tabClick: [${e?.name}] ${e?.message || e}`, tabItem, e) diff --git a/shared/domains/chelonia/chelonia.js b/shared/domains/chelonia/chelonia.js index 5788604679..1e03bb8a77 100644 --- a/shared/domains/chelonia/chelonia.js +++ b/shared/domains/chelonia/chelonia.js @@ -346,13 +346,13 @@ export default (sbp('sbp/selectors/register', { await postCleanupFn?.() // The following are all synchronous operations const rootState = sbp(this.config.stateSelector) - const contracts = rootState.contracts // Cancel all outgoing messages by replacing this._instance this._instance = Object.create(null) this.abortController.abort() this.abortController = new AbortController() // Remove all contracts, including all contracts from pending - reactiveClearObject(contracts, this.config.reactiveDel) + reactiveClearObject(rootState, this.config.reactiveDel) + this.config.reactiveSet(rootState, 'contracts', Object.create(null)) clearObject(this.ephemeralReferenceCount) this.pending.splice(0) clearObject(this.currentSyncs) diff --git a/shared/domains/chelonia/internals.js b/shared/domains/chelonia/internals.js index a161761267..bcd38ebf10 100644 --- a/shared/domains/chelonia/internals.js +++ b/shared/domains/chelonia/internals.js @@ -1166,6 +1166,7 @@ export default (sbp('sbp/selectors/register', { let latestHashFound = false const eventReader = eventsStream.getReader() // remove the first element in cases where we are not getting the contract for the first time + console.error('@@@sync, just before process', contractID, { recentHeight, currentHeight: state.contracts[contractID]?.height || '-', state: state[contractID] || '-' }) for (let skip = has(state.contracts, contractID) && has(state.contracts[contractID], 'HEAD'); ; skip = false) { const { done, value: event } = await eventReader.read() if (done) { @@ -1861,6 +1862,7 @@ const handleEvent = { // Allow having _volatile but nothing else if this is the first message, // as we should be starting off with a clean state if (Object.keys(state).some(k => k !== '_volatile')) { + console.error('@@@@', state) throw new ChelErrorUnrecoverable(`state for ${contractID} is already set`) } }