Skip to content

Commit

Permalink
feat: display title or favicon as fallback if no connections were found
Browse files Browse the repository at this point in the history
  • Loading branch information
helciofranco committed Jan 10, 2025
1 parent 7a0b55a commit b2419dd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cssObj } from '@fuel-ui/css';
import { Avatar, Box, ContentLoader, Tooltip } from '@fuel-ui/react';
import { Box, ContentLoader, Tooltip } from '@fuel-ui/react';
import { useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
import { useCurrentTab } from '~/systems/CRX/hooks/useCurrentTab';
Expand All @@ -18,8 +18,8 @@ export const QuickAccountConnect = () => {
const navigate = useNavigate();

const { account } = useCurrentAccount();
const { url } = useCurrentTab();
const { connection } = useConnection({ url });
const { currentTab } = useCurrentTab();
const { connection } = useConnection({ url: currentTab?.url });

const status = useMemo<ConnectionStatus>(() => {
if (!account || !connection) {
Expand Down Expand Up @@ -57,7 +57,9 @@ export const QuickAccountConnect = () => {
<Tooltip delayDuration={0} content={tooltip}>
<Box
css={styles.root}
data-has-connection={!!connection}
onClick={() => {
if (!connection) return;
navigate(
Pages.settingsConnectedApps(undefined, {
origin: connection?.origin,
Expand All @@ -68,8 +70,8 @@ export const QuickAccountConnect = () => {
>
<Box css={styles.favicon}>
<DappAvatar
favIconUrl={connection?.favIconUrl}
title={connection?.title}
favIconUrl={connection?.favIconUrl || currentTab?.faviconUrl}
title={connection?.title || currentTab?.title}
/>
</Box>

Expand All @@ -85,9 +87,15 @@ const styles = {
root: cssObj({
position: 'relative',
display: 'inline-block',
cursor: 'pointer',
width: 24,
height: 24,

'&[data-has-connection="true"]': {
cursor: 'pointer',
},
'&[data-has-connection="false"]': {
cursor: 'default',
},
}),
favicon: cssObj({
display: 'flex',
Expand Down
16 changes: 13 additions & 3 deletions packages/app/src/systems/CRX/hooks/useCurrentTab.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import { useEffect, useState } from 'react';

interface CurrentTab {
url: string | undefined;
title: string | undefined;
faviconUrl: string | undefined;
}

export function useCurrentTab() {
const [url, setUrl] = useState<string | undefined>();
const [currentTab, setCurrentTab] = useState<CurrentTab | undefined>();

useEffect(() => {
if (!chrome?.tabs) return;

chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const currentTab = tabs[0];
setUrl(currentTab?.url);
setCurrentTab({
url: currentTab?.url,
title: currentTab?.title,
faviconUrl: currentTab?.favIconUrl,
});
});
}, []);

return {
url,
currentTab,
};
}

0 comments on commit b2419dd

Please sign in to comment.