Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed May 3, 2024
1 parent def677e commit 9639c3b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
5 changes: 2 additions & 3 deletions frontend/controller/actions/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions frontend/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ async function startApp () {
// Since a runtime error just occured, we likely want to persist app logs to local storage now.
sbp('appLogs/save')
}
// @@@@ TODO: Wait for db to be ready
await new Promise(resolve => setTimeout(resolve, 200))
await sbp('gi.db/settings/load', 'CHELONIA_STATE').then(async (cheloniaState) => {
// TODO: PLACEHOLDER TO SIMULATE CHELONIA IN A SW
if (!cheloniaState) return
Expand All @@ -109,6 +111,7 @@ async function startApp () {
Object.assign(sbp('chelonia/rootState'), cheloniaState)
console.error('@@@@SET CHELONIA STATE[main.js]', identityContractID, sbp('chelonia/rootState'), cheloniaState)
})
console.error('@@@@@@@@')
await sbp('chelonia/configure', {
connectionURL: sbp('okTurtles.data/get', 'API_URL'),
/*
Expand Down
1 change: 1 addition & 0 deletions frontend/views/components/tabs/TabWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions shared/domains/chelonia/chelonia.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions shared/domains/chelonia/internals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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`)
}
}
Expand Down

0 comments on commit 9639c3b

Please sign in to comment.