Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: all dialogs now use <Dialog> headlessui component (and more). #257

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1a0d73e
Refactor the sendForm and TailwindDialog to use <dialog> tags
hansl Feb 7, 2025
c244f2e
Fix the tests
hansl Feb 8, 2025
a6b0bfa
Merge branch 'main' into dialog-fixes
hansl Feb 8, 2025
5a077dc
More WIP
hansl Feb 9, 2025
a46dd21
WIP
hansl Feb 9, 2025
0bdc7d3
WIP
hansl Feb 10, 2025
c526efb
WIP
hansl Feb 10, 2025
d32c4ee
Merge branch 'main' into dialog-fixes
hansl Feb 10, 2025
73bfb3d
WIP
hansl Feb 10, 2025
b0df919
WIP
hansl Feb 11, 2025
d8ff876
WIP
hansl Feb 11, 2025
edb29cb
WIP
hansl Feb 12, 2025
39c95b6
Fix tests
hansl Feb 12, 2025
2087b78
Merge remote-tracking branch 'upstream/main' into dialog-fixes
hansl Feb 12, 2025
ecea1a1
Fix stuff
hansl Feb 12, 2025
21cc274
Remove export of unused component
hansl Feb 12, 2025
2a35824
Apply some suggestions from coderabbitai
hansl Feb 12, 2025
2a3a985
Add bun.lock
hansl Feb 12, 2025
2df596f
Fix bech32 import
hansl Feb 12, 2025
f1b61b1
Address comments
hansl Feb 12, 2025
fd7b811
Address comments
hansl Feb 12, 2025
9a25de4
Fix typing
hansl Feb 12, 2025
fae7a4b
Re-add closing the signing dialog handler
hansl Feb 12, 2025
6a7b543
Simplify the onClose handler a little
hansl Feb 12, 2025
368890d
Add an environment variable to set minimum voting period allowed
hansl Feb 12, 2025
848656b
Merge branch 'fix-268' into dialog-fixes
hansl Feb 12, 2025
2d2c294
Add a onSigningStart/End to voteModal
hansl Feb 13, 2025
d802df7
Move the vote popup to pick and do not stack sign modal on it
hansl Feb 13, 2025
c6907fd
Remove unused stuff
hansl Feb 13, 2025
208c58d
Use proper typing and remove more unused stuff
hansl Feb 13, 2025
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
358 changes: 122 additions & 236 deletions bun.lock
hansl marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('ValidatorList', () => {

test('remove button works and shows the warning modal', async () => {
renderWithProps();
const allRemoveButtons = screen.getAllByText('Remove');
const allRemoveButtons = screen.getAllByTestId('remove-validator');
fireEvent.click(allRemoveButtons[0]);
await waitFor(() =>
expect(screen.getByText('Are you sure you want to remove the validator')).toBeInTheDocument()
Expand Down
7 changes: 3 additions & 4 deletions components/admins/components/validatorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,9 @@ export default function ValidatorList({
onClick={e => e.stopPropagation()}
>
<button
onClick={e => {
handleRemove(validator);
}}
className="btn btn-error btn-sm text-white "
onClick={() => handleRemove(validator)}
className="btn btn-error btn-sm text-white"
data-testid="remove-validator"
aria-label={`Remove validator ${validator.description.moniker}`}
>
<TrashIcon className="w-5 h-5" />
Expand Down
4 changes: 2 additions & 2 deletions components/admins/modals/__tests__/descriptionModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ describe('DescriptionModal Component', () => {
afterEach(cleanup);

test('renders modal with correct details', () => {
render(<DescriptionModal modalId={modalId} details={details} />);
render(<DescriptionModal open details={details} />);
expect(screen.getByText('Group Description')).toBeInTheDocument();
expect(screen.getByText(details)).toBeInTheDocument();
});

test('displays correct title for validator type', () => {
render(<DescriptionModal modalId={modalId} details={details} type="validator" />);
render(<DescriptionModal open details={details} type="validator" />);
expect(screen.getByText('Validator Description')).toBeInTheDocument();
});

Expand Down
11 changes: 10 additions & 1 deletion components/admins/modals/__tests__/validatorModal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { describe, test, afterEach, expect } from 'bun:test';
import { describe, test, afterEach, expect, mock, jest } from 'bun:test';
import React from 'react';
import { screen, fireEvent, cleanup, within, waitFor } from '@testing-library/react';
import { ValidatorDetailsModal } from '@/components/admins/modals/validatorModal';
import matchers from '@testing-library/jest-dom/matchers';
import { mockActiveValidators } from '@/tests/mock';
import { renderWithChainProvider } from '@/tests/render';

mock.module('next/router', () => ({
useRouter: jest.fn().mockReturnValue({
query: {},
push: jest.fn(),
}),
}));

expect.extend(matchers);

const validator = mockActiveValidators[0];
Expand All @@ -17,6 +24,8 @@ const validatorVPArray = [{ vp: BigInt(1000), moniker: 'Validator One' }];
function renderWithProps(props = {}) {
return renderWithChainProvider(
<ValidatorDetailsModal
openValidatorModal={true}
setOpenValidatorModal={() => {}}
validator={validator}
modalId={modalId}
admin={admin}
Expand Down
11 changes: 10 additions & 1 deletion components/admins/modals/__tests__/warningModal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { describe, test, afterEach, expect } from 'bun:test';
import { describe, test, afterEach, expect, mock, jest } from 'bun:test';
import React from 'react';
import { screen, cleanup } from '@testing-library/react';
import { WarningModal } from '@/components/admins/modals/warningModal';
import matchers from '@testing-library/jest-dom/matchers';
import { renderWithChainProvider } from '@/tests/render';

mock.module('next/router', () => ({
useRouter: jest.fn().mockReturnValue({
query: {},
push: jest.fn(),
}),
}));

expect.extend(matchers);

const admin = 'manifest1adminaddress';
Expand All @@ -15,6 +22,8 @@ const modalId = 'test-modal';
function renderWithProps(props = {}) {
return renderWithChainProvider(
<WarningModal
openWarningModal={true}
setOpenWarningModal={() => {}}
admin={admin}
address={address}
moniker={moniker}
Expand Down
61 changes: 14 additions & 47 deletions components/admins/modals/cancelUpgradeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import { MsgCancelUpgrade } from '@liftedinit/manifestjs/dist/codegen/cosmos/upgrade/v1beta1/tx';
import { PlanSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/upgrade/v1beta1/upgrade';
import env from '@/config/env';
import { Dialog } from '@headlessui/react';
import { SignModal } from '@/components/react';

interface BaseModalProps {
isOpen: boolean;
Expand Down Expand Up @@ -40,17 +42,6 @@
const { tx, isSigning, setIsSigning } = useTx(env.chain);
const { estimateFee } = useFeeEstimation(env.chain);

useEffect(() => {
const handleEscape = (e: KeyboardEvent) => {
if (e.key === 'Escape' && isOpen) {
onClose();
}
};

document.addEventListener('keydown', handleEscape);
return () => document.removeEventListener('keydown', handleEscape);
}, [isOpen, onClose]);

const handleCancelUpgrade = async () => {
setIsSigning(true);
try {
Expand Down Expand Up @@ -89,27 +80,23 @@
}
};

const modalContent = (
<dialog
className={`modal ${isOpen ? 'modal-open' : ''}`}
return (
<Dialog
open={isOpen}
onClose={onClose}
className={`modal ${isOpen ? 'modal-open' : ''} flex fixed p-0 m-0`}

Check warning on line 87 in components/admins/modals/cancelUpgradeModal.tsx

View check run for this annotation

Codecov / codecov/patch

components/admins/modals/cancelUpgradeModal.tsx#L83-L87

Added lines #L83 - L87 were not covered by tests
style={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: 9999,
backgroundColor: 'transparent',
padding: 0,
margin: 0,
height: '100vh',
width: '100vw',
display: isOpen ? 'flex' : 'none',
alignItems: 'center',
justifyContent: 'center',
}}
>
<div className="modal-box bg-secondary rounded-[24px] max-w-[542px] p-6">
<div className="fixed inset-0 bg-black/30" aria-hidden="true" />

<Dialog.Panel className="modal-box bg-secondary rounded-[24px] max-w-[542px] p-6">

Check warning on line 99 in components/admins/modals/cancelUpgradeModal.tsx

View check run for this annotation

Codecov / codecov/patch

components/admins/modals/cancelUpgradeModal.tsx#L97-L99

Added lines #L97 - L99 were not covered by tests
<div className="flex items-center justify-between mb-6">
<h3 className="font-bold text-lg">Cancel Upgrade</h3>
<form method="dialog">
Expand Down Expand Up @@ -158,29 +145,9 @@
{isSigning ? <span className="loading loading-dots"></span> : 'Cancel Upgrade'}
</button>
</div>
</div>
<form
method="dialog"
className="modal-backdrop"
style={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: -1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
}}
onClick={onClose}
>
<button>close</button>
</form>
</dialog>
);

if (typeof document !== 'undefined') {
return createPortal(modalContent, document.body);
}

return null;
<SignModal />
</Dialog.Panel>

Check warning on line 150 in components/admins/modals/cancelUpgradeModal.tsx

View check run for this annotation

Codecov / codecov/patch

components/admins/modals/cancelUpgradeModal.tsx#L149-L150

Added lines #L149 - L150 were not covered by tests
</Dialog>
);
}
69 changes: 46 additions & 23 deletions components/admins/modals/descriptionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,56 @@
import React from 'react';
import { PiWarning } from 'react-icons/pi';
import { Dialog } from '@headlessui/react';

interface DescriptionModalProps {
modalId: string;
open?: boolean;
onClose?: () => void;
details: string;
type?: 'group' | 'validator';
}

export function DescriptionModal({ modalId, details, type }: Readonly<DescriptionModalProps>) {
export function DescriptionModal({
open,
onClose,
details,
type,
}: Readonly<DescriptionModalProps>) {
if (!open) return null;

function handleClose() {

Check warning on line 19 in components/admins/modals/descriptionModal.tsx

View check run for this annotation

Codecov / codecov/patch

components/admins/modals/descriptionModal.tsx#L19

Added line #L19 was not covered by tests
onClose && onClose();
}
hansl marked this conversation as resolved.
Show resolved Hide resolved

return (
<dialog id={modalId} className="modal max-w-md mx-auto">
<form method="dialog" className="modal-box ">
<button
className="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
aria-label="x-close"
>
</button>
<h3 className="font-bold text-lg">
{type === 'validator' ? 'Validator' : 'Group'}&nbsp;Description
</h3>
<div className="divider divider-horizon -mt-0 -mb-2"></div>
<div className="py-4 flex flex-col gap-4">
<p className="">{details}</p>
</div>
</form>
<form method="dialog" className="modal-backdrop">
<button>close</button>
</form>
</dialog>
<Dialog
open={open}
onClose={handleClose}
className="modal modal-open mx-auto fixed flex p-0 m-0 top-0 z-[9999]"
style={{
alignItems: 'center',
justifyContent: 'center',
}}
>
<div className="fixed inset-0 bg-black/30" aria-hidden="true" />

<Dialog.Panel>
<form method="dialog" className="modal-box ">
<button
className="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
aria-label="x-close"
onClick={handleClose}
>
</button>
<h3 className="font-bold text-lg">
{type === 'validator' ? 'Validator' : 'Group'}&nbsp;Description
</h3>

<div className="divider divider-horizon -mt-0 -mb-2"></div>
<div className="py-4 flex flex-col gap-4">
<p className="">{details}</p>
</div>
</form>
</Dialog.Panel>
</Dialog>
);
}
67 changes: 16 additions & 51 deletions components/admins/modals/multiMfxBurnModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import { MetadataSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/bank/v1beta1/bank';
import { TailwindModal } from '@/components/react';
import env from '@/config/env';
import { SignModal } from '@/components/react';
import { Dialog } from '@headlessui/react';

interface BurnPair {
address: string;
Expand Down Expand Up @@ -55,17 +57,6 @@
const [isContactsOpen, setIsContactsOpen] = useState(false);
const [selectedIndex, setSelectedIndex] = useState<number | null>(null);

useEffect(() => {
const handleEscape = (e: KeyboardEvent) => {
if (e.key === 'Escape' && isOpen) {
onClose();
}
};

document.addEventListener('keydown', handleEscape);
return () => document.removeEventListener('keydown', handleEscape);
}, [isOpen, onClose]);

const updateBurnPair = (index: number, field: 'address' | 'amount', value: string) => {
const newPairs = [...burnPairs];
newPairs[index] = { ...newPairs[index], [field]: value };
Expand Down Expand Up @@ -126,28 +117,23 @@
}
};

const modalContent = (
<dialog
id="multi_burn_modal"
className={`modal ${isOpen ? 'modal-open' : ''}`}
if (!isOpen) return null;

return (
<Dialog
open
onClose={onClose}
className="modal modal-open fixed flex p-0 m-0 top-0"

Check warning on line 126 in components/admins/modals/multiMfxBurnModal.tsx

View check run for this annotation

Codecov / codecov/patch

components/admins/modals/multiMfxBurnModal.tsx#L120-L126

Added lines #L120 - L126 were not covered by tests
style={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: 9999,
backgroundColor: 'transparent',
padding: 0,
margin: 0,
height: '100vh',
width: '100vw',
display: isOpen ? 'flex' : 'none',
alignItems: 'center',
justifyContent: 'center',
}}
>
<div className="modal-box max-w-4xl mx-auto min-h-[30vh] max-h-[70vh] rounded-[24px] bg-[#F4F4FF] dark:bg-[#1D192D] shadow-lg overflow-y-auto">
<div className="fixed inset-0 bg-black/30" aria-hidden="true" />

<Dialog.Panel className="modal-box max-w-4xl mx-auto min-h-[30vh] max-h-[70vh] rounded-[24px] bg-[#F4F4FF] dark:bg-[#1D192D] shadow-lg overflow-y-auto">

Check warning on line 136 in components/admins/modals/multiMfxBurnModal.tsx

View check run for this annotation

Codecov / codecov/patch

components/admins/modals/multiMfxBurnModal.tsx#L134-L136

Added lines #L134 - L136 were not covered by tests
<form method="dialog" onSubmit={onClose}>
<button
aria-label="Close modal"
Expand Down Expand Up @@ -285,30 +271,9 @@
)}
</Formik>
</div>
</div>
<form
method="dialog"
className="modal-backdrop"
style={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: -1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
}}
onSubmit={onClose}
>
<button>close</button>
</form>
</dialog>
);

// Only render if we're in the browser
if (typeof document !== 'undefined') {
return createPortal(modalContent, document.body);
}

return null;
<SignModal />
</Dialog.Panel>

Check warning on line 276 in components/admins/modals/multiMfxBurnModal.tsx

View check run for this annotation

Codecov / codecov/patch

components/admins/modals/multiMfxBurnModal.tsx#L275-L276

Added lines #L275 - L276 were not covered by tests
</Dialog>
);
}
Loading