From 169de40dd51ce7d8f648304e4568908c82e026b9 Mon Sep 17 00:00:00 2001 From: Tomek Marciniak Date: Thu, 7 Nov 2024 15:22:57 +0100 Subject: [PATCH] chore(repo): set stricter type checking --- apps/extension/package.json | 2 +- packages/common/package.json | 2 +- packages/features/package.json | 2 +- .../address-book/components/contact-tile.tsx | 45 ----------- .../components/new-address-form.tsx | 76 ------------------- .../src/common/hooks/use-transactions.ts | 4 +- .../features/src/common/lib/validation.ts | 1 - .../features/src/components/autocomplete.tsx | 1 - .../features/src/components/hash-dropdown.tsx | 2 +- .../src/components/restart-wallet-alert.tsx | 22 ------ .../features/src/components/wizard-layout.tsx | 1 - .../features/src/lock/views/unlock-wallet.tsx | 7 -- .../src/onboarding/routes/restore-wallet.tsx | 1 - .../features/src/receive/index.stories.tsx | 2 +- packages/features/src/send/index.stories.tsx | 2 +- .../features/src/settings/index.stories.tsx | 15 +++- .../features/src/staking/index.stories.tsx | 4 +- .../src/staking/routes/staking-overview.tsx | 26 ++++++- .../components/transactions-list.tsx | 32 -------- .../src/transactions/components/tx-tile.tsx | 6 +- .../src/transactions/index.stories.tsx | 4 +- .../src/transactions/routes/transactions.tsx | 2 +- .../features/src/wallet/index.stories.tsx | 13 +++- .../src/web-connector/index.stories.tsx | 1 + packages/key-management/package.json | 2 +- packages/mina-core/package.json | 2 +- packages/offchain-data/package.json | 2 +- packages/pallad-core/package.json | 2 +- packages/providers/package.json | 2 +- packages/util/package.json | 2 +- packages/vault/package.json | 2 +- .../vault/src/token-info/token-info-store.ts | 2 +- packages/web-provider/package.json | 2 +- 33 files changed, 76 insertions(+), 215 deletions(-) delete mode 100644 packages/features/src/address-book/components/contact-tile.tsx delete mode 100644 packages/features/src/address-book/components/new-address-form.tsx delete mode 100644 packages/features/src/components/restart-wallet-alert.tsx delete mode 100644 packages/features/src/transactions/components/transactions-list.tsx diff --git a/apps/extension/package.json b/apps/extension/package.json index 183e956a..906d9e9d 100644 --- a/apps/extension/package.json +++ b/apps/extension/package.json @@ -4,7 +4,7 @@ "type": "module", "scripts": { "dev": "bunx --bun vite", - "build": "tsc --noEmit && bun run build:rpc && bunx --bun vite build", + "build": "bunx --bun tsc --noEmit && bun run build:rpc && bunx --bun vite build", "build:rpc": "bunx --bun tsup", "build:firefox": "web-ext build --source-dir=dist", "build:safari": "xcrun safari-web-extension-converter dist --app-name Pallad --bundle-identifier co.pallad.app --swift --no-prompt --force --macos-only --no-open", diff --git a/packages/common/package.json b/packages/common/package.json index 42866812..aebb59c1 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -17,7 +17,7 @@ } }, "scripts": { - "build": "bunx --bun tsup src/index.ts --dts --format esm --silent", + "build": "bunx --bun tsc --noEmit && bunx --bun tsup src/index.ts --dts --format esm --silent", "cleanup": "bunx --bun rimraf node_modules dist .turbo" } } diff --git a/packages/features/package.json b/packages/features/package.json index b7ed8db8..7bfe524c 100644 --- a/packages/features/package.json +++ b/packages/features/package.json @@ -24,7 +24,7 @@ } }, "scripts": { - "build": "bunx --bun tsup", + "build": "bunx --bun tsc --noEmit && bunx --bun tsup", "dev": "bunx --bun tsup --watch", "test:unit": "echo 'not yet'", "story:dev": "VITE_APP_LADLE=true bunx --bun ladle serve", diff --git a/packages/features/src/address-book/components/contact-tile.tsx b/packages/features/src/address-book/components/contact-tile.tsx deleted file mode 100644 index b06e6d5d..00000000 --- a/packages/features/src/address-book/components/contact-tile.tsx +++ /dev/null @@ -1,45 +0,0 @@ -// import { TrashIcon } from "lucide-react"; -import { useNavigate } from "react-router-dom" - -import { truncateString } from "@/common/lib/string" -// import { useAddressBookStore } from "@/common/store/address-book"; -import type { Contact } from "@/common/types" - -interface ContactTileProps { - contact: Contact - index?: number -} - -export const ContactTile = ({ contact }: ContactTileProps) => { - const navigate = useNavigate() - // const removeContact = useAddressBookStore((state) => state.removeContact); - return ( -
-
- -
-
-

- {contact?.address && - truncateString({ - value: contact.address, - firstCharCount: 4, - endCharCount: 4, - })} -

-
-
- ) -} diff --git a/packages/features/src/address-book/components/new-address-form.tsx b/packages/features/src/address-book/components/new-address-form.tsx deleted file mode 100644 index da9837e5..00000000 --- a/packages/features/src/address-book/components/new-address-form.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import { zodResolver } from "@hookform/resolvers/zod" -import { PlusIcon } from "lucide-react" -import { useForm } from "react-hook-form" -import { useNavigate } from "react-router-dom" - -import { useAddressBookStore } from "@/common/store/address-book" -import { FormError } from "@/components/form-error" - -import { NewAddressFormSchema } from "./new-address-form.schema" - -export const NewAddressForm = () => { - const navigate = useNavigate() - const addContact = useAddressBookStore((state) => state.addContact) - const { - register, - handleSubmit, - formState: { errors }, - } = useForm({ - resolver: zodResolver(NewAddressFormSchema), - defaultValues: { - name: "", - address: "", - }, - }) - const onSubmit = (data: Record) => { - addContact(data) - return navigate("/contacts") - } - return ( -
-
- - - {errors.name?.message} -
-
- - - {errors.address?.message} -
- -
- ) -} diff --git a/packages/features/src/common/hooks/use-transactions.ts b/packages/features/src/common/hooks/use-transactions.ts index 74e0d188..9247255b 100644 --- a/packages/features/src/common/hooks/use-transactions.ts +++ b/packages/features/src/common/hooks/use-transactions.ts @@ -1,3 +1,4 @@ +import type { Mina } from "@palladxyz/mina-core" import { getPublicKey, useVault } from "@palladxyz/vault" import useSWR from "swr" @@ -8,6 +9,7 @@ export const useTransactions = () => { const networkId = useVault((state) => state.currentNetworkId) return useSWR( publicKey ? [publicKey, "transactions", networkId] : null, - () => getTransactions(networkId, publicKey, "MINA"), // TODO: remove hardcoded 'MINA' + () => + getTransactions(networkId, publicKey, "MINA") as Mina.TransactionBody[], // TODO: remove hardcoded 'MINA' ) } diff --git a/packages/features/src/common/lib/validation.ts b/packages/features/src/common/lib/validation.ts index c4fd614a..c331abed 100644 --- a/packages/features/src/common/lib/validation.ts +++ b/packages/features/src/common/lib/validation.ts @@ -1,4 +1,3 @@ -import { utf8ToBytes } from "@noble/hashes/utils" import { z } from "zod" export const passwordSchema = z diff --git a/packages/features/src/components/autocomplete.tsx b/packages/features/src/components/autocomplete.tsx index af2d6ae6..7737e5a2 100644 --- a/packages/features/src/components/autocomplete.tsx +++ b/packages/features/src/components/autocomplete.tsx @@ -7,7 +7,6 @@ import { import clsx from "clsx" import { matchSorter } from "match-sorter" import { take } from "rambda" -import React from "react" import type { ClipboardEventHandler } from "react" import type { UseFormRegisterReturn } from "react-hook-form" diff --git a/packages/features/src/components/hash-dropdown.tsx b/packages/features/src/components/hash-dropdown.tsx index 720cca78..96c57f3e 100644 --- a/packages/features/src/components/hash-dropdown.tsx +++ b/packages/features/src/components/hash-dropdown.tsx @@ -21,7 +21,7 @@ export const HashDropdown = ({ hash, className }: HashDropdownProps) => { toast.success("Hash Copied") } const openInExplorer = () => { - const url = currentNetworkInfo.explorer.transactionUrl.replace( + const url = currentNetworkInfo?.explorer.transactionUrl.replace( "{hash}", hash, ) diff --git a/packages/features/src/components/restart-wallet-alert.tsx b/packages/features/src/components/restart-wallet-alert.tsx deleted file mode 100644 index 30eaf051..00000000 --- a/packages/features/src/components/restart-wallet-alert.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { useVault } from "@palladxyz/vault" - -type RestartWalletAlertProps = { - open: boolean - setOpen: (open: boolean) => void -} - -export const RestartWalletAlert = ({ - open, - setOpen, -}: RestartWalletAlertProps) => { - const confirm = async () => { - const { storage } = await import("webextension-polyfill") - useVault.persist.clearStorage() - await storage.local.clear() - await storage.session.clear() - await storage.sync.clear() - setOpen(false) - window.close() - } - return null -} diff --git a/packages/features/src/components/wizard-layout.tsx b/packages/features/src/components/wizard-layout.tsx index ea0ff691..6320deba 100644 --- a/packages/features/src/components/wizard-layout.tsx +++ b/packages/features/src/components/wizard-layout.tsx @@ -1,5 +1,4 @@ import clsx from "clsx" -import { ArrowLeftIcon } from "lucide-react" import { useNavigate } from "react-router-dom" import { MenuBar } from "./menu-bar" diff --git a/packages/features/src/lock/views/unlock-wallet.tsx b/packages/features/src/lock/views/unlock-wallet.tsx index 8be3e744..a88769da 100644 --- a/packages/features/src/lock/views/unlock-wallet.tsx +++ b/packages/features/src/lock/views/unlock-wallet.tsx @@ -1,7 +1,6 @@ import type { UseFormReturn } from "react-hook-form" import { FormError } from "@/components/form-error" -import { RestartWalletAlert } from "@/components/restart-wallet-alert" import { WizardLayout } from "@/components/wizard-layout" import clsx from "clsx" import { EyeIcon, EyeOffIcon } from "lucide-react" @@ -20,8 +19,6 @@ type UnlockWalletViewProps = { } export const UnlockWalletView = ({ - restartAlertVisible, - setRestartAlertVisible, form, onSubmit, showPassword, @@ -42,10 +39,6 @@ export const UnlockWalletView = ({ } > -
{ return ( = ({ advanced }) => ( fiatPrice={1.5} advanced={advanced} setAdvanced={action("Set Advanced")} - currentNetwork="Devnet" + networkId="mina:devnet" /> ) diff --git a/packages/features/src/settings/index.stories.tsx b/packages/features/src/settings/index.stories.tsx index caef17b7..983f68fa 100644 --- a/packages/features/src/settings/index.stories.tsx +++ b/packages/features/src/settings/index.stories.tsx @@ -15,12 +15,17 @@ export const Settings = () => ( ) export const About = () => export const AuthorizedZkApps = () => ( - + ) export const Support = () => @@ -39,7 +44,13 @@ export const Language = () => ( ) -export const Privacy = () => +export const Privacy = () => ( + +) export default { title: "Settings", diff --git a/packages/features/src/staking/index.stories.tsx b/packages/features/src/staking/index.stories.tsx index ca9b5f7d..e4d0ca8b 100644 --- a/packages/features/src/staking/index.stories.tsx +++ b/packages/features/src/staking/index.stories.tsx @@ -9,7 +9,9 @@ export const Overview: Story<{ stakeDelegated: boolean }> = ({ }) => ( ) diff --git a/packages/features/src/staking/routes/staking-overview.tsx b/packages/features/src/staking/routes/staking-overview.tsx index 1fde94e5..41a04adc 100644 --- a/packages/features/src/staking/routes/staking-overview.tsx +++ b/packages/features/src/staking/routes/staking-overview.tsx @@ -17,16 +17,34 @@ export const StakingOverviewRoute = () => { .filter((tx) => tx.from !== accountInfo.MINA.publicKey) const rewards = Array(6) .fill({ amount: 0 }) - .map((_, i) => ({ amount: rewardsTransactions?.[i]?.amount ?? 0 })) + .map((_, i) => ({ + amount: + Number.parseFloat( + rewardsTransactions?.[i]?.amount?.toString() ?? "0", + ) ?? 0, + })) return ( tx?.amount)) || 0, - totalReward: sum(rewardsTransactions.map((tx) => tx?.amount)), + lastReward: + Number.parseFloat( + rewardsTransactions?.[0]?.amount?.toString() ?? "0", + ) ?? 0, + avgReward: + mean( + rewardsTransactions?.map((tx) => + Number.parseFloat(tx?.amount?.toString() ?? "0"), + ) ?? [], + ) ?? 0, + totalReward: + sum( + rewardsTransactions?.map((tx) => + Number.parseFloat(tx?.amount?.toString() ?? "0"), + ) ?? [], + ) ?? 0, }} /> ) diff --git a/packages/features/src/transactions/components/transactions-list.tsx b/packages/features/src/transactions/components/transactions-list.tsx deleted file mode 100644 index 4af0b0c9..00000000 --- a/packages/features/src/transactions/components/transactions-list.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import type { Mina } from "@palladxyz/mina-core" - -import { useAccount } from "@/common/hooks/use-account" - -import { structurizeTransactions } from "../utils/structurize-transactions" -import { TxTile } from "./tx-tile" - -interface TransactionsListProps { - transactions: Mina.TransactionBody[] -} - -export const TransactionsList = ({ transactions }: TransactionsListProps) => { - const { publicKey } = useAccount() - if (!publicKey) return null - const txDates = - transactions && - Object.entries(structurizeTransactions([transactions, publicKey])) - return ( -
- {txDates?.map(([date, txs]) => ( -
-
{date}
-
- {txs.map((tx) => ( - - ))} -
-
- ))} -
- ) -} diff --git a/packages/features/src/transactions/components/tx-tile.tsx b/packages/features/src/transactions/components/tx-tile.tsx index d97c4ba5..408c22d4 100644 --- a/packages/features/src/transactions/components/tx-tile.tsx +++ b/packages/features/src/transactions/components/tx-tile.tsx @@ -5,7 +5,11 @@ import { clsx } from "clsx" import { Link } from "react-router-dom" type TxTileProps = { - tx: Mina.TransactionBody + tx: Mina.TransactionBody & { + time: string + fiatAmount: string + minaAmount: string + } currentWalletAddress: string } diff --git a/packages/features/src/transactions/index.stories.tsx b/packages/features/src/transactions/index.stories.tsx index 63c51289..c9070049 100644 --- a/packages/features/src/transactions/index.stories.tsx +++ b/packages/features/src/transactions/index.stories.tsx @@ -1,5 +1,4 @@ -import { TxSide } from "@/common/types" -import type { StoryDefault } from "@ladle/react" +import { type StoryDefault, action } from "@ladle/react" import { Mina } from "@palladxyz/mina-core" import { TransactionDetailsView } from "./views/transaction-details" @@ -54,6 +53,7 @@ export const Transactions = () => ( publicKey="B62qizYjLtUebFFQuAnPjpLrUdWx4rLnptvzbVdNpY6EXff2U68Ljf5" transactions={transactions as any} transactionsError={false} + openPendingTransactions={action("openPendingTransactions")} /> ) diff --git a/packages/features/src/transactions/routes/transactions.tsx b/packages/features/src/transactions/routes/transactions.tsx index b1063d8f..34bbc9fb 100644 --- a/packages/features/src/transactions/routes/transactions.tsx +++ b/packages/features/src/transactions/routes/transactions.tsx @@ -19,7 +19,7 @@ export const TransactionsRoute = () => { .filter((hash) => !transactions?.map((tx) => tx.hash).includes(hash)), ) const openPendingTransactions = () => { - const url = currentNetworkInfo.explorer.pendingTransactionsUrl.replace( + const url = currentNetworkInfo?.explorer.pendingTransactionsUrl.replace( "{publicKey}", publicKey, ) diff --git a/packages/features/src/wallet/index.stories.tsx b/packages/features/src/wallet/index.stories.tsx index 819db3e8..2a81521c 100644 --- a/packages/features/src/wallet/index.stories.tsx +++ b/packages/features/src/wallet/index.stories.tsx @@ -8,7 +8,6 @@ export const Dashboard = () => { return ( { publicAddress="B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS" onSend={action("Send Clicked")} onReceive={action("Receive Clicked")} + fiatBalance={100} + minaBalance={200} + setUseFiatBalance={action("Set Use Fiat Balance")} + useFiatBalance={true} /> ) } export const Networks = () => { - return + return ( + Promise.resolve(action("Switch")())} + /> + ) } export default { diff --git a/packages/features/src/web-connector/index.stories.tsx b/packages/features/src/web-connector/index.stories.tsx index 4dccca99..f6b6b395 100644 --- a/packages/features/src/web-connector/index.stories.tsx +++ b/packages/features/src/web-connector/index.stories.tsx @@ -4,6 +4,7 @@ import { WebConnectorView } from "./views/web-connector" export const Enable = () => { return ( = (set, get) => ({ getTokenInfo: (networkId, ticker) => { const { tokenInfoV2 } = get() const tokenId = tokenInfoV2[networkId]?.[ticker] ?? "undefined" - return { ticker: ticker, tokenId: tokenId } || undefined + return { ticker: ticker, tokenId: tokenId } }, removeTokenInfo: (networkId, ticker) => { set( diff --git a/packages/web-provider/package.json b/packages/web-provider/package.json index 7b7b639a..0cd9d7e6 100644 --- a/packages/web-provider/package.json +++ b/packages/web-provider/package.json @@ -12,7 +12,7 @@ } }, "scripts": { - "build": "bunx --bun tsup", + "build": "bunx --bun tsc --noEmit && bunx --bun tsup", "dev": "bunx --bun tsup --watch", "cleanup": "bunx --bun rimraf node_modules dist .turbo" },