Skip to content

Commit

Permalink
feat: added signer updates
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Nov 1, 2024
1 parent 7605378 commit 258f11c
Show file tree
Hide file tree
Showing 20 changed files with 1,319 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ exports[`BlockListWithControls renders correctly 1`] = `
class="css-16e8ooo"
>
<div
class="css-1kk2bc1"
class="css-1159lxg"
>
<span
class="chakra-text css-hnwgpl"
class="chakra-text css-12b8kh6"
>
Recent Blocks
</span>
Expand Down
17 changes: 17 additions & 0 deletions src/app/_components/time-filter/DateInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client';

import { forwardRef } from '@chakra-ui/react';

Check warning on line 3 in src/app/_components/time-filter/DateInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DateInput.tsx#L3

Added line #L3 was not covered by tests

import { Input } from '../../../ui/Input';

Check warning on line 5 in src/app/_components/time-filter/DateInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DateInput.tsx#L5

Added line #L5 was not covered by tests

export const DateInput = forwardRef((props, ref) => (

Check warning on line 7 in src/app/_components/time-filter/DateInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DateInput.tsx#L7

Added line #L7 was not covered by tests
<Input
sx={{
'::placeholder': {
color: 'textSubdued',
},
}}
ref={ref}
{...props}
/>
));
141 changes: 141 additions & 0 deletions src/app/_components/time-filter/DatePickerInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { FormLabel } from '@/ui/FormLabel';
import { UTCDate } from '@date-fns/utc';
import { Field, FieldProps, Form, Formik } from 'formik';
import DatePicker from 'react-datepicker';
import 'react-datepicker/dist/react-datepicker.css';

Check warning on line 5 in src/app/_components/time-filter/DatePickerInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerInput.tsx#L1-L5

Added lines #L1 - L5 were not covered by tests

import { Box } from '../../../ui/Box';
import { Button } from '../../../ui/Button';
import { FormControl } from '../../../ui/FormControl';
import { Stack } from '../../../ui/Stack';
import { DateInput } from './DateInput';

Check warning on line 11 in src/app/_components/time-filter/DatePickerInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerInput.tsx#L7-L11

Added lines #L7 - L11 were not covered by tests

type DateValue = number | undefined;

export interface DatePickerValues {
date: DateValue;
}

export interface DatePickerFormProps {
initialDate: DateValue;
onSubmit: (values: DatePickerValues) => void;
placeholder?: string;
label?: string;
key?: string;
}

// TODO: move this to the search
// function searchAfterDatePickerOnSubmitHandler({
// searchParams,
// router,
// onClose,
// }: {
// searchParams: URLSearchParams;
// router: ReturnType<typeof useRouter>;
// onClose: () => void;
// }) {
// return ({ date: startTime }: DatePickerFormValues) => {
// const params = new URLSearchParams(searchParams);
// const startTimeTs = startTime ? Math.floor(startTime).toString() : undefined;
// params.delete('endTime');
// if (startTimeTs) {
// params.set('startTime', startTimeTs);
// } else {
// params.delete('startTime');
// }
// router.push(`?${params.toString()}`, { scroll: false });
// onClose();
// };
// }

// TODO: move this to the search
// function searchBeforeDatePickerOnSubmitHandler({
// searchParams,
// router,
// onClose,
// }: {
// searchParams: URLSearchParams;
// router: ReturnType<typeof useRouter>;
// onClose: () => void;
// }) {
// return ({ date: endTime }: DatePickerFormValues) => {
// const params = new URLSearchParams(searchParams);
// const endTimeTs = endTime ? Math.floor(endTime).toString() : undefined;
// params.delete('startTime');
// if (endTimeTs) {
// params.set('endTime', endTimeTs);
// } else {
// params.delete('endTime');
// }
// router.push(`?${params.toString()}`, { scroll: false });
// onClose();
// };
// }

export function DatePickerInput({

Check warning on line 75 in src/app/_components/time-filter/DatePickerInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerInput.tsx#L75

Added line #L75 was not covered by tests
initialDate,
label = 'Date:',
onSubmit,
placeholder = 'YYYY-MM-DD',
key,
}: DatePickerFormProps) {
const initialValues: DatePickerValues = {

Check warning on line 82 in src/app/_components/time-filter/DatePickerInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerInput.tsx#L81-L82

Added lines #L81 - L82 were not covered by tests
date: initialDate,
};
return (

Check warning on line 85 in src/app/_components/time-filter/DatePickerInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerInput.tsx#L85

Added line #L85 was not covered by tests
<Formik
enableReinitialize
validateOnChange={false}
validateOnBlur={false}
initialValues={initialValues}
onSubmit={({ date }: DatePickerValues) => {
onSubmit({ date });

Check warning on line 92 in src/app/_components/time-filter/DatePickerInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerInput.tsx#L91-L92

Added lines #L91 - L92 were not covered by tests
}}
key={key}
>
{() => (
<Form>
<Stack gap={4}>
<Field name="date">
{({ field, form }: FieldProps<string, DatePickerValues>) => (
<FormControl>
<FormLabel>{label}</FormLabel>
<DatePicker
customInput={<DateInput placeholder={placeholder} fontSize="sm" />}
selected={form.values.date ? new UTCDate(form.values.date * 1000) : undefined}
onChange={date => {

Check warning on line 106 in src/app/_components/time-filter/DatePickerInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerInput.tsx#L106

Added line #L106 was not covered by tests
if (date) {
const utcDate = new UTCDate(

Check warning on line 108 in src/app/_components/time-filter/DatePickerInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerInput.tsx#L108

Added line #L108 was not covered by tests
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
0,
0,
0
);
form.setFieldValue('date', utcDate.getTime() / 1000);

Check warning on line 116 in src/app/_components/time-filter/DatePickerInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerInput.tsx#L116

Added line #L116 was not covered by tests
}
}}
dateFormat="yyyy-MM-dd"
/>
</FormControl>
)}
</Field>
</Stack>
<Box mt={4}>
<Button
width="full"
type="submit"
fontSize="sm"
variant="secondary"
height={10}
color="textSubdued"
>
Apply
</Button>
</Box>
</Form>
)}
</Formik>
);
}
142 changes: 142 additions & 0 deletions src/app/_components/time-filter/DatePickerRangeInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { UTCDate } from '@date-fns/utc';
import { Field, FieldProps, Form, Formik } from 'formik';
import DatePicker from 'react-datepicker';
import 'react-datepicker/dist/react-datepicker.css';

Check warning on line 4 in src/app/_components/time-filter/DatePickerRangeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerRangeInput.tsx#L1-L4

Added lines #L1 - L4 were not covered by tests

import { Box } from '../../../ui/Box';
import { Button } from '../../../ui/Button';
import { FormControl } from '../../../ui/FormControl';
import { FormLabel } from '../../../ui/FormLabel';
import { Stack } from '../../../ui/Stack';
import { DateInput } from './DateInput';

Check warning on line 11 in src/app/_components/time-filter/DatePickerRangeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerRangeInput.tsx#L6-L11

Added lines #L6 - L11 were not covered by tests

type DateValue = number | undefined;

export interface DatePickerRangeInputState {
startDate: DateValue;
endDate: DateValue;
}

interface DatePickerRangeInputProps {
onSubmit: (values: DatePickerRangeInputState) => void;
initialStartDate?: DateValue;
initialEndDate?: DateValue;
label?: string;
key?: string;
}

// // TODO: move this to the search
// function searchDatePickerRangeFormOnSubmitHandler({
// searchParams,
// router,
// onClose,
// }: {
// searchParams: URLSearchParams;
// router: ReturnType<typeof useRouter>;
// onClose: () => void;
// }) {
// return ({ startTime, endTime }: DateRangeFormValues) => {
// const params = new URLSearchParams(searchParams);
// const startTimeTs = startTime ? Math.floor(startTime).toString() : undefined;
// const endTimeTs = endTime ? Math.floor(endTime).toString() : undefined;
// if (startTimeTs) {
// params.set('startTime', startTimeTs);
// } else {
// params.delete('startTime');
// }
// if (endTimeTs) {
// params.set('endTime', endTimeTs);
// } else {
// params.delete('endTime');
// }
// router.push(`?${params.toString()}`, { scroll: false });
// onClose();
// };
// }

export function DatePickerRangeInput({

Check warning on line 57 in src/app/_components/time-filter/DatePickerRangeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerRangeInput.tsx#L57

Added line #L57 was not covered by tests
initialStartDate,
initialEndDate,
onSubmit,
label = 'Between:',
key,
}: DatePickerRangeInputProps) {
const initialValues: DatePickerRangeInputState = {

Check warning on line 64 in src/app/_components/time-filter/DatePickerRangeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerRangeInput.tsx#L63-L64

Added lines #L63 - L64 were not covered by tests
startDate: initialStartDate,
endDate: initialEndDate,
};
return (

Check warning on line 68 in src/app/_components/time-filter/DatePickerRangeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerRangeInput.tsx#L68

Added line #L68 was not covered by tests
<Formik
enableReinitialize
validateOnChange={false}
validateOnBlur={false}
initialValues={initialValues}
onSubmit={({ startDate, endDate }: DatePickerRangeInputState) => {
onSubmit({ startDate, endDate });

Check warning on line 75 in src/app/_components/time-filter/DatePickerRangeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerRangeInput.tsx#L74-L75

Added lines #L74 - L75 were not covered by tests
}}
key={key}
>
{() => (
<Form>
<Stack gap={4}>
<Field name="startTime">
{({ form }: FieldProps<string, DatePickerRangeInputState>) => (
<FormControl>
<FormLabel>{label}</FormLabel>
<DatePicker
selectsRange={true}
customInput={<DateInput placeholder="YYYY-MM-DD" fontSize={'sm'} />}
onChange={dateRange => {
const [startDate, endDate] = dateRange;

Check warning on line 90 in src/app/_components/time-filter/DatePickerRangeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerRangeInput.tsx#L89-L90

Added lines #L89 - L90 were not covered by tests
const utcStart = startDate
? new UTCDate(

Check warning on line 92 in src/app/_components/time-filter/DatePickerRangeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerRangeInput.tsx#L92

Added line #L92 was not covered by tests
startDate.getUTCFullYear(),
startDate.getUTCMonth(),
startDate.getUTCDate(),
0,
0,
0
).getTime() / 1000
: null;

Check warning on line 100 in src/app/_components/time-filter/DatePickerRangeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerRangeInput.tsx#L100

Added line #L100 was not covered by tests
const utcEnd = endDate
? new UTCDate(

Check warning on line 102 in src/app/_components/time-filter/DatePickerRangeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerRangeInput.tsx#L102

Added line #L102 was not covered by tests
endDate.getUTCFullYear(),
endDate.getUTCMonth(),
endDate.getUTCDate(),
23,
59,
59
).getTime() / 1000
: null;
form.setFieldValue('endTime', utcEnd);
form.setFieldValue('startTime', utcStart);

Check warning on line 112 in src/app/_components/time-filter/DatePickerRangeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/time-filter/DatePickerRangeInput.tsx#L110-L112

Added lines #L110 - L112 were not covered by tests
}}
startDate={
form.values.startDate ? new UTCDate(form.values.startDate * 1000) : undefined
}
endDate={
form.values.endDate ? new UTCDate(form.values.endDate * 1000) : undefined
}
dateFormat="yyyy-MM-dd"
/>
</FormControl>
)}
</Field>
</Stack>
<Box mt={4}>
<Button
width="100%"
type="submit"
fontSize={'sm'}
variant={'secondary'}
height={10}
color="textSubdued"
>
Apply
</Button>
</Box>
</Form>
)}
</Formik>
);
}
Loading

0 comments on commit 258f11c

Please sign in to comment.