From 7269487f75fd9cf0e5aa32c7b74481cf6543e45f Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Wed, 27 Dec 2023 11:11:26 +0100 Subject: [PATCH 01/49] Form initialization for stake/unstake action --- dapp/package.json | 1 + .../components/Modals/ActionForm/index.tsx | 45 ++++++++ .../components/Modals/Staking/StakeForm.tsx | 31 ++++-- dapp/src/components/Modals/Staking/index.tsx | 6 +- dapp/src/components/shared/Form/Form.tsx | 4 + .../shared/Form/FormTokenBalanceInput.tsx | 24 +++++ dapp/src/components/shared/Form/index.tsx | 2 + .../shared/FormBase/TransactionDetails.tsx | 100 ++++++++++++++++++ dapp/src/components/shared/FormBase/index.tsx | 49 +++++++++ .../shared/TokenBalanceInput/index.tsx | 20 ++-- dapp/src/theme/Tabs.ts | 51 +++++++++ dapp/src/theme/index.ts | 2 + dapp/src/types/index.ts | 1 + dapp/src/types/staking.ts | 1 + pnpm-lock.yaml | 43 ++++++++ 15 files changed, 362 insertions(+), 18 deletions(-) create mode 100644 dapp/src/components/Modals/ActionForm/index.tsx create mode 100644 dapp/src/components/shared/Form/Form.tsx create mode 100644 dapp/src/components/shared/Form/FormTokenBalanceInput.tsx create mode 100644 dapp/src/components/shared/Form/index.tsx create mode 100644 dapp/src/components/shared/FormBase/TransactionDetails.tsx create mode 100644 dapp/src/components/shared/FormBase/index.tsx create mode 100644 dapp/src/theme/Tabs.ts create mode 100644 dapp/src/types/staking.ts diff --git a/dapp/package.json b/dapp/package.json index 383bc7456..39fdc283b 100644 --- a/dapp/package.json +++ b/dapp/package.json @@ -20,6 +20,7 @@ "@emotion/styled": "^11.11.0", "@ledgerhq/wallet-api-client": "^1.2.1", "@ledgerhq/wallet-api-client-react": "^1.1.2", + "formik": "^2.4.5", "framer-motion": "^10.16.5", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/dapp/src/components/Modals/ActionForm/index.tsx b/dapp/src/components/Modals/ActionForm/index.tsx new file mode 100644 index 000000000..bacb4de49 --- /dev/null +++ b/dapp/src/components/Modals/ActionForm/index.tsx @@ -0,0 +1,45 @@ +import React from "react" +import { + ModalBody, + Tabs, + TabList, + Tab, + TabPanels, + TabPanel, +} from "@chakra-ui/react" +import { ModalStep } from "../../../contexts" +import StakeForm from "../Staking/StakeForm" + +const TABS = ["stake", "unstake"] as const + +type FormType = (typeof TABS)[number] + +type ActionFormProps = { defaultForm: FormType } & ModalStep + +function ActionForm({ defaultForm, goNext }: ActionFormProps) { + return ( + + + + {TABS.map((tab) => ( + + {tab} + + ))} + + + + + + {/* TODO: Add form for unstake */} + + + + ) +} + +export default ActionForm diff --git a/dapp/src/components/Modals/Staking/StakeForm.tsx b/dapp/src/components/Modals/Staking/StakeForm.tsx index 8d308ecff..fa76d849d 100644 --- a/dapp/src/components/Modals/Staking/StakeForm.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm.tsx @@ -1,15 +1,28 @@ import React from "react" -import { Button, ModalBody } from "@chakra-ui/react" +import { withFormik } from "formik" import { ModalStep } from "../../../contexts" -import { TextMd } from "../../shared/Typography" +import FormBase, { FormBaseProps, FormValues } from "../../shared/FormBase" +import { useWalletContext } from "../../../hooks" + +// TODO: Add a validate function +const StakeFormik = withFormik({ + handleSubmit: (values, { props }) => { + // TODO: Handle the correct form action + props.goNext() + }, +})(FormBase) + +function StakeForm({ goNext }: ModalStep) { + const { btcAccount } = useWalletContext() -export default function StakeModal({ goNext }: ModalStep) { return ( - - Stake modal - - + ) } + +export default StakeForm diff --git a/dapp/src/components/Modals/Staking/index.tsx b/dapp/src/components/Modals/Staking/index.tsx index d5b117df3..eb0b09387 100644 --- a/dapp/src/components/Modals/Staking/index.tsx +++ b/dapp/src/components/Modals/Staking/index.tsx @@ -1,17 +1,17 @@ import React from "react" import { useModalFlowContext } from "../../../hooks" -import StakeForm from "./StakeForm" import Overview from "./Overview" import ModalBase from "../../shared/ModalBase" +import ActionForm from "../ActionForm" function StakingSteps() { const { activeStep, goNext } = useModalFlowContext() switch (activeStep) { case 1: - return + return case 2: - return + return default: return null } diff --git a/dapp/src/components/shared/Form/Form.tsx b/dapp/src/components/shared/Form/Form.tsx new file mode 100644 index 000000000..8b3cbc2b1 --- /dev/null +++ b/dapp/src/components/shared/Form/Form.tsx @@ -0,0 +1,4 @@ +import { chakra } from "@chakra-ui/react" +import { Form as FormikForm } from "formik" + +export const Form = chakra(FormikForm) diff --git a/dapp/src/components/shared/Form/FormTokenBalanceInput.tsx b/dapp/src/components/shared/Form/FormTokenBalanceInput.tsx new file mode 100644 index 000000000..5f88f8bec --- /dev/null +++ b/dapp/src/components/shared/Form/FormTokenBalanceInput.tsx @@ -0,0 +1,24 @@ +import React from "react" +import { useField } from "formik" +import TokenBalanceInput, { TokenBalanceInputProps } from "../TokenBalanceInput" + +export type FormTokenBalanceInputProps = { + name: string +} & Omit +export function FormTokenBalanceInput({ + name, + ...restProps +}: FormTokenBalanceInputProps) { + const [field, meta, helpers] = useField(name) + + return ( + + ) +} diff --git a/dapp/src/components/shared/Form/index.tsx b/dapp/src/components/shared/Form/index.tsx new file mode 100644 index 000000000..57268f72b --- /dev/null +++ b/dapp/src/components/shared/Form/index.tsx @@ -0,0 +1,2 @@ +export * from "./Form" +export * from "./FormTokenBalanceInput" diff --git a/dapp/src/components/shared/FormBase/TransactionDetails.tsx b/dapp/src/components/shared/FormBase/TransactionDetails.tsx new file mode 100644 index 000000000..fe53538a7 --- /dev/null +++ b/dapp/src/components/shared/FormBase/TransactionDetails.tsx @@ -0,0 +1,100 @@ +import React from "react" +import { Box, Flex, VStack } from "@chakra-ui/react" +import { useField } from "formik" +import { CurrencyBalanceWithConversion } from "../CurrencyBalanceWithConversion" +import { TextMd } from "../Typography" +import { TransactionType } from "../../../types" + +const DETAILS: Record< + TransactionType, + { + btcAmountText: string + protocolFeeText: string + estimatedAmountText: string + } +> = { + stake: { + btcAmountText: "Amount to be staked", + protocolFeeText: "Protocol fee (0.01%)", + estimatedAmountText: "Approximately staked tokens", + }, + unstake: { + btcAmountText: "Amount to be unstaked from the pool", + protocolFeeText: "Protocol fee (0.01%)", + estimatedAmountText: "Approximately unstaked tokens", + }, +} + +function TransactionDetailsItem({ + text, + btcAmount, + usdAmount, +}: { + text: string + btcAmount: string | number + usdAmount: string +}) { + return ( + + + {text} + + + + + + ) +} + +function TransactionDetails({ + fieldName, + type, +}: { + fieldName: string + type: TransactionType +}) { + const [, { value }] = useField(fieldName) + + const { btcAmountText, protocolFeeText, estimatedAmountText } = DETAILS[type] + + // TODO: Let's simplify it and secure edge cases + const btcAmount = parseFloat(value) || 0 + const protocolFee = btcAmount * 0.01 + const stakedAmount = btcAmount - protocolFee + + return ( + + + + + + ) +} + +export default TransactionDetails diff --git a/dapp/src/components/shared/FormBase/index.tsx b/dapp/src/components/shared/FormBase/index.tsx new file mode 100644 index 000000000..b7cb33740 --- /dev/null +++ b/dapp/src/components/shared/FormBase/index.tsx @@ -0,0 +1,49 @@ +import React from "react" +import { Button } from "@chakra-ui/react" +import { FormikProps } from "formik" +import { Form, FormTokenBalanceInput } from "../Form" +import { CurrencyType, TransactionType } from "../../../types" +import TransactionDetails from "./TransactionDetails" + +export type FormValues = { + amount: string +} + +export type FormBaseProps = { + transactionType: TransactionType + btnText: string + tokenBalance: string + tokenBalanceInputPlaceholder?: string + currencyType?: CurrencyType + fieldName?: string + children?: React.ReactNode +} + +function FormBase({ + transactionType, + btnText, + tokenBalance, + tokenBalanceInputPlaceholder = "BTC", + currencyType = "bitcoin", + fieldName = "amount", + children, + ...formikProps +}: FormBaseProps & FormikProps) { + return ( +
+ + + {children} + + + ) +} + +export default FormBase diff --git a/dapp/src/components/shared/TokenBalanceInput/index.tsx b/dapp/src/components/shared/TokenBalanceInput/index.tsx index ff6f1da40..d5ec6244c 100644 --- a/dapp/src/components/shared/TokenBalanceInput/index.tsx +++ b/dapp/src/components/shared/TokenBalanceInput/index.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from "react" +import React, { useMemo, useRef } from "react" import { Box, Button, @@ -81,13 +81,13 @@ function FiatCurrencyBalance({ return null } -type TokenBalanceInputProps = { +export type TokenBalanceInputProps = { amount?: string currencyType: CurrencyType tokenBalance: string | number placeholder?: string size?: "lg" | "md" - setAmount: (value: string) => void + setAmount: (value?: string) => void } & InputProps & HelperErrorTextProps & FiatCurrencyBalanceProps @@ -106,6 +106,7 @@ export default function TokenBalanceInput({ fiatCurrencyType, ...inputProps }: TokenBalanceInputProps) { + const valueRef = useRef(amount) const styles = useMultiStyleConfig("TokenBalanceInput", { size }) const tokenBalanceAmount = useMemo( @@ -117,6 +118,10 @@ export default function TokenBalanceInput({ [currencyType, tokenBalance], ) + const handleValueChange = (value: string) => { + valueRef.current = value + } + return ( @@ -137,14 +142,17 @@ export default function TokenBalanceInput({ - setAmount(values.value) + handleValueChange(values.value) } - {...inputProps} + onChange={() => { + setAmount(valueRef?.current) + }} /> diff --git a/dapp/src/constants/index.ts b/dapp/src/constants/index.ts index 68cb50031..a5cb59713 100644 --- a/dapp/src/constants/index.ts +++ b/dapp/src/constants/index.ts @@ -1 +1,2 @@ export * from "./currency" +export * from "./staking" diff --git a/dapp/src/constants/staking.ts b/dapp/src/constants/staking.ts new file mode 100644 index 000000000..19cd34be0 --- /dev/null +++ b/dapp/src/constants/staking.ts @@ -0,0 +1,8 @@ +export const BITCOIN_MIN_AMOUNT = "1000000" // 0.01 BTC + +export const ERRORS = { + REQUIRED: "Required.", + EXCEEDED_VALUE: "The amount exceeds your current balance.", + INSUFFICIENT_VALUE: (minValue: string) => + `The minimum amount must be at least ${minValue} BTC.`, +} From 4c67f66a5ad63025b4e20883ede0384059181883 Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Thu, 28 Dec 2023 19:28:31 +0100 Subject: [PATCH 04/49] Handling the submission of the stake form --- .../components/Modals/Staking/StakeForm.tsx | 23 +++++++++---- .../src/components/shared/ModalBase/index.tsx | 26 ++++++++------ dapp/src/contexts/TransactionContext.tsx | 34 +++++++++++++++++++ dapp/src/contexts/index.tsx | 1 + dapp/src/hooks/index.ts | 1 + dapp/src/hooks/useTransactionContext.ts | 14 ++++++++ 6 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 dapp/src/contexts/TransactionContext.tsx create mode 100644 dapp/src/hooks/useTransactionContext.ts diff --git a/dapp/src/components/Modals/Staking/StakeForm.tsx b/dapp/src/components/Modals/Staking/StakeForm.tsx index d88628685..3af0c6712 100644 --- a/dapp/src/components/Modals/Staking/StakeForm.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm.tsx @@ -1,12 +1,15 @@ -import React from "react" +import React, { useCallback } from "react" import { FormikErrors, withFormik } from "formik" import { ModalStep } from "../../../contexts" import FormBase, { FormBaseProps, FormValues } from "../../shared/FormBase" -import { useWalletContext } from "../../../hooks" +import { useTransactionContext, useWalletContext } from "../../../hooks" import { formatSatoshiAmount } from "../../../utils" import { BITCOIN_MIN_AMOUNT, ERRORS } from "../../../constants" -const StakeFormik = withFormik({ +const StakeFormik = withFormik< + { onSubmitForm: (values: FormValues) => void } & FormBaseProps, + FormValues +>({ validate: ({ amount: value }, { tokenBalance }) => { const errors: FormikErrors = {} @@ -29,20 +32,28 @@ const StakeFormik = withFormik({ return errors }, handleSubmit: (values, { props }) => { - // TODO: Handle the correct form action - props.goNext() + props.onSubmitForm(values) }, })(FormBase) function StakeForm({ goNext }: ModalStep) { const { btcAccount } = useWalletContext() + const { setAmount } = useTransactionContext() + + const handleSubmitForm = useCallback( + (values: FormValues) => { + setAmount(values.amount) + goNext() + }, + [goNext, setAmount], + ) return ( ) } diff --git a/dapp/src/components/shared/ModalBase/index.tsx b/dapp/src/components/shared/ModalBase/index.tsx index 423f29e1c..cfeb34472 100644 --- a/dapp/src/components/shared/ModalBase/index.tsx +++ b/dapp/src/components/shared/ModalBase/index.tsx @@ -5,7 +5,11 @@ import { ModalContent, ModalOverlay, } from "@chakra-ui/react" -import { ModalFlowContext, ModalFlowContextValue } from "../../../contexts" +import { + ModalFlowContext, + ModalFlowContextValue, + TransactionContextProvider, +} from "../../../contexts" import { useSidebar } from "../../../hooks" import SupportWrapper from "../../Modals/Support" @@ -66,14 +70,16 @@ export default function ModalBase({ ) return ( - - - - - - {children} - - - + + + + + + + {children} + + + + ) } diff --git a/dapp/src/contexts/TransactionContext.tsx b/dapp/src/contexts/TransactionContext.tsx new file mode 100644 index 000000000..c61c84a7d --- /dev/null +++ b/dapp/src/contexts/TransactionContext.tsx @@ -0,0 +1,34 @@ +import React, { createContext, useMemo, useState } from "react" + +type TransactionContextValue = { + amount?: string + setAmount: React.Dispatch> +} + +export const TransactionContext = createContext({ + amount: undefined, + setAmount: () => {}, +}) + +export function TransactionContextProvider({ + children, +}: { + children: React.ReactNode +}): React.ReactElement { + const [amount, setAmount] = useState(undefined) + + const contextValue: TransactionContextValue = + useMemo( + () => ({ + amount, + setAmount, + }), + [amount], + ) + + return ( + + {children} + + ) +} diff --git a/dapp/src/contexts/index.tsx b/dapp/src/contexts/index.tsx index 6787e1cc6..a849afb3f 100644 --- a/dapp/src/contexts/index.tsx +++ b/dapp/src/contexts/index.tsx @@ -3,3 +3,4 @@ export * from "./LedgerWalletAPIProvider" export * from "./DocsDrawerContext" export * from "./SidebarContext" export * from "./ModalFlowContext" +export * from "./TransactionContext" diff --git a/dapp/src/hooks/index.ts b/dapp/src/hooks/index.ts index 076da9a53..4f2b42d57 100644 --- a/dapp/src/hooks/index.ts +++ b/dapp/src/hooks/index.ts @@ -5,3 +5,4 @@ export * from "./useWalletContext" export * from "./useSidebar" export * from "./useDocsDrawer" export * from "./useModalFlowContext" +export * from "./useTransactionContext" diff --git a/dapp/src/hooks/useTransactionContext.ts b/dapp/src/hooks/useTransactionContext.ts new file mode 100644 index 000000000..d28c8bf1b --- /dev/null +++ b/dapp/src/hooks/useTransactionContext.ts @@ -0,0 +1,14 @@ +import { useContext } from "react" +import { TransactionContext } from "../contexts" + +export function useTransactionContext() { + const context = useContext(TransactionContext) + + if (!context) { + throw new Error( + "TransactionContext used outside of TransactionContext component", + ) + } + + return context +} From 1b1b9ab6324d7ea371cd028cd2333af5360ddf5a Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Fri, 29 Dec 2023 09:07:32 +0100 Subject: [PATCH 05/49] Improvements for forms --- .../components/Modals/Staking/StakeForm.tsx | 26 ++++---------- dapp/src/constants/staking.ts | 7 ---- dapp/src/utils/forms.ts | 35 +++++++++++++++++++ dapp/src/utils/index.ts | 1 + 4 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 dapp/src/utils/forms.ts diff --git a/dapp/src/components/Modals/Staking/StakeForm.tsx b/dapp/src/components/Modals/Staking/StakeForm.tsx index 3af0c6712..c201dbc60 100644 --- a/dapp/src/components/Modals/Staking/StakeForm.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm.tsx @@ -3,33 +3,21 @@ import { FormikErrors, withFormik } from "formik" import { ModalStep } from "../../../contexts" import FormBase, { FormBaseProps, FormValues } from "../../shared/FormBase" import { useTransactionContext, useWalletContext } from "../../../hooks" -import { formatSatoshiAmount } from "../../../utils" -import { BITCOIN_MIN_AMOUNT, ERRORS } from "../../../constants" +import { getErrorsObj, validateTokenAmount } from "../../../utils" const StakeFormik = withFormik< { onSubmitForm: (values: FormValues) => void } & FormBaseProps, FormValues >({ - validate: ({ amount: value }, { tokenBalance }) => { + mapPropsToValues: () => ({ + amount: "", + }), + validate: async ({ amount }, { tokenBalance }) => { const errors: FormikErrors = {} - if (!value) errors.amount = ERRORS.REQUIRED - else { - const valueInBI = BigInt(value) - const maxValueInBI = BigInt(tokenBalance) - const minValueInBI = BigInt(BITCOIN_MIN_AMOUNT) + errors.amount = validateTokenAmount(amount, tokenBalance) - const isMaximumValueExceeded = valueInBI > maxValueInBI - const isMinimumValueFulfilled = valueInBI > minValueInBI - - if (isMaximumValueExceeded) errors.amount = ERRORS.EXCEEDED_VALUE - else if (!isMinimumValueFulfilled) - errors.amount = ERRORS.INSUFFICIENT_VALUE( - formatSatoshiAmount(BITCOIN_MIN_AMOUNT), - ) - } - - return errors + return getErrorsObj(errors) }, handleSubmit: (values, { props }) => { props.onSubmitForm(values) diff --git a/dapp/src/constants/staking.ts b/dapp/src/constants/staking.ts index 19cd34be0..421c57bb5 100644 --- a/dapp/src/constants/staking.ts +++ b/dapp/src/constants/staking.ts @@ -1,8 +1 @@ export const BITCOIN_MIN_AMOUNT = "1000000" // 0.01 BTC - -export const ERRORS = { - REQUIRED: "Required.", - EXCEEDED_VALUE: "The amount exceeds your current balance.", - INSUFFICIENT_VALUE: (minValue: string) => - `The minimum amount must be at least ${minValue} BTC.`, -} diff --git a/dapp/src/utils/forms.ts b/dapp/src/utils/forms.ts new file mode 100644 index 000000000..70249a13d --- /dev/null +++ b/dapp/src/utils/forms.ts @@ -0,0 +1,35 @@ +import { BITCOIN_MIN_AMOUNT } from "../constants" +import { formatSatoshiAmount } from "./numbers" + +const ERRORS = { + REQUIRED: "Required.", + EXCEEDED_VALUE: "The amount exceeds your current balance.", + INSUFFICIENT_VALUE: (minValue: string) => + `The minimum amount must be at least ${minValue} BTC.`, +} + +export function getErrorsObj(errors: { [key in keyof T]: string }) { + return (Object.keys(errors) as Array).every((name) => !errors[name]) + ? {} + : errors +} + +export function validateTokenAmount( + value: string, + tokenBalance: string, +): string | undefined { + if (!value) return ERRORS.REQUIRED + + const valueInBI = BigInt(value) + const maxValueInBI = BigInt(tokenBalance) + const minValueInBI = BigInt(BITCOIN_MIN_AMOUNT) + + const isMaximumValueExceeded = valueInBI > maxValueInBI + const isMinimumValueFulfilled = valueInBI >= minValueInBI + + if (isMaximumValueExceeded) return ERRORS.EXCEEDED_VALUE + if (!isMinimumValueFulfilled) + return ERRORS.INSUFFICIENT_VALUE(formatSatoshiAmount(BITCOIN_MIN_AMOUNT)) + + return undefined +} diff --git a/dapp/src/utils/index.ts b/dapp/src/utils/index.ts index 613e0f071..563f2e6d1 100644 --- a/dapp/src/utils/index.ts +++ b/dapp/src/utils/index.ts @@ -1,2 +1,3 @@ export * from "./numbers" export * from "./address" +export * from "./forms" From 4b845b96507701f4e3f3d0b32dd12e1d9e99c36b Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Fri, 29 Dec 2023 09:59:25 +0100 Subject: [PATCH 06/49] Define custom data from the form level --- .../components/Modals/Staking/StakeForm.tsx | 9 ++++-- .../shared/FormBase/TransactionDetails.tsx | 30 ++++--------------- dapp/src/components/shared/FormBase/index.tsx | 20 ++++++++----- dapp/src/types/index.ts | 1 - dapp/src/types/staking.ts | 1 - 5 files changed, 26 insertions(+), 35 deletions(-) delete mode 100644 dapp/src/types/staking.ts diff --git a/dapp/src/components/Modals/Staking/StakeForm.tsx b/dapp/src/components/Modals/Staking/StakeForm.tsx index c201dbc60..9ab138f24 100644 --- a/dapp/src/components/Modals/Staking/StakeForm.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm.tsx @@ -5,6 +5,12 @@ import FormBase, { FormBaseProps, FormValues } from "../../shared/FormBase" import { useTransactionContext, useWalletContext } from "../../../hooks" import { getErrorsObj, validateTokenAmount } from "../../../utils" +const CUSTOM_DATA = { + buttonText: "Stake", + btcAmountText: "Amount to be staked", + estimatedAmountText: "Approximately staked tokens", +} + const StakeFormik = withFormik< { onSubmitForm: (values: FormValues) => void } & FormBaseProps, FormValues @@ -38,8 +44,7 @@ function StakeForm({ goNext }: ModalStep) { return ( diff --git a/dapp/src/components/shared/FormBase/TransactionDetails.tsx b/dapp/src/components/shared/FormBase/TransactionDetails.tsx index bd8270919..4e9857d1e 100644 --- a/dapp/src/components/shared/FormBase/TransactionDetails.tsx +++ b/dapp/src/components/shared/FormBase/TransactionDetails.tsx @@ -3,27 +3,7 @@ import { Box, Flex, VStack } from "@chakra-ui/react" import { useField } from "formik" import { CurrencyBalanceWithConversion } from "../CurrencyBalanceWithConversion" import { TextMd } from "../Typography" -import { TransactionType } from "../../../types" -const DETAILS: Record< - TransactionType, - { - btcAmountText: string - protocolFeeText: string - estimatedAmountText: string - } -> = { - stake: { - btcAmountText: "Amount to be staked", - protocolFeeText: "Protocol fee (0.01%)", - estimatedAmountText: "Approximately staked tokens", - }, - unstake: { - btcAmountText: "Amount to be unstaked from the pool", - protocolFeeText: "Protocol fee (0.01%)", - estimatedAmountText: "Approximately unstaked tokens", - }, -} // TODO: Use data from the SDK function getTransactionDetails(value: string): | { @@ -83,14 +63,15 @@ function TransactionDetailsItem({ function TransactionDetails({ fieldName, - type, + btcAmountText, + estimatedAmountText, }: { fieldName: string - type: TransactionType + btcAmountText: string + estimatedAmountText: string }) { const [, { value }] = useField(fieldName) - const { btcAmountText, protocolFeeText, estimatedAmountText } = DETAILS[type] const details = getTransactionDetails(value) return ( @@ -101,7 +82,8 @@ function TransactionDetails({ usdAmount="45.725,91" /> diff --git a/dapp/src/components/shared/FormBase/index.tsx b/dapp/src/components/shared/FormBase/index.tsx index b7cb33740..371278b2a 100644 --- a/dapp/src/components/shared/FormBase/index.tsx +++ b/dapp/src/components/shared/FormBase/index.tsx @@ -2,7 +2,7 @@ import React from "react" import { Button } from "@chakra-ui/react" import { FormikProps } from "formik" import { Form, FormTokenBalanceInput } from "../Form" -import { CurrencyType, TransactionType } from "../../../types" +import { CurrencyType } from "../../../types" import TransactionDetails from "./TransactionDetails" export type FormValues = { @@ -10,8 +10,11 @@ export type FormValues = { } export type FormBaseProps = { - transactionType: TransactionType - btnText: string + customData: { + buttonText: string + btcAmountText: string + estimatedAmountText: string + } tokenBalance: string tokenBalanceInputPlaceholder?: string currencyType?: CurrencyType @@ -20,8 +23,7 @@ export type FormBaseProps = { } function FormBase({ - transactionType, - btnText, + customData, tokenBalance, tokenBalanceInputPlaceholder = "BTC", currencyType = "bitcoin", @@ -37,10 +39,14 @@ function FormBase({ placeholder={tokenBalanceInputPlaceholder} currencyType={currencyType} /> - + {children} ) diff --git a/dapp/src/types/index.ts b/dapp/src/types/index.ts index 32b259c7f..1e77e81e7 100644 --- a/dapp/src/types/index.ts +++ b/dapp/src/types/index.ts @@ -1,3 +1,2 @@ export * from "./ledger-live-app" export * from "./currency" -export * from "./staking" diff --git a/dapp/src/types/staking.ts b/dapp/src/types/staking.ts deleted file mode 100644 index 69e565c51..000000000 --- a/dapp/src/types/staking.ts +++ /dev/null @@ -1 +0,0 @@ -export type TransactionType = "stake" | "unstake" From e8faf951c00d6bf75ec7e0c2ef02bdd78c081494 Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Fri, 29 Dec 2023 15:43:10 +0100 Subject: [PATCH 07/49] Initial implementation of stake steps --- dapp/manifest-ledger-live-app.json | 2 +- dapp/package.json | 3 +- .../components/Modals/Staking/DepositBTC.tsx | 32 ++ .../components/Modals/Staking/Overview.tsx | 6 +- .../components/Modals/Staking/SignMessage.tsx | 45 +++ .../components/Modals/Staking/StakeForm.tsx | 6 +- .../components/Modals/Staking/StakeSteps.tsx | 80 ++++ dapp/src/components/Modals/Staking/index.tsx | 14 +- dapp/src/components/shared/Spinner/index.tsx | 17 + .../components/shared/StepperBase/index.tsx | 11 +- dapp/vite.config.ts | 3 +- pnpm-lock.yaml | 362 ++++++++++++++++++ 12 files changed, 567 insertions(+), 14 deletions(-) create mode 100644 dapp/src/components/Modals/Staking/DepositBTC.tsx create mode 100644 dapp/src/components/Modals/Staking/SignMessage.tsx create mode 100644 dapp/src/components/Modals/Staking/StakeSteps.tsx create mode 100644 dapp/src/components/shared/Spinner/index.tsx diff --git a/dapp/manifest-ledger-live-app.json b/dapp/manifest-ledger-live-app.json index 29f63c113..265928a59 100644 --- a/dapp/manifest-ledger-live-app.json +++ b/dapp/manifest-ledger-live-app.json @@ -18,6 +18,6 @@ "en": "Bitcoin Liquid Staking" } }, - "permissions": ["account.request"], + "permissions": ["account.request", "message.sign"], "domains": ["http://*"] } diff --git a/dapp/package.json b/dapp/package.json index 2d160d0a4..8345eb7e2 100644 --- a/dapp/package.json +++ b/dapp/package.json @@ -35,6 +35,7 @@ "eslint": "^8.54.0", "prettier": "^3.1.0", "typescript": "^5.3.2", - "vite": "^5.0.2" + "vite": "^5.0.2", + "vite-plugin-node-polyfills": "^0.19.0" } } diff --git a/dapp/src/components/Modals/Staking/DepositBTC.tsx b/dapp/src/components/Modals/Staking/DepositBTC.tsx new file mode 100644 index 000000000..91e7c8789 --- /dev/null +++ b/dapp/src/components/Modals/Staking/DepositBTC.tsx @@ -0,0 +1,32 @@ +import React from "react" +import Alert from "../../shared/Alert" +import { useModalFlowContext, useWalletContext } from "../../../hooks" +import StakeSteps from "./StakeSteps" +import { TextMd } from "../../shared/Typography" + +export default function DepositBTC() { + const { goNext } = useModalFlowContext() + const { btcAccount } = useWalletContext() + + const handleSendBTC = async () => { + if (!btcAccount?.id) return + + // TODO: Send the correct transaction + goNext() + } + + return ( + + + + Make a Bitcoin transaction to deposit and stake your BTC. + + + + ) +} diff --git a/dapp/src/components/Modals/Staking/Overview.tsx b/dapp/src/components/Modals/Staking/Overview.tsx index 2ad8a1e94..61023146d 100644 --- a/dapp/src/components/Modals/Staking/Overview.tsx +++ b/dapp/src/components/Modals/Staking/Overview.tsx @@ -1,9 +1,11 @@ import React from "react" import { Button, ModalBody, ModalFooter } from "@chakra-ui/react" -import { ModalStep } from "../../../contexts" import { TextMd } from "../../shared/Typography" +import { useModalFlowContext } from "../../../hooks" + +export default function Overview() { + const { goNext } = useModalFlowContext() -export default function Overview({ goNext }: ModalStep) { return ( <> diff --git a/dapp/src/components/Modals/Staking/SignMessage.tsx b/dapp/src/components/Modals/Staking/SignMessage.tsx new file mode 100644 index 000000000..9965966b8 --- /dev/null +++ b/dapp/src/components/Modals/Staking/SignMessage.tsx @@ -0,0 +1,45 @@ +import React, { useEffect } from "react" +import { Highlight } from "@chakra-ui/react" +import { useSignMessage } from "@ledgerhq/wallet-api-client-react" +import Alert from "../../shared/Alert" +import { useModalFlowContext, useWalletContext } from "../../../hooks" +import StakeSteps from "./StakeSteps" +import { TextMd } from "../../shared/Typography" + +const SIGN_MESSAGE = "Test message" + +export default function SignMessage() { + const { goNext } = useModalFlowContext() + const { ethAccount } = useWalletContext() + const { signMessage, signature } = useSignMessage() + + const handleSignMessage = async () => { + if (!ethAccount?.id) return + + await signMessage(ethAccount.id, Buffer.from(SIGN_MESSAGE, "utf-8")) + } + + useEffect(() => { + if (signature) { + goNext() + } + }, [goNext, signature]) + + return ( + + + + + You will receive stBTC liquid staking token at this Ethereum address + once the staking transaction is completed. + + + + + ) +} diff --git a/dapp/src/components/Modals/Staking/StakeForm.tsx b/dapp/src/components/Modals/Staking/StakeForm.tsx index 8d308ecff..a887dd052 100644 --- a/dapp/src/components/Modals/Staking/StakeForm.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm.tsx @@ -1,9 +1,11 @@ import React from "react" import { Button, ModalBody } from "@chakra-ui/react" -import { ModalStep } from "../../../contexts" import { TextMd } from "../../shared/Typography" +import { useModalFlowContext } from "../../../hooks" + +export default function StakeModal() { + const { goNext } = useModalFlowContext() -export default function StakeModal({ goNext }: ModalStep) { return ( Stake modal diff --git a/dapp/src/components/Modals/Staking/StakeSteps.tsx b/dapp/src/components/Modals/Staking/StakeSteps.tsx new file mode 100644 index 000000000..00318ad3e --- /dev/null +++ b/dapp/src/components/Modals/Staking/StakeSteps.tsx @@ -0,0 +1,80 @@ +import React from "react" +import { + Button, + HStack, + ModalBody, + ModalFooter, + ModalHeader, + StepNumber, +} from "@chakra-ui/react" +import StepperBase, { StepBase } from "../../shared/StepperBase" +import { TextLg, TextMd } from "../../shared/Typography" +import Spinner from "../../shared/Spinner" + +function Title({ children }: { children: React.ReactNode }) { + return {children} +} +function Description({ children }: { children: React.ReactNode }) { + return {children} +} + +const STEPS: StepBase[] = [ + { + id: "sign-message", + title: Sign message, + description: ( + + + Sign the message in your ETH wallet. + + ), + }, + { + id: "deposit-btc", + title: Deposit BTC, + description: ( + + + Waiting for your deposit... + + ), + }, +] + +export default function StakeSteps({ + header, + buttonText, + activeStep, + onClick, + children, +}: { + header: string + buttonText: string + activeStep: number + onClick: () => void + children: React.ReactNode +}) { + return ( + <> + {header} + + } + steps={STEPS} + hideDescriptionWhenInactive + /> + {children} + + + + + + ) +} diff --git a/dapp/src/components/Modals/Staking/index.tsx b/dapp/src/components/Modals/Staking/index.tsx index d5b117df3..2f65f91ca 100644 --- a/dapp/src/components/Modals/Staking/index.tsx +++ b/dapp/src/components/Modals/Staking/index.tsx @@ -3,15 +3,21 @@ import { useModalFlowContext } from "../../../hooks" import StakeForm from "./StakeForm" import Overview from "./Overview" import ModalBase from "../../shared/ModalBase" +import SignMessage from "./SignMessage" +import DepositBTC from "./DepositBTC" function StakingSteps() { - const { activeStep, goNext } = useModalFlowContext() + const { activeStep } = useModalFlowContext() switch (activeStep) { case 1: - return + return case 2: - return + return + case 3: + return + case 4: + return default: return null } @@ -25,7 +31,7 @@ export default function StakingModal({ onClose: () => void }) { return ( - + ) diff --git a/dapp/src/components/shared/Spinner/index.tsx b/dapp/src/components/shared/Spinner/index.tsx new file mode 100644 index 000000000..1e5c6a29d --- /dev/null +++ b/dapp/src/components/shared/Spinner/index.tsx @@ -0,0 +1,17 @@ +import React from "react" +import { + Spinner as ChakraSpinner, + SpinnerProps as ChakraSpinnerProps, +} from "@chakra-ui/react" + +export default function Spinner({ ...spinnerProps }: ChakraSpinnerProps) { + return ( + + ) +} diff --git a/dapp/src/components/shared/StepperBase/index.tsx b/dapp/src/components/shared/StepperBase/index.tsx index a58551d67..7121ddc40 100644 --- a/dapp/src/components/shared/StepperBase/index.tsx +++ b/dapp/src/components/shared/StepperBase/index.tsx @@ -24,6 +24,7 @@ type StepperBaseProps = { complete?: JSX.Element incomplete?: JSX.Element active?: JSX.Element + hideDescriptionWhenInactive?: boolean } & Omit export default function StepperBase({ @@ -31,11 +32,13 @@ export default function StepperBase({ complete, incomplete, active, + index: activeStep, + hideDescriptionWhenInactive, ...stepperProps }: StepperBaseProps) { return ( - - {steps.map((step) => ( + + {steps.map((step, index) => ( {step.title} - {step.description} + {(!hideDescriptionWhenInactive || activeStep === index) && ( + {step.description} + )} diff --git a/dapp/vite.config.ts b/dapp/vite.config.ts index ea1889ae7..cef82d65c 100644 --- a/dapp/vite.config.ts +++ b/dapp/vite.config.ts @@ -1,6 +1,7 @@ import { defineConfig } from "vite" import react from "@vitejs/plugin-react" +import { nodePolyfills } from "vite-plugin-node-polyfills" export default defineConfig({ - plugins: [react()], + plugins: [nodePolyfills(), react()], }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1c334a15e..521f0059e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -169,6 +169,9 @@ importers: vite: specifier: ^5.0.2 version: 5.0.2 + vite-plugin-node-polyfills: + specifier: ^0.19.0 + version: 0.19.0(vite@5.0.2) sdk: devDependencies: @@ -5113,6 +5116,34 @@ packages: resolution: {integrity: sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==} dev: false + /@rollup/plugin-inject@5.0.5: + resolution: {integrity: sha512-2+DEJbNBoPROPkgTDNe8/1YXWcqxbN5DTjASVIOx8HS+pITXushyNiBV56RB08zuptzz8gT3YfkqriTBVycepg==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 5.1.0 + estree-walker: 2.0.2 + magic-string: 0.30.5 + dev: true + + /@rollup/pluginutils@5.1.0: + resolution: {integrity: sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@types/estree': 1.0.5 + estree-walker: 2.0.2 + picomatch: 2.3.1 + dev: true + /@rollup/rollup-android-arm-eabi@4.5.1: resolution: {integrity: sha512-YaN43wTyEBaMqLDYeze+gQ4ZrW5RbTEGtT5o1GVDkhpdNcsLTnLRcLccvwy3E9wiDKWg9RIhuoy3JQKDRBfaZA==} cpu: [arm] @@ -6496,6 +6527,25 @@ packages: /asap@2.0.6: resolution: {integrity: sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==} + /asn1.js@5.4.1: + resolution: {integrity: sha512-+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA==} + dependencies: + bn.js: 4.12.0 + inherits: 2.0.4 + minimalistic-assert: 1.0.1 + safer-buffer: 2.1.2 + dev: true + + /assert@2.1.0: + resolution: {integrity: sha512-eLHpSK/Y4nhMJ07gDaAzoX/XAKS8PSaojml3M0DM4JpV1LAi5JOJ/p6H/XWrl8L+DzVEvVCW1z3vWAaB9oTsQw==} + dependencies: + call-bind: 1.0.5 + is-nan: 1.3.2 + object-is: 1.1.5 + object.assign: 4.1.4 + util: 0.12.5 + dev: true + /assertion-error@1.1.0: resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} dev: true @@ -6903,6 +6953,12 @@ packages: run-parallel-limit: 1.1.0 dev: true + /browser-resolve@2.0.0: + resolution: {integrity: sha512-7sWsQlYL2rGLy2IWm8WL8DCTJvYLc/qlOnsakDac87SOoCd16WLsaAMdCiAqsTNHIe+SXfaqyxyo6THoWqs8WQ==} + dependencies: + resolve: 1.22.8 + dev: true + /browser-stdout@1.3.1: resolution: {integrity: sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==} dev: true @@ -6918,6 +6974,51 @@ packages: safe-buffer: 5.2.1 dev: true + /browserify-cipher@1.0.1: + resolution: {integrity: sha512-sPhkz0ARKbf4rRQt2hTpAHqn47X3llLkUGn+xEJzLjwY8LRs2p0v7ljvI5EyoRO/mexrNunNECisZs+gw2zz1w==} + dependencies: + browserify-aes: 1.2.0 + browserify-des: 1.0.2 + evp_bytestokey: 1.0.3 + dev: true + + /browserify-des@1.0.2: + resolution: {integrity: sha512-BioO1xf3hFwz4kc6iBhI3ieDFompMhrMlnDFC4/0/vd5MokpuAc3R+LYbwTA9A5Yc9pq9UYPqffKpW2ObuwX5A==} + dependencies: + cipher-base: 1.0.4 + des.js: 1.1.0 + inherits: 2.0.4 + safe-buffer: 5.2.1 + dev: true + + /browserify-rsa@4.1.0: + resolution: {integrity: sha512-AdEER0Hkspgno2aR97SAf6vi0y0k8NuOpGnVH3O99rcA5Q6sh8QxcngtHuJ6uXwnfAXNM4Gn1Gb7/MV1+Ymbog==} + dependencies: + bn.js: 5.2.1 + randombytes: 2.1.0 + dev: true + + /browserify-sign@4.2.2: + resolution: {integrity: sha512-1rudGyeYY42Dk6texmv7c4VcQ0EsvVbLwZkA+AQB7SxvXxmcD93jcHie8bzecJ+ChDlmAm2Qyu0+Ccg5uhZXCg==} + engines: {node: '>= 4'} + dependencies: + bn.js: 5.2.1 + browserify-rsa: 4.1.0 + create-hash: 1.2.0 + create-hmac: 1.1.7 + elliptic: 6.5.4 + inherits: 2.0.4 + parse-asn1: 5.1.6 + readable-stream: 3.6.2 + safe-buffer: 5.2.1 + dev: true + + /browserify-zlib@0.2.0: + resolution: {integrity: sha512-Z942RysHXmJrhqk88FmKBVq/v5tqmSkDz7p54G/MGyjMnCFFnC79XWNbg+Vta8W6Wb2qtSZTSxIGkJrRpCFEiA==} + dependencies: + pako: 1.0.11 + dev: true + /browserslist@4.22.1: resolution: {integrity: sha512-FEVc202+2iuClEhZhrWy6ZiAcRLvNMyYcxZ8raemul1DYVOVdFsbqckWLdsixQZCpJlwe77Z3UTalE7jsjnKfQ==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} @@ -6976,6 +7077,10 @@ packages: ieee754: 1.2.1 dev: true + /builtin-status-codes@3.0.0: + resolution: {integrity: sha512-HpGFw18DgFWlncDfjTa2rcQ4W88O1mC8e8yZ2AvQY5KDaktSTwo+KRf6nHK6FRI5FyRyb/5T6+TSxfP7QyGsmQ==} + dev: true + /builtins@5.0.1: resolution: {integrity: sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==} dependencies: @@ -7506,6 +7611,10 @@ packages: /confusing-browser-globals@1.0.11: resolution: {integrity: sha512-JsPKdmh8ZkmnHxDk55FZ1TqVLvEQTvoByJZRN9jzI0UjxK/QgAmsphz7PGtqgPieQZ/CQcHWXCR7ATDNhGe+YA==} + /console-browserify@1.2.0: + resolution: {integrity: sha512-ZMkYO/LkF17QvCPqM0gxw8yUzigAOZOSWSHg91FH6orS7vcEj5dVZTidN2fQ14yBSdg97RqhSNwLUXInd52OTA==} + dev: true + /constant-case@3.0.4: resolution: {integrity: sha512-I2hSBi7Vvs7BEuJDr5dDHfzb/Ruj3FyvFyh7KLilAjNQw3Be+xgqUBA2W6scVEcL0hL1dwPRtIqEPVUCKkSsyQ==} dependencies: @@ -7513,6 +7622,10 @@ packages: tslib: 2.6.2 upper-case: 2.0.2 + /constants-browserify@1.0.0: + resolution: {integrity: sha512-xFxOwqIzR/e1k1gLiWEophSCMqXcwVHIH7akf7b/vxcUeGunlj3hvZaaqxwHsTgn+IndtkQJgSztIDWeumWJDQ==} + dev: true + /content-disposition@0.5.4: resolution: {integrity: sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==} engines: {node: '>= 0.6'} @@ -7615,6 +7728,13 @@ packages: hasBin: true dev: true + /create-ecdh@4.0.4: + resolution: {integrity: sha512-mf+TCx8wWc9VpuxfP2ht0iSISLZnt0JgWlrOKZiNqyUZWnjIaCIVNQArMHnCZKfEYRg6IM7A+NeJoN8gf/Ws0A==} + dependencies: + bn.js: 4.12.0 + elliptic: 6.5.4 + dev: true + /create-gatsby@3.12.3: resolution: {integrity: sha512-N0K/Z/MD5LMRJcBy669WpSgrn+31zBV72Lv0RHolX0fXa77Yx58HsEiLWz83j/dtciGMQfEOEHFRetUqZhOggA==} hasBin: true @@ -7675,6 +7795,22 @@ packages: resolution: {integrity: sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==} dev: true + /crypto-browserify@3.12.0: + resolution: {integrity: sha512-fz4spIh+znjO2VjL+IdhEpRJ3YN6sMzITSBijk6FK2UvTqruSQW+/cCZTSNsMiZNvUeq0CqurF+dAbyiGOY6Wg==} + dependencies: + browserify-cipher: 1.0.1 + browserify-sign: 4.2.2 + create-ecdh: 4.0.4 + create-hash: 1.2.0 + create-hmac: 1.1.7 + diffie-hellman: 5.0.3 + inherits: 2.0.4 + pbkdf2: 3.1.2 + public-encrypt: 4.0.3 + randombytes: 2.1.0 + randomfill: 1.0.4 + dev: true + /crypto-random-string@2.0.0: resolution: {integrity: sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==} engines: {node: '>=8'} @@ -7983,6 +8119,13 @@ packages: resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==} engines: {node: '>=6'} + /des.js@1.1.0: + resolution: {integrity: sha512-r17GxjhUCjSRy8aiJpr8/UadFIzMzJGexI3Nmz4ADi9LYSFx4gTBp80+NaX/YsXWWLhpZ7v/v/ubEc/bCNfKwg==} + dependencies: + inherits: 2.0.4 + minimalistic-assert: 1.0.1 + dev: true + /destroy@1.2.0: resolution: {integrity: sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==} engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16} @@ -8059,6 +8202,14 @@ packages: engines: {node: '>=0.3.1'} dev: true + /diffie-hellman@5.0.3: + resolution: {integrity: sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==} + dependencies: + bn.js: 4.12.0 + miller-rabin: 4.0.1 + randombytes: 2.1.0 + dev: true + /difflib@0.2.4: resolution: {integrity: sha512-9YVwmMb0wQHQNr5J9m6BSj6fk4pfGITGQOOs+D9Fl+INODWFOfvhIU1hNv6GgR1RBoC/9NJcwu77zShxV0kT7w==} dependencies: @@ -8095,6 +8246,11 @@ packages: domhandler: 4.3.1 entities: 2.2.0 + /domain-browser@4.23.0: + resolution: {integrity: sha512-ArzcM/II1wCCujdCNyQjXrAFwS4mrLh4C7DZWlaI8mdh7h3BfKdNd3bKXITfl2PT9FtfQqaGvhi1vPRQPimjGA==} + engines: {node: '>=10'} + dev: true + /domelementtype@2.3.0: resolution: {integrity: sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==} @@ -8888,6 +9044,10 @@ packages: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} + /estree-walker@2.0.2: + resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} + dev: true + /esutils@2.0.3: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} engines: {node: '>=0.10.0'} @@ -10676,6 +10836,10 @@ packages: quick-lru: 5.1.1 resolve-alpn: 1.2.1 + /https-browserify@1.0.0: + resolution: {integrity: sha512-J+FkSdyD+0mA0N+81tMotaRMfSL9SGi+xpD3T6YApKsc3bGSXJlfXri3VyFOeYkfLRQisDk1W+jIFFKBeUBbBg==} + dev: true + /https-proxy-agent@5.0.1: resolution: {integrity: sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==} engines: {node: '>= 6'} @@ -10828,6 +10992,14 @@ packages: is-relative: 1.0.0 is-windows: 1.0.2 + /is-arguments@1.1.1: + resolution: {integrity: sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==} + engines: {node: '>= 0.4'} + dependencies: + call-bind: 1.0.5 + has-tostringtag: 1.0.0 + dev: true + /is-array-buffer@3.0.2: resolution: {integrity: sha512-y+FyyR/w8vfIRq4eQcM1EYgSTnmHXPqaF+IgzgraytCFq5Xh8lllDVmAZolPJiZttZLeFSINPYMaEJ7/vWUa1w==} dependencies: @@ -10975,6 +11147,14 @@ packages: /is-map@2.0.2: resolution: {integrity: sha512-cOZFQQozTha1f4MxLFzlgKYPTyj26picdZTx82hbc/Xf4K/tZOOXSCkMvU4pKioRXGDLJRn0GM7Upe7kR721yg==} + /is-nan@1.3.2: + resolution: {integrity: sha512-E+zBKpQ2t6MEo1VsonYmluk9NxGrbzpeeLC2xIViuO2EjU2xsXsBPwTr3Ykv9l08UYEVEdWeRZNouaZqF6RN0w==} + engines: {node: '>= 0.4'} + dependencies: + call-bind: 1.0.5 + define-properties: 1.2.1 + dev: true + /is-negative-zero@2.0.2: resolution: {integrity: sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==} engines: {node: '>= 0.4'} @@ -11145,6 +11325,11 @@ packages: resolution: {integrity: sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==} engines: {node: '>=0.10.0'} + /isomorphic-timers-promises@1.0.1: + resolution: {integrity: sha512-u4sej9B1LPSxTGKB/HiuzvEQnXH0ECYkSVQU39koSwmFAxhlEAFl9RdTvLv4TOTQUgBS5O3O5fwUxk6byBZ+IQ==} + engines: {node: '>=10'} + dev: true + /isomorphic-unfetch@3.1.0: resolution: {integrity: sha512-geDJjpoZ8N0kWexiwkX8F9NkTsXhetLPVbZFQ+JTW239QNOwvB0gniuR1Wc6f0AMTn7/mFGyXvHTifrCp/GH8Q==} dependencies: @@ -11587,6 +11772,13 @@ packages: resolution: {integrity: sha512-Pn9cox5CsMYngeDbmChANltQl+5pi6XmTrraMSzhPmMBbmgcxmqWry0U3PGapCU1yB4/LqCcom7qhHZiF/jGfQ==} dev: true + /magic-string@0.30.5: + resolution: {integrity: sha512-7xlpfBaQaP/T6Vh8MO/EqXSW5En6INHEvEXQiuff7Gku0PWjU3uf6w/j9o7O+SpB5fOAkrI5HeoNgwjEO0pFsA==} + engines: {node: '>=12'} + dependencies: + '@jridgewell/sourcemap-codec': 1.4.15 + dev: true + /make-dir@3.1.0: resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==} engines: {node: '>=8'} @@ -11702,6 +11894,14 @@ packages: braces: 3.0.2 picomatch: 2.3.1 + /miller-rabin@4.0.1: + resolution: {integrity: sha512-115fLhvZVqWwHPbClyntxEVfVDfl9DLLTuJvq3g2O/Oxi8AiNouAHvDSzHS0viUJc+V5vm3eq91Xwqn9dp4jRA==} + hasBin: true + dependencies: + bn.js: 4.12.0 + brorand: 1.1.0 + dev: true + /mime-db@1.52.0: resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} engines: {node: '>= 0.6'} @@ -12021,6 +12221,39 @@ packages: /node-releases@2.0.13: resolution: {integrity: sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==} + /node-stdlib-browser@1.2.0: + resolution: {integrity: sha512-VSjFxUhRhkyed8AtLwSCkMrJRfQ3e2lGtG3sP6FEgaLKBBbxM/dLfjRe1+iLhjvyLFW3tBQ8+c0pcOtXGbAZJg==} + engines: {node: '>=10'} + dependencies: + assert: 2.1.0 + browser-resolve: 2.0.0 + browserify-zlib: 0.2.0 + buffer: 5.7.1 + console-browserify: 1.2.0 + constants-browserify: 1.0.0 + create-require: 1.1.1 + crypto-browserify: 3.12.0 + domain-browser: 4.23.0 + events: 3.3.0 + https-browserify: 1.0.0 + isomorphic-timers-promises: 1.0.1 + os-browserify: 0.3.0 + path-browserify: 1.0.1 + pkg-dir: 5.0.0 + process: 0.11.10 + punycode: 1.4.1 + querystring-es3: 0.2.1 + readable-stream: 3.6.2 + stream-browserify: 3.0.0 + stream-http: 3.2.0 + string_decoder: 1.3.0 + timers-browserify: 2.0.12 + tty-browserify: 0.0.1 + url: 0.11.3 + util: 0.12.5 + vm-browserify: 1.1.2 + dev: true + /nofilter@3.1.0: resolution: {integrity: sha512-l2NNj07e9afPnhAhvgVrCD/oy2Ai1yfLpuo3EpiO1jFTsB4sFz6oIfAfSZyQzVpkZQ9xS8ZS5g1jCBgq4Hwo0g==} engines: {node: '>=12.19'} @@ -12117,6 +12350,14 @@ packages: /object-inspect@1.13.1: resolution: {integrity: sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==} + /object-is@1.1.5: + resolution: {integrity: sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==} + engines: {node: '>= 0.4'} + dependencies: + call-bind: 1.0.5 + define-properties: 1.2.1 + dev: true + /object-keys@1.1.1: resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==} engines: {node: '>= 0.4'} @@ -12274,6 +12515,10 @@ packages: resolution: {integrity: sha512-cMddMgb2QElm8G7vdaa02jhUNbTSrhsgAGUz1OokD83uJTwSUn+nKoNoKVVaRa08yF6sgfO7Maou1+bgLd9rdQ==} dev: true + /os-browserify@0.3.0: + resolution: {integrity: sha512-gjcpUc3clBf9+210TRaDWbf+rZZZEshZ+DlXMRCeAjp0xhTrnQsKHypIy1J3d5hKdUzj69t708EHtU8P6bUn0A==} + dev: true + /os-tmpdir@1.0.2: resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} engines: {node: '>=0.10.0'} @@ -12367,6 +12612,10 @@ packages: registry-url: 6.0.1 semver: 7.5.4 + /pako@1.0.11: + resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==} + dev: true + /param-case@3.0.4: resolution: {integrity: sha512-RXlj7zCYokReqWpOPH9oYivUzLYZ5vAPIfEmCTNViosC78F8F0H9y7T7gG2M39ymgutxF5gcFEsyZQSph9Bp3A==} dependencies: @@ -12379,6 +12628,16 @@ packages: dependencies: callsites: 3.1.0 + /parse-asn1@5.1.6: + resolution: {integrity: sha512-RnZRo1EPU6JBnra2vGHj0yhp6ebyjBZpmUCLHWiFhxlzvBCCpAuZ7elsBp1PVAbQN0/04VD/19rfzlBSwLstMw==} + dependencies: + asn1.js: 5.4.1 + browserify-aes: 1.2.0 + evp_bytestokey: 1.0.3 + pbkdf2: 3.1.2 + safe-buffer: 5.2.1 + dev: true + /parse-cache-control@1.0.1: resolution: {integrity: sha512-60zvsJReQPX5/QP0Kzfd/VrpjScIQ7SHBW6bFCYfEP+fp0Eppr1SHhIO5nd1PjZtvclzSzES9D/p5nFJurwfWg==} dev: true @@ -12426,6 +12685,10 @@ packages: ansi-escapes: 4.3.2 cross-spawn: 7.0.3 + /path-browserify@1.0.1: + resolution: {integrity: sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==} + dev: true + /path-case@3.0.4: resolution: {integrity: sha512-qO4qCFjXqVTrcbPt/hQfhTQ+VhFsqNKOPtytgNKkKxSoEp3XPUQ8ObFuePylOIok5gjn69ry8XiULxCwot3Wfg==} dependencies: @@ -12517,6 +12780,13 @@ packages: dependencies: find-up: 4.1.0 + /pkg-dir@5.0.0: + resolution: {integrity: sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==} + engines: {node: '>=10'} + dependencies: + find-up: 5.0.0 + dev: true + /pkg-up@3.1.0: resolution: {integrity: sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==} engines: {node: '>=8'} @@ -12934,6 +13204,11 @@ packages: /process-nextick-args@2.0.1: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} + /process@0.11.10: + resolution: {integrity: sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==} + engines: {node: '>= 0.6.0'} + dev: true + /progress@2.0.3: resolution: {integrity: sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==} engines: {node: '>=0.4.0'} @@ -12990,12 +13265,27 @@ packages: /pseudomap@1.0.2: resolution: {integrity: sha512-b/YwNhb8lk1Zz2+bXXpS/LK9OisiZZ1SNsSLxN1x2OXVEhW2Ckr/7mWE5vrC1ZTiJlD9g19jWszTmJsB+oEpFQ==} + /public-encrypt@4.0.3: + resolution: {integrity: sha512-zVpa8oKZSz5bTMTFClc1fQOnyyEzpl5ozpi1B5YcvBrdohMjH2rfsBtyXcuNuwjsDIXmBYlF2N5FlJYhR29t8Q==} + dependencies: + bn.js: 4.12.0 + browserify-rsa: 4.1.0 + create-hash: 1.2.0 + parse-asn1: 5.1.6 + randombytes: 2.1.0 + safe-buffer: 5.2.1 + dev: true + /pump@3.0.0: resolution: {integrity: sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==} dependencies: end-of-stream: 1.4.4 once: 1.4.0 + /punycode@1.4.1: + resolution: {integrity: sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==} + dev: true + /punycode@2.3.1: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} @@ -13026,6 +13316,11 @@ packages: split-on-first: 1.1.0 strict-uri-encode: 2.0.0 + /querystring-es3@0.2.1: + resolution: {integrity: sha512-773xhDQnZBMFobEiztv8LIl70ch5MSF/jUQVlhwFyBILqq96anmoctVIYz+ZRp0qbCKATTn6ev02M3r7Ga5vqA==} + engines: {node: '>=0.4.x'} + dev: true + /queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} @@ -13042,6 +13337,13 @@ packages: dependencies: safe-buffer: 5.2.1 + /randomfill@1.0.4: + resolution: {integrity: sha512-87lcbR8+MhcWcUiQ+9e+Rwx8MyR2P7qnt15ynUlbm3TU/fjbgz4GsvfSUDTemtCCtVCqb4ZcEFlyPNTh9bBTLw==} + dependencies: + randombytes: 2.1.0 + safe-buffer: 5.2.1 + dev: true + /range-parser@1.2.1: resolution: {integrity: sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==} engines: {node: '>= 0.6'} @@ -14145,6 +14447,22 @@ packages: resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==} engines: {node: '>= 0.8'} + /stream-browserify@3.0.0: + resolution: {integrity: sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA==} + dependencies: + inherits: 2.0.4 + readable-stream: 3.6.2 + dev: true + + /stream-http@3.2.0: + resolution: {integrity: sha512-Oq1bLqisTyK3TSCXpPbT4sdeYNdmyZJv1LxpEm2vu1ZhK89kSE5YXwZc3cWk0MagGaKriBh9mCFbVGtO+vY29A==} + dependencies: + builtin-status-codes: 3.0.0 + inherits: 2.0.4 + readable-stream: 3.6.2 + xtend: 4.0.2 + dev: true + /streamsearch@1.1.0: resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==} engines: {node: '>=10.0.0'} @@ -14559,6 +14877,13 @@ packages: engines: {node: '>=14'} dev: true + /timers-browserify@2.0.12: + resolution: {integrity: sha512-9phl76Cqm6FhSX9Xe1ZUAMLtm1BLkKj2Qd5ApyWkXzsMRaA7dgr81kf4wJmQf/hAvg8EEyJxDo3du/0KlhPiKQ==} + engines: {node: '>=0.6.0'} + dependencies: + setimmediate: 1.0.5 + dev: true + /timers-ext@0.1.7: resolution: {integrity: sha512-b85NUNzTSdodShTIbky6ZF02e8STtVVfD+fu4aXXShEELpozH+bCpJLYMPZbsABN2wDH7fJpqIoXxJpzbf0NqQ==} dependencies: @@ -14716,6 +15041,10 @@ packages: tslib: 1.14.1 typescript: 5.3.2 + /tty-browserify@0.0.1: + resolution: {integrity: sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw==} + dev: true + /tunnel-agent@0.6.0: resolution: {integrity: sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==} requiresBuild: true @@ -14986,6 +15315,13 @@ packages: schema-utils: 3.3.0 webpack: 5.89.0 + /url@0.11.3: + resolution: {integrity: sha512-6hxOLGfZASQK/cijlZnZJTq8OXAkt/3YGfQX45vvMYXpZoo8NdWZcY73K108Jf759lS1Bv/8wXnHDTSz17dSRw==} + dependencies: + punycode: 1.4.1 + qs: 6.11.2 + dev: true + /use-callback-ref@1.3.0(@types/react@18.2.38)(react@18.2.0): resolution: {integrity: sha512-3FT9PRuRdbB9HfXhEq35u4oZkvpJ5kuYbpqhCfmiZyReuRgpnhDlbr2ZEnnuS0RrJAPn6l23xjFg9kpDM+Ms7w==} engines: {node: '>=10'} @@ -15024,6 +15360,16 @@ packages: /util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + /util@0.12.5: + resolution: {integrity: sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==} + dependencies: + inherits: 2.0.4 + is-arguments: 1.1.1 + is-generator-function: 1.0.10 + is-typed-array: 1.1.12 + which-typed-array: 1.1.13 + dev: true + /utila@0.4.0: resolution: {integrity: sha512-Z0DbgELS9/L/75wZbro8xAnT50pBVFQZ+hUEueGDU5FN51YSCYM+jdxsfCiHjwNP/4LCDD0i/graKpeBnOXKRA==} @@ -15066,6 +15412,18 @@ packages: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} + /vite-plugin-node-polyfills@0.19.0(vite@5.0.2): + resolution: {integrity: sha512-AhdVxAmVnd1doUlIRGUGV6ZRPfB9BvIwDF10oCOmL742IsvsFIAV4tSMxSfu5e0Px0QeJLgWVOSbtHIvblzqMw==} + peerDependencies: + vite: ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 + dependencies: + '@rollup/plugin-inject': 5.0.5 + node-stdlib-browser: 1.2.0 + vite: 5.0.2 + transitivePeerDependencies: + - rollup + dev: true + /vite@5.0.2: resolution: {integrity: sha512-6CCq1CAJCNM1ya2ZZA7+jS2KgnhbzvxakmlIjN24cF/PXhRMzpM/z8QgsVJA/Dm5fWUWnVEsmtBoMhmerPxT0g==} engines: {node: ^18.0.0 || >=20.0.0} @@ -15101,6 +15459,10 @@ packages: fsevents: 2.3.3 dev: true + /vm-browserify@1.1.2: + resolution: {integrity: sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ==} + dev: true + /watchpack@2.4.0: resolution: {integrity: sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==} engines: {node: '>=10.13.0'} From dc288d9f294421d73af9f146a5e53d5e646e69c1 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Fri, 29 Dec 2023 16:27:11 +0100 Subject: [PATCH 08/49] Define helpers wrapper for snapshots We take snapshots with before/after and beforeEach/afterEach blocks. Here we define common helper functions to simplify the code. --- core/test/Acre.test.ts | 66 ++++++++++-------------------------- core/test/Dispatcher.test.ts | 18 ++-------- core/test/helpers/context.ts | 38 +++++++++++++++++++-- 3 files changed, 56 insertions(+), 66 deletions(-) diff --git a/core/test/Acre.test.ts b/core/test/Acre.test.ts index 4a5b97620..683c4da4f 100644 --- a/core/test/Acre.test.ts +++ b/core/test/Acre.test.ts @@ -12,7 +12,11 @@ import { import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers" import type { SnapshotRestorer } from "@nomicfoundation/hardhat-toolbox/network-helpers" -import { deployment } from "./helpers/context" +import { + beforeAfterEachSnapshotWrapper, + beforeAfterSnapshotWrapper, + deployment, +} from "./helpers/context" import { getNamedSigner, getUnnamedSigner } from "./helpers/signer" import { to1e18 } from "./utils" @@ -45,16 +49,9 @@ describe("Acre", () => { describe("stake", () => { const referral = encodeBytes32String("referral") - let snapshot: SnapshotRestorer context("when staking as first staker", () => { - beforeEach(async () => { - snapshot = await takeSnapshot() - }) - - afterEach(async () => { - await snapshot.restore() - }) + beforeAfterEachSnapshotWrapper() context("with a referral", () => { const amountToStake = to1e18(1) @@ -258,6 +255,8 @@ describe("Acre", () => { }) context("when there are two stakers", () => { + beforeAfterSnapshotWrapper() + const staker1AmountToStake = to1e18(7) const staker2AmountToStake = to1e18(3) let afterStakesSnapshot: SnapshotRestorer @@ -276,10 +275,6 @@ describe("Acre", () => { await tbtc.connect(staker2).mint(staker2.address, staker2AmountToStake) }) - after(async () => { - await snapshot.restore() - }) - context( "when the vault is empty and has not yet earned yield from strategies", () => { @@ -529,15 +524,7 @@ describe("Acre", () => { }) describe("mint", () => { - let snapshot: SnapshotRestorer - - beforeEach(async () => { - snapshot = await takeSnapshot() - }) - - afterEach(async () => { - await snapshot.restore() - }) + beforeAfterEachSnapshotWrapper() context("when minting as first staker", () => { const amountToStake = to1e18(1) @@ -634,17 +621,10 @@ describe("Acre", () => { }) describe("updateDepositParameters", () => { + beforeAfterEachSnapshotWrapper() + const validMinimumDepositAmount = to1e18(1) const validMaximumTotalAssetsAmount = to1e18(30) - let snapshot: SnapshotRestorer - - beforeEach(async () => { - snapshot = await takeSnapshot() - }) - - afterEach(async () => { - await snapshot.restore() - }) context("when is called by owner", () => { context("when all parameters are valid", () => { @@ -728,20 +708,16 @@ describe("Acre", () => { }) describe("maxDeposit", () => { + beforeAfterEachSnapshotWrapper() + let maximumTotalAssets: bigint let minimumDepositAmount: bigint - let snapshot: SnapshotRestorer beforeEach(async () => { - snapshot = await takeSnapshot() ;[minimumDepositAmount, maximumTotalAssets] = await acre.depositParameters() }) - afterEach(async () => { - await snapshot.restore() - }) - context( "when total assets is greater than maximum total assets amount", () => { @@ -817,20 +793,16 @@ describe("Acre", () => { }) describe("maxMint", () => { + beforeAfterEachSnapshotWrapper() + let maximumTotalAssets: bigint let minimumDepositAmount: bigint - let snapshot: SnapshotRestorer beforeEach(async () => { - snapshot = await takeSnapshot() ;[minimumDepositAmount, maximumTotalAssets] = await acre.depositParameters() }) - afterEach(async () => { - await snapshot.restore() - }) - context( "when total assets is greater than maximum total assets amount", () => { @@ -922,19 +894,15 @@ describe("Acre", () => { }) describe("deposit", () => { + beforeAfterEachSnapshotWrapper() + let amountToDeposit: bigint let minimumDepositAmount: bigint - let snapshot: SnapshotRestorer beforeEach(async () => { - snapshot = await takeSnapshot() minimumDepositAmount = await acre.minimumDepositAmount() }) - afterEach(async () => { - await snapshot.restore() - }) - context("when the deposit amount is less than minimum", () => { beforeEach(() => { amountToDeposit = minimumDepositAmount - 1n diff --git a/core/test/Dispatcher.test.ts b/core/test/Dispatcher.test.ts index 1fdecc5d9..3b986674e 100644 --- a/core/test/Dispatcher.test.ts +++ b/core/test/Dispatcher.test.ts @@ -1,13 +1,9 @@ import { ethers } from "hardhat" import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers" import { expect } from "chai" -import { - SnapshotRestorer, - takeSnapshot, - loadFixture, -} from "@nomicfoundation/hardhat-toolbox/network-helpers" +import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers" import type { Dispatcher } from "../typechain" -import { deployment } from "./helpers/context" +import { beforeAfterEachSnapshotWrapper, deployment } from "./helpers/context" import { getNamedSigner, getUnnamedSigner } from "./helpers/signer" async function fixture() { @@ -19,8 +15,6 @@ async function fixture() { } describe("Dispatcher", () => { - let snapshot: SnapshotRestorer - let dispatcher: Dispatcher let governance: HardhatEthersSigner let thirdParty: HardhatEthersSigner @@ -38,13 +32,7 @@ describe("Dispatcher", () => { vaultAddress4 = await ethers.Wallet.createRandom().getAddress() }) - beforeEach(async () => { - snapshot = await takeSnapshot() - }) - - afterEach(async () => { - await snapshot.restore() - }) + beforeAfterEachSnapshotWrapper() describe("authorizeVault", () => { context("when caller is not a governance account", () => { diff --git a/core/test/helpers/context.ts b/core/test/helpers/context.ts index 34875e43d..8bbc206f1 100644 --- a/core/test/helpers/context.ts +++ b/core/test/helpers/context.ts @@ -1,10 +1,44 @@ import { deployments } from "hardhat" - +import { + SnapshotRestorer, + takeSnapshot, +} from "@nomicfoundation/hardhat-toolbox/network-helpers" import { getDeployedContract } from "./contract" import type { Acre, Dispatcher, TestERC20 } from "../../typechain" -// eslint-disable-next-line import/prefer-default-export +/** + * Adds a before/after hook pair to snapshot the EVM state before and after tests + * in a test suite. + */ +export function beforeAfterSnapshotWrapper(): void { + let snapshot: SnapshotRestorer + + before(async () => { + snapshot = await takeSnapshot() + }) + + after(async () => { + await snapshot.restore() + }) +} + +/** + * Adds a beforeEach/afterEach hook pair to snapshot the EVM state before and + * after each of tests in a test suite. + */ +export function beforeAfterEachSnapshotWrapper(): void { + let snapshot: SnapshotRestorer + + beforeEach(async () => { + snapshot = await takeSnapshot() + }) + + afterEach(async () => { + await snapshot.restore() + }) +} + export async function deployment() { await deployments.fixture() From 11becd098cb13b8af098e57c7433ba96a4cc1960 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Fri, 29 Dec 2023 16:33:52 +0100 Subject: [PATCH 09/49] Update order of actions in before block --- core/test/Acre.test.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/test/Acre.test.ts b/core/test/Acre.test.ts index 683c4da4f..85e86c4ec 100644 --- a/core/test/Acre.test.ts +++ b/core/test/Acre.test.ts @@ -263,16 +263,17 @@ describe("Acre", () => { let afterSimulatingYieldSnapshot: SnapshotRestorer before(async () => { + // Mint tBTC. + await tbtc.mint(staker1.address, staker1AmountToStake) + await tbtc.mint(staker2.address, staker2AmountToStake) + + // Approve tBTC. await tbtc .connect(staker1) .approve(await acre.getAddress(), staker1AmountToStake) await tbtc .connect(staker2) .approve(await acre.getAddress(), staker2AmountToStake) - - // Mint tokens. - await tbtc.connect(staker1).mint(staker1.address, staker1AmountToStake) - await tbtc.connect(staker2).mint(staker2.address, staker2AmountToStake) }) context( From 03b4e377337cc3a770e9f8af4c052671b6b2465f Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Fri, 29 Dec 2023 17:06:55 +0100 Subject: [PATCH 10/49] Improve stake tests Minor improvements to stake tests to restructure the tests and clean up a little bit. --- core/test/Acre.test.ts | 432 ++++++++++++++++++++--------------------- 1 file changed, 215 insertions(+), 217 deletions(-) diff --git a/core/test/Acre.test.ts b/core/test/Acre.test.ts index 85e86c4ec..94af3f3aa 100644 --- a/core/test/Acre.test.ts +++ b/core/test/Acre.test.ts @@ -37,6 +37,8 @@ async function fixture() { } describe("Acre", () => { + const referral = encodeBytes32String("referral") + let acre: Acre let tbtc: TestERC20 let owner: HardhatEthersSigner @@ -48,8 +50,6 @@ describe("Acre", () => { }) describe("stake", () => { - const referral = encodeBytes32String("referral") - context("when staking as first staker", () => { beforeAfterEachSnapshotWrapper() @@ -254,11 +254,13 @@ describe("Acre", () => { ) }) - context("when there are two stakers", () => { + describe("when staking by multiple stakers", () => { beforeAfterSnapshotWrapper() const staker1AmountToStake = to1e18(7) const staker2AmountToStake = to1e18(3) + const earnedYield = to1e18(5) + let afterStakesSnapshot: SnapshotRestorer let afterSimulatingYieldSnapshot: SnapshotRestorer @@ -276,250 +278,248 @@ describe("Acre", () => { .approve(await acre.getAddress(), staker2AmountToStake) }) - context( - "when the vault is empty and has not yet earned yield from strategies", - () => { - after(async () => { + context("when the vault is in initial state", () => { + describe("when two stakers stake", () => { + let stakeTx1: ContractTransactionResponse + let stakeTx2: ContractTransactionResponse + + before(async () => { + stakeTx1 = await acre + .connect(staker1) + .stake(staker1AmountToStake, staker1.address, referral) + + stakeTx2 = await acre + .connect(staker2) + .stake(staker2AmountToStake, staker2.address, referral) + afterStakesSnapshot = await takeSnapshot() }) - context("when staker A stakes tokens", () => { - it("should receive shares equal to a staked amount", async () => { - const tx = await acre - .connect(staker1) - .stake(staker1AmountToStake, staker1.address, referral) - - await expect(tx).to.changeTokenBalances( - acre, - [staker1.address], - [staker1AmountToStake], - ) - }) + it("staker A should receive shares equal to a staked amount", async () => { + await expect(stakeTx1).to.changeTokenBalances( + acre, + [staker1.address], + [staker1AmountToStake], + ) }) - context("when staker B stakes tokens", () => { - it("should receive shares equal to a staked amount", async () => { - const tx = await acre - .connect(staker2) - .stake(staker2AmountToStake, staker2.address, referral) - - await expect(tx).to.changeTokenBalances( - acre, - [staker2.address], - [staker2AmountToStake], - ) - }) + it("staker B should receive shares equal to a staked amount", async () => { + await expect(stakeTx2).to.changeTokenBalances( + acre, + [staker2.address], + [staker2AmountToStake], + ) }) - }, - ) - - context("when the vault has stakes", () => { - before(async () => { - await afterStakesSnapshot.restore() - }) - - it("the total assets amount should be equal to all staked tokens", async () => { - const totalAssets = await acre.totalAssets() - expect(totalAssets).to.eq(staker1AmountToStake + staker2AmountToStake) + it("the total assets amount should be equal to all staked tokens", async () => { + expect(await acre.totalAssets()).to.eq( + staker1AmountToStake + staker2AmountToStake, + ) + }) }) }) - context("when vault earns yield", () => { - let staker1SharesBefore: bigint - let staker2SharesBefore: bigint - let vaultYield: bigint + context("when vault has two stakers", () => { + context("when vault earns yield", () => { + let staker1SharesBefore: bigint + let staker2SharesBefore: bigint - before(async () => { - // Current state: - // Staker A shares = 7 - // Staker B shares = 3 - // Total assets = 7(staker A) + 3(staker B) + 5(yield) - await afterStakesSnapshot.restore() + before(async () => { + // Current state: + // Staker A shares = 7 + // Staker B shares = 3 + // Total assets = 7(staker A) + 3(staker B) + 5(yield) + await afterStakesSnapshot.restore() - staker1SharesBefore = await acre.balanceOf(staker1.address) - staker2SharesBefore = await acre.balanceOf(staker2.address) - vaultYield = to1e18(5) + staker1SharesBefore = await acre.balanceOf(staker1.address) + staker2SharesBefore = await acre.balanceOf(staker2.address) - // Simulating yield returned from strategies. The vault now contains - // more tokens than deposited which causes the exchange rate to - // change. - await tbtc.mint(await acre.getAddress(), vaultYield) - }) + // Simulating yield returned from strategies. The vault now contains + // more tokens than deposited which causes the exchange rate to + // change. + await tbtc.mint(await acre.getAddress(), earnedYield) + }) - after(async () => { - afterSimulatingYieldSnapshot = await takeSnapshot() - }) + after(async () => { + afterSimulatingYieldSnapshot = await takeSnapshot() + }) - it("the vault should hold more assets", async () => { - expect(await acre.totalAssets()).to.be.eq( - staker1AmountToStake + staker2AmountToStake + vaultYield, - ) - }) + it("the vault should hold more assets", async () => { + expect(await acre.totalAssets()).to.be.eq( + staker1AmountToStake + staker2AmountToStake + earnedYield, + ) + }) - it("the staker's shares should be the same", async () => { - expect(await acre.balanceOf(staker1.address)).to.be.eq( - staker1SharesBefore, - ) - expect(await acre.balanceOf(staker2.address)).to.be.eq( - staker2SharesBefore, - ) - }) + it("the stakers shares should be the same", async () => { + expect(await acre.balanceOf(staker1.address)).to.be.eq( + staker1SharesBefore, + ) + expect(await acre.balanceOf(staker2.address)).to.be.eq( + staker2SharesBefore, + ) + }) - it("the staker A should be able to redeem more tokens than before", async () => { - const shares = await acre.balanceOf(staker1.address) - const availableAssetsToRedeem = await acre.previewRedeem(shares) + it("the staker A should be able to redeem more tokens than before", async () => { + const shares = await acre.balanceOf(staker1.address) + const availableAssetsToRedeem = await acre.previewRedeem(shares) - // Expected amount w/o rounding: 7 * 15 / 10 = 10.5 - // Expected amount w/ support for rounding: 10499999999999999999 in - // tBTC token precision. - const expectedAssetsToRedeem = 10499999999999999999n + // Expected amount w/o rounding: 7 * 15 / 10 = 10.5 + // Expected amount w/ support for rounding: 10499999999999999999 in + // tBTC token precision. + const expectedAssetsToRedeem = 10499999999999999999n - expect(availableAssetsToRedeem).to.be.eq(expectedAssetsToRedeem) - }) + expect(availableAssetsToRedeem).to.be.eq(expectedAssetsToRedeem) + }) - it("the staker B should be able to redeem more tokens than before", async () => { - const shares = await acre.balanceOf(staker2.address) - const availableAssetsToRedeem = await acre.previewRedeem(shares) + it("the staker B should be able to redeem more tokens than before", async () => { + const shares = await acre.balanceOf(staker2.address) + const availableAssetsToRedeem = await acre.previewRedeem(shares) - // Expected amount w/o rounding: 3 * 15 / 10 = 4.5 - // Expected amount w/ support for rounding: 4499999999999999999 in - // tBTC token precision. - const expectedAssetsToRedeem = 4499999999999999999n + // Expected amount w/o rounding: 3 * 15 / 10 = 4.5 + // Expected amount w/ support for rounding: 4499999999999999999 in + // tBTC token precision. + const expectedAssetsToRedeem = 4499999999999999999n - expect(availableAssetsToRedeem).to.be.eq(expectedAssetsToRedeem) + expect(availableAssetsToRedeem).to.be.eq(expectedAssetsToRedeem) + }) }) - }) - - context("when staker A stakes more tokens", () => { - context( - "when total tBTC amount after staking would not exceed max amount", - () => { - const newAmountToStake = to1e18(2) - // Current state: - // Total assets = 7(staker A) + 3(staker B) + 5(yield) - // Total shares = 7 + 3 = 10 - // Shares to mint = 2 * 10 / 15 = 1.(3) -> 1333333333333333333 in stBTC - // token precision - const expectedSharesToMint = 1333333333333333333n - let sharesBefore: bigint - let availableToRedeemBefore: bigint - - before(async () => { - await afterSimulatingYieldSnapshot.restore() - - sharesBefore = await acre.balanceOf(staker1.address) - availableToRedeemBefore = await acre.previewRedeem(sharesBefore) - - await tbtc.mint(staker1.address, newAmountToStake) - - await tbtc - .connect(staker1) - .approve(await acre.getAddress(), newAmountToStake) - - // State after stake: - // Total assets = 7(staker A) + 3(staker B) + 5(yield) + 2(staker - // A) = 17 - // Total shares = 7 + 3 + 1.(3) = 11.(3) - await acre - .connect(staker1) - .stake(newAmountToStake, staker1.address, referral) - }) - - it("should receive more shares", async () => { - const shares = await acre.balanceOf(staker1.address) - - expect(shares).to.be.eq(sharesBefore + expectedSharesToMint) - }) - - it("should be able to redeem more tokens than before", async () => { - const shares = await acre.balanceOf(staker1.address) - const availableToRedeem = await acre.previewRedeem(shares) - - // Expected amount w/o rounding: 8.(3) * 17 / 11.(3) = 12.5 - // Expected amount w/ support for rounding: 12499999999999999999 in - // tBTC token precision. - const expectedTotalAssetsAvailableToRedeem = 12499999999999999999n - - expect(availableToRedeem).to.be.greaterThan( - availableToRedeemBefore, - ) - expect(availableToRedeem).to.be.eq( - expectedTotalAssetsAvailableToRedeem, - ) - }) - }, - ) - context( - "when total tBTC amount after staking would exceed max amount", - () => { - let possibleMaxAmountToStake: bigint - let amountToStake: bigint - - before(async () => { - await afterSimulatingYieldSnapshot.restore() - - // In the current implementation of the `maxDeposit` the - // `address` param is not taken into account - it means it will - // return the same value for any address. - possibleMaxAmountToStake = await acre.maxDeposit(staker1.address) - amountToStake = possibleMaxAmountToStake + 1n - - await tbtc - .connect(staker1) - .approve(await acre.getAddress(), amountToStake) - }) - - it("should revert", async () => { - await expect(acre.stake(amountToStake, staker1.address, referral)) - .to.be.revertedWithCustomError( - acre, - "ERC4626ExceededMaxDeposit", + context("when staker A stakes more tokens", () => { + context( + "when total tBTC amount after staking would not exceed max amount", + () => { + const newAmountToStake = to1e18(2) + // Current state: + // Total assets = 7(staker A) + 3(staker B) + 5(yield) + // Total shares = 7 + 3 = 10 + // New stake amount = 2 + // Shares to mint = 2 * 10 / 15 = 1.(3) -> 1333333333333333333 in stBTC + // token precision + const expectedSharesToMint = 1333333333333333333n + let sharesBefore: bigint + let availableToRedeemBefore: bigint + + before(async () => { + await afterSimulatingYieldSnapshot.restore() + + sharesBefore = await acre.balanceOf(staker1.address) + availableToRedeemBefore = await acre.previewRedeem(sharesBefore) + + await tbtc.mint(staker1.address, newAmountToStake) + + await tbtc + .connect(staker1) + .approve(await acre.getAddress(), newAmountToStake) + + // State after stake: + // Total assets = 7(staker A) + 3(staker B) + 5(yield) + 2(staker + // A) = 17 + // Total shares = 7 + 3 + 1.(3) = 11.(3) + await acre + .connect(staker1) + .stake(newAmountToStake, staker1.address, referral) + }) + + it("should receive more shares", async () => { + const shares = await acre.balanceOf(staker1.address) + + expect(shares).to.be.eq(sharesBefore + expectedSharesToMint) + }) + + it("should be able to redeem more tokens than before", async () => { + const shares = await acre.balanceOf(staker1.address) + const availableToRedeem = await acre.previewRedeem(shares) + + // Expected amount w/o rounding: 8.(3) * 17 / 11.(3) = 12.5 + // Expected amount w/ support for rounding: 12499999999999999999 in + // tBTC token precision. + const expectedTotalAssetsAvailableToRedeem = + 12499999999999999999n + + expect(availableToRedeem).to.be.greaterThan( + availableToRedeemBefore, ) - .withArgs( - staker1.address, - amountToStake, - possibleMaxAmountToStake, + expect(availableToRedeem).to.be.eq( + expectedTotalAssetsAvailableToRedeem, ) - }) - }, - ) - - context( - "when total tBTC amount after staking would be equal to the max amount", - () => { - let amountToStake: bigint - let tx: ContractTransactionResponse + }) + }, + ) - before(async () => { - amountToStake = await acre.maxDeposit(staker1.address) + context( + "when total tBTC amount after staking would exceed max amount", + () => { + let possibleMaxAmountToStake: bigint + let amountToStake: bigint - await tbtc - .connect(staker1) - .approve(await acre.getAddress(), amountToStake) + before(async () => { + await afterSimulatingYieldSnapshot.restore() - tx = await acre.stake(amountToStake, staker1, referral) - }) - - it("should stake tokens correctly", async () => { - await expect(tx).to.emit(acre, "Deposit") - }) + // In the current implementation of the `maxDeposit` the + // `address` param is not taken into account - it means it will + // return the same value for any address. + possibleMaxAmountToStake = await acre.maxDeposit( + staker1.address, + ) + amountToStake = possibleMaxAmountToStake + 1n - it("the max deposit amount should be equal 0", async () => { - expect(await acre.maxDeposit(staker1)).to.eq(0) - }) + await tbtc + .connect(staker1) + .approve(await acre.getAddress(), amountToStake) + }) - it("should not be able to stake more tokens", async () => { - await expect(acre.stake(amountToStake, staker1, referral)) - .to.be.revertedWithCustomError( - acre, - "ERC4626ExceededMaxDeposit", + it("should revert", async () => { + await expect( + acre.stake(amountToStake, staker1.address, referral), ) - .withArgs(staker1.address, amountToStake, 0) - }) - }, - ) + .to.be.revertedWithCustomError( + acre, + "ERC4626ExceededMaxDeposit", + ) + .withArgs( + staker1.address, + amountToStake, + possibleMaxAmountToStake, + ) + }) + }, + ) + + context( + "when total tBTC amount after staking would be equal to the max amount", + () => { + let amountToStake: bigint + let tx: ContractTransactionResponse + + before(async () => { + amountToStake = await acre.maxDeposit(staker1.address) + + await tbtc + .connect(staker1) + .approve(await acre.getAddress(), amountToStake) + + tx = await acre.stake(amountToStake, staker1, referral) + }) + + it("should stake tokens correctly", async () => { + await expect(tx).to.emit(acre, "Deposit") + }) + + it("the max deposit amount should be equal 0", async () => { + expect(await acre.maxDeposit(staker1)).to.eq(0) + }) + + it("should not be able to stake more tokens", async () => { + await expect(acre.stake(amountToStake, staker1, referral)) + .to.be.revertedWithCustomError( + acre, + "ERC4626ExceededMaxDeposit", + ) + .withArgs(staker1.address, amountToStake, 0) + }) + }, + ) + }) }) }) }) @@ -774,7 +774,6 @@ describe("Acre", () => { context("when the vault is not empty", () => { const amountToStake = to1e18(1) - const referral = encodeBytes32String("referral") beforeEach(async () => { await tbtc @@ -875,7 +874,6 @@ describe("Acre", () => { context("when the vault is not empty", () => { const amountToStake = to1e18(1) - const referral = encodeBytes32String("referral") beforeEach(async () => { await tbtc From 303f3b20a0c17e3198f96e05e95d2d3d5344bdc7 Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Tue, 2 Jan 2024 10:38:16 +0100 Subject: [PATCH 11/49] Make a `validate` function more general --- dapp/src/components/Modals/Staking/StakeForm.tsx | 10 ++++++++-- dapp/src/utils/forms.ts | 16 ++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/dapp/src/components/Modals/Staking/StakeForm.tsx b/dapp/src/components/Modals/Staking/StakeForm.tsx index 9ab138f24..59916670a 100644 --- a/dapp/src/components/Modals/Staking/StakeForm.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm.tsx @@ -4,6 +4,7 @@ import { ModalStep } from "../../../contexts" import FormBase, { FormBaseProps, FormValues } from "../../shared/FormBase" import { useTransactionContext, useWalletContext } from "../../../hooks" import { getErrorsObj, validateTokenAmount } from "../../../utils" +import { BITCOIN_MIN_AMOUNT } from "../../../constants" const CUSTOM_DATA = { buttonText: "Stake", @@ -18,10 +19,15 @@ const StakeFormik = withFormik< mapPropsToValues: () => ({ amount: "", }), - validate: async ({ amount }, { tokenBalance }) => { + validate: async ({ amount }, { tokenBalance, currencyType }) => { const errors: FormikErrors = {} - errors.amount = validateTokenAmount(amount, tokenBalance) + errors.amount = validateTokenAmount( + amount, + tokenBalance, + BITCOIN_MIN_AMOUNT, + currencyType ?? "bitcoin", + ) return getErrorsObj(errors) }, diff --git a/dapp/src/utils/forms.ts b/dapp/src/utils/forms.ts index 70249a13d..299322cb5 100644 --- a/dapp/src/utils/forms.ts +++ b/dapp/src/utils/forms.ts @@ -1,5 +1,6 @@ -import { BITCOIN_MIN_AMOUNT } from "../constants" -import { formatSatoshiAmount } from "./numbers" +import { CURRENCIES_BY_TYPE } from "../constants" +import { CurrencyType } from "../types" +import { formatTokenAmount } from "./numbers" const ERRORS = { REQUIRED: "Required.", @@ -16,20 +17,23 @@ export function getErrorsObj(errors: { [key in keyof T]: string }) { export function validateTokenAmount( value: string, - tokenBalance: string, + maxValue: string, + minValue: string, + currencyType: CurrencyType, ): string | undefined { if (!value) return ERRORS.REQUIRED + const { decimals } = CURRENCIES_BY_TYPE[currencyType] const valueInBI = BigInt(value) - const maxValueInBI = BigInt(tokenBalance) - const minValueInBI = BigInt(BITCOIN_MIN_AMOUNT) + const maxValueInBI = BigInt(maxValue) + const minValueInBI = BigInt(minValue) const isMaximumValueExceeded = valueInBI > maxValueInBI const isMinimumValueFulfilled = valueInBI >= minValueInBI if (isMaximumValueExceeded) return ERRORS.EXCEEDED_VALUE if (!isMinimumValueFulfilled) - return ERRORS.INSUFFICIENT_VALUE(formatSatoshiAmount(BITCOIN_MIN_AMOUNT)) + return ERRORS.INSUFFICIENT_VALUE(formatTokenAmount(minValue, decimals)) return undefined } From c697ec8448ac7bc223194befbcb4db65b2411478 Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Tue, 2 Jan 2024 14:54:25 +0100 Subject: [PATCH 12/49] Create a utils function to find for currency by type --- dapp/src/components/Modals/Support/MissingAccount.tsx | 4 ++-- dapp/src/components/shared/CurrencyBalance/index.tsx | 9 ++++++--- dapp/src/components/shared/TokenBalanceInput/index.tsx | 9 ++++++--- dapp/src/utils/currency.ts | 5 +++++ dapp/src/utils/forms.ts | 4 ++-- dapp/src/utils/index.ts | 1 + 6 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 dapp/src/utils/currency.ts diff --git a/dapp/src/components/Modals/Support/MissingAccount.tsx b/dapp/src/components/Modals/Support/MissingAccount.tsx index 7b6216276..710388917 100644 --- a/dapp/src/components/Modals/Support/MissingAccount.tsx +++ b/dapp/src/components/Modals/Support/MissingAccount.tsx @@ -10,7 +10,7 @@ import { import { CurrencyType, RequestAccountParams } from "../../../types" import { TextMd } from "../../shared/Typography" import AlertWrapper from "../../shared/Alert" -import { CURRENCIES_BY_TYPE } from "../../../constants" +import { getCurrencyByType } from "../../../utils" type MissingAccountProps = { currencyType: CurrencyType @@ -23,7 +23,7 @@ export default function MissingAccount({ icon, requestAccount, }: MissingAccountProps) { - const currency = CURRENCIES_BY_TYPE[currencyType] + const currency = getCurrencyByType(currencyType) return ( <> diff --git a/dapp/src/components/shared/CurrencyBalance/index.tsx b/dapp/src/components/shared/CurrencyBalance/index.tsx index 1f307d853..d6e72f64e 100644 --- a/dapp/src/components/shared/CurrencyBalance/index.tsx +++ b/dapp/src/components/shared/CurrencyBalance/index.tsx @@ -1,8 +1,11 @@ import React, { useMemo } from "react" import { Box, useMultiStyleConfig, TextProps } from "@chakra-ui/react" -import { formatTokenAmount, numberToLocaleString } from "../../../utils" +import { + formatTokenAmount, + getCurrencyByType, + numberToLocaleString, +} from "../../../utils" import { CurrencyType } from "../../../types" -import { CURRENCIES_BY_TYPE } from "../../../constants" export type CurrencyBalanceProps = { currencyType: CurrencyType @@ -24,7 +27,7 @@ export function CurrencyBalance({ }: CurrencyBalanceProps) { const styles = useMultiStyleConfig("CurrencyBalance", { size, variant }) - const currency = CURRENCIES_BY_TYPE[currencyType] + const currency = getCurrencyByType(currencyType) const balance = useMemo(() => { const value = amount ?? 0 diff --git a/dapp/src/components/shared/TokenBalanceInput/index.tsx b/dapp/src/components/shared/TokenBalanceInput/index.tsx index 8a6536e9a..418a90fb9 100644 --- a/dapp/src/components/shared/TokenBalanceInput/index.tsx +++ b/dapp/src/components/shared/TokenBalanceInput/index.tsx @@ -12,9 +12,12 @@ import { InputRightElement, useMultiStyleConfig, } from "@chakra-ui/react" -import { fixedPointNumberToString, userAmountToBigInt } from "../../../utils" +import { + fixedPointNumberToString, + getCurrencyByType, + userAmountToBigInt, +} from "../../../utils" import { CurrencyType } from "../../../types" -import { CURRENCIES_BY_TYPE } from "../../../constants" import NumberFormatInput, { NumberFormatInputValues, } from "../NumberFormatInput" @@ -109,7 +112,7 @@ export default function TokenBalanceInput({ const valueRef = useRef(amount) const styles = useMultiStyleConfig("TokenBalanceInput", { size }) - const currency = CURRENCIES_BY_TYPE[currencyType] + const currency = getCurrencyByType(currencyType) const handleValueChange = (value: string) => { valueRef.current = value diff --git a/dapp/src/utils/currency.ts b/dapp/src/utils/currency.ts new file mode 100644 index 000000000..dd745e373 --- /dev/null +++ b/dapp/src/utils/currency.ts @@ -0,0 +1,5 @@ +import { CURRENCIES_BY_TYPE } from "../constants" +import { Currency, CurrencyType } from "../types" + +export const getCurrencyByType = (type: CurrencyType): Currency => + CURRENCIES_BY_TYPE[type] diff --git a/dapp/src/utils/forms.ts b/dapp/src/utils/forms.ts index 299322cb5..844fa5bf0 100644 --- a/dapp/src/utils/forms.ts +++ b/dapp/src/utils/forms.ts @@ -1,5 +1,5 @@ -import { CURRENCIES_BY_TYPE } from "../constants" import { CurrencyType } from "../types" +import { getCurrencyByType } from "./currency" import { formatTokenAmount } from "./numbers" const ERRORS = { @@ -23,7 +23,7 @@ export function validateTokenAmount( ): string | undefined { if (!value) return ERRORS.REQUIRED - const { decimals } = CURRENCIES_BY_TYPE[currencyType] + const { decimals } = getCurrencyByType(currencyType) const valueInBI = BigInt(value) const maxValueInBI = BigInt(maxValue) const minValueInBI = BigInt(minValue) diff --git a/dapp/src/utils/index.ts b/dapp/src/utils/index.ts index 563f2e6d1..02eaa61b8 100644 --- a/dapp/src/utils/index.ts +++ b/dapp/src/utils/index.ts @@ -1,3 +1,4 @@ export * from "./numbers" export * from "./address" export * from "./forms" +export * from "./currency" From 998407678780832f722d33abaf0b1709472dda63 Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Tue, 2 Jan 2024 17:14:03 +0100 Subject: [PATCH 13/49] Make the token amount form component clearer --- .../components/Modals/Staking/StakeForm.tsx | 35 +++------------ .../TransactionDetails.tsx | 0 .../{FormBase => TokenAmountForm}/index.tsx | 45 ++++++++++++++++--- 3 files changed, 44 insertions(+), 36 deletions(-) rename dapp/src/components/shared/{FormBase => TokenAmountForm}/TransactionDetails.tsx (100%) rename dapp/src/components/shared/{FormBase => TokenAmountForm}/index.tsx (52%) diff --git a/dapp/src/components/Modals/Staking/StakeForm.tsx b/dapp/src/components/Modals/Staking/StakeForm.tsx index 59916670a..40e05ea2f 100644 --- a/dapp/src/components/Modals/Staking/StakeForm.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm.tsx @@ -1,9 +1,9 @@ import React, { useCallback } from "react" -import { FormikErrors, withFormik } from "formik" import { ModalStep } from "../../../contexts" -import FormBase, { FormBaseProps, FormValues } from "../../shared/FormBase" +import TokenAmountForm, { + TokenAmountFormValues, +} from "../../shared/TokenAmountForm" import { useTransactionContext, useWalletContext } from "../../../hooks" -import { getErrorsObj, validateTokenAmount } from "../../../utils" import { BITCOIN_MIN_AMOUNT } from "../../../constants" const CUSTOM_DATA = { @@ -12,36 +12,12 @@ const CUSTOM_DATA = { estimatedAmountText: "Approximately staked tokens", } -const StakeFormik = withFormik< - { onSubmitForm: (values: FormValues) => void } & FormBaseProps, - FormValues ->({ - mapPropsToValues: () => ({ - amount: "", - }), - validate: async ({ amount }, { tokenBalance, currencyType }) => { - const errors: FormikErrors = {} - - errors.amount = validateTokenAmount( - amount, - tokenBalance, - BITCOIN_MIN_AMOUNT, - currencyType ?? "bitcoin", - ) - - return getErrorsObj(errors) - }, - handleSubmit: (values, { props }) => { - props.onSubmitForm(values) - }, -})(FormBase) - function StakeForm({ goNext }: ModalStep) { const { btcAccount } = useWalletContext() const { setAmount } = useTransactionContext() const handleSubmitForm = useCallback( - (values: FormValues) => { + (values: TokenAmountFormValues) => { setAmount(values.amount) goNext() }, @@ -49,9 +25,10 @@ function StakeForm({ goNext }: ModalStep) { ) return ( - ) diff --git a/dapp/src/components/shared/FormBase/TransactionDetails.tsx b/dapp/src/components/shared/TokenAmountForm/TransactionDetails.tsx similarity index 100% rename from dapp/src/components/shared/FormBase/TransactionDetails.tsx rename to dapp/src/components/shared/TokenAmountForm/TransactionDetails.tsx diff --git a/dapp/src/components/shared/FormBase/index.tsx b/dapp/src/components/shared/TokenAmountForm/index.tsx similarity index 52% rename from dapp/src/components/shared/FormBase/index.tsx rename to dapp/src/components/shared/TokenAmountForm/index.tsx index 371278b2a..7cede79dd 100644 --- a/dapp/src/components/shared/FormBase/index.tsx +++ b/dapp/src/components/shared/TokenAmountForm/index.tsx @@ -1,15 +1,15 @@ import React from "react" import { Button } from "@chakra-ui/react" -import { FormikProps } from "formik" +import { FormikProps, FormikErrors, withFormik } from "formik" import { Form, FormTokenBalanceInput } from "../Form" import { CurrencyType } from "../../../types" import TransactionDetails from "./TransactionDetails" +import { getErrorsObj, validateTokenAmount } from "../../../utils" -export type FormValues = { +export type TokenAmountFormValues = { amount: string } - -export type FormBaseProps = { +type TokenAmountFormBaseProps = { customData: { buttonText: string btcAmountText: string @@ -22,7 +22,7 @@ export type FormBaseProps = { children?: React.ReactNode } -function FormBase({ +function TokenAmountFormBase({ customData, tokenBalance, tokenBalanceInputPlaceholder = "BTC", @@ -30,7 +30,7 @@ function FormBase({ fieldName = "amount", children, ...formikProps -}: FormBaseProps & FormikProps) { +}: TokenAmountFormBaseProps & FormikProps) { return (
void + minTokenAmount: string +} & TokenAmountFormBaseProps + +const TokenAmountForm = withFormik( + { + mapPropsToValues: () => ({ + amount: "", + }), + validate: async ( + { amount }, + { tokenBalance, currencyType, minTokenAmount }, + ) => { + const errors: FormikErrors = {} + + errors.amount = validateTokenAmount( + amount, + tokenBalance, + minTokenAmount, + currencyType ?? "bitcoin", + ) + + return getErrorsObj(errors) + }, + handleSubmit: (values, { props }) => { + props.onSubmitForm(values) + }, + }, +)(TokenAmountFormBase) + +export default TokenAmountForm From 4399b2c2f89d3f4dec420ab5d7eeba033887c101 Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Wed, 3 Jan 2024 08:47:06 +0100 Subject: [PATCH 14/49] Simplify the ActionForm component --- dapp/src/components/Modals/ActionForm/index.tsx | 12 ++++-------- dapp/src/components/Modals/Staking/index.tsx | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/dapp/src/components/Modals/ActionForm/index.tsx b/dapp/src/components/Modals/ActionForm/index.tsx index bacb4de49..c108da36e 100644 --- a/dapp/src/components/Modals/ActionForm/index.tsx +++ b/dapp/src/components/Modals/ActionForm/index.tsx @@ -12,18 +12,14 @@ import StakeForm from "../Staking/StakeForm" const TABS = ["stake", "unstake"] as const -type FormType = (typeof TABS)[number] +type Action = (typeof TABS)[number] -type ActionFormProps = { defaultForm: FormType } & ModalStep +type ActionFormProps = { action: Action } & ModalStep -function ActionForm({ defaultForm, goNext }: ActionFormProps) { +function ActionForm({ action, goNext }: ActionFormProps) { return ( - + {TABS.map((tab) => ( diff --git a/dapp/src/components/Modals/Staking/index.tsx b/dapp/src/components/Modals/Staking/index.tsx index eb0b09387..24b51bb12 100644 --- a/dapp/src/components/Modals/Staking/index.tsx +++ b/dapp/src/components/Modals/Staking/index.tsx @@ -9,7 +9,7 @@ function StakingSteps() { switch (activeStep) { case 1: - return + return case 2: return default: From 8c8d2a18155a4b4a12ebfeb829d1762ececab5ba Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Wed, 3 Jan 2024 11:00:04 +0100 Subject: [PATCH 15/49] Store the amount as bigint for the token amount form --- .../components/Modals/Staking/StakeForm.tsx | 13 +++++++++---- .../shared/TokenAmountForm/index.tsx | 10 +++++----- .../shared/TokenBalanceInput/index.tsx | 10 +++++----- dapp/src/contexts/TransactionContext.tsx | 19 +++++++++++-------- dapp/src/types/index.ts | 1 + dapp/src/types/staking.ts | 6 ++++++ dapp/src/utils/forms.ts | 9 ++++----- 7 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 dapp/src/types/staking.ts diff --git a/dapp/src/components/Modals/Staking/StakeForm.tsx b/dapp/src/components/Modals/Staking/StakeForm.tsx index 40e05ea2f..4055fedb5 100644 --- a/dapp/src/components/Modals/Staking/StakeForm.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm.tsx @@ -5,7 +5,9 @@ import TokenAmountForm, { } from "../../shared/TokenAmountForm" import { useTransactionContext, useWalletContext } from "../../../hooks" import { BITCOIN_MIN_AMOUNT } from "../../../constants" +import { CurrencyType } from "../../../types" +const CURRENCY_TYPE: CurrencyType = "bitcoin" const CUSTOM_DATA = { buttonText: "Stake", btcAmountText: "Amount to be staked", @@ -14,18 +16,21 @@ const CUSTOM_DATA = { function StakeForm({ goNext }: ModalStep) { const { btcAccount } = useWalletContext() - const { setAmount } = useTransactionContext() + const { seTokenAmount } = useTransactionContext() const handleSubmitForm = useCallback( (values: TokenAmountFormValues) => { - setAmount(values.amount) - goNext() + if (values.amount) { + seTokenAmount({ amount: values.amount, currencyType: CURRENCY_TYPE }) + goNext() + } }, - [goNext, setAmount], + [goNext, seTokenAmount], ) return ( ( { mapPropsToValues: () => ({ - amount: "", + amount: undefined, }), validate: async ( { amount }, @@ -72,7 +72,7 @@ const TokenAmountForm = withFormik( amount, tokenBalance, minTokenAmount, - currencyType ?? "bitcoin", + currencyType, ) return getErrorsObj(errors) diff --git a/dapp/src/components/shared/TokenBalanceInput/index.tsx b/dapp/src/components/shared/TokenBalanceInput/index.tsx index 418a90fb9..23b66f35c 100644 --- a/dapp/src/components/shared/TokenBalanceInput/index.tsx +++ b/dapp/src/components/shared/TokenBalanceInput/index.tsx @@ -85,12 +85,12 @@ function FiatCurrencyBalance({ } export type TokenBalanceInputProps = { - amount?: string + amount?: bigint currencyType: CurrencyType tokenBalance: string | number placeholder?: string size?: "lg" | "md" - setAmount: (value?: string) => void + setAmount: (value?: bigint) => void } & InputProps & HelperErrorTextProps & FiatCurrencyBalanceProps @@ -109,14 +109,14 @@ export default function TokenBalanceInput({ fiatCurrencyType, ...inputProps }: TokenBalanceInputProps) { - const valueRef = useRef(amount) + const valueRef = useRef(amount) const styles = useMultiStyleConfig("TokenBalanceInput", { size }) const currency = getCurrencyByType(currencyType) const handleValueChange = (value: string) => { valueRef.current = value - ? userAmountToBigInt(value, currency.decimals)?.toString() + ? userAmountToBigInt(value, currency.decimals) : undefined } @@ -157,7 +157,7 @@ export default function TokenBalanceInput({ }} /> - diff --git a/dapp/src/contexts/TransactionContext.tsx b/dapp/src/contexts/TransactionContext.tsx index c61c84a7d..b0f92ac6c 100644 --- a/dapp/src/contexts/TransactionContext.tsx +++ b/dapp/src/contexts/TransactionContext.tsx @@ -1,13 +1,14 @@ import React, { createContext, useMemo, useState } from "react" +import { TokenAmount } from "../types" type TransactionContextValue = { - amount?: string - setAmount: React.Dispatch> + tokenAmount?: TokenAmount + seTokenAmount: React.Dispatch> } export const TransactionContext = createContext({ - amount: undefined, - setAmount: () => {}, + tokenAmount: undefined, + seTokenAmount: () => {}, }) export function TransactionContextProvider({ @@ -15,15 +16,17 @@ export function TransactionContextProvider({ }: { children: React.ReactNode }): React.ReactElement { - const [amount, setAmount] = useState(undefined) + const [tokenAmount, seTokenAmount] = useState( + undefined, + ) const contextValue: TransactionContextValue = useMemo( () => ({ - amount, - setAmount, + tokenAmount, + seTokenAmount, }), - [amount], + [tokenAmount], ) return ( diff --git a/dapp/src/types/index.ts b/dapp/src/types/index.ts index 1e77e81e7..32b259c7f 100644 --- a/dapp/src/types/index.ts +++ b/dapp/src/types/index.ts @@ -1,2 +1,3 @@ export * from "./ledger-live-app" export * from "./currency" +export * from "./staking" diff --git a/dapp/src/types/staking.ts b/dapp/src/types/staking.ts new file mode 100644 index 000000000..f3d2d902b --- /dev/null +++ b/dapp/src/types/staking.ts @@ -0,0 +1,6 @@ +import { CurrencyType } from "./currency" + +export type TokenAmount = { + amount: bigint + currencyType: CurrencyType +} diff --git a/dapp/src/utils/forms.ts b/dapp/src/utils/forms.ts index 844fa5bf0..eb5d947da 100644 --- a/dapp/src/utils/forms.ts +++ b/dapp/src/utils/forms.ts @@ -16,20 +16,19 @@ export function getErrorsObj(errors: { [key in keyof T]: string }) { } export function validateTokenAmount( - value: string, + value: bigint | undefined, maxValue: string, minValue: string, currencyType: CurrencyType, ): string | undefined { - if (!value) return ERRORS.REQUIRED + if (value === undefined) return ERRORS.REQUIRED const { decimals } = getCurrencyByType(currencyType) - const valueInBI = BigInt(value) const maxValueInBI = BigInt(maxValue) const minValueInBI = BigInt(minValue) - const isMaximumValueExceeded = valueInBI > maxValueInBI - const isMinimumValueFulfilled = valueInBI >= minValueInBI + const isMaximumValueExceeded = value > maxValueInBI + const isMinimumValueFulfilled = value >= minValueInBI if (isMaximumValueExceeded) return ERRORS.EXCEEDED_VALUE if (!isMinimumValueFulfilled) From fe8ac88935ae5d59f83d18c7e115d5b39173f30a Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Wed, 3 Jan 2024 13:08:44 +0100 Subject: [PATCH 16/49] Prepare custom action hooks for staking steps --- .../components/Modals/Staking/DepositBTC.tsx | 13 +++------- .../components/Modals/Staking/SignMessage.tsx | 24 +++-------------- dapp/src/hooks/index.ts | 2 ++ dapp/src/hooks/useDepositBTCTransaction.ts | 13 ++++++++++ dapp/src/hooks/useSignMessage.ts | 26 +++++++++++++++++++ dapp/src/types/callback.ts | 1 + dapp/src/types/index.ts | 1 + 7 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 dapp/src/hooks/useDepositBTCTransaction.ts create mode 100644 dapp/src/hooks/useSignMessage.ts create mode 100644 dapp/src/types/callback.ts diff --git a/dapp/src/components/Modals/Staking/DepositBTC.tsx b/dapp/src/components/Modals/Staking/DepositBTC.tsx index 91e7c8789..befde8e9a 100644 --- a/dapp/src/components/Modals/Staking/DepositBTC.tsx +++ b/dapp/src/components/Modals/Staking/DepositBTC.tsx @@ -1,26 +1,19 @@ import React from "react" import Alert from "../../shared/Alert" -import { useModalFlowContext, useWalletContext } from "../../../hooks" +import { useDepositBTCTransaction, useModalFlowContext } from "../../../hooks" import StakeSteps from "./StakeSteps" import { TextMd } from "../../shared/Typography" export default function DepositBTC() { const { goNext } = useModalFlowContext() - const { btcAccount } = useWalletContext() - - const handleSendBTC = async () => { - if (!btcAccount?.id) return - - // TODO: Send the correct transaction - goNext() - } + const { depositBTC } = useDepositBTCTransaction(goNext) return ( diff --git a/dapp/src/components/Modals/Staking/SignMessage.tsx b/dapp/src/components/Modals/Staking/SignMessage.tsx index 9965966b8..e7f4abcc2 100644 --- a/dapp/src/components/Modals/Staking/SignMessage.tsx +++ b/dapp/src/components/Modals/Staking/SignMessage.tsx @@ -1,36 +1,20 @@ -import React, { useEffect } from "react" +import React from "react" import { Highlight } from "@chakra-ui/react" -import { useSignMessage } from "@ledgerhq/wallet-api-client-react" import Alert from "../../shared/Alert" -import { useModalFlowContext, useWalletContext } from "../../../hooks" +import { useModalFlowContext, useSignMessage } from "../../../hooks" import StakeSteps from "./StakeSteps" import { TextMd } from "../../shared/Typography" -const SIGN_MESSAGE = "Test message" - export default function SignMessage() { const { goNext } = useModalFlowContext() - const { ethAccount } = useWalletContext() - const { signMessage, signature } = useSignMessage() - - const handleSignMessage = async () => { - if (!ethAccount?.id) return - - await signMessage(ethAccount.id, Buffer.from(SIGN_MESSAGE, "utf-8")) - } - - useEffect(() => { - if (signature) { - goNext() - } - }, [goNext, signature]) + const { signMessage } = useSignMessage(goNext) return ( diff --git a/dapp/src/hooks/index.ts b/dapp/src/hooks/index.ts index 076da9a53..f49a34ed6 100644 --- a/dapp/src/hooks/index.ts +++ b/dapp/src/hooks/index.ts @@ -5,3 +5,5 @@ export * from "./useWalletContext" export * from "./useSidebar" export * from "./useDocsDrawer" export * from "./useModalFlowContext" +export * from "./useSignMessage" +export * from "./useDepositBTCTransaction" diff --git a/dapp/src/hooks/useDepositBTCTransaction.ts b/dapp/src/hooks/useDepositBTCTransaction.ts new file mode 100644 index 000000000..a629e6485 --- /dev/null +++ b/dapp/src/hooks/useDepositBTCTransaction.ts @@ -0,0 +1,13 @@ +import { useCallback } from "react" +import { OnSuccessCallback } from "../types" + +export function useDepositBTCTransaction(onSuccess?: OnSuccessCallback) { + // TODO: sending transactions using the SDK + const depositBTC = useCallback(() => { + if (onSuccess) { + setTimeout(onSuccess, 1000) + } + }, [onSuccess]) + + return { depositBTC } +} diff --git a/dapp/src/hooks/useSignMessage.ts b/dapp/src/hooks/useSignMessage.ts new file mode 100644 index 000000000..cc3cadc3e --- /dev/null +++ b/dapp/src/hooks/useSignMessage.ts @@ -0,0 +1,26 @@ +import { useSignMessage as useSignMessageLedgerLive } from "@ledgerhq/wallet-api-client-react" +import { useCallback, useEffect } from "react" +import { useWalletContext } from "./useWalletContext" +import { OnSuccessCallback } from "../types" + +const SIGN_MESSAGE = "Test message" + +export function useSignMessage(onSuccess?: OnSuccessCallback) { + const { ethAccount } = useWalletContext() + const { signMessage, signature } = useSignMessageLedgerLive() + + useEffect(() => { + if (signature && onSuccess) { + onSuccess() + } + }, [onSuccess, signature]) + + // TODO: signing message using the SDK + const handleSignMessage = useCallback(async () => { + if (!ethAccount?.id) return + + await signMessage(ethAccount.id, Buffer.from(SIGN_MESSAGE, "utf-8")) + }, [ethAccount, signMessage]) + + return { signMessage: handleSignMessage } +} diff --git a/dapp/src/types/callback.ts b/dapp/src/types/callback.ts new file mode 100644 index 000000000..526705388 --- /dev/null +++ b/dapp/src/types/callback.ts @@ -0,0 +1 @@ +export type OnSuccessCallback = () => void | Promise diff --git a/dapp/src/types/index.ts b/dapp/src/types/index.ts index 1e77e81e7..e89af2ea6 100644 --- a/dapp/src/types/index.ts +++ b/dapp/src/types/index.ts @@ -1,2 +1,3 @@ export * from "./ledger-live-app" export * from "./currency" +export * from "./callback" From 1ed9381b3548ead55bd38e0e1a1c368a61190233 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Wed, 3 Jan 2024 13:15:32 +0100 Subject: [PATCH 17/49] Use different staker and receiver in deposit test --- core/test/Acre.test.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/test/Acre.test.ts b/core/test/Acre.test.ts index 94af3f3aa..de8599a82 100644 --- a/core/test/Acre.test.ts +++ b/core/test/Acre.test.ts @@ -895,6 +895,8 @@ describe("Acre", () => { describe("deposit", () => { beforeAfterEachSnapshotWrapper() + const receiver = ethers.Wallet.createRandom() + let amountToDeposit: bigint let minimumDepositAmount: bigint @@ -908,7 +910,7 @@ describe("Acre", () => { }) it("should revert", async () => { - await expect(acre.deposit(amountToDeposit, staker1.address)) + await expect(acre.deposit(amountToDeposit, receiver.address)) .to.be.revertedWithCustomError(acre, "DepositAmountLessThanMin") .withArgs(amountToDeposit, minimumDepositAmount) }) @@ -925,7 +927,9 @@ describe("Acre", () => { expectedReceivedShares = amountToDeposit await tbtc.approve(await acre.getAddress(), amountToDeposit) - tx = await acre.deposit(amountToDeposit, staker1.address) + tx = await acre + .connect(staker1) + .deposit(amountToDeposit, receiver.address) }) it("should emit Deposit event", () => { @@ -933,7 +937,7 @@ describe("Acre", () => { // Caller. staker1.address, // Receiver. - staker1.address, + receiver.address, // Staked tokens. amountToDeposit, // Received shares. @@ -944,7 +948,7 @@ describe("Acre", () => { it("should mint stBTC tokens", async () => { await expect(tx).to.changeTokenBalances( acre, - [staker1.address], + [receiver.address], [expectedReceivedShares], ) }) From 755afbe5d609eabda34f4b2c88ee5d8afab02e98 Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Wed, 3 Jan 2024 13:41:29 +0100 Subject: [PATCH 18/49] Create a custom theme for the spinner --- dapp/src/components/shared/Spinner/index.tsx | 10 +--------- dapp/src/theme/Spinner.ts | 13 +++++++++++++ dapp/src/theme/index.ts | 2 ++ 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 dapp/src/theme/Spinner.ts diff --git a/dapp/src/components/shared/Spinner/index.tsx b/dapp/src/components/shared/Spinner/index.tsx index 1e5c6a29d..144138932 100644 --- a/dapp/src/components/shared/Spinner/index.tsx +++ b/dapp/src/components/shared/Spinner/index.tsx @@ -5,13 +5,5 @@ import { } from "@chakra-ui/react" export default function Spinner({ ...spinnerProps }: ChakraSpinnerProps) { - return ( - - ) + return } diff --git a/dapp/src/theme/Spinner.ts b/dapp/src/theme/Spinner.ts new file mode 100644 index 000000000..1e6082e84 --- /dev/null +++ b/dapp/src/theme/Spinner.ts @@ -0,0 +1,13 @@ +import { defineStyle, defineStyleConfig } from "@chakra-ui/react" + +const baseStyle = defineStyle({ + color: "brand.400", + borderWidth: 3, + borderTopColor: "gold.400", + borderBottomColor: "gold.400", + borderLeftColor: "gold.400", +}) + +const Spinner = defineStyleConfig({ baseStyle }) + +export default Spinner diff --git a/dapp/src/theme/index.ts b/dapp/src/theme/index.ts index 6e7babc46..64ae2d130 100644 --- a/dapp/src/theme/index.ts +++ b/dapp/src/theme/index.ts @@ -17,6 +17,7 @@ import Alert from "./Alert" import Form from "./Form" import FormLabel from "./FormLabel" import FormError from "./FormError" +import Spinner from "./Spinner" const defaultTheme = { colors, @@ -50,6 +51,7 @@ const defaultTheme = { Form, FormLabel, FormError, + Spinner, }, } From d2736999542f6c57f437e91ea60afdae731cef4d Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Wed, 3 Jan 2024 14:11:50 +0100 Subject: [PATCH 19/49] Extract snapshot wrappers to a separate file --- core/test/Acre.test.ts | 5 +++-- core/test/Dispatcher.test.ts | 8 ++++++-- core/test/helpers/context.ts | 37 +---------------------------------- core/test/helpers/index.ts | 1 + core/test/helpers/snapshot.ts | 36 ++++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 core/test/helpers/snapshot.ts diff --git a/core/test/Acre.test.ts b/core/test/Acre.test.ts index de8599a82..3b80c834c 100644 --- a/core/test/Acre.test.ts +++ b/core/test/Acre.test.ts @@ -16,8 +16,9 @@ import { beforeAfterEachSnapshotWrapper, beforeAfterSnapshotWrapper, deployment, -} from "./helpers/context" -import { getNamedSigner, getUnnamedSigner } from "./helpers/signer" + getNamedSigner, + getUnnamedSigner, +} from "./helpers" import { to1e18 } from "./utils" diff --git a/core/test/Dispatcher.test.ts b/core/test/Dispatcher.test.ts index 3b986674e..1ec669166 100644 --- a/core/test/Dispatcher.test.ts +++ b/core/test/Dispatcher.test.ts @@ -3,8 +3,12 @@ import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers" import { expect } from "chai" import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers" import type { Dispatcher } from "../typechain" -import { beforeAfterEachSnapshotWrapper, deployment } from "./helpers/context" -import { getNamedSigner, getUnnamedSigner } from "./helpers/signer" +import { + beforeAfterEachSnapshotWrapper, + deployment, + getNamedSigner, + getUnnamedSigner, +} from "./helpers" async function fixture() { const { dispatcher } = await deployment() diff --git a/core/test/helpers/context.ts b/core/test/helpers/context.ts index 8bbc206f1..99f4696af 100644 --- a/core/test/helpers/context.ts +++ b/core/test/helpers/context.ts @@ -1,44 +1,9 @@ import { deployments } from "hardhat" -import { - SnapshotRestorer, - takeSnapshot, -} from "@nomicfoundation/hardhat-toolbox/network-helpers" import { getDeployedContract } from "./contract" import type { Acre, Dispatcher, TestERC20 } from "../../typechain" -/** - * Adds a before/after hook pair to snapshot the EVM state before and after tests - * in a test suite. - */ -export function beforeAfterSnapshotWrapper(): void { - let snapshot: SnapshotRestorer - - before(async () => { - snapshot = await takeSnapshot() - }) - - after(async () => { - await snapshot.restore() - }) -} - -/** - * Adds a beforeEach/afterEach hook pair to snapshot the EVM state before and - * after each of tests in a test suite. - */ -export function beforeAfterEachSnapshotWrapper(): void { - let snapshot: SnapshotRestorer - - beforeEach(async () => { - snapshot = await takeSnapshot() - }) - - afterEach(async () => { - await snapshot.restore() - }) -} - +// eslint-disable-next-line import/prefer-default-export export async function deployment() { await deployments.fixture() diff --git a/core/test/helpers/index.ts b/core/test/helpers/index.ts index 27ddcb0b9..e4df2196a 100644 --- a/core/test/helpers/index.ts +++ b/core/test/helpers/index.ts @@ -1,3 +1,4 @@ export * from "./context" export * from "./contract" export * from "./signer" +export * from "./snapshot" diff --git a/core/test/helpers/snapshot.ts b/core/test/helpers/snapshot.ts new file mode 100644 index 000000000..804c0455d --- /dev/null +++ b/core/test/helpers/snapshot.ts @@ -0,0 +1,36 @@ +import { + SnapshotRestorer, + takeSnapshot, +} from "@nomicfoundation/hardhat-toolbox/network-helpers" + +/** + * Adds a before/after hook pair to snapshot the EVM state before and after tests + * in a test suite. + */ +export function beforeAfterSnapshotWrapper(): void { + let snapshot: SnapshotRestorer + + before(async () => { + snapshot = await takeSnapshot() + }) + + after(async () => { + await snapshot.restore() + }) +} + +/** + * Adds a beforeEach/afterEach hook pair to snapshot the EVM state before and + * after each of tests in a test suite. + */ +export function beforeAfterEachSnapshotWrapper(): void { + let snapshot: SnapshotRestorer + + beforeEach(async () => { + snapshot = await takeSnapshot() + }) + + afterEach(async () => { + await snapshot.restore() + }) +} From a43d2424568d5adb7fe1d166d74c6cd6a55b8ddd Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Thu, 4 Jan 2024 09:50:44 +0100 Subject: [PATCH 20/49] Add an action icon for the alert --- .../components/Modals/Staking/DepositBTC.tsx | 2 +- .../components/Modals/Staking/SignMessage.tsx | 3 ++- .../Modals/Support/MissingAccount.tsx | 6 ++--- dapp/src/components/shared/Alert/index.tsx | 27 +++++++++++++++---- dapp/src/theme/Alert.ts | 18 ++++++++++++- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/dapp/src/components/Modals/Staking/DepositBTC.tsx b/dapp/src/components/Modals/Staking/DepositBTC.tsx index befde8e9a..f07f0821d 100644 --- a/dapp/src/components/Modals/Staking/DepositBTC.tsx +++ b/dapp/src/components/Modals/Staking/DepositBTC.tsx @@ -15,7 +15,7 @@ export default function DepositBTC() { activeStep={1} onClick={depositBTC} > - + Make a Bitcoin transaction to deposit and stake your BTC. diff --git a/dapp/src/components/Modals/Staking/SignMessage.tsx b/dapp/src/components/Modals/Staking/SignMessage.tsx index e7f4abcc2..b78700ffc 100644 --- a/dapp/src/components/Modals/Staking/SignMessage.tsx +++ b/dapp/src/components/Modals/Staking/SignMessage.tsx @@ -16,7 +16,8 @@ export default function SignMessage() { activeStep={0} onClick={signMessage} > - + {/* TODO: Add the correct action after click */} + {}}> You will receive stBTC liquid staking token at this Ethereum address diff --git a/dapp/src/components/Modals/Support/MissingAccount.tsx b/dapp/src/components/Modals/Support/MissingAccount.tsx index 7b6216276..19566c355 100644 --- a/dapp/src/components/Modals/Support/MissingAccount.tsx +++ b/dapp/src/components/Modals/Support/MissingAccount.tsx @@ -9,7 +9,7 @@ import { } from "@chakra-ui/react" import { CurrencyType, RequestAccountParams } from "../../../types" import { TextMd } from "../../shared/Typography" -import AlertWrapper from "../../shared/Alert" +import Alert from "../../shared/Alert" import { CURRENCIES_BY_TYPE } from "../../../constants" type MissingAccountProps = { @@ -34,14 +34,14 @@ export default function MissingAccount({ {currency.name} account is required to make transactions for depositing and staking your {currency.symbol}. - + You will be sent to the Ledger Accounts section to perform this action. - + + + ) +} + +export default StakeForm diff --git a/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx new file mode 100644 index 000000000..c5343319d --- /dev/null +++ b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx @@ -0,0 +1,39 @@ +import React from "react" +import { FormikProps } from "formik" +import { Form, FormTokenBalanceInput } from "../Form" +import { CurrencyType } from "../../../types" + +export type TokenAmountFormValues = { + amount?: bigint +} + +export type TokenAmountFormBaseProps = { + formId: string + tokenBalance: string + tokenBalanceInputPlaceholder: string + currencyType: CurrencyType + fieldName: string + children?: React.ReactNode +} + +export default function TokenAmountFormBase({ + formId, + tokenBalance, + currencyType, + tokenBalanceInputPlaceholder, + fieldName, + children, + ...formikProps +}: TokenAmountFormBaseProps & FormikProps) { + return ( + + + {children} + + ) +} diff --git a/dapp/src/components/shared/TokenAmountForm/TransactionDetails.tsx b/dapp/src/components/shared/TokenAmountForm/TransactionDetails.tsx deleted file mode 100644 index 4e9857d1e..000000000 --- a/dapp/src/components/shared/TokenAmountForm/TransactionDetails.tsx +++ /dev/null @@ -1,99 +0,0 @@ -import React from "react" -import { Box, Flex, VStack } from "@chakra-ui/react" -import { useField } from "formik" -import { CurrencyBalanceWithConversion } from "../CurrencyBalanceWithConversion" -import { TextMd } from "../Typography" - -// TODO: Use data from the SDK -function getTransactionDetails(value: string): - | { - btcAmount: string - protocolFee: string - stakedAmount: string - } - | undefined { - const btcAmount = value ?? 0n - const btcAmountInBI = BigInt(btcAmount) - - if (btcAmountInBI <= 0n) return undefined - - const protocolFee = btcAmountInBI / 10000n - const stakedAmount = btcAmountInBI - protocolFee - - return { - btcAmount, - protocolFee: protocolFee.toString(), - stakedAmount: stakedAmount.toString(), - } -} - -function TransactionDetailsItem({ - text, - btcAmount, - usdAmount, -}: { - text: string - btcAmount?: string | number - usdAmount: string -}) { - return ( - - - {text} - - - - - - ) -} - -function TransactionDetails({ - fieldName, - btcAmountText, - estimatedAmountText, -}: { - fieldName: string - btcAmountText: string - estimatedAmountText: string -}) { - const [, { value }] = useField(fieldName) - - const details = getTransactionDetails(value) - - return ( - - - - - - ) -} - -export default TransactionDetails diff --git a/dapp/src/components/shared/TokenAmountForm/index.tsx b/dapp/src/components/shared/TokenAmountForm/index.tsx index fa2bda0b9..638ee56e4 100644 --- a/dapp/src/components/shared/TokenAmountForm/index.tsx +++ b/dapp/src/components/shared/TokenAmountForm/index.tsx @@ -1,56 +1,9 @@ -import React from "react" -import { Button } from "@chakra-ui/react" -import { FormikProps, FormikErrors, withFormik } from "formik" -import { Form, FormTokenBalanceInput } from "../Form" -import { CurrencyType } from "../../../types" -import TransactionDetails from "./TransactionDetails" +import { FormikErrors, withFormik } from "formik" import { getErrorsObj, validateTokenAmount } from "../../../utils" - -export type TokenAmountFormValues = { - amount?: bigint -} -type TokenAmountFormBaseProps = { - customData: { - buttonText: string - btcAmountText: string - estimatedAmountText: string - } - tokenBalance: string - tokenBalanceInputPlaceholder?: string - currencyType: CurrencyType - fieldName?: string - children?: React.ReactNode -} - -function TokenAmountFormBase({ - customData, - tokenBalance, - currencyType, - tokenBalanceInputPlaceholder = "BTC", - fieldName = "amount", - children, - ...formikProps -}: TokenAmountFormBaseProps & FormikProps) { - return ( -
- - - {children} - - - ) -} +import TokenAmountFormBase, { + TokenAmountFormBaseProps, + TokenAmountFormValues, +} from "./TokenAmountFormBase" type TokenAmountFormProps = { onSubmitForm: (values: TokenAmountFormValues) => void diff --git a/dapp/src/components/shared/TransactionDetails/AmountItem.tsx b/dapp/src/components/shared/TransactionDetails/AmountItem.tsx new file mode 100644 index 000000000..7acebc823 --- /dev/null +++ b/dapp/src/components/shared/TransactionDetails/AmountItem.tsx @@ -0,0 +1,36 @@ +import React, { ComponentProps } from "react" +import { Box } from "@chakra-ui/react" +import TransactionDetailsItem, { TransactionDetailsItemProps } from "." +import { CurrencyBalanceWithConversion } from "../CurrencyBalanceWithConversion" + +type TransactionDetailsAmountItemProps = ComponentProps< + typeof CurrencyBalanceWithConversion +> & + Pick + +function TransactionDetailsAmountItem({ + label, + from, + to, +}: TransactionDetailsAmountItemProps) { + return ( + + + + + + ) +} + +export default TransactionDetailsAmountItem diff --git a/dapp/src/components/shared/TransactionDetails/index.tsx b/dapp/src/components/shared/TransactionDetails/index.tsx new file mode 100644 index 000000000..bdaf6552c --- /dev/null +++ b/dapp/src/components/shared/TransactionDetails/index.tsx @@ -0,0 +1,32 @@ +import React from "react" +import { ListItem, ListItemProps } from "@chakra-ui/react" +import { TextMd } from "../Typography" + +export type TransactionDetailsItemProps = { + label: string + value?: string + children?: React.ReactNode +} & ListItemProps + +function TransactionDetailsItem({ + label, + value, + children, + ...listItemProps +}: TransactionDetailsItemProps) { + return ( + + + {label} + + {value ? {value} : children} + + ) +} + +export default TransactionDetailsItem diff --git a/dapp/src/constants/staking.ts b/dapp/src/constants/staking.ts index 421c57bb5..45bfcba88 100644 --- a/dapp/src/constants/staking.ts +++ b/dapp/src/constants/staking.ts @@ -1 +1,2 @@ export const BITCOIN_MIN_AMOUNT = "1000000" // 0.01 BTC +export const ZERO_AMOUNT = 0n diff --git a/dapp/src/hooks/index.ts b/dapp/src/hooks/index.ts index 4f2b42d57..d4d7accb0 100644 --- a/dapp/src/hooks/index.ts +++ b/dapp/src/hooks/index.ts @@ -6,3 +6,4 @@ export * from "./useSidebar" export * from "./useDocsDrawer" export * from "./useModalFlowContext" export * from "./useTransactionContext" +export * from "./useTransactionDetails" diff --git a/dapp/src/hooks/useTransactionDetails.ts b/dapp/src/hooks/useTransactionDetails.ts new file mode 100644 index 000000000..4cf9e6711 --- /dev/null +++ b/dapp/src/hooks/useTransactionDetails.ts @@ -0,0 +1,26 @@ +import { useEffect, useState } from "react" +import { ZERO_AMOUNT } from "../constants" + +export function useTransactionDetails(amount: bigint): { + protocolFee: string + estimatedAmount: string +} { + const [protocolFee, setProtocolFee] = useState(ZERO_AMOUNT) + const [estimatedAmount, setEstimatedAmount] = useState(ZERO_AMOUNT) + + useEffect(() => { + if (amount <= ZERO_AMOUNT) { + setProtocolFee(ZERO_AMOUNT) + setEstimatedAmount(ZERO_AMOUNT) + } else { + const newProtocolFee = amount / 10000n + setProtocolFee(newProtocolFee) + setEstimatedAmount(amount - newProtocolFee) + } + }, [amount]) + + return { + protocolFee: protocolFee.toString(), + estimatedAmount: estimatedAmount.toString(), + } +} From d49a39c4e5b2a2bb78554c6f44610dec494c40fb Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Tue, 9 Jan 2024 11:48:49 +0100 Subject: [PATCH 28/49] Use `Currency` instead `CurrencyType` for TokenAmountForm --- dapp/src/components/Header/ConnectWallet.tsx | 2 +- .../Modals/Staking/StakeForm/Details.tsx | 18 +++++++++--------- .../Modals/Staking/StakeForm/index.tsx | 10 ++++------ .../components/Overview/PositionDetails.tsx | 4 ++-- .../shared/CurrencyBalance/index.tsx | 17 ++++++++++------- .../TokenAmountForm/TokenAmountFormBase.tsx | 8 ++++---- .../shared/TokenAmountForm/index.tsx | 4 ++-- .../shared/TokenBalanceInput/index.tsx | 18 ++++++------------ dapp/src/types/staking.ts | 4 ++-- dapp/src/utils/currency.ts | 4 ++++ dapp/src/utils/forms.ts | 7 +++---- 11 files changed, 47 insertions(+), 49 deletions(-) diff --git a/dapp/src/components/Header/ConnectWallet.tsx b/dapp/src/components/Header/ConnectWallet.tsx index 3bb5af7d9..90069b4e7 100644 --- a/dapp/src/components/Header/ConnectWallet.tsx +++ b/dapp/src/components/Header/ConnectWallet.tsx @@ -46,7 +46,7 @@ export default function ConnectWallet() { Balance diff --git a/dapp/src/components/Modals/Staking/StakeForm/Details.tsx b/dapp/src/components/Modals/Staking/StakeForm/Details.tsx index 8f1584c09..af84180a9 100644 --- a/dapp/src/components/Modals/Staking/StakeForm/Details.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm/Details.tsx @@ -3,14 +3,14 @@ import { List } from "@chakra-ui/react" import { useField } from "formik" import { useTransactionDetails } from "../../../../hooks" import TransactionDetailsAmountItem from "../../../shared/TransactionDetails/AmountItem" -import { CurrencyType } from "../../../../types" +import { Currency } from "../../../../types" function Details({ fieldName, - currencyType, + currency, }: { fieldName: string - currencyType: CurrencyType + currency: Currency }) { const [, { value }] = useField(fieldName) const btcAmount = value ?? 0n @@ -22,11 +22,11 @@ function Details({ { if (!values.amount) return - seTokenAmount({ amount: values.amount, currencyType: CURRENCY_TYPE }) + seTokenAmount({ amount: values.amount, currency: BITCOIN }) goNext() }, [goNext, seTokenAmount], @@ -32,12 +30,12 @@ function StakeForm({ goNext }: ModalStep) { formId={FORM_ID} fieldName={FORM_FIELD_NAME} tokenBalanceInputPlaceholder="BTC" - currencyType={CURRENCY_TYPE} + currency={BITCOIN} tokenBalance={btcAccount?.balance.toString() ?? "0"} minTokenAmount={BITCOIN_MIN_AMOUNT} onSubmitForm={handleSubmitForm} > -
+
- + ) } From c6b6c7b1a6044fc9d9b6fd6ac6a6aad4296c40a9 Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Wed, 10 Jan 2024 12:05:11 +0100 Subject: [PATCH 35/49] Use always `CurrencyType` --- .../Modals/Staking/StakeForm/Details.tsx | 4 +-- .../Modals/Staking/StakeForm/index.tsx | 8 ++--- .../Modals/Support/MissingAccount.tsx | 12 ++++---- dapp/src/components/Modals/Support/index.tsx | 4 +-- .../shared/CurrencyBalance/index.tsx | 9 ++---- .../TokenAmountForm/TokenAmountFormBase.tsx | 4 +-- .../shared/TokenBalanceInput/index.tsx | 30 +++++++++++-------- dapp/src/types/staking.ts | 4 +-- dapp/src/utils/currency.ts | 8 ++--- dapp/src/utils/forms.ts | 8 +++-- 10 files changed, 45 insertions(+), 46 deletions(-) diff --git a/dapp/src/components/Modals/Staking/StakeForm/Details.tsx b/dapp/src/components/Modals/Staking/StakeForm/Details.tsx index eb548b449..e334c5403 100644 --- a/dapp/src/components/Modals/Staking/StakeForm/Details.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm/Details.tsx @@ -3,10 +3,10 @@ import { List } from "@chakra-ui/react" import { useField } from "formik" import { useTransactionDetails } from "../../../../hooks" import TransactionDetailsAmountItem from "../../../shared/TransactionDetails/AmountItem" -import { Currency } from "../../../../types" +import { CurrencyType } from "../../../../types" import { TOKEN_AMOUNT_FIELD_NAME } from "../../../../constants" -function Details({ currency }: { currency: Currency }) { +function Details({ currency }: { currency: CurrencyType }) { const [, { value }] = useField(TOKEN_AMOUNT_FIELD_NAME) const details = useTransactionDetails(value ?? 0n) diff --git a/dapp/src/components/Modals/Staking/StakeForm/index.tsx b/dapp/src/components/Modals/Staking/StakeForm/index.tsx index fba2566bb..38ea05136 100644 --- a/dapp/src/components/Modals/Staking/StakeForm/index.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm/index.tsx @@ -1,6 +1,6 @@ import React, { useCallback } from "react" import { Button } from "@chakra-ui/react" -import { BITCOIN, BITCOIN_MIN_AMOUNT } from "../../../../constants" +import { BITCOIN_MIN_AMOUNT } from "../../../../constants" import { ModalStep } from "../../../../contexts" import { useWalletContext, useTransactionContext } from "../../../../hooks" import TokenAmountForm from "../../../shared/TokenAmountForm" @@ -15,7 +15,7 @@ function StakeForm({ goNext }: ModalStep) { (values: TokenAmountFormValues) => { if (!values.amount) return - seTokenAmount({ amount: values.amount, currency: BITCOIN }) + seTokenAmount({ amount: values.amount, currency: "bitcoin" }) goNext() }, [goNext, seTokenAmount], @@ -24,12 +24,12 @@ function StakeForm({ goNext }: ModalStep) { return ( -
+
diff --git a/dapp/src/components/Modals/Support/MissingAccount.tsx b/dapp/src/components/Modals/Support/MissingAccount.tsx index e0b66938e..2c32b354e 100644 --- a/dapp/src/components/Modals/Support/MissingAccount.tsx +++ b/dapp/src/components/Modals/Support/MissingAccount.tsx @@ -13,26 +13,26 @@ import Alert from "../../shared/Alert" import { getCurrencyByType } from "../../../utils" type MissingAccountProps = { - currencyType: CurrencyType + currency: CurrencyType icon: typeof Icon requestAccount: (...params: RequestAccountParams) => Promise } export default function MissingAccount({ - currencyType, + currency, icon, requestAccount, }: MissingAccountProps) { - const currency = getCurrencyByType(currencyType) + const { name, symbol } = getCurrencyByType(currency) return ( <> - {currency.name} account not installed + {name} account not installed - {currency.name} account is required to make transactions for - depositing and staking your {currency.symbol}. + {name} account is required to make transactions for depositing and + staking your {symbol}. diff --git a/dapp/src/components/Modals/Support/index.tsx b/dapp/src/components/Modals/Support/index.tsx index c6d8953c2..c6784fff4 100644 --- a/dapp/src/components/Modals/Support/index.tsx +++ b/dapp/src/components/Modals/Support/index.tsx @@ -19,7 +19,7 @@ export default function SupportWrapper({ if (!btcAccount) return ( @@ -28,7 +28,7 @@ export default function SupportWrapper({ if (!ethAccount) return ( diff --git a/dapp/src/components/shared/CurrencyBalance/index.tsx b/dapp/src/components/shared/CurrencyBalance/index.tsx index 178e2ec0c..f44f7505e 100644 --- a/dapp/src/components/shared/CurrencyBalance/index.tsx +++ b/dapp/src/components/shared/CurrencyBalance/index.tsx @@ -3,13 +3,12 @@ import { Box, useMultiStyleConfig, TextProps } from "@chakra-ui/react" import { formatTokenAmount, getCurrencyByType, - isCurrencyType, numberToLocaleString, } from "../../../utils" -import { Currency, CurrencyType } from "../../../types" +import { CurrencyType } from "../../../types" export type CurrencyBalanceProps = { - currency: Currency | CurrencyType + currency: CurrencyType amount?: string | number shouldBeFormatted?: boolean desiredDecimals?: number @@ -28,9 +27,7 @@ export function CurrencyBalance({ }: CurrencyBalanceProps) { const styles = useMultiStyleConfig("CurrencyBalance", { size, variant }) - const { symbol, decimals } = isCurrencyType(currency) - ? getCurrencyByType(currency) - : currency + const { symbol, decimals } = getCurrencyByType(currency) const balance = useMemo(() => { const value = amount ?? 0 diff --git a/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx index fd4e5d5f1..fd4b6a05b 100644 --- a/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx +++ b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx @@ -1,7 +1,7 @@ import React from "react" import { FormikProps } from "formik" import { Form, FormTokenBalanceInput } from "../Form" -import { Currency } from "../../../types" +import { CurrencyType } from "../../../types" import { TOKEN_AMOUNT_FIELD_NAME } from "../../../constants" export type TokenAmountFormValues = { @@ -12,7 +12,7 @@ export type TokenAmountFormBaseProps = { formId?: string tokenBalance: string tokenBalanceInputPlaceholder: string - currency: Currency + currency: CurrencyType children?: React.ReactNode } diff --git a/dapp/src/components/shared/TokenBalanceInput/index.tsx b/dapp/src/components/shared/TokenBalanceInput/index.tsx index e6a533671..82aa75fee 100644 --- a/dapp/src/components/shared/TokenBalanceInput/index.tsx +++ b/dapp/src/components/shared/TokenBalanceInput/index.tsx @@ -12,8 +12,12 @@ import { InputRightElement, useMultiStyleConfig, } from "@chakra-ui/react" -import { fixedPointNumberToString, userAmountToBigInt } from "../../../utils" -import { Currency, CurrencyType } from "../../../types" +import { + fixedPointNumberToString, + getCurrencyByType, + userAmountToBigInt, +} from "../../../utils" +import { CurrencyType } from "../../../types" import NumberFormatInput, { NumberFormatInputValues, } from "../NumberFormatInput" @@ -55,20 +59,20 @@ function HelperErrorText({ type FiatCurrencyBalanceProps = { fiatAmount?: string - fiatCurrencyType?: CurrencyType + fiatCurrency?: CurrencyType } function FiatCurrencyBalance({ fiatAmount, - fiatCurrencyType, + fiatCurrency, }: FiatCurrencyBalanceProps) { const styles = useMultiStyleConfig("Form") const { fontWeight } = styles.helperText - if (fiatAmount && fiatCurrencyType) { + if (fiatAmount && fiatCurrency) { return ( (amount) const styles = useMultiStyleConfig("TokenBalanceInput", { size }) + const { decimals } = getCurrencyByType(currency) + const handleValueChange = (value: string) => { - valueRef.current = value - ? userAmountToBigInt(value, currency.decimals) - : undefined + valueRef.current = value ? userAmountToBigInt(value, decimals) : undefined } return ( @@ -140,7 +144,7 @@ export default function TokenBalanceInput({ {...inputProps} value={ amount - ? fixedPointNumberToString(BigInt(amount), currency.decimals) + ? fixedPointNumberToString(BigInt(amount), decimals) : undefined } onValueChange={(values: NumberFormatInputValues) => @@ -165,7 +169,7 @@ export default function TokenBalanceInput({ )} diff --git a/dapp/src/types/staking.ts b/dapp/src/types/staking.ts index 009207492..56b4740be 100644 --- a/dapp/src/types/staking.ts +++ b/dapp/src/types/staking.ts @@ -1,6 +1,6 @@ -import { Currency } from "./currency" +import { CurrencyType } from "./currency" export type TokenAmount = { amount: bigint - currency: Currency + currency: CurrencyType } diff --git a/dapp/src/utils/currency.ts b/dapp/src/utils/currency.ts index 3763060f5..39eda0651 100644 --- a/dapp/src/utils/currency.ts +++ b/dapp/src/utils/currency.ts @@ -1,9 +1,5 @@ import { CURRENCIES_BY_TYPE } from "../constants" import { Currency, CurrencyType } from "../types" -export const getCurrencyByType = (type: CurrencyType): Currency => - CURRENCIES_BY_TYPE[type] - -export const isCurrencyType = ( - currency: Currency | CurrencyType, -): currency is CurrencyType => typeof currency === "string" +export const getCurrencyByType = (currency: CurrencyType): Currency => + CURRENCIES_BY_TYPE[currency] diff --git a/dapp/src/utils/forms.ts b/dapp/src/utils/forms.ts index 283d42595..9f7f34759 100644 --- a/dapp/src/utils/forms.ts +++ b/dapp/src/utils/forms.ts @@ -1,4 +1,5 @@ -import { Currency } from "../types" +import { CurrencyType } from "../types" +import { getCurrencyByType } from "./currency" import { formatTokenAmount } from "./numbers" const ERRORS = { @@ -18,11 +19,12 @@ export function validateTokenAmount( value: bigint | undefined, maxValue: string, minValue: string, - currency: Currency, + currency: CurrencyType, ): string | undefined { if (value === undefined) return ERRORS.REQUIRED - const { decimals } = currency + const { decimals } = getCurrencyByType(currency) + const maxValueInBI = BigInt(maxValue) const minValueInBI = BigInt(minValue) From 1f7419d6dd84939acb75e49feabb4e8a90be9d97 Mon Sep 17 00:00:00 2001 From: ioay Date: Tue, 9 Jan 2024 16:39:45 +0100 Subject: [PATCH 36/49] Thesis - eslint config --- dapp/package.json | 2 +- pnpm-lock.yaml | 33 ++------------------------------- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/dapp/package.json b/dapp/package.json index 8345eb7e2..d2d3e6458 100644 --- a/dapp/package.json +++ b/dapp/package.json @@ -26,7 +26,7 @@ "react-number-format": "^5.3.1" }, "devDependencies": { - "@thesis-co/eslint-config": "^0.6.1", + "@thesis-co/eslint-config": "github:thesis/eslint-config#7b9bc8c", "@types/react": "^18.2.38", "@types/react-dom": "^18.2.17", "@typescript-eslint/eslint-plugin": "^6.12.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b5614ee89..9465bed28 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -143,8 +143,8 @@ importers: version: 5.3.1(react-dom@18.2.0)(react@18.2.0) devDependencies: '@thesis-co/eslint-config': - specifier: ^0.6.1 - version: 0.6.1(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2) + specifier: github:thesis/eslint-config#7b9bc8c + version: github.com/thesis/eslint-config/7b9bc8c(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2) '@types/react': specifier: ^18.2.38 version: 18.2.38 @@ -5425,35 +5425,6 @@ packages: dependencies: defer-to-connect: 2.0.1 - /@thesis-co/eslint-config@0.6.1(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2): - resolution: {integrity: sha512-0vJCCI4UwUdniDCQeTFlMBT+bSp5pGkrtHrZrG2vmyLZwSVdJNtInjkBc/Jd0sGfMtPo3pqQRwA40Zo80lPi+Q==} - engines: {node: '>=14.0.0'} - peerDependencies: - eslint: '>=6.8.0' - dependencies: - '@thesis-co/prettier-config': github.com/thesis/prettier-config/daeaac564056a7885e4366ce12bfde6fd823fc90(prettier@3.1.0) - '@typescript-eslint/eslint-plugin': 6.12.0(@typescript-eslint/parser@6.12.0)(eslint@8.54.0)(typescript@5.3.2) - '@typescript-eslint/parser': 6.12.0(eslint@8.54.0)(typescript@5.3.2) - eslint: 8.54.0 - eslint-config-airbnb: 19.0.4(eslint-plugin-import@2.29.0)(eslint-plugin-jsx-a11y@6.8.0)(eslint-plugin-react-hooks@4.6.0)(eslint-plugin-react@7.33.2)(eslint@8.54.0) - eslint-config-airbnb-base: 15.0.0(eslint-plugin-import@2.29.0)(eslint@8.54.0) - eslint-config-airbnb-typescript: 17.1.0(@typescript-eslint/eslint-plugin@6.12.0)(@typescript-eslint/parser@6.12.0)(eslint-plugin-import@2.29.0)(eslint@8.54.0) - eslint-config-prettier: 9.0.0(eslint@8.54.0) - eslint-plugin-import: 2.29.0(@typescript-eslint/parser@6.12.0)(eslint@8.54.0) - eslint-plugin-jsx-a11y: 6.8.0(eslint@8.54.0) - eslint-plugin-no-only-tests: 3.1.0 - eslint-plugin-prettier: 5.0.1(eslint-config-prettier@9.0.0)(eslint@8.54.0)(prettier@3.1.0) - eslint-plugin-react: 7.33.2(eslint@8.54.0) - eslint-plugin-react-hooks: 4.6.0(eslint@8.54.0) - transitivePeerDependencies: - - '@types/eslint' - - eslint-import-resolver-typescript - - eslint-import-resolver-webpack - - prettier - - supports-color - - typescript - dev: true - /@tokenizer/token@0.3.0: resolution: {integrity: sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A==} From 1c5a9604f0998d6f05ad1eb2477042033e8b5136 Mon Sep 17 00:00:00 2001 From: ioay Date: Tue, 9 Jan 2024 22:16:39 +0100 Subject: [PATCH 37/49] Added eslint rules --- dapp/.eslintrc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dapp/.eslintrc b/dapp/.eslintrc index 4317c87a7..a1c6935a5 100644 --- a/dapp/.eslintrc +++ b/dapp/.eslintrc @@ -15,6 +15,9 @@ 2, { "allowRequiredDefaults": true } ], - "react/require-default-props": [0] + "react/require-default-props": [0], + "@typescript-eslint/no-misused-promises": "off", + "@typescript-eslint/unbound-method": "off", + "@typescript-eslint/no-unsafe-member-access": "off" } } From 1cf230937dbcf50594c377d4d70924ac4b6402f6 Mon Sep 17 00:00:00 2001 From: ioay Date: Wed, 10 Jan 2024 10:39:16 +0100 Subject: [PATCH 38/49] Added comments to eslint config --- dapp/.eslintrc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dapp/.eslintrc b/dapp/.eslintrc index a1c6935a5..b8736f5e6 100644 --- a/dapp/.eslintrc +++ b/dapp/.eslintrc @@ -16,8 +16,12 @@ { "allowRequiredDefaults": true } ], "react/require-default-props": [0], + // Regarding the fact we are using now: @thesis-co/eslint-config": "github:thesis/eslint-config#7b9bc8c" + // Promise-returning function provided to attribute where a void return was expected. + // Avoid referencing unbound methods which may cause unintentional scoping of `this`, used in theme files. "@typescript-eslint/no-misused-promises": "off", "@typescript-eslint/unbound-method": "off", + // Computed name [status] resolves to any value (related to external chakra-ui package) "@typescript-eslint/no-unsafe-member-access": "off" } } From 25884ef5d921de010adda4da289ac3737f51a5ac Mon Sep 17 00:00:00 2001 From: ioay Date: Wed, 10 Jan 2024 12:34:03 +0100 Subject: [PATCH 39/49] Added new eslint rule related with the last #105 changes --- dapp/.eslintrc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dapp/.eslintrc b/dapp/.eslintrc index b8736f5e6..63815d434 100644 --- a/dapp/.eslintrc +++ b/dapp/.eslintrc @@ -22,6 +22,8 @@ "@typescript-eslint/no-misused-promises": "off", "@typescript-eslint/unbound-method": "off", // Computed name [status] resolves to any value (related to external chakra-ui package) - "@typescript-eslint/no-unsafe-member-access": "off" + "@typescript-eslint/no-unsafe-member-access": "off", + // Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator + "@typescript-eslint/no-floating-promises": "off" } } From 39cfbbcdb4e2190d37ff7575aab6a1fe9b70791d Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Wed, 10 Jan 2024 14:14:28 +0100 Subject: [PATCH 40/49] Fix typo from `seTokenAmount` to `setTokenAmount` --- dapp/src/components/Modals/Staking/StakeForm/index.tsx | 6 +++--- dapp/src/contexts/TransactionContext.tsx | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dapp/src/components/Modals/Staking/StakeForm/index.tsx b/dapp/src/components/Modals/Staking/StakeForm/index.tsx index 38ea05136..635e17e23 100644 --- a/dapp/src/components/Modals/Staking/StakeForm/index.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm/index.tsx @@ -9,16 +9,16 @@ import Details from "./Details" function StakeForm({ goNext }: ModalStep) { const { btcAccount } = useWalletContext() - const { seTokenAmount } = useTransactionContext() + const { setTokenAmount } = useTransactionContext() const handleSubmitForm = useCallback( (values: TokenAmountFormValues) => { if (!values.amount) return - seTokenAmount({ amount: values.amount, currency: "bitcoin" }) + setTokenAmount({ amount: values.amount, currency: "bitcoin" }) goNext() }, - [goNext, seTokenAmount], + [goNext, setTokenAmount], ) return ( diff --git a/dapp/src/contexts/TransactionContext.tsx b/dapp/src/contexts/TransactionContext.tsx index b0f92ac6c..384bfb2e5 100644 --- a/dapp/src/contexts/TransactionContext.tsx +++ b/dapp/src/contexts/TransactionContext.tsx @@ -3,12 +3,12 @@ import { TokenAmount } from "../types" type TransactionContextValue = { tokenAmount?: TokenAmount - seTokenAmount: React.Dispatch> + setTokenAmount: React.Dispatch> } export const TransactionContext = createContext({ tokenAmount: undefined, - seTokenAmount: () => {}, + setTokenAmount: () => {}, }) export function TransactionContextProvider({ @@ -16,7 +16,7 @@ export function TransactionContextProvider({ }: { children: React.ReactNode }): React.ReactElement { - const [tokenAmount, seTokenAmount] = useState( + const [tokenAmount, setTokenAmount] = useState( undefined, ) @@ -24,7 +24,7 @@ export function TransactionContextProvider({ useMemo( () => ({ tokenAmount, - seTokenAmount, + setTokenAmount, }), [tokenAmount], ) From 597a89072be9e3b31c7e03ef3636b9d68cb4294c Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Wed, 10 Jan 2024 14:21:52 +0100 Subject: [PATCH 41/49] Create a special hook for the token amount value from form --- .../components/Modals/Staking/StakeForm/Details.tsx | 6 ++---- .../shared/TokenAmountForm/TokenAmountFormBase.tsx | 13 +++++++++++-- dapp/src/constants/forms.ts | 1 - dapp/src/constants/index.ts | 1 - 4 files changed, 13 insertions(+), 8 deletions(-) delete mode 100644 dapp/src/constants/forms.ts diff --git a/dapp/src/components/Modals/Staking/StakeForm/Details.tsx b/dapp/src/components/Modals/Staking/StakeForm/Details.tsx index e334c5403..efa0f70a3 100644 --- a/dapp/src/components/Modals/Staking/StakeForm/Details.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm/Details.tsx @@ -1,14 +1,12 @@ import React from "react" import { List } from "@chakra-ui/react" -import { useField } from "formik" import { useTransactionDetails } from "../../../../hooks" import TransactionDetailsAmountItem from "../../../shared/TransactionDetails/AmountItem" import { CurrencyType } from "../../../../types" -import { TOKEN_AMOUNT_FIELD_NAME } from "../../../../constants" +import { useTokenAmountFormValue } from "../../../shared/TokenAmountForm/TokenAmountFormBase" function Details({ currency }: { currency: CurrencyType }) { - const [, { value }] = useField(TOKEN_AMOUNT_FIELD_NAME) - + const value = useTokenAmountFormValue() const details = useTransactionDetails(value ?? 0n) return ( diff --git a/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx index fd4b6a05b..7324f2251 100644 --- a/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx +++ b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx @@ -1,13 +1,22 @@ import React from "react" -import { FormikProps } from "formik" +import { FormikProps, useField } from "formik" import { Form, FormTokenBalanceInput } from "../Form" import { CurrencyType } from "../../../types" -import { TOKEN_AMOUNT_FIELD_NAME } from "../../../constants" + +const TOKEN_AMOUNT_FIELD_NAME = "amount" export type TokenAmountFormValues = { [TOKEN_AMOUNT_FIELD_NAME]?: bigint } +export const useTokenAmountFormValue = () => { + const [, { value }] = useField< + TokenAmountFormValues[typeof TOKEN_AMOUNT_FIELD_NAME] + >(TOKEN_AMOUNT_FIELD_NAME) + + return value +} + export type TokenAmountFormBaseProps = { formId?: string tokenBalance: string diff --git a/dapp/src/constants/forms.ts b/dapp/src/constants/forms.ts deleted file mode 100644 index aba16ef3f..000000000 --- a/dapp/src/constants/forms.ts +++ /dev/null @@ -1 +0,0 @@ -export const TOKEN_AMOUNT_FIELD_NAME = "amount" diff --git a/dapp/src/constants/index.ts b/dapp/src/constants/index.ts index 46dfb30a7..a5cb59713 100644 --- a/dapp/src/constants/index.ts +++ b/dapp/src/constants/index.ts @@ -1,3 +1,2 @@ export * from "./currency" export * from "./staking" -export * from "./forms" From ed538622be7b58a064e005d7eae4c390c87b05d6 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 11 Jan 2024 11:59:41 +0100 Subject: [PATCH 42/49] Use beforeAfterSnapshotWrapper in Dispatcher test file Use snapshots to isolate test suites, so the chain state doesn't leak from one test suite to another. --- core/test/Dispatcher.test.ts | 37 +++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/core/test/Dispatcher.test.ts b/core/test/Dispatcher.test.ts index 6abb80a1b..eabcc46ac 100644 --- a/core/test/Dispatcher.test.ts +++ b/core/test/Dispatcher.test.ts @@ -3,9 +3,10 @@ import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers" import { expect } from "chai" import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers" -import { ZeroAddress } from "ethers" +import { ContractTransactionResponse, ZeroAddress } from "ethers" import { beforeAfterEachSnapshotWrapper, + beforeAfterSnapshotWrapper, deployment, getNamedSigner, getUnnamedSigner, @@ -47,10 +48,12 @@ describe("Dispatcher", () => { vaultAddress4 = await ethers.Wallet.createRandom().getAddress() }) - beforeAfterEachSnapshotWrapper() - describe("authorizeVault", () => { + beforeAfterSnapshotWrapper() + context("when caller is not a governance account", () => { + beforeAfterSnapshotWrapper() + it("should revert when adding a vault", async () => { await expect( dispatcher.connect(thirdParty).authorizeVault(vaultAddress1), @@ -64,9 +67,11 @@ describe("Dispatcher", () => { }) context("when caller is a governance account", () => { + beforeAfterSnapshotWrapper() + let tx: ContractTransactionResponse - beforeEach(async () => { + before(async () => { tx = await dispatcher.connect(governance).authorizeVault(vaultAddress1) await dispatcher.connect(governance).authorizeVault(vaultAddress2) await dispatcher.connect(governance).authorizeVault(vaultAddress3) @@ -98,7 +103,9 @@ describe("Dispatcher", () => { }) describe("deauthorizeVault", () => { - beforeEach(async () => { + beforeAfterSnapshotWrapper() + + before(async () => { await dispatcher.connect(governance).authorizeVault(vaultAddress1) await dispatcher.connect(governance).authorizeVault(vaultAddress2) await dispatcher.connect(governance).authorizeVault(vaultAddress3) @@ -118,6 +125,8 @@ describe("Dispatcher", () => { }) context("when caller is a governance account", () => { + beforeAfterEachSnapshotWrapper() + it("should deauthorize vaults", async () => { await dispatcher.connect(governance).deauthorizeVault(vaultAddress1) @@ -163,6 +172,8 @@ describe("Dispatcher", () => { }) describe("depositToVault", () => { + beforeAfterSnapshotWrapper() + const assetsToAllocate = to1e18(100) const minSharesOut = to1e18(100) @@ -172,6 +183,8 @@ describe("Dispatcher", () => { }) context("when caller is not maintainer", () => { + beforeAfterSnapshotWrapper() + it("should revert when depositing to a vault", async () => { await expect( dispatcher @@ -187,6 +200,8 @@ describe("Dispatcher", () => { context("when caller is maintainer", () => { context("when vault is not authorized", () => { + beforeAfterSnapshotWrapper() + it("should revert", async () => { const randomAddress = await ethers.Wallet.createRandom().getAddress() await expect( @@ -205,6 +220,8 @@ describe("Dispatcher", () => { }) context("when allocation is successful", () => { + beforeAfterSnapshotWrapper() + let tx: ContractTransactionResponse before(async () => { @@ -239,6 +256,8 @@ describe("Dispatcher", () => { context( "when the expected returned shares are less than the actual returned shares", () => { + beforeAfterSnapshotWrapper() + const sharesOut = assetsToAllocate const minShares = to1e18(101) @@ -258,6 +277,8 @@ describe("Dispatcher", () => { }) describe("updateMaintainer", () => { + beforeAfterSnapshotWrapper() + let newMaintainer: string before(async () => { @@ -265,6 +286,8 @@ describe("Dispatcher", () => { }) context("when caller is not an owner", () => { + beforeAfterSnapshotWrapper() + it("should revert", async () => { await expect( dispatcher.connect(thirdParty).updateMaintainer(newMaintainer), @@ -279,6 +302,8 @@ describe("Dispatcher", () => { context("when caller is an owner", () => { context("when maintainer is a zero address", () => { + beforeAfterSnapshotWrapper() + it("should revert", async () => { await expect( dispatcher.connect(governance).updateMaintainer(ZeroAddress), @@ -287,6 +312,8 @@ describe("Dispatcher", () => { }) context("when maintainer is not a zero address", () => { + beforeAfterSnapshotWrapper() + let tx: ContractTransactionResponse before(async () => { From 5e9248b1b22be032f011fa9eb45c01c39aa55242 Mon Sep 17 00:00:00 2001 From: ioay Date: Thu, 11 Jan 2024 14:17:34 +0100 Subject: [PATCH 43/49] Update config files --- dapp/.eslintrc | 10 +++ dapp/package.json | 6 +- dapp/tsconfig.json | 7 +- dapp/vite.config.ts | 10 ++- pnpm-lock.yaml | 186 +++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 211 insertions(+), 8 deletions(-) diff --git a/dapp/.eslintrc b/dapp/.eslintrc index 4317c87a7..528de4b43 100644 --- a/dapp/.eslintrc +++ b/dapp/.eslintrc @@ -16,5 +16,15 @@ { "allowRequiredDefaults": true } ], "react/require-default-props": [0] + }, + "settings": { + "import/resolver": { + "alias": { + "map": [ + ["~", "./src"] + ], + "extensions": [".js", ".jsx",".ts", ".tsx"] + } + } } } diff --git a/dapp/package.json b/dapp/package.json index c3b061d02..439201a1c 100644 --- a/dapp/package.json +++ b/dapp/package.json @@ -34,9 +34,13 @@ "@typescript-eslint/parser": "^6.12.0", "@vitejs/plugin-react": "^4.2.0", "eslint": "^8.54.0", + "eslint-import-resolver-alias": "^1.1.2", + "eslint-plugin-import": "^2.29.1", "prettier": "^3.1.0", "typescript": "^5.3.2", "vite": "^5.0.2", - "vite-plugin-node-polyfills": "^0.19.0" + "vite-plugin-eslint": "^1.8.1", + "vite-plugin-node-polyfills": "^0.19.0", + "vite-tsconfig-paths": "^4.2.3" } } diff --git a/dapp/tsconfig.json b/dapp/tsconfig.json index 2e31274ea..0d679c735 100644 --- a/dapp/tsconfig.json +++ b/dapp/tsconfig.json @@ -11,8 +11,11 @@ "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", - "strict": true + "strict": true, + "baseUrl": ".", + "paths": { + "~/*": ["./src/*"] + } }, - "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/dapp/vite.config.ts b/dapp/vite.config.ts index cef82d65c..14ad46477 100644 --- a/dapp/vite.config.ts +++ b/dapp/vite.config.ts @@ -1,7 +1,15 @@ import { defineConfig } from "vite" import react from "@vitejs/plugin-react" import { nodePolyfills } from "vite-plugin-node-polyfills" +import eslint from "vite-plugin-eslint" + +import { resolve } from "path" export default defineConfig({ - plugins: [nodePolyfills(), react()], + resolve: { + alias: { + "~": resolve(__dirname, "./src"), + }, + }, + plugins: [nodePolyfills(), react(), eslint()], }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cbe06e8d4..48a4c27dc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -166,6 +166,12 @@ importers: eslint: specifier: ^8.54.0 version: 8.54.0 + eslint-import-resolver-alias: + specifier: ^1.1.2 + version: 1.1.2(eslint-plugin-import@2.29.1) + eslint-plugin-import: + specifier: ^2.29.1 + version: 2.29.1(@typescript-eslint/parser@6.12.0)(eslint@8.54.0) prettier: specifier: ^3.1.0 version: 3.1.0 @@ -175,9 +181,15 @@ importers: vite: specifier: ^5.0.2 version: 5.0.2 + vite-plugin-eslint: + specifier: ^1.8.1 + version: 1.8.1(eslint@8.54.0)(vite@5.0.2) vite-plugin-node-polyfills: specifier: ^0.19.0 version: 0.19.0(vite@5.0.2) + vite-tsconfig-paths: + specifier: ^4.2.3 + version: 4.2.3(typescript@5.3.2)(vite@5.0.2) sdk: devDependencies: @@ -5088,6 +5100,14 @@ packages: magic-string: 0.30.5 dev: true + /@rollup/pluginutils@4.2.1: + resolution: {integrity: sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==} + engines: {node: '>= 8.0.0'} + dependencies: + estree-walker: 2.0.2 + picomatch: 2.3.1 + dev: true + /@rollup/pluginutils@5.1.0: resolution: {integrity: sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==} engines: {node: '>=14.0.0'} @@ -5390,11 +5410,11 @@ packages: '@typescript-eslint/eslint-plugin': 6.12.0(@typescript-eslint/parser@6.12.0)(eslint@8.54.0)(typescript@5.3.2) '@typescript-eslint/parser': 6.12.0(eslint@8.54.0)(typescript@5.3.2) eslint: 8.54.0 - eslint-config-airbnb: 19.0.4(eslint-plugin-import@2.29.0)(eslint-plugin-jsx-a11y@6.8.0)(eslint-plugin-react-hooks@4.6.0)(eslint-plugin-react@7.33.2)(eslint@8.54.0) - eslint-config-airbnb-base: 15.0.0(eslint-plugin-import@2.29.0)(eslint@8.54.0) - eslint-config-airbnb-typescript: 17.1.0(@typescript-eslint/eslint-plugin@6.12.0)(@typescript-eslint/parser@6.12.0)(eslint-plugin-import@2.29.0)(eslint@8.54.0) + eslint-config-airbnb: 19.0.4(eslint-plugin-import@2.29.1)(eslint-plugin-jsx-a11y@6.8.0)(eslint-plugin-react-hooks@4.6.0)(eslint-plugin-react@7.33.2)(eslint@8.54.0) + eslint-config-airbnb-base: 15.0.0(eslint-plugin-import@2.29.1)(eslint@8.54.0) + eslint-config-airbnb-typescript: 17.1.0(@typescript-eslint/eslint-plugin@6.12.0)(@typescript-eslint/parser@6.12.0)(eslint-plugin-import@2.29.1)(eslint@8.54.0) eslint-config-prettier: 9.0.0(eslint@8.54.0) - eslint-plugin-import: 2.29.0(@typescript-eslint/parser@6.12.0)(eslint@8.54.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.12.0)(eslint@8.54.0) eslint-plugin-jsx-a11y: 6.8.0(eslint@8.54.0) eslint-plugin-no-only-tests: 3.1.0 eslint-plugin-prettier: 5.0.1(eslint-config-prettier@9.0.0)(eslint@8.54.0)(prettier@3.1.0) @@ -8577,6 +8597,21 @@ packages: semver: 6.3.1 dev: true + /eslint-config-airbnb-base@15.0.0(eslint-plugin-import@2.29.1)(eslint@8.54.0): + resolution: {integrity: sha512-xaX3z4ZZIcFLvh2oUNvcX5oEofXda7giYmuplVxoOg5A7EXJMrUyqRgR+mhDhPK8LZ4PttFOBvCYDbX3sUoUig==} + engines: {node: ^10.12.0 || >=12.0.0} + peerDependencies: + eslint: ^7.32.0 || ^8.2.0 + eslint-plugin-import: ^2.25.2 + dependencies: + confusing-browser-globals: 1.0.11 + eslint: 8.54.0 + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.12.0)(eslint@8.54.0) + object.assign: 4.1.4 + object.entries: 1.1.7 + semver: 6.3.1 + dev: true + /eslint-config-airbnb-typescript@17.1.0(@typescript-eslint/eslint-plugin@6.12.0)(@typescript-eslint/parser@6.12.0)(eslint-plugin-import@2.29.0)(eslint@8.54.0): resolution: {integrity: sha512-GPxI5URre6dDpJ0CtcthSZVBAfI+Uw7un5OYNVxP2EYi3H81Jw701yFP7AU+/vCE7xBtFmjge7kfhhk4+RAiig==} peerDependencies: @@ -8592,6 +8627,21 @@ packages: eslint-plugin-import: 2.29.0(@typescript-eslint/parser@6.12.0)(eslint@8.54.0) dev: true + /eslint-config-airbnb-typescript@17.1.0(@typescript-eslint/eslint-plugin@6.12.0)(@typescript-eslint/parser@6.12.0)(eslint-plugin-import@2.29.1)(eslint@8.54.0): + resolution: {integrity: sha512-GPxI5URre6dDpJ0CtcthSZVBAfI+Uw7un5OYNVxP2EYi3H81Jw701yFP7AU+/vCE7xBtFmjge7kfhhk4+RAiig==} + peerDependencies: + '@typescript-eslint/eslint-plugin': ^5.13.0 || ^6.0.0 + '@typescript-eslint/parser': ^5.0.0 || ^6.0.0 + eslint: ^7.32.0 || ^8.2.0 + eslint-plugin-import: ^2.25.3 + dependencies: + '@typescript-eslint/eslint-plugin': 6.12.0(@typescript-eslint/parser@6.12.0)(eslint@8.54.0)(typescript@5.3.2) + '@typescript-eslint/parser': 6.12.0(eslint@8.54.0)(typescript@5.3.2) + eslint: 8.54.0 + eslint-config-airbnb-base: 15.0.0(eslint-plugin-import@2.29.1)(eslint@8.54.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.12.0)(eslint@8.54.0) + dev: true + /eslint-config-airbnb@19.0.4(eslint-plugin-import@2.29.0)(eslint-plugin-jsx-a11y@6.8.0)(eslint-plugin-react-hooks@4.6.0)(eslint-plugin-react@7.33.2)(eslint@8.54.0): resolution: {integrity: sha512-T75QYQVQX57jiNgpF9r1KegMICE94VYwoFQyMGhrvc+lB8YF2E/M/PYDaQe1AJcWaEgqLE+ErXV1Og/+6Vyzew==} engines: {node: ^10.12.0 || ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -8612,6 +8662,26 @@ packages: object.entries: 1.1.7 dev: true + /eslint-config-airbnb@19.0.4(eslint-plugin-import@2.29.1)(eslint-plugin-jsx-a11y@6.8.0)(eslint-plugin-react-hooks@4.6.0)(eslint-plugin-react@7.33.2)(eslint@8.54.0): + resolution: {integrity: sha512-T75QYQVQX57jiNgpF9r1KegMICE94VYwoFQyMGhrvc+lB8YF2E/M/PYDaQe1AJcWaEgqLE+ErXV1Og/+6Vyzew==} + engines: {node: ^10.12.0 || ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: ^7.32.0 || ^8.2.0 + eslint-plugin-import: ^2.25.3 + eslint-plugin-jsx-a11y: ^6.5.1 + eslint-plugin-react: ^7.28.0 + eslint-plugin-react-hooks: ^4.3.0 + dependencies: + eslint: 8.54.0 + eslint-config-airbnb-base: 15.0.0(eslint-plugin-import@2.29.1)(eslint@8.54.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.12.0)(eslint@8.54.0) + eslint-plugin-jsx-a11y: 6.8.0(eslint@8.54.0) + eslint-plugin-react: 7.33.2(eslint@8.54.0) + eslint-plugin-react-hooks: 4.6.0(eslint@8.54.0) + object.assign: 4.1.4 + object.entries: 1.1.7 + dev: true + /eslint-config-prettier@9.0.0(eslint@8.54.0): resolution: {integrity: sha512-IcJsTkJae2S35pRsRAwoCE+925rJJStOdkKnLVgtE+tEpqU0EVVM7OqrwxqgptKdX29NUwC82I5pXsGFIgSevw==} hasBin: true @@ -8657,6 +8727,15 @@ packages: eslint-plugin-react-hooks: 4.6.0(eslint@8.54.0) typescript: 5.3.2 + /eslint-import-resolver-alias@1.1.2(eslint-plugin-import@2.29.1): + resolution: {integrity: sha512-WdviM1Eu834zsfjHtcGHtGfcu+F30Od3V7I9Fi57uhBEwPkjDcii7/yW8jAT+gOhn4P/vOxxNAXbFAKsrrc15w==} + engines: {node: '>= 4'} + peerDependencies: + eslint-plugin-import: '>=1.4.0' + dependencies: + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.12.0)(eslint@8.54.0) + dev: true + /eslint-import-resolver-node@0.3.9: resolution: {integrity: sha512-WFj2isz22JahUv+B788TlO3N6zL3nNJGU8CcZbPZvVEkBPaJdCV4vy5wyghty5ROFbCRnm132v8BScu5/1BQ8g==} dependencies: @@ -8738,6 +8817,41 @@ packages: - eslint-import-resolver-webpack - supports-color + /eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.12.0)(eslint@8.54.0): + resolution: {integrity: sha512-BbPC0cuExzhiMo4Ff1BTVwHpjjv28C5R+btTOGaCRC7UEz801up0JadwkeSk5Ued6TG34uaczuVuH6qyy5YUxw==} + engines: {node: '>=4'} + peerDependencies: + '@typescript-eslint/parser': '*' + eslint: ^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8 + peerDependenciesMeta: + '@typescript-eslint/parser': + optional: true + dependencies: + '@typescript-eslint/parser': 6.12.0(eslint@8.54.0)(typescript@5.3.2) + array-includes: 3.1.7 + array.prototype.findlastindex: 1.2.3 + array.prototype.flat: 1.3.2 + array.prototype.flatmap: 1.3.2 + debug: 3.2.7 + doctrine: 2.1.0 + eslint: 8.54.0 + eslint-import-resolver-node: 0.3.9 + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.12.0)(eslint-import-resolver-node@0.3.9)(eslint@8.54.0) + hasown: 2.0.0 + is-core-module: 2.13.1 + is-glob: 4.0.3 + minimatch: 3.1.2 + object.fromentries: 2.0.7 + object.groupby: 1.0.1 + object.values: 1.1.7 + semver: 6.3.1 + tsconfig-paths: 3.15.0 + transitivePeerDependencies: + - eslint-import-resolver-typescript + - eslint-import-resolver-webpack + - supports-color + dev: true + /eslint-plugin-jsx-a11y@6.8.0(eslint@8.54.0): resolution: {integrity: sha512-Hdh937BS3KdwwbBaKd5+PLCOmYY6U4f2h9Z2ktwtNKvIdIEu137rjYbcb9ApSbVJfWxANNuiKTD/9tOKjK9qOA==} engines: {node: '>=4.0'} @@ -10431,6 +10545,10 @@ packages: merge2: 1.4.1 slash: 3.0.0 + /globrex@0.1.2: + resolution: {integrity: sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==} + dev: true + /gopd@1.0.1: resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} dependencies: @@ -13874,6 +13992,14 @@ packages: bn.js: 5.2.1 dev: true + /rollup@2.79.1: + resolution: {integrity: sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==} + engines: {node: '>=10.0.0'} + hasBin: true + optionalDependencies: + fsevents: 2.3.3 + dev: true + /rollup@4.5.1: resolution: {integrity: sha512-0EQribZoPKpb5z1NW/QYm3XSR//Xr8BeEXU49Lc/mQmpmVVG5jPUVrpc2iptup/0WMrY9mzas0fxH+TjYvG2CA==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} @@ -15016,6 +15142,19 @@ packages: resolution: {integrity: sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w==} dev: true + /tsconfck@2.1.2(typescript@5.3.2): + resolution: {integrity: sha512-ghqN1b0puy3MhhviwO2kGF8SeMDNhEbnKxjK7h6+fvY9JAxqvXi8y5NAHSQv687OVboS2uZIByzGd45/YxrRHg==} + engines: {node: ^14.13.1 || ^16 || >=18} + hasBin: true + peerDependencies: + typescript: ^4.3.5 || ^5.0.0 + peerDependenciesMeta: + typescript: + optional: true + dependencies: + typescript: 5.3.2 + dev: true + /tsconfig-paths@3.14.2: resolution: {integrity: sha512-o/9iXgCYc5L/JxCHPe3Hvh8Q/2xm5Z+p18PESBU6Ff33695QnCHBEjcytY2q19ua7Mbl/DavtBOLq+oG0RCL+g==} dependencies: @@ -15024,6 +15163,15 @@ packages: minimist: 1.2.8 strip-bom: 3.0.0 + /tsconfig-paths@3.15.0: + resolution: {integrity: sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg==} + dependencies: + '@types/json5': 0.0.29 + json5: 1.0.2 + minimist: 1.2.8 + strip-bom: 3.0.0 + dev: true + /tslib@1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} @@ -15420,6 +15568,19 @@ packages: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} + /vite-plugin-eslint@1.8.1(eslint@8.54.0)(vite@5.0.2): + resolution: {integrity: sha512-PqdMf3Y2fLO9FsNPmMX+//2BF5SF8nEWspZdgl4kSt7UvHDRHVVfHvxsD7ULYzZrJDGRxR81Nq7TOFgwMnUang==} + peerDependencies: + eslint: '>=7' + vite: '>=2' + dependencies: + '@rollup/pluginutils': 4.2.1 + '@types/eslint': 8.44.7 + eslint: 8.54.0 + rollup: 2.79.1 + vite: 5.0.2 + dev: true + /vite-plugin-node-polyfills@0.19.0(vite@5.0.2): resolution: {integrity: sha512-AhdVxAmVnd1doUlIRGUGV6ZRPfB9BvIwDF10oCOmL742IsvsFIAV4tSMxSfu5e0Px0QeJLgWVOSbtHIvblzqMw==} peerDependencies: @@ -15432,6 +15593,23 @@ packages: - rollup dev: true + /vite-tsconfig-paths@4.2.3(typescript@5.3.2)(vite@5.0.2): + resolution: {integrity: sha512-xVsA2xe6QSlzBujtWF8q2NYexh7PAUYfzJ4C8Axpe/7d2pcERYxuxGgph9F4f0iQO36g5tyGq6eBUYIssdUrVw==} + peerDependencies: + vite: '*' + peerDependenciesMeta: + vite: + optional: true + dependencies: + debug: 4.3.4(supports-color@8.1.1) + globrex: 0.1.2 + tsconfck: 2.1.2(typescript@5.3.2) + vite: 5.0.2 + transitivePeerDependencies: + - supports-color + - typescript + dev: true + /vite@5.0.2: resolution: {integrity: sha512-6CCq1CAJCNM1ya2ZZA7+jS2KgnhbzvxakmlIjN24cF/PXhRMzpM/z8QgsVJA/Dm5fWUWnVEsmtBoMhmerPxT0g==} engines: {node: ^18.0.0 || >=20.0.0} From 2cdb45088f230e3e0c5f504b23ee2030c9dbfdda Mon Sep 17 00:00:00 2001 From: ioay Date: Thu, 11 Jan 2024 14:28:14 +0100 Subject: [PATCH 44/49] Update imports --- dapp/package.json | 1 - dapp/src/components/DocsDrawer/index.tsx | 4 +- dapp/src/components/GlobalStyles/index.tsx | 10 +-- dapp/src/components/Header/ConnectWallet.tsx | 10 +-- dapp/src/components/Header/index.tsx | 2 +- .../components/Modals/ActionForm/index.tsx | 2 +- .../components/Modals/Staking/DepositBTC.tsx | 6 +- .../Modals/Staking/Overview/index.tsx | 4 +- .../Modals/Staking/Overview/steps.tsx | 2 +- .../components/Modals/Staking/SignMessage.tsx | 6 +- .../Modals/Staking/StakeForm/Details.tsx | 8 +-- .../Modals/Staking/StakeForm/index.tsx | 10 +-- .../Staking/components/StakingSteps.tsx | 6 +- dapp/src/components/Modals/Staking/index.tsx | 4 +- .../Modals/Support/MissingAccount.tsx | 8 +-- dapp/src/components/Modals/Support/index.tsx | 4 +- .../components/Overview/PositionDetails.tsx | 6 +- dapp/src/components/Overview/Statistics.tsx | 2 +- .../Overview/TransactionHistory.tsx | 2 +- dapp/src/components/Overview/index.tsx | 8 +-- dapp/src/components/Sidebar/index.tsx | 2 +- dapp/src/components/shared/Alert/index.tsx | 2 +- .../shared/CurrencyBalance/index.tsx | 4 +- .../src/components/shared/ModalBase/index.tsx | 4 +- .../TokenAmountForm/TokenAmountFormBase.tsx | 2 +- .../shared/TokenAmountForm/index.tsx | 2 +- .../shared/TokenBalanceInput/index.tsx | 6 +- dapp/src/constants/currency.ts | 2 +- dapp/src/contexts/TransactionContext.tsx | 2 +- dapp/src/hooks/useDepositBTCTransaction.ts | 2 +- dapp/src/hooks/useDocsDrawer.ts | 2 +- dapp/src/hooks/useModalFlowContext.ts | 2 +- dapp/src/hooks/useRequestBitcoinAccount.ts | 6 +- dapp/src/hooks/useRequestEthereumAccount.ts | 6 +- dapp/src/hooks/useSidebar.ts | 2 +- dapp/src/hooks/useSignMessage.ts | 2 +- dapp/src/hooks/useTransactionContext.ts | 2 +- dapp/src/hooks/useWalletContext.ts | 2 +- dapp/src/utils/currency.ts | 4 +- dapp/src/utils/forms.ts | 2 +- dapp/vite.config.ts | 3 +- pnpm-lock.yaml | 63 +++++++------------ 42 files changed, 103 insertions(+), 126 deletions(-) diff --git a/dapp/package.json b/dapp/package.json index 439201a1c..9abe245b2 100644 --- a/dapp/package.json +++ b/dapp/package.json @@ -39,7 +39,6 @@ "prettier": "^3.1.0", "typescript": "^5.3.2", "vite": "^5.0.2", - "vite-plugin-eslint": "^1.8.1", "vite-plugin-node-polyfills": "^0.19.0", "vite-tsconfig-paths": "^4.2.3" } diff --git a/dapp/src/components/DocsDrawer/index.tsx b/dapp/src/components/DocsDrawer/index.tsx index 5082af57b..35e49647c 100644 --- a/dapp/src/components/DocsDrawer/index.tsx +++ b/dapp/src/components/DocsDrawer/index.tsx @@ -5,8 +5,8 @@ import { DrawerContent, DrawerOverlay, } from "@chakra-ui/react" -import { useDocsDrawer } from "../../hooks" -import { TextMd } from "../shared/Typography" +import { useDocsDrawer } from "~/hooks" +import { TextMd } from "~/components/shared/Typography" export default function DocsDrawer() { const { isOpen, onClose } = useDocsDrawer() diff --git a/dapp/src/components/GlobalStyles/index.tsx b/dapp/src/components/GlobalStyles/index.tsx index 80b36e6e8..d316cead6 100644 --- a/dapp/src/components/GlobalStyles/index.tsx +++ b/dapp/src/components/GlobalStyles/index.tsx @@ -1,11 +1,11 @@ import React from "react" import { Global } from "@emotion/react" -import SegmentRegular from "../../fonts/Segment-Regular.otf" -import SegmentMedium from "../../fonts/Segment-Medium.otf" -import SegmentSemiBold from "../../fonts/Segment-SemiBold.otf" -import SegmentBold from "../../fonts/Segment-Bold.otf" -import SegmentBlack from "../../fonts/Segment-Black.otf" +import SegmentRegular from "~/fonts/Segment-Regular.otf" +import SegmentMedium from "~/fonts/Segment-Medium.otf" +import SegmentSemiBold from "~/fonts/Segment-SemiBold.otf" +import SegmentBold from "~/fonts/Segment-Bold.otf" +import SegmentBlack from "~/fonts/Segment-Black.otf" export default function GlobalStyles() { return ( diff --git a/dapp/src/components/Header/ConnectWallet.tsx b/dapp/src/components/Header/ConnectWallet.tsx index 90069b4e7..28bad070d 100644 --- a/dapp/src/components/Header/ConnectWallet.tsx +++ b/dapp/src/components/Header/ConnectWallet.tsx @@ -1,15 +1,15 @@ import React from "react" import { Button, HStack, Icon } from "@chakra-ui/react" import { Account } from "@ledgerhq/wallet-api-client" -import { Bitcoin, Ethereum } from "../../static/icons" import { useRequestBitcoinAccount, useRequestEthereumAccount, useWalletContext, -} from "../../hooks" -import { truncateAddress } from "../../utils" -import { CurrencyBalance } from "../shared/CurrencyBalance" -import { TextMd } from "../shared/Typography" +} from "~/hooks" +import { CurrencyBalance } from "~/components/shared/CurrencyBalance" +import { TextMd } from "~/components/shared/Typography" +import { Bitcoin, Ethereum } from "~/static/icons" +import { truncateAddress } from "~/utils" export type ConnectButtonsProps = { leftIcon: typeof Icon diff --git a/dapp/src/components/Header/index.tsx b/dapp/src/components/Header/index.tsx index 544fbdee9..b0d47f2ab 100644 --- a/dapp/src/components/Header/index.tsx +++ b/dapp/src/components/Header/index.tsx @@ -1,7 +1,7 @@ import React from "react" import { Flex, HStack, Icon } from "@chakra-ui/react" +import { AcreLogo } from "~/static/icons" import ConnectWallet from "./ConnectWallet" -import { AcreLogo } from "../../static/icons" export default function Header() { return ( diff --git a/dapp/src/components/Modals/ActionForm/index.tsx b/dapp/src/components/Modals/ActionForm/index.tsx index 0eae3fe5b..d6a595d5d 100644 --- a/dapp/src/components/Modals/ActionForm/index.tsx +++ b/dapp/src/components/Modals/ActionForm/index.tsx @@ -7,8 +7,8 @@ import { TabPanels, TabPanel, } from "@chakra-ui/react" +import { useModalFlowContext } from "~/hooks" import StakeForm from "../Staking/StakeForm" -import { useModalFlowContext } from "../../../hooks" const TABS = ["stake", "unstake"] as const diff --git a/dapp/src/components/Modals/Staking/DepositBTC.tsx b/dapp/src/components/Modals/Staking/DepositBTC.tsx index 853159262..20e649956 100644 --- a/dapp/src/components/Modals/Staking/DepositBTC.tsx +++ b/dapp/src/components/Modals/Staking/DepositBTC.tsx @@ -1,7 +1,7 @@ import React from "react" -import Alert from "../../shared/Alert" -import { useDepositBTCTransaction, useModalFlowContext } from "../../../hooks" -import { TextMd } from "../../shared/Typography" +import { useDepositBTCTransaction, useModalFlowContext } from "~/hooks" +import Alert from "~/components/shared/Alert" +import { TextMd } from "~/components/shared/Typography" import StakingSteps from "./components/StakingSteps" export default function DepositBTC() { diff --git a/dapp/src/components/Modals/Staking/Overview/index.tsx b/dapp/src/components/Modals/Staking/Overview/index.tsx index ecb2c310a..330bb7289 100644 --- a/dapp/src/components/Modals/Staking/Overview/index.tsx +++ b/dapp/src/components/Modals/Staking/Overview/index.tsx @@ -6,8 +6,8 @@ import { ModalHeader, StepNumber, } from "@chakra-ui/react" -import { useModalFlowContext } from "../../../../hooks" -import StepperBase from "../../../shared/StepperBase" +import StepperBase from "~/components/shared/StepperBase" +import { useModalFlowContext } from "~/hooks" import { STEPS } from "./steps" export default function Overview() { diff --git a/dapp/src/components/Modals/Staking/Overview/steps.tsx b/dapp/src/components/Modals/Staking/Overview/steps.tsx index 257c671fa..532e35e50 100644 --- a/dapp/src/components/Modals/Staking/Overview/steps.tsx +++ b/dapp/src/components/Modals/Staking/Overview/steps.tsx @@ -1,5 +1,5 @@ import React from "react" -import { StepBase } from "../../../shared/StepperBase" +import { StepBase } from "~/components/shared/StepperBase" import { Description, Title } from "../components/StakingSteps" export const STEPS: StepBase[] = [ diff --git a/dapp/src/components/Modals/Staking/SignMessage.tsx b/dapp/src/components/Modals/Staking/SignMessage.tsx index 3c6442676..dfe7d2dc1 100644 --- a/dapp/src/components/Modals/Staking/SignMessage.tsx +++ b/dapp/src/components/Modals/Staking/SignMessage.tsx @@ -1,8 +1,8 @@ import React from "react" import { Highlight } from "@chakra-ui/react" -import Alert from "../../shared/Alert" -import { useModalFlowContext, useSignMessage } from "../../../hooks" -import { TextMd } from "../../shared/Typography" +import { useModalFlowContext, useSignMessage } from "~/hooks" +import Alert from "~/components/shared/Alert" +import { TextMd } from "~/components/shared/Typography" import StakingSteps from "./components/StakingSteps" export default function SignMessage() { diff --git a/dapp/src/components/Modals/Staking/StakeForm/Details.tsx b/dapp/src/components/Modals/Staking/StakeForm/Details.tsx index efa0f70a3..5d16cd8e2 100644 --- a/dapp/src/components/Modals/Staking/StakeForm/Details.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm/Details.tsx @@ -1,9 +1,9 @@ import React from "react" import { List } from "@chakra-ui/react" -import { useTransactionDetails } from "../../../../hooks" -import TransactionDetailsAmountItem from "../../../shared/TransactionDetails/AmountItem" -import { CurrencyType } from "../../../../types" -import { useTokenAmountFormValue } from "../../../shared/TokenAmountForm/TokenAmountFormBase" +import TransactionDetailsAmountItem from "~/components/shared/TransactionDetails/AmountItem" +import { useTokenAmountFormValue } from "~/components/shared/TokenAmountForm/TokenAmountFormBase" +import { useTransactionDetails } from "~/hooks" +import { CurrencyType } from "~/types" function Details({ currency }: { currency: CurrencyType }) { const value = useTokenAmountFormValue() diff --git a/dapp/src/components/Modals/Staking/StakeForm/index.tsx b/dapp/src/components/Modals/Staking/StakeForm/index.tsx index 635e17e23..5f9b57bf0 100644 --- a/dapp/src/components/Modals/Staking/StakeForm/index.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm/index.tsx @@ -1,10 +1,10 @@ import React, { useCallback } from "react" import { Button } from "@chakra-ui/react" -import { BITCOIN_MIN_AMOUNT } from "../../../../constants" -import { ModalStep } from "../../../../contexts" -import { useWalletContext, useTransactionContext } from "../../../../hooks" -import TokenAmountForm from "../../../shared/TokenAmountForm" -import { TokenAmountFormValues } from "../../../shared/TokenAmountForm/TokenAmountFormBase" +import { BITCOIN_MIN_AMOUNT } from "~/constants" +import { ModalStep } from "~/contexts" +import TokenAmountForm from "~/components/shared/TokenAmountForm" +import { TokenAmountFormValues } from "~/components/shared/TokenAmountForm/TokenAmountFormBase" +import { useWalletContext, useTransactionContext } from "~/hooks" import Details from "./Details" function StakeForm({ goNext }: ModalStep) { diff --git a/dapp/src/components/Modals/Staking/components/StakingSteps.tsx b/dapp/src/components/Modals/Staking/components/StakingSteps.tsx index a0ebfd4cb..4f0a11d06 100644 --- a/dapp/src/components/Modals/Staking/components/StakingSteps.tsx +++ b/dapp/src/components/Modals/Staking/components/StakingSteps.tsx @@ -6,9 +6,9 @@ import { ModalFooter, ModalHeader, } from "@chakra-ui/react" -import { TextLg, TextMd } from "../../../shared/Typography" -import StepperBase, { StepBase } from "../../../shared/StepperBase" -import Spinner from "../../../shared/Spinner" +import { TextLg, TextMd } from "~/components/shared/Typography" +import StepperBase, { StepBase } from "~/components/shared/StepperBase" +import Spinner from "~/components/shared/Spinner" export function Title({ children }: { children: React.ReactNode }) { return {children} diff --git a/dapp/src/components/Modals/Staking/index.tsx b/dapp/src/components/Modals/Staking/index.tsx index 78d04706c..8bad1b0c4 100644 --- a/dapp/src/components/Modals/Staking/index.tsx +++ b/dapp/src/components/Modals/Staking/index.tsx @@ -1,7 +1,7 @@ import React from "react" -import { useModalFlowContext } from "../../../hooks" +import { useModalFlowContext } from "~/hooks" +import ModalBase from "~/components/shared/ModalBase" import Overview from "./Overview" -import ModalBase from "../../shared/ModalBase" import ActionForm from "../ActionForm" import SignMessage from "./SignMessage" import DepositBTC from "./DepositBTC" diff --git a/dapp/src/components/Modals/Support/MissingAccount.tsx b/dapp/src/components/Modals/Support/MissingAccount.tsx index 2c32b354e..df879d260 100644 --- a/dapp/src/components/Modals/Support/MissingAccount.tsx +++ b/dapp/src/components/Modals/Support/MissingAccount.tsx @@ -7,10 +7,10 @@ import { ModalFooter, ModalHeader, } from "@chakra-ui/react" -import { CurrencyType, RequestAccountParams } from "../../../types" -import { TextMd } from "../../shared/Typography" -import Alert from "../../shared/Alert" -import { getCurrencyByType } from "../../../utils" +import { TextMd } from "~/components/shared/Typography" +import Alert from "~/components/shared/Alert" +import { getCurrencyByType } from "~/utils" +import { CurrencyType, RequestAccountParams } from "~/types" type MissingAccountProps = { currency: CurrencyType diff --git a/dapp/src/components/Modals/Support/index.tsx b/dapp/src/components/Modals/Support/index.tsx index c6784fff4..ca6e51453 100644 --- a/dapp/src/components/Modals/Support/index.tsx +++ b/dapp/src/components/Modals/Support/index.tsx @@ -3,9 +3,9 @@ import { useRequestBitcoinAccount, useRequestEthereumAccount, useWalletContext, -} from "../../../hooks" +} from "~/hooks" +import { ConnectBTCAccount, ConnectETHAccount } from "~/static/icons" import MissingAccount from "./MissingAccount" -import { ConnectBTCAccount, ConnectETHAccount } from "../../../static/icons" export default function SupportWrapper({ children, diff --git a/dapp/src/components/Overview/PositionDetails.tsx b/dapp/src/components/Overview/PositionDetails.tsx index c1de13f71..907be66f1 100644 --- a/dapp/src/components/Overview/PositionDetails.tsx +++ b/dapp/src/components/Overview/PositionDetails.tsx @@ -10,10 +10,10 @@ import { CardProps, useBoolean, } from "@chakra-ui/react" -import { Info } from "../../static/icons" +import { CurrencyBalanceWithConversion } from "~/components/shared/CurrencyBalanceWithConversion" +import { TextMd } from "~/components/shared/Typography" +import { Info } from "~/static/icons" import StakingModal from "../Modals/Staking" -import { CurrencyBalanceWithConversion } from "../shared/CurrencyBalanceWithConversion" -import { TextMd } from "../shared/Typography" export default function PositionDetails(props: CardProps) { const [isOpenStakingModal, stakingModal] = useBoolean() diff --git a/dapp/src/components/Overview/Statistics.tsx b/dapp/src/components/Overview/Statistics.tsx index 8b9c5979e..e8a5df0c5 100644 --- a/dapp/src/components/Overview/Statistics.tsx +++ b/dapp/src/components/Overview/Statistics.tsx @@ -1,6 +1,6 @@ import React from "react" import { CardBody, Card, CardProps } from "@chakra-ui/react" -import { TextMd } from "../shared/Typography" +import { TextMd } from "~/components/shared/Typography" export default function Statistics(props: CardProps) { return ( diff --git a/dapp/src/components/Overview/TransactionHistory.tsx b/dapp/src/components/Overview/TransactionHistory.tsx index e0ff1fb26..557556bd4 100644 --- a/dapp/src/components/Overview/TransactionHistory.tsx +++ b/dapp/src/components/Overview/TransactionHistory.tsx @@ -1,6 +1,6 @@ import React from "react" import { CardBody, Card, CardProps } from "@chakra-ui/react" -import { TextMd } from "../shared/Typography" +import { TextMd } from "~/components/shared/Typography" export default function TransactionHistory(props: CardProps) { return ( diff --git a/dapp/src/components/Overview/index.tsx b/dapp/src/components/Overview/index.tsx index 0ac2b4041..1bee1a175 100644 --- a/dapp/src/components/Overview/index.tsx +++ b/dapp/src/components/Overview/index.tsx @@ -1,12 +1,12 @@ import React from "react" import { Button, Flex, Grid, HStack, Icon, Switch } from "@chakra-ui/react" +import { useDocsDrawer } from "~/hooks" +import { TextSm } from "~/components/shared/Typography" +import { ArrowUpRight } from "~/static/icons" +import { USD } from "~/constants" import PositionDetails from "./PositionDetails" import Statistics from "./Statistics" import TransactionHistory from "./TransactionHistory" -import { USD } from "../../constants" -import { ArrowUpRight } from "../../static/icons" -import { TextSm } from "../shared/Typography" -import { useDocsDrawer } from "../../hooks" export default function Overview() { const { onOpen } = useDocsDrawer() diff --git a/dapp/src/components/Sidebar/index.tsx b/dapp/src/components/Sidebar/index.tsx index a7625698f..2217cfe7c 100644 --- a/dapp/src/components/Sidebar/index.tsx +++ b/dapp/src/components/Sidebar/index.tsx @@ -1,6 +1,6 @@ import React from "react" import { Box, Button, useMultiStyleConfig } from "@chakra-ui/react" -import { useDocsDrawer, useSidebar } from "../../hooks" +import { useDocsDrawer, useSidebar } from "~/hooks" export default function Sidebar() { const { isOpen } = useSidebar() diff --git a/dapp/src/components/shared/Alert/index.tsx b/dapp/src/components/shared/Alert/index.tsx index 2ab05a8f2..cb3d94fd1 100644 --- a/dapp/src/components/shared/Alert/index.tsx +++ b/dapp/src/components/shared/Alert/index.tsx @@ -7,7 +7,7 @@ import { Icon, useMultiStyleConfig, } from "@chakra-ui/react" -import { AlertInfo, ArrowUpRight } from "../../../static/icons" +import { AlertInfo, ArrowUpRight } from "~/static/icons" const ICONS = { info: AlertInfo, diff --git a/dapp/src/components/shared/CurrencyBalance/index.tsx b/dapp/src/components/shared/CurrencyBalance/index.tsx index f44f7505e..65991979a 100644 --- a/dapp/src/components/shared/CurrencyBalance/index.tsx +++ b/dapp/src/components/shared/CurrencyBalance/index.tsx @@ -4,8 +4,8 @@ import { formatTokenAmount, getCurrencyByType, numberToLocaleString, -} from "../../../utils" -import { CurrencyType } from "../../../types" +} from "~/utils" +import { CurrencyType } from "~/types" export type CurrencyBalanceProps = { currency: CurrencyType diff --git a/dapp/src/components/shared/ModalBase/index.tsx b/dapp/src/components/shared/ModalBase/index.tsx index cfeb34472..034527614 100644 --- a/dapp/src/components/shared/ModalBase/index.tsx +++ b/dapp/src/components/shared/ModalBase/index.tsx @@ -5,12 +5,12 @@ import { ModalContent, ModalOverlay, } from "@chakra-ui/react" +import { useSidebar } from "~/hooks" import { ModalFlowContext, ModalFlowContextValue, TransactionContextProvider, -} from "../../../contexts" -import { useSidebar } from "../../../hooks" +} from "~/contexts" import SupportWrapper from "../../Modals/Support" export default function ModalBase({ diff --git a/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx index 7324f2251..3f07bfe45 100644 --- a/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx +++ b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx @@ -1,7 +1,7 @@ import React from "react" import { FormikProps, useField } from "formik" +import { CurrencyType } from "~/types" import { Form, FormTokenBalanceInput } from "../Form" -import { CurrencyType } from "../../../types" const TOKEN_AMOUNT_FIELD_NAME = "amount" diff --git a/dapp/src/components/shared/TokenAmountForm/index.tsx b/dapp/src/components/shared/TokenAmountForm/index.tsx index d6d0716c1..50a792af8 100644 --- a/dapp/src/components/shared/TokenAmountForm/index.tsx +++ b/dapp/src/components/shared/TokenAmountForm/index.tsx @@ -1,5 +1,5 @@ import { FormikErrors, withFormik } from "formik" -import { getErrorsObj, validateTokenAmount } from "../../../utils" +import { getErrorsObj, validateTokenAmount } from "~/utils" import TokenAmountFormBase, { TokenAmountFormBaseProps, TokenAmountFormValues, diff --git a/dapp/src/components/shared/TokenBalanceInput/index.tsx b/dapp/src/components/shared/TokenBalanceInput/index.tsx index 82aa75fee..289451c11 100644 --- a/dapp/src/components/shared/TokenBalanceInput/index.tsx +++ b/dapp/src/components/shared/TokenBalanceInput/index.tsx @@ -16,13 +16,13 @@ import { fixedPointNumberToString, getCurrencyByType, userAmountToBigInt, -} from "../../../utils" -import { CurrencyType } from "../../../types" +} from "~/utils" +import { AlertInfo } from "~/static/icons" +import { CurrencyType } from "~/types" import NumberFormatInput, { NumberFormatInputValues, } from "../NumberFormatInput" import { CurrencyBalance } from "../CurrencyBalance" -import { AlertInfo } from "../../../static/icons" const VARIANT = "balance" diff --git a/dapp/src/constants/currency.ts b/dapp/src/constants/currency.ts index 420adb8b6..75b1c572b 100644 --- a/dapp/src/constants/currency.ts +++ b/dapp/src/constants/currency.ts @@ -1,4 +1,4 @@ -import { Currency, CurrencyType } from "../types" +import { Currency, CurrencyType } from "~/types" export const BITCOIN: Currency = { name: "Bitcoin", diff --git a/dapp/src/contexts/TransactionContext.tsx b/dapp/src/contexts/TransactionContext.tsx index 384bfb2e5..47bb3b801 100644 --- a/dapp/src/contexts/TransactionContext.tsx +++ b/dapp/src/contexts/TransactionContext.tsx @@ -1,5 +1,5 @@ import React, { createContext, useMemo, useState } from "react" -import { TokenAmount } from "../types" +import { TokenAmount } from "~/types" type TransactionContextValue = { tokenAmount?: TokenAmount diff --git a/dapp/src/hooks/useDepositBTCTransaction.ts b/dapp/src/hooks/useDepositBTCTransaction.ts index a629e6485..861e55870 100644 --- a/dapp/src/hooks/useDepositBTCTransaction.ts +++ b/dapp/src/hooks/useDepositBTCTransaction.ts @@ -1,5 +1,5 @@ import { useCallback } from "react" -import { OnSuccessCallback } from "../types" +import { OnSuccessCallback } from "~/types" export function useDepositBTCTransaction(onSuccess?: OnSuccessCallback) { // TODO: sending transactions using the SDK diff --git a/dapp/src/hooks/useDocsDrawer.ts b/dapp/src/hooks/useDocsDrawer.ts index 4ce8bba3e..e560afa83 100644 --- a/dapp/src/hooks/useDocsDrawer.ts +++ b/dapp/src/hooks/useDocsDrawer.ts @@ -1,5 +1,5 @@ import { useContext } from "react" -import { DocsDrawerContext } from "../contexts" +import { DocsDrawerContext } from "~/contexts" export function useDocsDrawer() { const context = useContext(DocsDrawerContext) diff --git a/dapp/src/hooks/useModalFlowContext.ts b/dapp/src/hooks/useModalFlowContext.ts index 48882c561..fafb6a565 100644 --- a/dapp/src/hooks/useModalFlowContext.ts +++ b/dapp/src/hooks/useModalFlowContext.ts @@ -1,5 +1,5 @@ import { useContext } from "react" -import { ModalFlowContext } from "../contexts" +import { ModalFlowContext } from "~/contexts" export function useModalFlowContext() { const context = useContext(ModalFlowContext) diff --git a/dapp/src/hooks/useRequestBitcoinAccount.ts b/dapp/src/hooks/useRequestBitcoinAccount.ts index 036db196d..d780eb016 100644 --- a/dapp/src/hooks/useRequestBitcoinAccount.ts +++ b/dapp/src/hooks/useRequestBitcoinAccount.ts @@ -1,8 +1,8 @@ import { useRequestAccount } from "@ledgerhq/wallet-api-client-react" import { useCallback, useContext, useEffect } from "react" -import { CURRENCY_ID_BITCOIN } from "../constants" -import { UseRequestAccountReturn } from "../types" -import { WalletContext } from "../contexts" +import { WalletContext } from "~/contexts" +import { UseRequestAccountReturn } from "~/types" +import { CURRENCY_ID_BITCOIN } from "~/constants" export function useRequestBitcoinAccount(): UseRequestAccountReturn { const { setBtcAccount } = useContext(WalletContext) diff --git a/dapp/src/hooks/useRequestEthereumAccount.ts b/dapp/src/hooks/useRequestEthereumAccount.ts index 5c3cad1f1..d1dd87ad7 100644 --- a/dapp/src/hooks/useRequestEthereumAccount.ts +++ b/dapp/src/hooks/useRequestEthereumAccount.ts @@ -1,8 +1,8 @@ import { useRequestAccount } from "@ledgerhq/wallet-api-client-react" import { useCallback, useContext, useEffect } from "react" -import { CURRENCY_ID_ETHEREUM } from "../constants" -import { UseRequestAccountReturn } from "../types" -import { WalletContext } from "../contexts" +import { WalletContext } from "~/contexts" +import { UseRequestAccountReturn } from "~/types" +import { CURRENCY_ID_ETHEREUM } from "~/constants" export function useRequestEthereumAccount(): UseRequestAccountReturn { const { setEthAccount } = useContext(WalletContext) diff --git a/dapp/src/hooks/useSidebar.ts b/dapp/src/hooks/useSidebar.ts index 986143a89..714330b48 100644 --- a/dapp/src/hooks/useSidebar.ts +++ b/dapp/src/hooks/useSidebar.ts @@ -1,5 +1,5 @@ import { useContext } from "react" -import { SidebarContext } from "../contexts" +import { SidebarContext } from "~/contexts" export function useSidebar() { const context = useContext(SidebarContext) diff --git a/dapp/src/hooks/useSignMessage.ts b/dapp/src/hooks/useSignMessage.ts index cc3cadc3e..21ef804b0 100644 --- a/dapp/src/hooks/useSignMessage.ts +++ b/dapp/src/hooks/useSignMessage.ts @@ -1,7 +1,7 @@ import { useSignMessage as useSignMessageLedgerLive } from "@ledgerhq/wallet-api-client-react" import { useCallback, useEffect } from "react" +import { OnSuccessCallback } from "~/types" import { useWalletContext } from "./useWalletContext" -import { OnSuccessCallback } from "../types" const SIGN_MESSAGE = "Test message" diff --git a/dapp/src/hooks/useTransactionContext.ts b/dapp/src/hooks/useTransactionContext.ts index d28c8bf1b..85b663a51 100644 --- a/dapp/src/hooks/useTransactionContext.ts +++ b/dapp/src/hooks/useTransactionContext.ts @@ -1,5 +1,5 @@ import { useContext } from "react" -import { TransactionContext } from "../contexts" +import { TransactionContext } from "~/contexts" export function useTransactionContext() { const context = useContext(TransactionContext) diff --git a/dapp/src/hooks/useWalletContext.ts b/dapp/src/hooks/useWalletContext.ts index 0da19204b..c786a76dd 100644 --- a/dapp/src/hooks/useWalletContext.ts +++ b/dapp/src/hooks/useWalletContext.ts @@ -1,5 +1,5 @@ import { useContext } from "react" -import { WalletContext } from "../contexts" +import { WalletContext } from "~/contexts" export function useWalletContext() { const context = useContext(WalletContext) diff --git a/dapp/src/utils/currency.ts b/dapp/src/utils/currency.ts index 39eda0651..99d93710a 100644 --- a/dapp/src/utils/currency.ts +++ b/dapp/src/utils/currency.ts @@ -1,5 +1,5 @@ -import { CURRENCIES_BY_TYPE } from "../constants" -import { Currency, CurrencyType } from "../types" +import { Currency, CurrencyType } from "~/types" +import { CURRENCIES_BY_TYPE } from "~/constants" export const getCurrencyByType = (currency: CurrencyType): Currency => CURRENCIES_BY_TYPE[currency] diff --git a/dapp/src/utils/forms.ts b/dapp/src/utils/forms.ts index 9f7f34759..a2fc7b8c4 100644 --- a/dapp/src/utils/forms.ts +++ b/dapp/src/utils/forms.ts @@ -1,4 +1,4 @@ -import { CurrencyType } from "../types" +import { CurrencyType } from "~/types" import { getCurrencyByType } from "./currency" import { formatTokenAmount } from "./numbers" diff --git a/dapp/vite.config.ts b/dapp/vite.config.ts index 14ad46477..71034c086 100644 --- a/dapp/vite.config.ts +++ b/dapp/vite.config.ts @@ -1,7 +1,6 @@ import { defineConfig } from "vite" import react from "@vitejs/plugin-react" import { nodePolyfills } from "vite-plugin-node-polyfills" -import eslint from "vite-plugin-eslint" import { resolve } from "path" @@ -11,5 +10,5 @@ export default defineConfig({ "~": resolve(__dirname, "./src"), }, }, - plugins: [nodePolyfills(), react(), eslint()], + plugins: [nodePolyfills(), react()], }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 48a4c27dc..89f1905c3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -181,9 +181,6 @@ importers: vite: specifier: ^5.0.2 version: 5.0.2 - vite-plugin-eslint: - specifier: ^1.8.1 - version: 1.8.1(eslint@8.54.0)(vite@5.0.2) vite-plugin-node-polyfills: specifier: ^0.19.0 version: 0.19.0(vite@5.0.2) @@ -385,7 +382,7 @@ packages: '@babel/traverse': 7.23.4 '@babel/types': 7.23.4 convert-source-map: 2.0.0 - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 gensync: 1.0.0-beta.2 json5: 2.2.3 semver: 6.3.1 @@ -1629,7 +1626,7 @@ packages: '@babel/helper-split-export-declaration': 7.22.6 '@babel/parser': 7.23.4 '@babel/types': 7.23.4 - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 globals: 11.12.0 transitivePeerDependencies: - supports-color @@ -3182,7 +3179,7 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: ajv: 6.12.6 - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 espree: 9.6.1 globals: 13.23.0 ignore: 5.3.0 @@ -3787,7 +3784,7 @@ packages: engines: {node: '>=10.10.0'} dependencies: '@humanwhocodes/object-schema': 2.0.1 - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 minimatch: 3.1.2 transitivePeerDependencies: - supports-color @@ -5100,14 +5097,6 @@ packages: magic-string: 0.30.5 dev: true - /@rollup/pluginutils@4.2.1: - resolution: {integrity: sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==} - engines: {node: '>= 8.0.0'} - dependencies: - estree-walker: 2.0.2 - picomatch: 2.3.1 - dev: true - /@rollup/pluginutils@5.1.0: resolution: {integrity: sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==} engines: {node: '>=14.0.0'} @@ -5813,7 +5802,7 @@ packages: '@typescript-eslint/type-utils': 6.12.0(eslint@8.54.0)(typescript@5.3.2) '@typescript-eslint/utils': 6.12.0(eslint@8.54.0)(typescript@5.3.2) '@typescript-eslint/visitor-keys': 6.12.0 - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 eslint: 8.54.0 graphemer: 1.4.0 ignore: 5.3.0 @@ -5858,7 +5847,7 @@ packages: '@typescript-eslint/types': 6.12.0 '@typescript-eslint/typescript-estree': 6.12.0(typescript@5.3.2) '@typescript-eslint/visitor-keys': 6.12.0 - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 eslint: 8.54.0 typescript: 5.3.2 transitivePeerDependencies: @@ -5909,7 +5898,7 @@ packages: dependencies: '@typescript-eslint/typescript-estree': 6.12.0(typescript@5.3.2) '@typescript-eslint/utils': 6.12.0(eslint@8.54.0)(typescript@5.3.2) - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 eslint: 8.54.0 ts-api-utils: 1.0.3(typescript@5.3.2) typescript: 5.3.2 @@ -5956,7 +5945,7 @@ packages: dependencies: '@typescript-eslint/types': 6.12.0 '@typescript-eslint/visitor-keys': 6.12.0 - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 semver: 7.5.4 @@ -7986,6 +7975,17 @@ packages: dependencies: ms: 2.1.3 + /debug@4.3.4: + resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} + engines: {node: '>=6.0'} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + dependencies: + ms: 2.1.2 + /debug@4.3.4(supports-color@8.1.1): resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} @@ -9046,7 +9046,7 @@ packages: ajv: 6.12.6 chalk: 4.1.2 cross-spawn: 7.0.3 - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 doctrine: 3.0.0 escape-string-regexp: 4.0.0 eslint-scope: 7.2.2 @@ -13992,14 +13992,6 @@ packages: bn.js: 5.2.1 dev: true - /rollup@2.79.1: - resolution: {integrity: sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==} - engines: {node: '>=10.0.0'} - hasBin: true - optionalDependencies: - fsevents: 2.3.3 - dev: true - /rollup@4.5.1: resolution: {integrity: sha512-0EQribZoPKpb5z1NW/QYm3XSR//Xr8BeEXU49Lc/mQmpmVVG5jPUVrpc2iptup/0WMrY9mzas0fxH+TjYvG2CA==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} @@ -15568,19 +15560,6 @@ packages: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} - /vite-plugin-eslint@1.8.1(eslint@8.54.0)(vite@5.0.2): - resolution: {integrity: sha512-PqdMf3Y2fLO9FsNPmMX+//2BF5SF8nEWspZdgl4kSt7UvHDRHVVfHvxsD7ULYzZrJDGRxR81Nq7TOFgwMnUang==} - peerDependencies: - eslint: '>=7' - vite: '>=2' - dependencies: - '@rollup/pluginutils': 4.2.1 - '@types/eslint': 8.44.7 - eslint: 8.54.0 - rollup: 2.79.1 - vite: 5.0.2 - dev: true - /vite-plugin-node-polyfills@0.19.0(vite@5.0.2): resolution: {integrity: sha512-AhdVxAmVnd1doUlIRGUGV6ZRPfB9BvIwDF10oCOmL742IsvsFIAV4tSMxSfu5e0Px0QeJLgWVOSbtHIvblzqMw==} peerDependencies: @@ -15601,7 +15580,7 @@ packages: vite: optional: true dependencies: - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 globrex: 0.1.2 tsconfck: 2.1.2(typescript@5.3.2) vite: 5.0.2 From 59731bbba5c2e933be8d3f3e1655b157ff03cf6e Mon Sep 17 00:00:00 2001 From: ioay Date: Thu, 11 Jan 2024 16:14:04 +0100 Subject: [PATCH 45/49] Change prefix for alias: ~ -> # --- dapp/.eslintrc | 2 +- dapp/src/components/DocsDrawer/index.tsx | 4 ++-- dapp/src/components/GlobalStyles/index.tsx | 10 +++++----- dapp/src/components/Header/ConnectWallet.tsx | 10 +++++----- dapp/src/components/Header/index.tsx | 2 +- dapp/src/components/Modals/ActionForm/index.tsx | 2 +- dapp/src/components/Modals/Staking/DepositBTC.tsx | 6 +++--- dapp/src/components/Modals/Staking/Overview/index.tsx | 4 ++-- dapp/src/components/Modals/Staking/Overview/steps.tsx | 2 +- dapp/src/components/Modals/Staking/SignMessage.tsx | 6 +++--- .../components/Modals/Staking/StakeForm/Details.tsx | 8 ++++---- dapp/src/components/Modals/Staking/StakeForm/index.tsx | 10 +++++----- .../Modals/Staking/components/StakingSteps.tsx | 6 +++--- dapp/src/components/Modals/Staking/index.tsx | 4 ++-- dapp/src/components/Modals/Support/MissingAccount.tsx | 8 ++++---- dapp/src/components/Modals/Support/index.tsx | 4 ++-- dapp/src/components/Overview/PositionDetails.tsx | 6 +++--- dapp/src/components/Overview/Statistics.tsx | 2 +- dapp/src/components/Overview/TransactionHistory.tsx | 2 +- dapp/src/components/Overview/index.tsx | 8 ++++---- dapp/src/components/Sidebar/index.tsx | 2 +- dapp/src/components/shared/Alert/index.tsx | 2 +- dapp/src/components/shared/CurrencyBalance/index.tsx | 4 ++-- dapp/src/components/shared/ModalBase/index.tsx | 4 ++-- .../shared/TokenAmountForm/TokenAmountFormBase.tsx | 2 +- dapp/src/components/shared/TokenAmountForm/index.tsx | 2 +- dapp/src/components/shared/TokenBalanceInput/index.tsx | 6 +++--- dapp/src/constants/currency.ts | 2 +- dapp/src/contexts/TransactionContext.tsx | 2 +- dapp/src/hooks/useDepositBTCTransaction.ts | 2 +- dapp/src/hooks/useDocsDrawer.ts | 2 +- dapp/src/hooks/useModalFlowContext.ts | 2 +- dapp/src/hooks/useRequestBitcoinAccount.ts | 6 +++--- dapp/src/hooks/useRequestEthereumAccount.ts | 6 +++--- dapp/src/hooks/useSidebar.ts | 2 +- dapp/src/hooks/useSignMessage.ts | 2 +- dapp/src/hooks/useTransactionContext.ts | 2 +- dapp/src/hooks/useWalletContext.ts | 2 +- dapp/src/utils/currency.ts | 4 ++-- dapp/src/utils/forms.ts | 2 +- dapp/tsconfig.json | 2 +- dapp/vite.config.ts | 2 +- 42 files changed, 84 insertions(+), 84 deletions(-) diff --git a/dapp/.eslintrc b/dapp/.eslintrc index 528de4b43..637e91d05 100644 --- a/dapp/.eslintrc +++ b/dapp/.eslintrc @@ -21,7 +21,7 @@ "import/resolver": { "alias": { "map": [ - ["~", "./src"] + ["#", "./src"] ], "extensions": [".js", ".jsx",".ts", ".tsx"] } diff --git a/dapp/src/components/DocsDrawer/index.tsx b/dapp/src/components/DocsDrawer/index.tsx index 35e49647c..060c6e731 100644 --- a/dapp/src/components/DocsDrawer/index.tsx +++ b/dapp/src/components/DocsDrawer/index.tsx @@ -5,8 +5,8 @@ import { DrawerContent, DrawerOverlay, } from "@chakra-ui/react" -import { useDocsDrawer } from "~/hooks" -import { TextMd } from "~/components/shared/Typography" +import { useDocsDrawer } from "#/hooks" +import { TextMd } from "#/components/shared/Typography" export default function DocsDrawer() { const { isOpen, onClose } = useDocsDrawer() diff --git a/dapp/src/components/GlobalStyles/index.tsx b/dapp/src/components/GlobalStyles/index.tsx index d316cead6..352fe7af0 100644 --- a/dapp/src/components/GlobalStyles/index.tsx +++ b/dapp/src/components/GlobalStyles/index.tsx @@ -1,11 +1,11 @@ import React from "react" import { Global } from "@emotion/react" -import SegmentRegular from "~/fonts/Segment-Regular.otf" -import SegmentMedium from "~/fonts/Segment-Medium.otf" -import SegmentSemiBold from "~/fonts/Segment-SemiBold.otf" -import SegmentBold from "~/fonts/Segment-Bold.otf" -import SegmentBlack from "~/fonts/Segment-Black.otf" +import SegmentRegular from "#/fonts/Segment-Regular.otf" +import SegmentMedium from "#/fonts/Segment-Medium.otf" +import SegmentSemiBold from "#/fonts/Segment-SemiBold.otf" +import SegmentBold from "#/fonts/Segment-Bold.otf" +import SegmentBlack from "#/fonts/Segment-Black.otf" export default function GlobalStyles() { return ( diff --git a/dapp/src/components/Header/ConnectWallet.tsx b/dapp/src/components/Header/ConnectWallet.tsx index 28bad070d..5319a04ca 100644 --- a/dapp/src/components/Header/ConnectWallet.tsx +++ b/dapp/src/components/Header/ConnectWallet.tsx @@ -5,11 +5,11 @@ import { useRequestBitcoinAccount, useRequestEthereumAccount, useWalletContext, -} from "~/hooks" -import { CurrencyBalance } from "~/components/shared/CurrencyBalance" -import { TextMd } from "~/components/shared/Typography" -import { Bitcoin, Ethereum } from "~/static/icons" -import { truncateAddress } from "~/utils" +} from "#/hooks" +import { CurrencyBalance } from "#/components/shared/CurrencyBalance" +import { TextMd } from "#/components/shared/Typography" +import { Bitcoin, Ethereum } from "#/static/icons" +import { truncateAddress } from "#/utils" export type ConnectButtonsProps = { leftIcon: typeof Icon diff --git a/dapp/src/components/Header/index.tsx b/dapp/src/components/Header/index.tsx index b0d47f2ab..480cb502e 100644 --- a/dapp/src/components/Header/index.tsx +++ b/dapp/src/components/Header/index.tsx @@ -1,6 +1,6 @@ import React from "react" import { Flex, HStack, Icon } from "@chakra-ui/react" -import { AcreLogo } from "~/static/icons" +import { AcreLogo } from "#/static/icons" import ConnectWallet from "./ConnectWallet" export default function Header() { diff --git a/dapp/src/components/Modals/ActionForm/index.tsx b/dapp/src/components/Modals/ActionForm/index.tsx index d6a595d5d..eabb156bb 100644 --- a/dapp/src/components/Modals/ActionForm/index.tsx +++ b/dapp/src/components/Modals/ActionForm/index.tsx @@ -7,7 +7,7 @@ import { TabPanels, TabPanel, } from "@chakra-ui/react" -import { useModalFlowContext } from "~/hooks" +import { useModalFlowContext } from "#/hooks" import StakeForm from "../Staking/StakeForm" const TABS = ["stake", "unstake"] as const diff --git a/dapp/src/components/Modals/Staking/DepositBTC.tsx b/dapp/src/components/Modals/Staking/DepositBTC.tsx index 20e649956..924a0ee24 100644 --- a/dapp/src/components/Modals/Staking/DepositBTC.tsx +++ b/dapp/src/components/Modals/Staking/DepositBTC.tsx @@ -1,7 +1,7 @@ import React from "react" -import { useDepositBTCTransaction, useModalFlowContext } from "~/hooks" -import Alert from "~/components/shared/Alert" -import { TextMd } from "~/components/shared/Typography" +import { useDepositBTCTransaction, useModalFlowContext } from "#/hooks" +import Alert from "#/components/shared/Alert" +import { TextMd } from "#/components/shared/Typography" import StakingSteps from "./components/StakingSteps" export default function DepositBTC() { diff --git a/dapp/src/components/Modals/Staking/Overview/index.tsx b/dapp/src/components/Modals/Staking/Overview/index.tsx index 330bb7289..af2485db6 100644 --- a/dapp/src/components/Modals/Staking/Overview/index.tsx +++ b/dapp/src/components/Modals/Staking/Overview/index.tsx @@ -6,8 +6,8 @@ import { ModalHeader, StepNumber, } from "@chakra-ui/react" -import StepperBase from "~/components/shared/StepperBase" -import { useModalFlowContext } from "~/hooks" +import StepperBase from "#/components/shared/StepperBase" +import { useModalFlowContext } from "#/hooks" import { STEPS } from "./steps" export default function Overview() { diff --git a/dapp/src/components/Modals/Staking/Overview/steps.tsx b/dapp/src/components/Modals/Staking/Overview/steps.tsx index 532e35e50..7a6c3ce7a 100644 --- a/dapp/src/components/Modals/Staking/Overview/steps.tsx +++ b/dapp/src/components/Modals/Staking/Overview/steps.tsx @@ -1,5 +1,5 @@ import React from "react" -import { StepBase } from "~/components/shared/StepperBase" +import { StepBase } from "#/components/shared/StepperBase" import { Description, Title } from "../components/StakingSteps" export const STEPS: StepBase[] = [ diff --git a/dapp/src/components/Modals/Staking/SignMessage.tsx b/dapp/src/components/Modals/Staking/SignMessage.tsx index dfe7d2dc1..e3cda7886 100644 --- a/dapp/src/components/Modals/Staking/SignMessage.tsx +++ b/dapp/src/components/Modals/Staking/SignMessage.tsx @@ -1,8 +1,8 @@ import React from "react" import { Highlight } from "@chakra-ui/react" -import { useModalFlowContext, useSignMessage } from "~/hooks" -import Alert from "~/components/shared/Alert" -import { TextMd } from "~/components/shared/Typography" +import { useModalFlowContext, useSignMessage } from "#/hooks" +import Alert from "#/components/shared/Alert" +import { TextMd } from "#/components/shared/Typography" import StakingSteps from "./components/StakingSteps" export default function SignMessage() { diff --git a/dapp/src/components/Modals/Staking/StakeForm/Details.tsx b/dapp/src/components/Modals/Staking/StakeForm/Details.tsx index 5d16cd8e2..698e6da54 100644 --- a/dapp/src/components/Modals/Staking/StakeForm/Details.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm/Details.tsx @@ -1,9 +1,9 @@ import React from "react" import { List } from "@chakra-ui/react" -import TransactionDetailsAmountItem from "~/components/shared/TransactionDetails/AmountItem" -import { useTokenAmountFormValue } from "~/components/shared/TokenAmountForm/TokenAmountFormBase" -import { useTransactionDetails } from "~/hooks" -import { CurrencyType } from "~/types" +import TransactionDetailsAmountItem from "#/components/shared/TransactionDetails/AmountItem" +import { useTokenAmountFormValue } from "#/components/shared/TokenAmountForm/TokenAmountFormBase" +import { useTransactionDetails } from "#/hooks" +import { CurrencyType } from "#/types" function Details({ currency }: { currency: CurrencyType }) { const value = useTokenAmountFormValue() diff --git a/dapp/src/components/Modals/Staking/StakeForm/index.tsx b/dapp/src/components/Modals/Staking/StakeForm/index.tsx index 5f9b57bf0..e5d5a0754 100644 --- a/dapp/src/components/Modals/Staking/StakeForm/index.tsx +++ b/dapp/src/components/Modals/Staking/StakeForm/index.tsx @@ -1,10 +1,10 @@ import React, { useCallback } from "react" import { Button } from "@chakra-ui/react" -import { BITCOIN_MIN_AMOUNT } from "~/constants" -import { ModalStep } from "~/contexts" -import TokenAmountForm from "~/components/shared/TokenAmountForm" -import { TokenAmountFormValues } from "~/components/shared/TokenAmountForm/TokenAmountFormBase" -import { useWalletContext, useTransactionContext } from "~/hooks" +import { BITCOIN_MIN_AMOUNT } from "#/constants" +import { ModalStep } from "#/contexts" +import TokenAmountForm from "#/components/shared/TokenAmountForm" +import { TokenAmountFormValues } from "#/components/shared/TokenAmountForm/TokenAmountFormBase" +import { useWalletContext, useTransactionContext } from "#/hooks" import Details from "./Details" function StakeForm({ goNext }: ModalStep) { diff --git a/dapp/src/components/Modals/Staking/components/StakingSteps.tsx b/dapp/src/components/Modals/Staking/components/StakingSteps.tsx index 4f0a11d06..f092ad079 100644 --- a/dapp/src/components/Modals/Staking/components/StakingSteps.tsx +++ b/dapp/src/components/Modals/Staking/components/StakingSteps.tsx @@ -6,9 +6,9 @@ import { ModalFooter, ModalHeader, } from "@chakra-ui/react" -import { TextLg, TextMd } from "~/components/shared/Typography" -import StepperBase, { StepBase } from "~/components/shared/StepperBase" -import Spinner from "~/components/shared/Spinner" +import { TextLg, TextMd } from "#/components/shared/Typography" +import StepperBase, { StepBase } from "#/components/shared/StepperBase" +import Spinner from "#/components/shared/Spinner" export function Title({ children }: { children: React.ReactNode }) { return {children} diff --git a/dapp/src/components/Modals/Staking/index.tsx b/dapp/src/components/Modals/Staking/index.tsx index 8bad1b0c4..e74dd57ea 100644 --- a/dapp/src/components/Modals/Staking/index.tsx +++ b/dapp/src/components/Modals/Staking/index.tsx @@ -1,6 +1,6 @@ import React from "react" -import { useModalFlowContext } from "~/hooks" -import ModalBase from "~/components/shared/ModalBase" +import { useModalFlowContext } from "#/hooks" +import ModalBase from "#/components/shared/ModalBase" import Overview from "./Overview" import ActionForm from "../ActionForm" import SignMessage from "./SignMessage" diff --git a/dapp/src/components/Modals/Support/MissingAccount.tsx b/dapp/src/components/Modals/Support/MissingAccount.tsx index df879d260..89ca3effd 100644 --- a/dapp/src/components/Modals/Support/MissingAccount.tsx +++ b/dapp/src/components/Modals/Support/MissingAccount.tsx @@ -7,10 +7,10 @@ import { ModalFooter, ModalHeader, } from "@chakra-ui/react" -import { TextMd } from "~/components/shared/Typography" -import Alert from "~/components/shared/Alert" -import { getCurrencyByType } from "~/utils" -import { CurrencyType, RequestAccountParams } from "~/types" +import { TextMd } from "#/components/shared/Typography" +import Alert from "#/components/shared/Alert" +import { getCurrencyByType } from "#/utils" +import { CurrencyType, RequestAccountParams } from "#/types" type MissingAccountProps = { currency: CurrencyType diff --git a/dapp/src/components/Modals/Support/index.tsx b/dapp/src/components/Modals/Support/index.tsx index ca6e51453..ae5aa98eb 100644 --- a/dapp/src/components/Modals/Support/index.tsx +++ b/dapp/src/components/Modals/Support/index.tsx @@ -3,8 +3,8 @@ import { useRequestBitcoinAccount, useRequestEthereumAccount, useWalletContext, -} from "~/hooks" -import { ConnectBTCAccount, ConnectETHAccount } from "~/static/icons" +} from "#/hooks" +import { ConnectBTCAccount, ConnectETHAccount } from "#/static/icons" import MissingAccount from "./MissingAccount" export default function SupportWrapper({ diff --git a/dapp/src/components/Overview/PositionDetails.tsx b/dapp/src/components/Overview/PositionDetails.tsx index 907be66f1..0555c3ddf 100644 --- a/dapp/src/components/Overview/PositionDetails.tsx +++ b/dapp/src/components/Overview/PositionDetails.tsx @@ -10,9 +10,9 @@ import { CardProps, useBoolean, } from "@chakra-ui/react" -import { CurrencyBalanceWithConversion } from "~/components/shared/CurrencyBalanceWithConversion" -import { TextMd } from "~/components/shared/Typography" -import { Info } from "~/static/icons" +import { CurrencyBalanceWithConversion } from "#/components/shared/CurrencyBalanceWithConversion" +import { TextMd } from "#/components/shared/Typography" +import { Info } from "#/static/icons" import StakingModal from "../Modals/Staking" export default function PositionDetails(props: CardProps) { diff --git a/dapp/src/components/Overview/Statistics.tsx b/dapp/src/components/Overview/Statistics.tsx index e8a5df0c5..b8681ac3e 100644 --- a/dapp/src/components/Overview/Statistics.tsx +++ b/dapp/src/components/Overview/Statistics.tsx @@ -1,6 +1,6 @@ import React from "react" import { CardBody, Card, CardProps } from "@chakra-ui/react" -import { TextMd } from "~/components/shared/Typography" +import { TextMd } from "#/components/shared/Typography" export default function Statistics(props: CardProps) { return ( diff --git a/dapp/src/components/Overview/TransactionHistory.tsx b/dapp/src/components/Overview/TransactionHistory.tsx index 557556bd4..a151804df 100644 --- a/dapp/src/components/Overview/TransactionHistory.tsx +++ b/dapp/src/components/Overview/TransactionHistory.tsx @@ -1,6 +1,6 @@ import React from "react" import { CardBody, Card, CardProps } from "@chakra-ui/react" -import { TextMd } from "~/components/shared/Typography" +import { TextMd } from "#/components/shared/Typography" export default function TransactionHistory(props: CardProps) { return ( diff --git a/dapp/src/components/Overview/index.tsx b/dapp/src/components/Overview/index.tsx index 1bee1a175..d67bed7a8 100644 --- a/dapp/src/components/Overview/index.tsx +++ b/dapp/src/components/Overview/index.tsx @@ -1,9 +1,9 @@ import React from "react" import { Button, Flex, Grid, HStack, Icon, Switch } from "@chakra-ui/react" -import { useDocsDrawer } from "~/hooks" -import { TextSm } from "~/components/shared/Typography" -import { ArrowUpRight } from "~/static/icons" -import { USD } from "~/constants" +import { useDocsDrawer } from "#/hooks" +import { TextSm } from "#/components/shared/Typography" +import { ArrowUpRight } from "#/static/icons" +import { USD } from "#/constants" import PositionDetails from "./PositionDetails" import Statistics from "./Statistics" import TransactionHistory from "./TransactionHistory" diff --git a/dapp/src/components/Sidebar/index.tsx b/dapp/src/components/Sidebar/index.tsx index 2217cfe7c..faebd8be0 100644 --- a/dapp/src/components/Sidebar/index.tsx +++ b/dapp/src/components/Sidebar/index.tsx @@ -1,6 +1,6 @@ import React from "react" import { Box, Button, useMultiStyleConfig } from "@chakra-ui/react" -import { useDocsDrawer, useSidebar } from "~/hooks" +import { useDocsDrawer, useSidebar } from "#/hooks" export default function Sidebar() { const { isOpen } = useSidebar() diff --git a/dapp/src/components/shared/Alert/index.tsx b/dapp/src/components/shared/Alert/index.tsx index cb3d94fd1..687e0599b 100644 --- a/dapp/src/components/shared/Alert/index.tsx +++ b/dapp/src/components/shared/Alert/index.tsx @@ -7,7 +7,7 @@ import { Icon, useMultiStyleConfig, } from "@chakra-ui/react" -import { AlertInfo, ArrowUpRight } from "~/static/icons" +import { AlertInfo, ArrowUpRight } from "#/static/icons" const ICONS = { info: AlertInfo, diff --git a/dapp/src/components/shared/CurrencyBalance/index.tsx b/dapp/src/components/shared/CurrencyBalance/index.tsx index 65991979a..fdf136420 100644 --- a/dapp/src/components/shared/CurrencyBalance/index.tsx +++ b/dapp/src/components/shared/CurrencyBalance/index.tsx @@ -4,8 +4,8 @@ import { formatTokenAmount, getCurrencyByType, numberToLocaleString, -} from "~/utils" -import { CurrencyType } from "~/types" +} from "#/utils" +import { CurrencyType } from "#/types" export type CurrencyBalanceProps = { currency: CurrencyType diff --git a/dapp/src/components/shared/ModalBase/index.tsx b/dapp/src/components/shared/ModalBase/index.tsx index 034527614..a2c31cddd 100644 --- a/dapp/src/components/shared/ModalBase/index.tsx +++ b/dapp/src/components/shared/ModalBase/index.tsx @@ -5,12 +5,12 @@ import { ModalContent, ModalOverlay, } from "@chakra-ui/react" -import { useSidebar } from "~/hooks" +import { useSidebar } from "#/hooks" import { ModalFlowContext, ModalFlowContextValue, TransactionContextProvider, -} from "~/contexts" +} from "#/contexts" import SupportWrapper from "../../Modals/Support" export default function ModalBase({ diff --git a/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx index 3f07bfe45..18e4bd712 100644 --- a/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx +++ b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx @@ -1,6 +1,6 @@ import React from "react" import { FormikProps, useField } from "formik" -import { CurrencyType } from "~/types" +import { CurrencyType } from "#/types" import { Form, FormTokenBalanceInput } from "../Form" const TOKEN_AMOUNT_FIELD_NAME = "amount" diff --git a/dapp/src/components/shared/TokenAmountForm/index.tsx b/dapp/src/components/shared/TokenAmountForm/index.tsx index 50a792af8..c4b8dfec7 100644 --- a/dapp/src/components/shared/TokenAmountForm/index.tsx +++ b/dapp/src/components/shared/TokenAmountForm/index.tsx @@ -1,5 +1,5 @@ import { FormikErrors, withFormik } from "formik" -import { getErrorsObj, validateTokenAmount } from "~/utils" +import { getErrorsObj, validateTokenAmount } from "#/utils" import TokenAmountFormBase, { TokenAmountFormBaseProps, TokenAmountFormValues, diff --git a/dapp/src/components/shared/TokenBalanceInput/index.tsx b/dapp/src/components/shared/TokenBalanceInput/index.tsx index 289451c11..68975da92 100644 --- a/dapp/src/components/shared/TokenBalanceInput/index.tsx +++ b/dapp/src/components/shared/TokenBalanceInput/index.tsx @@ -16,9 +16,9 @@ import { fixedPointNumberToString, getCurrencyByType, userAmountToBigInt, -} from "~/utils" -import { AlertInfo } from "~/static/icons" -import { CurrencyType } from "~/types" +} from "#/utils" +import { AlertInfo } from "#/static/icons" +import { CurrencyType } from "#/types" import NumberFormatInput, { NumberFormatInputValues, } from "../NumberFormatInput" diff --git a/dapp/src/constants/currency.ts b/dapp/src/constants/currency.ts index 75b1c572b..6f747bb1a 100644 --- a/dapp/src/constants/currency.ts +++ b/dapp/src/constants/currency.ts @@ -1,4 +1,4 @@ -import { Currency, CurrencyType } from "~/types" +import { Currency, CurrencyType } from "#/types" export const BITCOIN: Currency = { name: "Bitcoin", diff --git a/dapp/src/contexts/TransactionContext.tsx b/dapp/src/contexts/TransactionContext.tsx index 47bb3b801..3064bd530 100644 --- a/dapp/src/contexts/TransactionContext.tsx +++ b/dapp/src/contexts/TransactionContext.tsx @@ -1,5 +1,5 @@ import React, { createContext, useMemo, useState } from "react" -import { TokenAmount } from "~/types" +import { TokenAmount } from "#/types" type TransactionContextValue = { tokenAmount?: TokenAmount diff --git a/dapp/src/hooks/useDepositBTCTransaction.ts b/dapp/src/hooks/useDepositBTCTransaction.ts index 861e55870..0bef0c4be 100644 --- a/dapp/src/hooks/useDepositBTCTransaction.ts +++ b/dapp/src/hooks/useDepositBTCTransaction.ts @@ -1,5 +1,5 @@ import { useCallback } from "react" -import { OnSuccessCallback } from "~/types" +import { OnSuccessCallback } from "#/types" export function useDepositBTCTransaction(onSuccess?: OnSuccessCallback) { // TODO: sending transactions using the SDK diff --git a/dapp/src/hooks/useDocsDrawer.ts b/dapp/src/hooks/useDocsDrawer.ts index e560afa83..3536dba2a 100644 --- a/dapp/src/hooks/useDocsDrawer.ts +++ b/dapp/src/hooks/useDocsDrawer.ts @@ -1,5 +1,5 @@ import { useContext } from "react" -import { DocsDrawerContext } from "~/contexts" +import { DocsDrawerContext } from "#/contexts" export function useDocsDrawer() { const context = useContext(DocsDrawerContext) diff --git a/dapp/src/hooks/useModalFlowContext.ts b/dapp/src/hooks/useModalFlowContext.ts index fafb6a565..fda6eb681 100644 --- a/dapp/src/hooks/useModalFlowContext.ts +++ b/dapp/src/hooks/useModalFlowContext.ts @@ -1,5 +1,5 @@ import { useContext } from "react" -import { ModalFlowContext } from "~/contexts" +import { ModalFlowContext } from "#/contexts" export function useModalFlowContext() { const context = useContext(ModalFlowContext) diff --git a/dapp/src/hooks/useRequestBitcoinAccount.ts b/dapp/src/hooks/useRequestBitcoinAccount.ts index d780eb016..051467dcf 100644 --- a/dapp/src/hooks/useRequestBitcoinAccount.ts +++ b/dapp/src/hooks/useRequestBitcoinAccount.ts @@ -1,8 +1,8 @@ import { useRequestAccount } from "@ledgerhq/wallet-api-client-react" import { useCallback, useContext, useEffect } from "react" -import { WalletContext } from "~/contexts" -import { UseRequestAccountReturn } from "~/types" -import { CURRENCY_ID_BITCOIN } from "~/constants" +import { WalletContext } from "#/contexts" +import { UseRequestAccountReturn } from "#/types" +import { CURRENCY_ID_BITCOIN } from "#/constants" export function useRequestBitcoinAccount(): UseRequestAccountReturn { const { setBtcAccount } = useContext(WalletContext) diff --git a/dapp/src/hooks/useRequestEthereumAccount.ts b/dapp/src/hooks/useRequestEthereumAccount.ts index d1dd87ad7..fcf18c6ff 100644 --- a/dapp/src/hooks/useRequestEthereumAccount.ts +++ b/dapp/src/hooks/useRequestEthereumAccount.ts @@ -1,8 +1,8 @@ import { useRequestAccount } from "@ledgerhq/wallet-api-client-react" import { useCallback, useContext, useEffect } from "react" -import { WalletContext } from "~/contexts" -import { UseRequestAccountReturn } from "~/types" -import { CURRENCY_ID_ETHEREUM } from "~/constants" +import { WalletContext } from "#/contexts" +import { UseRequestAccountReturn } from "#/types" +import { CURRENCY_ID_ETHEREUM } from "#/constants" export function useRequestEthereumAccount(): UseRequestAccountReturn { const { setEthAccount } = useContext(WalletContext) diff --git a/dapp/src/hooks/useSidebar.ts b/dapp/src/hooks/useSidebar.ts index 714330b48..944364076 100644 --- a/dapp/src/hooks/useSidebar.ts +++ b/dapp/src/hooks/useSidebar.ts @@ -1,5 +1,5 @@ import { useContext } from "react" -import { SidebarContext } from "~/contexts" +import { SidebarContext } from "#/contexts" export function useSidebar() { const context = useContext(SidebarContext) diff --git a/dapp/src/hooks/useSignMessage.ts b/dapp/src/hooks/useSignMessage.ts index 21ef804b0..cd38d1001 100644 --- a/dapp/src/hooks/useSignMessage.ts +++ b/dapp/src/hooks/useSignMessage.ts @@ -1,6 +1,6 @@ import { useSignMessage as useSignMessageLedgerLive } from "@ledgerhq/wallet-api-client-react" import { useCallback, useEffect } from "react" -import { OnSuccessCallback } from "~/types" +import { OnSuccessCallback } from "#/types" import { useWalletContext } from "./useWalletContext" const SIGN_MESSAGE = "Test message" diff --git a/dapp/src/hooks/useTransactionContext.ts b/dapp/src/hooks/useTransactionContext.ts index 85b663a51..41a8a8359 100644 --- a/dapp/src/hooks/useTransactionContext.ts +++ b/dapp/src/hooks/useTransactionContext.ts @@ -1,5 +1,5 @@ import { useContext } from "react" -import { TransactionContext } from "~/contexts" +import { TransactionContext } from "#/contexts" export function useTransactionContext() { const context = useContext(TransactionContext) diff --git a/dapp/src/hooks/useWalletContext.ts b/dapp/src/hooks/useWalletContext.ts index c786a76dd..afca84aff 100644 --- a/dapp/src/hooks/useWalletContext.ts +++ b/dapp/src/hooks/useWalletContext.ts @@ -1,5 +1,5 @@ import { useContext } from "react" -import { WalletContext } from "~/contexts" +import { WalletContext } from "#/contexts" export function useWalletContext() { const context = useContext(WalletContext) diff --git a/dapp/src/utils/currency.ts b/dapp/src/utils/currency.ts index 99d93710a..4d8b02a78 100644 --- a/dapp/src/utils/currency.ts +++ b/dapp/src/utils/currency.ts @@ -1,5 +1,5 @@ -import { Currency, CurrencyType } from "~/types" -import { CURRENCIES_BY_TYPE } from "~/constants" +import { Currency, CurrencyType } from "#/types" +import { CURRENCIES_BY_TYPE } from "#/constants" export const getCurrencyByType = (currency: CurrencyType): Currency => CURRENCIES_BY_TYPE[currency] diff --git a/dapp/src/utils/forms.ts b/dapp/src/utils/forms.ts index a2fc7b8c4..97872a8f4 100644 --- a/dapp/src/utils/forms.ts +++ b/dapp/src/utils/forms.ts @@ -1,4 +1,4 @@ -import { CurrencyType } from "~/types" +import { CurrencyType } from "#/types" import { getCurrencyByType } from "./currency" import { formatTokenAmount } from "./numbers" diff --git a/dapp/tsconfig.json b/dapp/tsconfig.json index 0d679c735..03b8b2fe1 100644 --- a/dapp/tsconfig.json +++ b/dapp/tsconfig.json @@ -14,7 +14,7 @@ "strict": true, "baseUrl": ".", "paths": { - "~/*": ["./src/*"] + "#/*": ["./src/*"] } }, "references": [{ "path": "./tsconfig.node.json" }] diff --git a/dapp/vite.config.ts b/dapp/vite.config.ts index 71034c086..b60415bd0 100644 --- a/dapp/vite.config.ts +++ b/dapp/vite.config.ts @@ -7,7 +7,7 @@ import { resolve } from "path" export default defineConfig({ resolve: { alias: { - "~": resolve(__dirname, "./src"), + "#": resolve(__dirname, "./src"), }, }, plugins: [nodePolyfills(), react()], From 2e2737be8d49fb2f108115cf08e7fabbf02e7133 Mon Sep 17 00:00:00 2001 From: ioay Date: Thu, 11 Jan 2024 16:25:28 +0100 Subject: [PATCH 46/49] Removed vite-tsconfig-paths package --- dapp/package.json | 3 +-- pnpm-lock.yaml | 37 ------------------------------------- 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/dapp/package.json b/dapp/package.json index 9abe245b2..98a2673bf 100644 --- a/dapp/package.json +++ b/dapp/package.json @@ -39,7 +39,6 @@ "prettier": "^3.1.0", "typescript": "^5.3.2", "vite": "^5.0.2", - "vite-plugin-node-polyfills": "^0.19.0", - "vite-tsconfig-paths": "^4.2.3" + "vite-plugin-node-polyfills": "^0.19.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 89f1905c3..ef9c6254c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -184,9 +184,6 @@ importers: vite-plugin-node-polyfills: specifier: ^0.19.0 version: 0.19.0(vite@5.0.2) - vite-tsconfig-paths: - specifier: ^4.2.3 - version: 4.2.3(typescript@5.3.2)(vite@5.0.2) sdk: devDependencies: @@ -10545,10 +10542,6 @@ packages: merge2: 1.4.1 slash: 3.0.0 - /globrex@0.1.2: - resolution: {integrity: sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==} - dev: true - /gopd@1.0.1: resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} dependencies: @@ -15134,19 +15127,6 @@ packages: resolution: {integrity: sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w==} dev: true - /tsconfck@2.1.2(typescript@5.3.2): - resolution: {integrity: sha512-ghqN1b0puy3MhhviwO2kGF8SeMDNhEbnKxjK7h6+fvY9JAxqvXi8y5NAHSQv687OVboS2uZIByzGd45/YxrRHg==} - engines: {node: ^14.13.1 || ^16 || >=18} - hasBin: true - peerDependencies: - typescript: ^4.3.5 || ^5.0.0 - peerDependenciesMeta: - typescript: - optional: true - dependencies: - typescript: 5.3.2 - dev: true - /tsconfig-paths@3.14.2: resolution: {integrity: sha512-o/9iXgCYc5L/JxCHPe3Hvh8Q/2xm5Z+p18PESBU6Ff33695QnCHBEjcytY2q19ua7Mbl/DavtBOLq+oG0RCL+g==} dependencies: @@ -15572,23 +15552,6 @@ packages: - rollup dev: true - /vite-tsconfig-paths@4.2.3(typescript@5.3.2)(vite@5.0.2): - resolution: {integrity: sha512-xVsA2xe6QSlzBujtWF8q2NYexh7PAUYfzJ4C8Axpe/7d2pcERYxuxGgph9F4f0iQO36g5tyGq6eBUYIssdUrVw==} - peerDependencies: - vite: '*' - peerDependenciesMeta: - vite: - optional: true - dependencies: - debug: 4.3.4 - globrex: 0.1.2 - tsconfck: 2.1.2(typescript@5.3.2) - vite: 5.0.2 - transitivePeerDependencies: - - supports-color - - typescript - dev: true - /vite@5.0.2: resolution: {integrity: sha512-6CCq1CAJCNM1ya2ZZA7+jS2KgnhbzvxakmlIjN24cF/PXhRMzpM/z8QgsVJA/Dm5fWUWnVEsmtBoMhmerPxT0g==} engines: {node: ^18.0.0 || >=20.0.0} From 23ca229f99d450c5829466a8ad662137c3c3c37b Mon Sep 17 00:00:00 2001 From: ioay Date: Thu, 11 Jan 2024 17:06:49 +0100 Subject: [PATCH 47/49] Update path in ModalBase component --- dapp/src/components/shared/ModalBase/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dapp/src/components/shared/ModalBase/index.tsx b/dapp/src/components/shared/ModalBase/index.tsx index a2c31cddd..6b253e89d 100644 --- a/dapp/src/components/shared/ModalBase/index.tsx +++ b/dapp/src/components/shared/ModalBase/index.tsx @@ -11,7 +11,7 @@ import { ModalFlowContextValue, TransactionContextProvider, } from "#/contexts" -import SupportWrapper from "../../Modals/Support" +import SupportWrapper from "#/components/Modals/Support" export default function ModalBase({ isOpen, From bc983bed7c6ed9f17d9f666074d7912069926414 Mon Sep 17 00:00:00 2001 From: ioay Date: Thu, 11 Jan 2024 19:44:12 +0100 Subject: [PATCH 48/49] Removal of global exclusion rules, added temporary overrides rules for existing files --- dapp/.eslintrc | 51 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/dapp/.eslintrc b/dapp/.eslintrc index 63815d434..de11435fb 100644 --- a/dapp/.eslintrc +++ b/dapp/.eslintrc @@ -16,14 +16,45 @@ { "allowRequiredDefaults": true } ], "react/require-default-props": [0], - // Regarding the fact we are using now: @thesis-co/eslint-config": "github:thesis/eslint-config#7b9bc8c" - // Promise-returning function provided to attribute where a void return was expected. - // Avoid referencing unbound methods which may cause unintentional scoping of `this`, used in theme files. - "@typescript-eslint/no-misused-promises": "off", - "@typescript-eslint/unbound-method": "off", - // Computed name [status] resolves to any value (related to external chakra-ui package) - "@typescript-eslint/no-unsafe-member-access": "off", - // Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator - "@typescript-eslint/no-floating-promises": "off" - } + }, + // FIXME: + // This is temporary solution after changes of the eslint-config version: @thesis-co/eslint-config: "github:thesis/eslint-config#7b9bc8c" + // Overrides rules should be fixed file by file. + "overrides": [ + { + "files": [ + "src/components/Header/ConnectWallet.tsx", + "src/components/Modals/Support/MissingAccount.tsx", + "src/components/Modals/Staking/SignMessage.tsx", + "src/hooks/useDepositBTCTransaction.ts" + ], + "rules": { + "@typescript-eslint/no-misused-promises": "off" + } + }, + { + "files": [ + "src/hooks/useSignMessage.ts" + ], + "rules": { + "@typescript-eslint/no-floating-promises": "off" + } + }, + { + "files": [ + "src/theme/*" + ], + "rules": { + "@typescript-eslint/unbound-method": "off" + } + }, + { + "files": [ + "src/theme/Alert.ts" + ], + "rules": { + "@typescript-eslint/no-unsafe-member-access": "off" + } + } + ] } From f903ed1905df488ce58431435ec03919eddb0fe0 Mon Sep 17 00:00:00 2001 From: ioay Date: Thu, 11 Jan 2024 19:59:12 +0100 Subject: [PATCH 49/49] Eslint rules extension after last changes on main branch --- dapp/.eslintrc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/dapp/.eslintrc b/dapp/.eslintrc index 67b8362d7..35437e4ed 100644 --- a/dapp/.eslintrc +++ b/dapp/.eslintrc @@ -26,7 +26,8 @@ "src/components/Header/ConnectWallet.tsx", "src/components/Modals/Support/MissingAccount.tsx", "src/components/Modals/Staking/SignMessage.tsx", - "src/hooks/useDepositBTCTransaction.ts" + "src/hooks/useDepositBTCTransaction.ts", + "src/components/shared/Form/FormTokenBalanceInput.tsx" ], "rules": { "@typescript-eslint/no-misused-promises": "off" @@ -55,6 +56,22 @@ "rules": { "@typescript-eslint/no-unsafe-member-access": "off" } + }, + { + "files": [ + "src/components/shared/Form/FormTokenBalanceInput.tsx" + ], + "rules": { + "@typescript-eslint/no-unsafe-assignment": "off" + } + }, + { + "files": [ + "src/components/shared/TokenAmountForm/index.tsx" + ], + "rules": { + "@typescript-eslint/require-await": "off" + } } ], "settings": {