Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Dashboard notify user if no Frame account is / can be connected #6071

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Menu, Text, useMantineColorScheme, createStyles } from "@mantine/core";
import { showNotification, hideNotification } from "@mantine/notifications";
import { useAccount, useConnect, useDisconnect } from "wagmi";
import { InjectedConnector } from "@wagmi/core";
import { Slash } from "react-feather";
import { useDash } from "src/hooks";
import Button from "src/components/composed/Sidebar/Bottom/MenuButton/Button";
import {
frameWalletNotifications,
frameWalletNotificationId
} from "src/utils/notifications";

const useStyles = createStyles((theme, _params, _getRef) => {
const { colors, colorScheme, fn } = theme;
Expand Down Expand Up @@ -33,7 +38,20 @@ function MenuButton(): JSX.Element {
const { classes } = useStyles();

if (!isConnected) {
return <Button onClick={() => void connect()} />;
return (
<Button
onClick={async () => {
try {
await window.ethereum?.request({ method: "eth_requestAccounts" });
hideNotification(frameWalletNotificationId);
} catch (err) {
if (/^No Frame account selected$/i.test((err as any)?.message))
showNotification(frameWalletNotifications["no-account"]);
}
connect();
}}
/>
);
} else {
return (
<Menu
Expand Down
14 changes: 14 additions & 0 deletions packages/dashboard/src/utils/notifications/frame-wallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { NotificationProps } from "@mantine/notifications";

export const frameWalletNotificationId = "frame-wallet";

export const frameWalletNotifications: Record<"no-account", NotificationProps> =
{
"no-account": {
id: frameWalletNotificationId,
autoClose: false,
color: "yellow",
title: "Frame wallet not ready",
message: "Connect a Frame account to continue"
}
};
1 change: 1 addition & 0 deletions packages/dashboard/src/utils/notifications/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "src/utils/notifications/decode";
export * from "src/utils/notifications/analytics";
export * from "src/utils/notifications/frame-wallet";