Skip to content

Commit

Permalink
Fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
raducristianpopa committed Apr 30, 2024
1 parent 22b88b3 commit 5a88f55
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 43 deletions.
3 changes: 0 additions & 3 deletions src/background/services/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ export class Background {

bindTabHandlers() {
this.browser.tabs.onRemoved.addListener(this.tabEvents.onRemovedTab)
// this.browser.webNavigation.onCommitted.addListener((details) => {
// console.log(details)
// })
this.browser.tabs.onUpdated.addListener(this.tabEvents.onUpdatedTab)
}

Expand Down
7 changes: 2 additions & 5 deletions src/background/services/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ 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'
Expand Down Expand Up @@ -121,16 +119,15 @@ export class MonetizationService {
this.logger.debug(`Cleared ${sessions.size} sessions for tab ${tabId}.`)
}

async pay(amount: number) {
async pay(amount: string) {
const tab = await getCurrentActiveTab(this.browser)
if (!tab || !tab.id) return

const sessions = this.sessions[tab.id]
const splitAmount = amount / sessions.size
const splitAmount = Number(amount) / sessions.size

for (const session of sessions.values()) {
session.pay(splitAmount)
}

}
}
3 changes: 1 addition & 2 deletions src/background/services/tabEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ export class TabEvents {
// TODO: This is not ideal. Find a better way to clear the sessions for a specific tab.
// When closing the tab, we receive the STOP_MONETIZATION message as well.
// Maybe check if the tab is closed in the content script?
onUpdatedTab = (tabId: number, ...rest: any) => {
console.log(tabId, rest)
onUpdatedTab = (tabId: number) => {
this.monetizationService.clearTabSessions(tabId)
}
}
7 changes: 2 additions & 5 deletions src/popup/components/PayWebsiteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { Button } from '@/popup/components/ui/Button'
import { Input } from '@/popup/components/ui/Input'
import { PopupStateContext } from '@/popup/lib/context'
import { payWebsite } from '@/popup/lib/messages'
import {
getCurrencySymbol,
charIsNumber,
} from '@/popup/lib/utils'
import { getCurrencySymbol, charIsNumber } from '@/popup/lib/utils'
import React from 'react'
import { useForm } from 'react-hook-form'
import { numericFormatter } from 'react-number-format'
Expand Down Expand Up @@ -57,7 +54,7 @@ export const PayWebsiteForm = () => {
errorMessage={errors.amount?.message}
{...register('amount', {
required: { value: true, message: 'Amount is required.' },
valueAsNumber: false,
valueAsNumber: true,
onBlur: (e: React.FocusEvent<HTMLInputElement>) => {
setValue(
'amount',
Expand Down
2 changes: 0 additions & 2 deletions src/popup/lib/messages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
BackgroundToContentAction,
BackgroundToContentActionPayload,
BackgroundToContentMessage,
MessageManager,
PopupToBackgroundAction,
Expand Down
52 changes: 27 additions & 25 deletions src/popup/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,36 @@ export const Component = () => {
})
}

if (!enabled) {
return (
<div className="flex items-center gap-2">
<WarningSign />
<p className="text-base text-medium">
Web Monetization has been turned off.
</p>
</div>
)
}

return (
<div className="space-y-4">
{!enabled ? (
<div className="flex items-center gap-2">
<WarningSign />
<p className="text-base text-medium">
Web Monetization has been turned off.
</p>
</div>
) : (
<div className="space-y-2">
<Label className="px-2 text-base font-medium text-medium">
Current rate of pay
</Label>
<Slider
onChange={onRateChange}
min={Number(minRateOfPay)}
max={Number(maxRateOfPay)}
step={Number(minRateOfPay)}
value={Number(rateOfPay)}
/>
<div className="flex w-full items-center justify-between px-2">
<span className="text-sm">
{rate} {getCurrencySymbol(walletAddress.assetCode)} per hour test
</span>
</div>
<div className="space-y-2">
<Label className="px-2 text-base font-medium text-medium">
Current rate of pay
</Label>
<Slider
onChange={onRateChange}
min={Number(minRateOfPay)}
max={Number(maxRateOfPay)}
step={Number(minRateOfPay)}
value={Number(rateOfPay)}
/>
<div className="flex w-full items-center justify-between px-2">
<span className="text-sm">
{rate} {getCurrencySymbol(walletAddress.assetCode)} per hour test
</span>
</div>
)}
</div>
{url ? <PayWebsiteForm /> : null}
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion src/shared/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface ConnectWalletPayload {
}

export interface PayWebsitePayload {
amount: number
amount: string
}

export interface UpdateRateOfPayPayload {
Expand Down

0 comments on commit 5a88f55

Please sign in to comment.