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

fix(background): fix order when calling start #440

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions src/background/services/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class Background {
) {}

async start() {
this.scheduleResetOutOfFundsState()
this.bindOnInstalled()
await this.onStart()
this.bindMessageHandler()
this.bindPermissionsHandler()
this.bindEventsHandler()
Expand All @@ -49,6 +49,12 @@ export class Background {
this.sendToPopup.start()
}

async onStart() {
await this.storage.populate()
await this.checkPermissions()
await this.scheduleResetOutOfFundsState()
}

async scheduleResetOutOfFundsState() {
// Reset out_of_funds state, we'll detect latest state as we make a payment.
await this.storage.setState({ out_of_funds: false })
Expand Down Expand Up @@ -238,7 +244,6 @@ export class Background {
)
}
}
await this.checkPermissions()
})
}

Expand Down
3 changes: 3 additions & 0 deletions src/background/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export class StorageService {
this.currentState = { ...defaultStorage.state }
}

/**
* Needs to run before any other storage `set` call.
*/
async populate(): Promise<void> {
const data = await this.get(Object.keys(defaultStorage) as StorageKey[])

Expand Down
Loading