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

chore: giant typing pr #1175

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 2 additions & 1 deletion src/clients/metadataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MetadataServicePricesResponse,
} from '@/constants/assetMetadata';

import { MapOf } from '@/lib/objectHelpers';
import { log } from '@/lib/telemetry';

/**
Expand Down Expand Up @@ -37,7 +38,7 @@ class MetadataServiceClient {
return fetch(`${this.host}/${endpoint}`).then((res) => res.json());
}

async getMarketmap(): Promise<Record<string, string>> {
async getMarketmap(): Promise<MapOf<string>> {
return this._get(MetadataServicePath.MARKET_MAP);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/BackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const BackButton = ({
const navigation = globalThis.navigation;

if (!navigation) {
globalThis.history?.back();
globalThis.history.back();
// @ts-ignore
} else if (navigation.canGoBack) {
navigation.back();
Expand Down
6 changes: 4 additions & 2 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import { LoadingDots } from '@/components/Loading/LoadingDots';

import { MapOf } from '@/lib/objectHelpers';

import { BaseButton, BaseButtonProps } from './BaseButton';

export type ButtonStateConfig = {
Expand All @@ -27,7 +29,7 @@

type StyleProps = {
action?: ButtonAction;
state: Record<string, boolean | undefined>;
state: MapOf<boolean>;
className?: string;
};

Expand All @@ -50,7 +52,7 @@
},
ref
) => {
const state: Record<string, boolean | undefined> =
const state: MapOf<boolean> =
typeof stateConfig === 'string'
? { [stateConfig]: true }
: {
Expand Down Expand Up @@ -165,7 +167,7 @@
${({ action }) => action && buttonActionVariants[action]}

${({ action, state }) =>
state &&

Check warning on line 170 in src/components/Button.tsx

View workflow job for this annotation

GitHub Actions / lint

Unnecessary conditional, value is always truthy
css`
// Ordered from lowest to highest priority (ie. Disabled should overwrite Active and Loading states)
${state[ButtonState.Loading] && buttonStateVariants(action)[ButtonState.Loading]}
Expand Down
6 changes: 4 additions & 2 deletions src/components/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import { WithSeparators } from '@/components/Separator';
import { WithTooltip } from '@/components/WithTooltip';

import { MapOf } from '@/lib/objectHelpers';

export type DetailsItem = {
// eslint-disable-next-line react/no-unused-prop-types
key: string;
tooltip?: TooltipStringKeys;
tooltipParams?: Record<string, string>;
tooltipParams?: MapOf<string>;
label: string | JSX.Element;
value?: Nullable<string> | JSX.Element | undefined;
// eslint-disable-next-line react/no-unused-prop-types
Expand Down Expand Up @@ -210,7 +212,7 @@
justify-items: start;
gap: 0.375rem;
`,
} satisfies Record<string, ReturnType<typeof css>>;
} satisfies MapOf<ReturnType<typeof css>>;
const $Details = styled.dl<{
layout: 'column' | 'row' | 'rowColumns' | 'grid' | 'stackColumn';
withSeparators: boolean;
Expand All @@ -221,7 +223,7 @@
--details-grid-numColumns: 2;
--details-item-vertical-padding: ;

${({ layout }) => layout && detailsLayoutVariants[layout]}

Check warning on line 226 in src/components/Details.tsx

View workflow job for this annotation

GitHub Actions / lint

Unnecessary conditional, value is always truthy
`;

const $Item = styled.div<{
Expand All @@ -229,7 +231,7 @@
justifyItems?: 'start' | 'end';
withOverflow?: boolean;
}>`
${({ layout }) => layout && itemLayoutVariants[layout]}

Check warning on line 234 in src/components/Details.tsx

View workflow job for this annotation

GitHub Actions / lint

Unnecessary conditional, value is always truthy

${({ justifyItems }) =>
justifyItems === 'end' &&
Expand All @@ -241,7 +243,7 @@
`}

${({ layout, withOverflow }) =>
layout &&

Check warning on line 246 in src/components/Details.tsx

View workflow job for this annotation

GitHub Actions / lint

Unnecessary conditional, value is always truthy
withOverflow &&
{
column: css`
Expand Down
2 changes: 1 addition & 1 deletion src/components/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const DropdownMenu = forwardRefFn(
<$Item
disabled={!item.onSelect}
$highlightColor={item.highlightColor}
onSelect={item?.onSelect}
onSelect={item.onSelect}
>
{item.icon}
{item.label}
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const FormInput = forwardRef<HTMLInputElement, FormInputProps>(
<$FormInputContainer className={className} isValidationAttached={validationConfig?.attached}>
<$InputContainer hasLabel={!!label} hasSlotRight={!!slotRight}>
{label ? (
<$WithLabel label={label} inputID={id} disabled={otherProps?.disabled}>
<$WithLabel label={label} inputID={id} disabled={otherProps.disabled}>
<Input ref={ref} id={id} {...otherProps} />
</$WithLabel>
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
? undefined
: Number(newFormattedValue.replace(',', '.'));

onInput?.({ value: newValue, floatValue, formattedValue: newFormattedValue, ...e });
onInput({ value: newValue, floatValue, formattedValue: newFormattedValue, ...e });
}}
// Native
disabled={disabled}
Expand Down
4 changes: 2 additions & 2 deletions src/components/NavigationMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ export const NavigationMenu = <MenuItemValue extends string, MenuGroupValue exte
<$List
data-orientation={depth > 0 ? 'menu' : orientation === 'vertical' ? 'vertical' : 'menu'}
>
{item?.subitems?.map((subitem) => (
{item.subitems?.map((subitem) => (
<$ListItem key={subitem.value} value={subitem.value} data-item={subitem.value}>
{subitem?.subitems ? (
{subitem.subitems ? (
renderSubitems({ item: subitem, depth: depth + 1 })
) : (
<$NavItem onSelect={onSelectItem} orientation={itemOrientation} {...subitem} />
Expand Down
27 changes: 14 additions & 13 deletions src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import breakpoints from '@/styles/breakpoints';
import { layoutMixins } from '@/styles/layoutMixins';

import { MustBigNumber } from '@/lib/numbers';
import { MapOf } from '@/lib/objectHelpers';
import { testFlags } from '@/lib/testFlags';

import { Icon, IconName } from './Icon';
Expand Down Expand Up @@ -99,7 +100,7 @@ export type TableElementProps<TableRowData extends BaseTableRowData | CustomRowC
columns: ColumnDef<TableRowData>[];
data: Array<TableRowData | CustomRowConfig>;
getRowKey: (rowData: TableRowData, rowIndex?: number) => Key;
getRowAttributes?: (rowData: TableRowData, rowIndex?: number) => Record<string, any>;
getRowAttributes?: (rowData: TableRowData, rowIndex?: number) => MapOf<any>;
defaultSortDescriptor?: SortDescriptor;
selectionMode?: 'multiple' | 'single';
selectionBehavior?: 'replace' | 'toggle';
Expand Down Expand Up @@ -215,10 +216,10 @@ export const Table = <TableRowData extends BaseTableRowData | CustomRowConfig>({

const [sortDescriptor, setSortDescriptor] = useState<SortDescriptor>(defaultSortDescriptor ?? {});
const items = useMemo(() => {
return sortDescriptor?.column
? [...data].sort((a, b) => sortFn(a, b, sortDescriptor?.column, sortDescriptor?.direction))
return sortDescriptor.column
? [...data].sort((a, b) => sortFn(a, b, sortDescriptor.column, sortDescriptor.direction))
: data;
}, [data, sortDescriptor?.column, sortDescriptor?.direction, sortFn]);
}, [data, sortDescriptor.column, sortDescriptor.direction, sortFn]);

const isEmpty = data.length === 0;
const shouldPaginate = paginationBehavior === 'paginate' && data.length > Math.min(...PAGE_SIZES);
Expand Down Expand Up @@ -299,7 +300,7 @@ export const Table = <TableRowData extends BaseTableRowData | CustomRowConfig>({
{(columnKey) => (
<Cell key={`${internalGetRowKey(item)}-${columnKey}`}>
{isTableRowData(item) &&
columns.find((column) => column.columnKey === columnKey)?.renderCell?.(item)}
columns.find((column) => column.columnKey === columnKey)?.renderCell(item)}
</Cell>
)}
</Row>
Expand All @@ -325,7 +326,7 @@ const TableRoot = <TableRowData extends BaseTableRowData | CustomRowConfig>(prop
getRowAttributes?: (
rowData: TableRowData,
rowIndex?: number
) => Record<string, string | number | Record<string, string | number>>;
) => MapOf<string | number | MapOf<string | number>>;
onRowAction?: (key: Key) => void;
children: TableStateProps<TableRowData>['children'];
numColumns: number;
Expand Down Expand Up @@ -425,7 +426,7 @@ const TableRoot = <TableRowData extends BaseTableRowData | CustomRowConfig>(prop
withOuterBorder={withOuterBorder}
>
{[...collection.body.childNodes].map((row) =>
(row.value as CustomRowConfig)?.slotCustomRow ? (
(row.value as CustomRowConfig).slotCustomRow ? (
(row.value as CustomRowConfig).slotCustomRow({
item: row,
state,
Expand All @@ -452,7 +453,7 @@ const TableRoot = <TableRowData extends BaseTableRowData | CustomRowConfig>(prop
state={state}
isActionable={
((cell as GridNode<TableRowData>).column?.value as ColumnDef<TableRowData>)
?.isActionable
.isActionable
}
/>
)
Expand Down Expand Up @@ -568,7 +569,7 @@ const TableColumnHeader = <TableRowData extends BaseTableRowData>({
// data-focused={isFocusVisible || undefined}
style={{
width: column.props?.width,
textAlign: (column?.value as any)?.align,
textAlign: (column.value as any)?.align,
}}
ref={ref}
allowSorting={column.props?.allowsSorting ?? true}
Expand All @@ -580,17 +581,17 @@ const TableColumnHeader = <TableRowData extends BaseTableRowData>({
(uiRefresh ? (
<SortIcon
sortDirection={
state.sortDescriptor?.column === column.key
? state.sortDescriptor?.direction ?? 'none'
state.sortDescriptor.column === column.key
? state.sortDescriptor.direction ?? 'none'
: 'none'
}
/>
) : (
<$SortArrow
aria-hidden="true"
sortDirection={
state.sortDescriptor?.column === column.key
? state.sortDescriptor?.direction ?? 'none'
state.sortDescriptor.column === column.key
? state.sortDescriptor.direction ?? 'none'
: 'none'
}
>
Expand Down
4 changes: 2 additions & 2 deletions src/components/TimeoutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export const TimeoutButton = ({
state={{
isDisabled:
secondsLeft > 0 ||
otherProps?.state === ButtonState.Disabled ||
(otherProps?.state as ButtonStateConfig)?.isDisabled,
otherProps.state === ButtonState.Disabled ||
(otherProps.state as ButtonStateConfig).isDisabled,
}}
>
{secondsLeft
Expand Down
2 changes: 1 addition & 1 deletion src/components/ValidatorIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const ValidatorIcons = ({
const validatorNames = validators.map((validator) => validator.description?.moniker).join(', ');
return (
<$ValidatorIcons className={className}>
{validators?.length <= numToShow
{validators.length <= numToShow
? validators.map((validator) => (
<$ValidatorIcon
key={validator.description?.moniker}
Expand Down
4 changes: 3 additions & 1 deletion src/components/WithHovercard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import { useStringGetter } from '@/hooks/useStringGetter';

import { popoverMixins } from '@/styles/popoverMixins';

import { MapOf } from '@/lib/objectHelpers';

type ElementProps = {
hovercard?: TooltipStringKeys;
stringParams?: Record<string, string | undefined>;
stringParams?: MapOf<string>;
slotTrigger?: ReactNode;
slotButton?: ReactNode;
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/WithTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import { popoverMixins } from '@/styles/popoverMixins';
import { Icon, IconName } from '@/components/Icon';
import { Link } from '@/components/Link';

import { MapOf } from '@/lib/objectHelpers';

type ElementProps = {
tooltip?: TooltipStringKeys;
tooltipString?: string;
tooltipStringTitle?: string;
stringParams?: Record<string, string | undefined>;
stringParams?: MapOf<string>;
withIcon?: boolean;
children?: ReactNode;
slotTooltip?: ReactNode;
Expand Down
8 changes: 4 additions & 4 deletions src/components/visx/TimeSeriesChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ export const TimeSeriesChart = <Datum extends {}>({
// Chart data
const { xAccessor, yAccessor } = series[0];

const earliestDatum = data?.[0];
const latestDatum = data?.[data.length - 1];
const earliestDatum = data[0];
const latestDatum = data[data.length - 1];

// Chart state
const getClampedZoomDomain = useCallback(
Expand Down Expand Up @@ -361,8 +361,8 @@ export const TimeSeriesChart = <Datum extends {}>({
colorAccessor={
childSeries.threshold ? () => 'transparent' : childSeries.colorAccessor
}
onPointerMove={childSeries?.onPointerMove}
onPointerOut={childSeries?.onPointerOut}
onPointerMove={childSeries.onPointerMove}
onPointerOut={childSeries.onPointerOut}
/>

{(childSeries.glyphSize ?? childSeries.getGlyphSize) && (
Expand Down
22 changes: 11 additions & 11 deletions src/components/visx/XYChartTooltipWithBounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ const TooltipInner = <Datum extends object>({
onTooltipContext?.(tooltipContext);
}, [tooltipContext]);

const tooltipContent = tooltipContext?.tooltipOpen
const tooltipContent = tooltipContext.tooltipOpen
? renderTooltip({ ...tooltipContext, colorScale })
: null;

const showTooltip = tooltipContext?.tooltipOpen && tooltipContent != null;
const showTooltip = tooltipContext.tooltipOpen && tooltipContent != null;

let computedTooltipLeft = tooltipContext?.tooltipLeft ?? 0;
let computedTooltipTop = tooltipContext?.tooltipTop ?? 0;
let computedTooltipLeft = tooltipContext.tooltipLeft ?? 0;
let computedTooltipTop = tooltipContext.tooltipTop ?? 0;
let crosshairLeft = computedTooltipLeft;
let crosshairTop = computedTooltipTop;

Expand All @@ -164,7 +164,7 @@ const TooltipInner = <Datum extends object>({
[dataRegistry, xScaleBandwidth, yScaleBandwidth, xScale, yScale]
);

const nearestDatum = tooltipContext?.tooltipData?.nearestDatum;
const nearestDatum = tooltipContext.tooltipData?.nearestDatum;
const nearestDatumKey = nearestDatum?.key ?? '';

if (showTooltip && nearestDatum) {
Expand All @@ -185,7 +185,7 @@ const TooltipInner = <Datum extends object>({
const size = Number(glyphStyle?.radius ?? 4);

if (showSeriesGlyphs) {
Object.values(tooltipContext?.tooltipData?.datumByKey ?? {}).forEach(
Object.values(tooltipContext.tooltipData?.datumByKey ?? {}).forEach(
({ key, datum, index }) => {
const color = colorScale?.(key) ?? theme?.htmlLabel?.color ?? '#222';
const { left, top } = getDatumLeftTop(key, datum);
Expand Down Expand Up @@ -213,7 +213,7 @@ const TooltipInner = <Datum extends object>({
const color =
(nearestDatumKey && colorScale?.(nearestDatumKey)) ??
null ??
theme?.gridStyles?.stroke ??
theme?.gridStyles.stroke ??
theme?.htmlLabel?.color ??
'#222';
glyphProps.push({
Expand Down Expand Up @@ -249,7 +249,7 @@ const TooltipInner = <Datum extends object>({
y1={margin.top}
y2={margin.top + innerHeight}
strokeWidth={1.5}
stroke={theme?.gridStyles?.stroke ?? theme?.htmlLabel?.color ?? '#222'}
stroke={theme?.gridStyles.stroke ?? theme?.htmlLabel?.color ?? '#222'}
{...verticalCrosshairStyle}
/>
)}
Expand All @@ -261,15 +261,15 @@ const TooltipInner = <Datum extends object>({
y1={crosshairTop}
y2={crosshairTop}
strokeWidth={1.5}
stroke={theme?.gridStyles?.stroke ?? theme?.htmlLabel?.color ?? '#222'}
stroke={theme?.gridStyles.stroke ?? theme?.htmlLabel?.color ?? '#222'}
{...horizontalCrosshairStyle}
/>
)}

{nearestDatum && renderXAxisLabel && (
<Group left={crosshairLeft} top={margin.top + innerHeight + margin.bottom / 2}>
<foreignObject style={{ overflow: 'visible' }}>
{renderXAxisLabel?.({ ...tooltipContext, colorScale })}
{renderXAxisLabel({ ...tooltipContext, colorScale })}
</foreignObject>
</Group>
)}
Expand All @@ -281,7 +281,7 @@ const TooltipInner = <Datum extends object>({
top={crosshairTop}
>
<foreignObject style={{ overflow: 'visible' }}>
{renderYAxisLabel?.({ ...tooltipContext, colorScale })}
{renderYAxisLabel({ ...tooltipContext, colorScale })}
</foreignObject>
</Group>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/visx/getScaleBandwidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
import { AxisScale } from '@visx/axis';

export function getScaleBandwidth<Scale extends AxisScale>(s?: Scale) {
return s && 'bandwidth' in s ? s?.bandwidth() ?? 0 : 0;
return s && 'bandwidth' in s ? s.bandwidth() ?? 0 : 0;
}
4 changes: 3 additions & 1 deletion src/constants/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { RecordOf, TagsOf, UnionOf, ofType, unionize } from 'unionize';
import { StatsigFlags } from '@/constants/statsig';
import { ConnectorType, WalletType } from '@/constants/wallets';

import { MapOf } from '@/lib/objectHelpers';

import type { AbacusApiStatus, HumanReadablePlaceOrderPayload } from './abacus';
import type { OnboardingState, OnboardingSteps } from './account';
import { DialogTypesTypes } from './dialogs';
Expand Down Expand Up @@ -231,7 +233,7 @@ export const AnalyticsEvents = unionize(
TransferNotification: ofType<{
type: TransferNotificationTypes | undefined;
toAmount: number | undefined;
timeSpent: Record<string, number> | number | undefined;
timeSpent: MapOf<number> | number | undefined;
txHash: string;
status: 'new' | 'success' | 'error';
triggeredAt: number | undefined;
Expand Down
Loading
Loading