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

clean types for opportunity #61

Merged
merged 9 commits into from
Jan 28, 2025
Merged
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
49 changes: 47 additions & 2 deletions .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,41 @@ defaults:
run:
shell: bash

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
install-dependencies:
if: ${{ always() }}
runs-on: ubuntu-latest
name: 'Dependencies'
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Check dependencies
run: bun install

check-lint:
name: 'Linting'
needs: install-dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Bun
uses: oven-sh/setup-bun@v1
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

Expand All @@ -24,5 +51,23 @@ jobs:
- name: Check codebase linting
run: bun lint:ci

check-type:
name: 'Typing'
runs-on: ubuntu-latest
needs: check-lint
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Check dependencies
run: bun install

- name: Check codebase typing
run: bun typecheck
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
.DS_Store
1 change: 1 addition & 0 deletions dist/dappkit/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
},
"devDependencies": {
"@biomejs/biome": "1.9.2",
"@remix-run/dev": "^2.11.2",
"@remix-run/dev": "^2.15.2",
"@types/bun": "^1.1.14",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"autoprefixer": "^10.4.19",
"elysia": "^1.1.19",
"postcss": "^8.4.38",
"typescript": "^5.6.2",
"typescript": "^5.8.0-dev.20250116",
"vite": "^5.1.0",
"vite-tsconfig-paths": "^4.2.1"
},
Expand Down
7 changes: 5 additions & 2 deletions src/components/dapp/TransactionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import List from "../primitives/List";
import { Notifier } from "../primitives/Notifications";
import Tooltip from "../primitives/Tooltip";

type WagmiTx = Parameters<UseSendTransactionReturnType<ResolvedRegister["config"], unknown>["sendTransaction"]>["0"];

export type TransactionButtonProps = ButtonProps & {
enableSponsorCheckbox?: boolean;
tx?: Parameters<UseSendTransactionReturnType<ResolvedRegister["config"], unknown>["sendTransaction"]>["0"];
tx?: { [K in keyof WagmiTx]: K extends "data" | "to" ? string : WagmiTx[K] };
name?: ReactNode;
iconProps?: IconProps;
onExecute?: (hash: string) => void;
Expand Down Expand Up @@ -82,7 +84,8 @@ export default function TransactionButton({
let receipt = null;
while (receipt === null) {
try {
const res = await getTransactionReceipt(client, { hash });
// biome-ignore lint/suspicious/noExplicitAny: TODO: tx clients overall
const res = await getTransactionReceipt(client as any, { hash });
receipt = res;
} catch {
delay(1000);
Expand Down
6 changes: 4 additions & 2 deletions src/components/extenders/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ export type DropdownProps = Component<
state?: GetSet<boolean>;
content?: ReactNode;
onHover?: boolean;
children?: ReactNode;
},
BoxProps
>;
HTMLButtonElement
> &
Omit<BoxProps, "content">;

export default function Dropdown({
state,
Expand Down
2 changes: 1 addition & 1 deletion src/components/extenders/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type ModalProps = Component<{
modal?: ReactNode;
state?: GetSet<boolean>;
}> &
BoxProps;
Omit<BoxProps, "title">;

export default function Modal({ state, title, description, modal, children, className, ...props }: ModalProps) {
const { vars } = useTheme();
Expand Down
5 changes: 3 additions & 2 deletions src/components/primitives/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ Input.BigInt = function InputBigInt({ state, base, ...props }: InputProps<bigint
displayed?.split(".")?.[1]?.[displayed?.split?.(".")?.[1]?.length - 1] === "0" ||
displayed?.[displayed.length - 1] === ".";

if (_chosenValue === undefined || _chosenValue === "") return "";
// biome-ignore lint/suspicious/noExplicitAny: Making sure it's not an empty string for numbers input
if (_chosenValue === undefined || (_chosenValue as any as string) === "") return "";
if (displayed === "0" || isInputtingDecimals) return displayed;
return transformed ?? displayed;
}, [internal, state, displayed, base, _getter]);
Expand All @@ -110,7 +111,7 @@ Input.BigInt = function InputBigInt({ state, base, ...props }: InputProps<bigint
(v: string | undefined) => {
try {
if (v === undefined || v === "") {
setter?.(v) ?? setInternal(v);
setter?.(undefined) ?? setInternal(undefined);
setDisplayed(undefined);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/primitives/Notifications.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { ReactNode } from "react";
import { ToastContainer, toast } from "react-toastify";
import { Button, Group, Icon, type IconProps, type State, Text, mergeClass } from "../..";
import { Button, Group, Icon, type IconProps, Text, mergeClass } from "../..";
import { boxStyles } from "./Box";
import "react-toastify/dist/ReactToastify.css";
import type { State } from "../../theming/variables";

export function NotificationText({ title, subtitle }: { title: ReactNode; subtitle: ReactNode }) {
return (
Expand Down
11 changes: 11 additions & 0 deletions src/components/primitives/Show.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { PropsWithChildren } from "react";

/**
* Shorthand for conditionally displaying components
* @param if show or not
*/
export default function Show({ if: enabled, children }: PropsWithChildren<{ if: boolean }>) {
//TODO: add collapsible options to animate enabling/disabling
if (!enabled) return;
return children;
}
4 changes: 3 additions & 1 deletion src/components/primitives/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ export type RowProps<T extends Columns> = Component<
PropsWithChildren<
{
columns: T;
size?: ListProps["size"];
exclude?: (keyof T)[];
} & TableColumns<T>
} & Partial<TableColumns<T>>
>
>;

Expand Down Expand Up @@ -141,6 +142,7 @@ export function Row<T extends Columns>({ columns, exclude, children, ...props }:
export type TableProps<T extends Columns> = Component<
Styled<typeof tableStyles> & {
columns: T;
exclude?: (keyof T)[];
header?: ReactNode;
footer?: ReactNode;
order?: Order;
Expand Down
2 changes: 1 addition & 1 deletion src/components/primitives/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ import { Link, useLocation } from "@remix-run/react";

import type { ReactNode } from "react";
import { type VariantProps, tv } from "tailwind-variants";
import { Container } from "../..";
import useThemableProps from "../../hooks/theming/useThemableProps";
import { mergeClass } from "../../utils/css";
import type { Component, Styled, Themable } from "../../utils/types";
import Group from "../extenders/Group";
import Container from "../layout/Container";
import EventBlocker from "./EventBlocker";

export const tabsStyles = tv(
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/theming/useThemedVariables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function useThemedVariables(
return Object.assign({}, currentTheme(coloring).accent, currentTheme(coloring).main);

if (coloring) {
const v = reduceColorIntoVariables(coloring);
const v = reduceColorIntoVariables(coloring as Coloring);

return Object.assign({}, v[mode]?.accent, v[mode]?.main);
}
Expand Down
19 changes: 12 additions & 7 deletions src/hooks/useWalletState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type Config, useAccount, useConfig, useConnect, useDisconnect } from "w
//TODO: remove merkl-related typings in favor of redeclarations for better abstraction
import type { Chain, Explorer } from "@merkl/api";
import { http, type WalletClient, createPublicClient, createWalletClient, custom } from "viem";
import { eip712WalletActions, zksync } from "viem/zksync";
import { type SendTransactionParameters, eip712WalletActions, zksync } from "viem/zksync";

export type WalletOptions = {
sponsorTransactions?: boolean;
Expand Down Expand Up @@ -44,7 +44,9 @@ export default function useWalletState(chains: (Chain & { explorers: Explorer[]
}, [account, wrapClient]);

const wrapTransaction = useCallback(
async (tx: Parameters<WalletClient["sendTransaction"]>) => {
async (
tx: [SendTransactionParameters & { paymaster?: string; paymasterInput?: string; gasPerPubdata?: string }],
) => {
if (!client) return;
const configWrappedTx = await options?.transaction?.(tx, { client, config });

Expand All @@ -56,24 +58,27 @@ export default function useWalletState(chains: (Chain & { explorers: Explorer[]
});

const payload = {
account,
to: `${tx[0].to}`,
account: account.address as `0x${string}`,
to: `${tx[0].to}` as `0x${string}`,
chain: client.chain,
from: account.address,
value: BigInt(tx[0].value ?? "0"),
gas: tx[0].gas ? BigInt(tx[0].gas ?? "0") : undefined,
gasPerPubdata: tx[0].gasPerPubdata ? BigInt(tx[0].gasPerPubdata) : undefined,
maxPriorityFeePerGas: BigInt(0),
maxFeePerGas: tx[0].maxFeePerGas ? BigInt(tx[0].maxFeePerGas) : undefined,
nonce: await nonce.getTransactionCount({ address: account.address }),
nonce: await nonce.getTransactionCount({ address: account.address! }),
data: tx[0].data,

kzg: undefined,
paymaster: tx[0].paymaster,
paymasterInput: tx[0].paymasterInput,
};

return createWalletClient({
chain: zksync,
transport: custom(window.ethereum!),
//TODO: refactor transaction pipeline and embed this in clietn somehow
// biome-ignore lint/suspicious/noExplicitAny: Delete this in favor of using same as wallet client
transport: custom((window as any).ethereum!),
})
.extend(eip712WalletActions())
.sendTransaction(payload);
Expand Down
Loading