Skip to content

Commit

Permalink
feat: Tag listener (#203)
Browse files Browse the repository at this point in the history
* Tag listener

* Monetization tag

* Add stop & resume

* Move message handler in contentScript

* Add contentScript file changes

---------

Co-authored-by: Diana Fulga <diana.fulga@breakointit.eu>
  • Loading branch information
dianafulga and Diana Fulga committed Apr 18, 2024
1 parent 930c0eb commit 3f56d12
Show file tree
Hide file tree
Showing 15 changed files with 541 additions and 600 deletions.
14 changes: 12 additions & 2 deletions src/background/services/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
import { type Browser } from 'webextension-polyfill'
import {
type ToBackgroundMessage,
PopupToBackgroundAction
PopupToBackgroundAction,
ContentToBackgroundAction
} from '@/shared/messages'
import type {
MonetizationService,
OpenPaymentsService,
StorageService
} from '.'
import { Logger } from '@/shared/logger'
import { failure, success } from '@/shared/helpers'
import { failure, getWalletInformation, success } from '@/shared/helpers'
import { OpenPaymentsClientError } from '@interledger/open-payments/dist/client/error'
import { OPEN_PAYMENTS_ERRORS } from '@/background/utils'

Expand Down Expand Up @@ -55,6 +56,15 @@ export class Background {
)
throw new Error('Not implemented')

case ContentToBackgroundAction.CHECK_WALLET_ADDRESS_URL:
return success(
await getWalletInformation(message.payload.walletAddressUrl)
)

case ContentToBackgroundAction.START_MONETIZATION:
// start from monetization service
return

case PopupToBackgroundAction.UPDATE_RATE_OF_PAY:
return success(
await this.storage.set({
Expand Down
5 changes: 5 additions & 0 deletions src/content/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { asClass, asValue, createContainer, InjectionMode } from 'awilix'
import browser, { type Browser } from 'webextension-polyfill'
import { createLogger, Logger } from '@/shared/logger'
import { ContentScript } from './services/contentScript'
import { MonetizationTagManager } from './services/monetizationTagManager'
import { LOG_LEVEL } from '@/shared/defines'

interface Cradle {
logger: Logger
browser: Browser
document: Document
monetizationTagManager: MonetizationTagManager
contentScript: ContentScript
}

Expand All @@ -20,6 +23,8 @@ export const configureContainer = () => {
container.register({
logger: asValue(logger),
browser: asValue(browser),
document: asValue(document),
monetizationTagManager: asClass(MonetizationTagManager).singleton(),
contentScript: asClass(ContentScript)
.singleton()
.inject(() => ({
Expand Down
File renamed without changes.
46 changes: 46 additions & 0 deletions src/content/lib/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
MessageManager,
ContentToBackgroundAction,
ContentToBackgroundActionPayload,
type ContentToBackgroundMessage
} from '@/shared/messages'
import { WalletAddress } from '@interledger/open-payments/dist/types'
import browser from 'webextension-polyfill'

export const message = new MessageManager<ContentToBackgroundMessage>(browser)

export const checkWalletAddressUrlCall = async (
payload: ContentToBackgroundActionPayload[ContentToBackgroundAction.CHECK_WALLET_ADDRESS_URL]
) => {
return await message.send<WalletAddress>({
action: ContentToBackgroundAction.CHECK_WALLET_ADDRESS_URL,
payload
})
}

export const startMonetization = async (
payload: ContentToBackgroundActionPayload[ContentToBackgroundAction.START_MONETIZATION]
) => {
return await message.send({
action: ContentToBackgroundAction.START_MONETIZATION,
payload
})
}

export const stopMonetization = async (
payload: ContentToBackgroundActionPayload[ContentToBackgroundAction.STOP_MONETIZATION]
) => {
return await message.send({
action: ContentToBackgroundAction.STOP_MONETIZATION,
payload
})
}

export const resumeMonetization = async (
payload: ContentToBackgroundActionPayload[ContentToBackgroundAction.RESUME_MONETIZATION]
) => {
return await message.send({
action: ContentToBackgroundAction.RESUME_MONETIZATION,
payload
})
}
16 changes: 0 additions & 16 deletions src/content/monetizationTagManager/CustomError.ts

This file was deleted.

Loading

0 comments on commit 3f56d12

Please sign in to comment.