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
1 change: 1 addition & 0 deletions examples/testapp/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const PAGES = [
'/payment',
'/pay-playground',
'/subscribe-playground',
'/prolink-playground',
];

export function Layout({ children }: LayoutProps) {
Expand Down
11 changes: 4 additions & 7 deletions examples/testapp/src/pages/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import { useEIP1193Provider } from '../context/EIP1193ProviderContextProvider';

export default function Home() {
const { provider } = useEIP1193Provider();
// @ts-expect-error refactor soon
const [connected, setConnected] = React.useState(Boolean(provider?.connected));
const [connected, setConnected] = React.useState(false);
const [chainId, setChainId] = React.useState<number | undefined>(undefined);
// This is for Extension compatibility, Extension with SDK3.9 does not emit connect event
// correctly, so we manually check if the extension is connected, and set the connected state
Expand All @@ -40,21 +39,19 @@ export default function Home() {
setConnected(true);
});
provider?.on('chainChanged', (newChainId) => {
// @ts-expect-error refactor soon
setChainId(newChainId);
setChainId(Number.parseInt(newChainId as string, 16));
});
}, [provider]);

useEffect(() => {
if (connected) {
provider?.request({ method: 'eth_chainId' }).then((chainId) => {
// @ts-expect-error refactor soon
setChainId(Number.parseInt(chainId, 16));
setChainId(Number.parseInt(chainId as string, 16));
});
}

// Injected provider does not emit a 'connect' event
// @ts-expect-error refactor soon
// @ts-expect-error isCoinbaseBrowser only exists on injected providers
if (provider?.isCoinbaseBrowser) {
setConnected(true);
}
Expand Down
Loading