Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcramer committed Aug 2, 2024
1 parent a348e27 commit c1ca1ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
4 changes: 2 additions & 2 deletions site/docs/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
import { OnchainKitProvider } from '@coinbase/onchainkit';
// import { OnchainKitProvider } from '../pages/src/OnchainKitProvider';
// import { OnchainKitProvider } from '@coinbase/onchainkit';
import { OnchainKitProvider } from '../pages/src/OnchainKitProvider';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import type { ReactNode } from 'react';
import { http, WagmiProvider, createConfig } from 'wagmi';
Expand Down
4 changes: 2 additions & 2 deletions site/docs/pages/wallet/wallet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {
WalletDropdown,
WalletDropdownLink,
WalletDropdownDisconnect,
} from '@coinbase/onchainkit/wallet';
} from '../src/wallet';
import {
Address,
Avatar,
Name,
Badge,
Identity,
EthBalance,
} from '@coinbase/onchainkit/identity';
} from '../src/identity';
import { color } from '@coinbase/onchainkit/theme';
import AppWithRK from '../../components/AppWithRK';
import WalletComponents from '../../components/WalletComponents';
Expand Down
40 changes: 30 additions & 10 deletions src/wallet/components/Wallet.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
import { Children, useMemo } from 'react';
import { Children, useMemo, useRef, useEffect } from 'react';
import type { WalletReact } from '../types';
import { ConnectWallet } from './ConnectWallet';
import { WalletDropdown } from './WalletDropdown';
import { WalletProvider } from './WalletProvider';
import { WalletProvider, useWalletContext } from './WalletProvider';

function WalletContent({ children }: WalletReact) {
const { isOpen, setIsOpen } = useWalletContext();
const containerRef = useRef<HTMLDivElement>(null);

export function Wallet({ children }: WalletReact) {
const { connect, dropdown } = useMemo(() => {
const childrenArray = Children.toArray(children);
return {
// @ts-ignore
connect: childrenArray.filter(({ type }) => type === ConnectWallet),
// @ts-ignore
dropdown: childrenArray.filter(({ type }) => type === WalletDropdown),
};
}, [children]);

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (containerRef.current && !containerRef.current.contains(event.target as Node) && isOpen) {
setIsOpen(false);
}
};

document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, [isOpen, setIsOpen]);

return (
<div ref={containerRef} className="relative w-fit shrink-0">
{connect}
{isOpen && dropdown}
</div>
);
}

export function Wallet({ children }: WalletReact) {
return (
<WalletProvider>
<div className="relative w-fit shrink-0">
{connect}
{dropdown}
</div>
<WalletContent>{children}</WalletContent>
</WalletProvider>
);
}
}

0 comments on commit c1ca1ea

Please sign in to comment.