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(popup): improve warning message for non-monetized tabs #624

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 14 additions & 4 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,22 @@
"missingHostPermission_state_text": {
"message": "Permission to access your data for all websites is required to use Web Monetization."
},
"siteNotMonetized_state_text": {
"notMonetized_text_allInvalid": {
"message": "At the moment, you cannot pay this website",
sidvishnoi marked this conversation as resolved.
Show resolved Hide resolved
"description": "We cannot send money (probable cause: un-peered wallets)"
},
"notMonetized_text_noLinks": {
"message": "This website is not monetized."
},
"notMonetized_text_newTab": {
"message": "The extension doesn't support empty tabs."
},
"notMonetized_text_internalPage": {
"message": "The extension can't access browser's internal pages."
},
"notMonetized_text_unsupportedScheme": {
"message": "Web Monetization only works with https:// websites."
},
"keyRevoked_error_title": {
"message": "Unauthorized access to wallet"
},
Expand Down Expand Up @@ -90,8 +103,5 @@
},
"connectWallet_error_invalidClient": {
"message": "Failed to connect. Please make sure you have added the public key to the correct wallet address."
},
"allInvalidLinks_state_text": {
"message": "At the moment, you can not pay this website."
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React from 'react';
import { WarningSign } from '@/popup/components/Icons';
import { useTranslation } from '@/popup/lib/context';

export const AllSessionsInvalid = () => {
const t = useTranslation();
export const NotMonetized = ({ text }: { text: string }) => {
return (
<div className="flex h-full flex-col items-center justify-center gap-1 p-1 text-lg">
<div className="flex h-full flex-col items-center justify-center gap-1 p-1">
<div className="flex-shrink-0">
<WarningSign className="size-10 text-medium" />
</div>
<h3 className="text-medium">{t('allInvalidLinks_state_text')}</h3>
<h3 className="text-center text-lg leading-tight text-medium">{text}</h3>
</div>
);
};
15 changes: 0 additions & 15 deletions src/popup/components/SiteNotMonetized.tsx

This file was deleted.

22 changes: 15 additions & 7 deletions src/popup/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { usePopupState, useMessage } from '@/popup/lib/context';
import { usePopupState, useMessage, useTranslation } from '@/popup/lib/context';
import { WarningSign } from '@/popup/components/Icons';
import { Slider } from '../components/ui/Slider';
import { Label } from '../components/ui/Label';
Expand All @@ -9,12 +9,12 @@ import {
roundWithPrecision,
} from '../lib/utils';
import { PayWebsiteForm } from '../components/PayWebsiteForm';
import { SiteNotMonetized } from '@/popup/components/SiteNotMonetized';
import { NotMonetized } from '@/popup/components/NotMonetized';
import { debounceAsync } from '@/shared/helpers';
import { Switch } from '../components/ui/Switch';
import { AllSessionsInvalid } from '@/popup/components/AllSessionsInvalid';

export const Component = () => {
const t = useTranslation();
const message = useMessage();
const {
state: {
Expand Down Expand Up @@ -64,10 +64,18 @@ export const Component = () => {
};

if (tab.status !== 'monetized') {
if (tab.status === 'all_sessions_invalid') {
return <AllSessionsInvalid />;
} else {
return <SiteNotMonetized />;
switch (tab.status) {
case 'all_sessions_invalid':
return <NotMonetized text={t('notMonetized_text_allInvalid')} />;
case 'internal_page':
return <NotMonetized text={t('notMonetized_text_internalPage')} />;
case 'new_tab':
return <NotMonetized text={t('notMonetized_text_newTab')} />;
case 'unsupported_scheme':
return <NotMonetized text={t('notMonetized_text_unsupportedScheme')} />;
case 'no_monetization_links':
default:
return <NotMonetized text={t('notMonetized_text_noLinks')} />;
}
}

Expand Down
10 changes: 6 additions & 4 deletions tests/e2e/connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test('connects with correct details provided', async ({
background,
popup,
i18n,
page,
}) => {
const {
CONNECT_KEY_ID,
Expand Down Expand Up @@ -44,10 +45,6 @@ test('connects with correct details provided', async ({
const settingsLink = popup.locator(`[href="/settings"]`).first();
await expect(settingsLink).toBeVisible();

await expect(popup.locator('h3')).toHaveText(
i18n.getMessage('siteNotMonetized_state_text'),
);

const storage = await background.evaluate(() => {
return chrome.storage.local.get([
'connected',
Expand All @@ -66,6 +63,11 @@ test('connects with correct details provided', async ({
},
});

await page.goto('https://webmonetization.org/play/');
await expect(popup.locator('h3')).toHaveText(
i18n.getMessage('notMonetized_text_noLinks'),
);

await disconnectWallet(popup);
expect(
await background.evaluate(() => {
Expand Down
Loading