Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions libs/connect-context/src/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { logChains } from './utils/debug';
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { Buffer } = require('buffer');
if (typeof window !== 'undefined' && !(window as any).Buffer) {
(window as any).Buffer = Buffer;
if (typeof window !== 'undefined' && !(window as unknown as { Buffer?: unknown }).Buffer) {
(window as unknown as { Buffer?: unknown }).Buffer = Buffer;
}
} catch (err) {
// Buffer polyfill failed – non-fatal.
Expand Down
1 change: 0 additions & 1 deletion libs/connect-context/src/ConnectContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
isValidNetwork,
NetworkConfigs,
ValidNetwork,
VIEM_CHAINS,
} from '@daohaus/keychain-utils';

import { defaultConnectValues } from './utils/defaults';
Expand Down
36 changes: 36 additions & 0 deletions libs/connect-context/src/assets/icons/rabby-avatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 23 additions & 3 deletions libs/connect-context/src/components/InternalConnectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
// If MetaMask is NOT available, hide the dedicated metaMask connector (some providers misreport) and show generic injected.
const hasMetaMask =
connectors.some((c) => c.id === 'metaMask' && c.ready) ||
(typeof (window as any)?.ethereum !== 'undefined' &&
(window as any).ethereum?.isMetaMask);
(typeof window !== 'undefined' && (window as any)?.ethereum?.isMetaMask);

Check warning on line 62 in libs/connect-context/src/components/InternalConnectModal.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type

const filteredConnectors = connectors.filter((c) => {
// Hide generic injected when MetaMask present
Expand Down Expand Up @@ -156,7 +155,28 @@
style={{ display: 'flex', alignItems: 'center', gap: 8 }}
>
{connectorIcon(c.id)}
<span>{c.name || 'Unknown Wallet'}</span>
<span>
{(() => {
if (typeof window !== 'undefined' && window.ethereum) {
if (
window.ethereum.isRabby &&
(c.id === 'metaMask' || c.id === 'injected')
) {
return 'Rabby';
}
if (
window.ethereum.isMetaMask &&
c.id === 'metaMask'
) {
return 'MetaMask';
}
if (c.id === 'injected') {
return 'Browser Wallet';
}
}
return c.name || 'Unknown Wallet';
})()}
</span>
</span>
<span style={{ fontSize: 11, opacity: 0.75 }}>
{c.id === lastUsed && 'Recent'}
Expand Down
33 changes: 31 additions & 2 deletions libs/connect-context/src/components/WalletIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
// Local copies of brand assets (moved here to avoid app->lib dependency cycles)
// They may resolve either to a ReactComponent (SVGR) or a URL string depending on tooling.
import metaMaskAsset from '../assets/icons/MetaMask-icon-fox.svg';
import rabbyAsset from '../assets/icons/rabby-avatar.svg';
import coinbaseAsset from '../assets/icons/coinbase_wallet_appicon.svg';
import walletConnectAsset from '../assets/icons/walletconnect-icon.svg';

const renderImportedSvg = (
mod: any,
mod: unknown,
size: number,
fallback: React.ReactNode,
alt: string
): React.ReactNode => {
if (!mod) return fallback;
const possible = mod.default ?? mod; // CommonJS vs ES interop
const possible = (mod as any).default ?? (mod as any); // CommonJS vs ES interop

Check warning on line 16 in libs/connect-context/src/components/WalletIcons.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type

Check warning on line 16 in libs/connect-context/src/components/WalletIcons.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
if (typeof possible === 'string') {
return (
<img
Expand All @@ -31,6 +32,22 @@
return <Cmp width={size} height={size} aria-label={alt} />;
};

export const IconRabby: React.FC<{ size?: number }> = ({ size = 20 }) => {
const Fallback = (
<svg
width={size}
height={size}
viewBox="0 0 32 32"
xmlns="http://www.w3.org/2000/svg"
style={{ display: 'block' }}
>
<circle cx="16" cy="16" r="16" fill="#1F1A17" />
</svg>
);
const inner = renderImportedSvg(rabbyAsset, size, Fallback, 'Rabby');
return <IconWrapper brand="metamask">{inner}</IconWrapper>;
};

export const IconMetaMask: React.FC<{ size?: number }> = ({ size = 20 }) => {
const Fallback = (
<svg
Expand Down Expand Up @@ -154,6 +171,18 @@
};

export const connectorIcon = (id: string): React.ReactNode => {
if (typeof window !== 'undefined' && window.ethereum) {
if (window.ethereum.isRabby && (id === 'metaMask' || id === 'injected')) {
return <IconRabby />;
}
if (window.ethereum.isMetaMask && id === 'metaMask') {
return <IconMetaMask />;
}
// fallback: generic browser wallet icon for injected
if (id === 'injected') {
return <IconBrowserWallet />;
}
}
switch (id) {
case 'metaMask':
return <IconMetaMask />;
Expand Down
11 changes: 8 additions & 3 deletions libs/connect-context/src/utils/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

// Enable by setting NX_CONNECT_DEBUG=true in env (or toggling window.__CONNECT_DEBUG = true)
const isDebug = () => {
if (typeof window !== 'undefined' && (window as any).__CONNECT_DEBUG)
if (
typeof window !== 'undefined' &&
(window as unknown as { __CONNECT_DEBUG?: boolean }).__CONNECT_DEBUG
)
return true;
return process.env['NX_CONNECT_DEBUG'] === 'true';
};
Expand All @@ -20,7 +23,7 @@ type ProviderLike = Record<string, unknown> & {

export const collectInjectedProviders = (): ProviderLike[] => {
if (typeof window === 'undefined') return [];
const eth = (window as any).ethereum as ProviderLike | undefined;
const eth = (window as unknown as { ethereum?: ProviderLike }).ethereum;
if (!eth) return [];
if (Array.isArray(eth.providers)) return eth.providers as ProviderLike[];
return [eth];
Expand All @@ -34,7 +37,9 @@ export const logInjectedWallets = () => {
const summarized = providers.map((p, idx) => ({
index: idx,
flags: Object.keys(p)
.filter((k) => k.startsWith('is') && (p as any)[k] === true)
.filter(
(k) => k.startsWith('is') && (p as Record<string, unknown>)[k] === true
)
.join(','),
isMetaMask: !!p.isMetaMask,
isCoinbase: !!p.isCoinbaseWallet,
Expand Down
Loading