Skip to content

Commit

Permalink
feat(background): check WM state when receiving messages (temp) (#235)
Browse files Browse the repository at this point in the history
Check WM State when receiving start/stop/resume
  • Loading branch information
raducristianpopa committed Apr 19, 2024
1 parent a554fe6 commit faf75e5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/background/services/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export class MonetizationService {
payload: StartMonetizationPayload,
sender: Runtime.MessageSender
) {
// TODO: This is not ideal. We should not receive monetization events
// from the content script if WM is disabled or a wallet is not connected.
const { connected, enabled } = await this.storage.get([
'enabled',
'connected'
])
if (connected === false || enabled === false) return

const { requestId, walletAddress } = payload
const { tabId, frameId } = getSender(sender)

Expand Down Expand Up @@ -62,6 +70,12 @@ export class MonetizationService {
) {
const { requestId } = payload
const tabId = getTabId(sender)
const sessions = this.sessions[tabId]

if (!sessions) {
this.logger.debug(`No active sessions found for tab ${tabId}.`)
return
}

this.sessions[tabId].get(requestId)?.stop()
}
Expand All @@ -72,6 +86,12 @@ export class MonetizationService {
) {
const { requestId } = payload
const tabId = getTabId(sender)
const sessions = this.sessions[tabId]

if (!sessions) {
this.logger.debug(`No active sessions found for tab ${tabId}.`)
return
}

this.sessions[tabId].get(requestId)?.resume()
}
Expand Down

0 comments on commit faf75e5

Please sign in to comment.