Dialogs slice

From LedgerHQ/ledger-live · View interactive version

Dialogs slice is an AI agent skill from the GitHub repository LedgerHQ/ledger-live. Open and close a Ledger Wallet Desktop global dialog through the shared `dialogs` Redux slice (`DIALOG_IDS`, `openDialog`, `selectIsDialogOpen`) and mount it once in `GlobalDialogs`. Use when adding a desktop dialog mounted at the app root and opened from a distant part of the tree, or when editing

How to use this skill

Skill file

Global Dialogs Slice Pattern

Centralized Redux state for global dialog open/close, avoiding one slice per dialog.

When to use

Use this pattern for dialogs that are:

Do NOT use this for dialogs that are local to a single component or screen -- prefer a simple useState instead.

Architecture

Adding a new global dialog

Step 1: Register the dialog ID

Add the new ID to the DIALOG_IDS array in renderer/reducers/dialogs.ts. The DialogId type updates automatically:

export const DIALOG_IDS = ["RELEASE_NOTES", "MY_NEW_DIALOG"] as const;
// DialogId is now "RELEASE_NOTES" | "MY_NEW_DIALOG"

Step 2: Create the feature dialog file

Create myFeature/myNewDialog.ts in the feature folder:

import {
  openDialog,
  closeDialog,
  selectIsDialogOpen,
  type DialogId,
} from "~/renderer/reducers/dialogs";
import type { State } from "~/renderer/reducers";

const DIALOG_ID: DialogId = "MY_NEW_DIALOG";

export const openMyNewDialog = () => openDialog(DIALOG_ID);
export const closeMyNewDialog = () => closeDialog(DIALOG_ID);
export const selectIsMyNewDialogOpen = (state: State) => selectIsDialogOpen(state, DIALOG_ID);

Step 3: Use in the view model

import { selectIsMyNewDialogOpen, closeMyNewDialog } from "../myNewDialog";

const useMyNewDialogViewModel = () => {
  const isOpen = useSelector(selectIsMyNewDialogOpen);
  const dispatch = useDispatch();
  const onClose = useCallback(() => dispatch(closeMyNewDialog()), [dispatch]);
  return { isOpen, onClose };
};

Step 4: Mount in GlobalDialogs

Add the dialog component to

CODE0,

lazy-loaded and in its own Suspense like the dialogs already there. A sketch of that file:

const MyNewDialog = lazy(() => import("LLD/features/MyFeature"));

const GlobalDialogs = () => (
  <>
    {/* ...existing dialogs */}
    <Suspense fallback={null}>
      <MyNewDialog />
    </Suspense>
  </>
);

Step 5: Trigger from anywhere

import { openMyNewDialog } from "LLD/features/MyFeature/myNewDialog";

dispatch(openMyNewDialog());

Rules

Reference

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.