Skip to content

Commit

Permalink
fix(Popup): update global payment toggle UI (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarianM authored Dec 18, 2024
1 parent 3705cd4 commit c0b2055
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"no-extra-semi": "off",
"maxWarnings": "off",
"no-constant-condition": "off",
"no-duplicate-imports": "error",
"block-scoped-var": "error",
"consistent-return": "off",
"no-console": "warn",
Expand Down
2 changes: 1 addition & 1 deletion src/background/services/tabEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class TabEvents {
if (!connected) {
// use defaults
} else if (!enabled) {
iconData = ICONS.default_gray;
iconData = ICONS.default;
} else if (!isOkState(state) || tabInfo.status === 'all_sessions_invalid') {
iconData = continuousPaymentsEnabled
? ICONS.enabled_warn
Expand Down
14 changes: 5 additions & 9 deletions src/pages/popup/components/TogglePaymentsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ import React from 'react';
import { Power } from '@/pages/shared/components/Icons';
import { cn } from '@/shared/helpers';
import { useMessage } from '@/popup/lib/context';
import { dispatch } from '@/popup/lib/store';
import { dispatch, usePopupState } from '@/popup/lib/store';

export const TogglePaymentsButton = ({
large = false,
enabled = false,
}: {
large?: boolean;
enabled?: boolean;
}) => {
export const TogglePaymentsButton = () => {
const { enabled } = usePopupState();
const message = useMessage();
const title = enabled ? 'Disable extension' : 'Enable extension';

Expand All @@ -31,10 +26,11 @@ export const TogglePaymentsButton = ({
message.send('TOGGLE_PAYMENTS');
dispatch({ type: 'TOGGLE_PAYMENTS' });
}}
onClick={(ev) => ev.currentTarget.blur()}
aria-label={title}
className="sr-only"
/>
<Power className={large ? 'w-32' : 'w-6'} />
<Power className={'w-6'} />
</label>
);
};
6 changes: 3 additions & 3 deletions src/pages/popup/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { usePopupState } from '@/popup/lib/store';

const NavigationButton = () => {
const location = useLocation();
const { connected, enabled } = usePopupState();
const { connected } = usePopupState();

return React.useMemo(() => {
if (!connected) return null;
Expand All @@ -28,13 +28,13 @@ const NavigationButton = () => {
</Link>
) : (
<React.Fragment>
{enabled && connected && <TogglePaymentsButton enabled={true} />}
{connected && <TogglePaymentsButton />}
<Link to={ROUTES_PATH.SETTINGS}>
<Settings className="h-6" />
</Link>
</React.Fragment>
);
}, [location, connected, enabled]);
}, [location, connected]);
};

export const Header = () => {
Expand Down
10 changes: 1 addition & 9 deletions src/pages/popup/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Settings } from '@/pages/shared/components/Icons';
import { formatNumber, roundWithPrecision } from '@/pages/shared/lib/utils';
import { PayWebsiteForm } from '@/popup/components/PayWebsiteForm';
import { NotMonetized } from '@/popup/components/NotMonetized';
import { TogglePaymentsButton } from '@/popup/components/TogglePaymentsButton';
import { useTranslation } from '@/popup/lib/context';
import { usePopupState } from '@/popup/lib/store';

Expand All @@ -13,14 +12,7 @@ export const Component = () => {
const { tab, enabled } = usePopupState();

if (!enabled) {
return (
<div className="flex h-full flex-col items-center justify-center gap-4 text-center">
<TogglePaymentsButton enabled={false} large={true} />
<p className="text-center text-lg leading-tight text-medium">
{t('app_text_disabled')}
</p>
</div>
);
return <NotMonetized text={t('app_text_disabled')} />;
}

if (tab.status !== 'monetized') {
Expand Down

0 comments on commit c0b2055

Please sign in to comment.