Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problems reported by eslint #179

Merged
merged 10 commits into from
Jan 23, 2024
57 changes: 0 additions & 57 deletions dapp/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,6 @@
],
"react/require-default-props": [0],
},
// 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",
"src/components/shared/Form/FormTokenBalanceInput.tsx"
],
"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"
}
},
{
"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": {
"import/resolver": {
"alias": {
Expand Down
8 changes: 6 additions & 2 deletions dapp/src/components/Header/ConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { CurrencyBalance } from "#/components/shared/CurrencyBalance"
import { TextMd } from "#/components/shared/Typography"
import { Bitcoin, Ethereum } from "#/static/icons"
import { truncateAddress } from "#/utils"
import { truncateAddress, asyncWrapper } from "#/utils"

export type ConnectButtonsProps = {
leftIcon: typeof Icon
Expand All @@ -24,12 +24,16 @@ function ConnectButton({
}: ConnectButtonsProps) {
const colorScheme = !account ? "error" : undefined

const handleClick = () => {
asyncWrapper(requestAccount())
}

return (
<Button
variant="card"
colorScheme={colorScheme}
leftIcon={<Icon as={leftIcon} boxSize={6} />}
onClick={requestAccount}
onClick={handleClick}
>
{account ? truncateAddress(account.address) : "Not connected"}
</Button>
Expand Down
7 changes: 6 additions & 1 deletion dapp/src/components/Modals/Staking/SignMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import { Highlight } from "@chakra-ui/react"
import { useModalFlowContext, useSignMessage } from "#/hooks"
import Alert from "#/components/shared/Alert"
import { TextMd } from "#/components/shared/Typography"
import { asyncWrapper } from "#/utils"
import StakingSteps from "./components/StakingSteps"

export default function SignMessage() {
const { goNext } = useModalFlowContext()
const { signMessage } = useSignMessage(goNext)

const handleClick = () => {
asyncWrapper(signMessage())
}

return (
<StakingSteps buttonText="Continue" activeStep={0} onClick={signMessage}>
<StakingSteps buttonText="Continue" activeStep={0} onClick={handleClick}>
{/* TODO: Add the correct action after click */}
<Alert withActionIcon onclick={() => {}}>
<TextMd>
Expand Down
14 changes: 6 additions & 8 deletions dapp/src/components/Modals/Support/MissingAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@chakra-ui/react"
import { TextMd } from "#/components/shared/Typography"
import Alert from "#/components/shared/Alert"
import { getCurrencyByType } from "#/utils"
import { asyncWrapper, getCurrencyByType } from "#/utils"
import { CurrencyType, RequestAccountParams } from "#/types"

type MissingAccountProps = {
Expand All @@ -25,6 +25,10 @@ export default function MissingAccount({
}: MissingAccountProps) {
const { name, symbol } = getCurrencyByType(currency)

const handleClick = () => {
asyncWrapper(requestAccount())
}

return (
<>
<ModalHeader>{name} account not installed</ModalHeader>
Expand All @@ -44,13 +48,7 @@ export default function MissingAccount({
</Alert>
</ModalBody>
<ModalFooter mt={4}>
<Button
size="lg"
width="100%"
onClick={async () => {
await requestAccount()
}}
>
<Button size="lg" width="100%" onClick={handleClick}>
Connect wallet
</Button>
</ModalFooter>
Expand Down
9 changes: 7 additions & 2 deletions dapp/src/components/shared/Form/FormTokenBalanceInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react"
import { useField } from "formik"
import { asyncWrapper } from "#/utils"
import TokenBalanceInput, { TokenBalanceInputProps } from "../TokenBalanceInput"

export type FormTokenBalanceInputProps = {
Expand All @@ -11,12 +12,16 @@ export function FormTokenBalanceInput({
}: FormTokenBalanceInputProps) {
const [field, meta, helpers] = useField(name)

const setAmount = (value?: bigint) => {
asyncWrapper(helpers.setValue(value))
}

return (
<TokenBalanceInput
{...restProps}
{...field}
amount={meta.value}
setAmount={helpers.setValue}
amount={meta.value as bigint}
setAmount={setAmount}
hasError={Boolean(meta.touched && meta.error)}
errorMsgText={meta.error}
/>
Expand Down
5 changes: 1 addition & 4 deletions dapp/src/components/shared/TokenAmountForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ const TokenAmountForm = withFormik<TokenAmountFormProps, TokenAmountFormValues>(
mapPropsToValues: () => ({
amount: undefined,
}),
validate: async (
{ amount },
{ tokenBalance, currency, minTokenAmount },
) => {
validate: ({ amount }, { tokenBalance, currency, minTokenAmount }) => {
const errors: FormikErrors<TokenAmountFormValues> = {}

errors.amount = validateTokenAmount(
Expand Down
20 changes: 12 additions & 8 deletions dapp/src/theme/Alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import {

const KEYS = [...parts.keys, "rightIconContainer"] as const

const { defineMultiStyleConfig, definePartsStyle } =
createMultiStyleConfigHelpers(KEYS)

const baseStyleDialog = defineStyle({
py: 5,
pl: 5,
Expand Down Expand Up @@ -39,13 +36,15 @@ const baseStyleRightIconContainer = defineStyle({
w: 14,
})

const baseStyle = definePartsStyle({
const multiStyleConfig = createMultiStyleConfigHelpers(KEYS)

const baseStyle = multiStyleConfig.definePartsStyle({
container: baseStyleDialog,
icon: baseStyleIcon,
rightIconContainer: baseStyleRightIconContainer,
})

const statusInfo = definePartsStyle({
const statusInfo = multiStyleConfig.definePartsStyle({
container: {
bg: "gold.200",
},
Expand All @@ -63,13 +62,18 @@ const statusStyles = (props: StyleFunctionProps) => {
info: statusInfo,
}

return styleMap[status] || {}
return styleMap[status as string] || {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking comment

The more I look at it the more I realize that this isn't how we should handle the different styles for the Alert component. 🤔 At that time, I used a solution from the threshold dashboard. But now I realize that we should handle it by passing colorScheme. Just as it was done in the Chakra UI.

However, let's leave it as it is but please add a TODO comment here or create a new issue that we should update this and start using a colorScheme instead of status props.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

const variantSubtle = definePartsStyle((props) => statusStyles(props))
const variantSubtle = multiStyleConfig.definePartsStyle((props) =>
statusStyles(props),
)

const variants = {
subtle: variantSubtle,
}

export const alertTheme = defineMultiStyleConfig({ baseStyle, variants })
export const alertTheme = multiStyleConfig.defineMultiStyleConfig({
baseStyle,
variants,
})
21 changes: 10 additions & 11 deletions dapp/src/theme/CurrencyBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import { createMultiStyleConfigHelpers, defineStyle } from "@chakra-ui/react"

const PARTS = ["balance", "symbol"]

const { defineMultiStyleConfig, definePartsStyle } =
createMultiStyleConfigHelpers(PARTS)

const baseStyleBalance = defineStyle({
fontWeight: "bold",
fontSize: "md",
Expand All @@ -18,12 +15,14 @@ const baseStyleSymbol = defineStyle({
lineHeight: "md",
})

const baseStyle = definePartsStyle({
const multiStyleConfig = createMultiStyleConfigHelpers(PARTS)

const baseStyle = multiStyleConfig.definePartsStyle({
balance: baseStyleBalance,
symbol: baseStyleSymbol,
})

const variantGreaterBalance = definePartsStyle({
const variantGreaterBalance = multiStyleConfig.definePartsStyle({
balance: {
fontSize: "4xl",
lineHeight: "4xl",
Expand All @@ -38,7 +37,7 @@ const variants = {
"greater-balance": variantGreaterBalance,
}

const sizeXs = definePartsStyle({
const sizeXs = multiStyleConfig.definePartsStyle({
balance: {
fontSize: "xs",
lineHeight: "xs",
Expand All @@ -49,7 +48,7 @@ const sizeXs = definePartsStyle({
},
})

const sizeSm = definePartsStyle({
const sizeSm = multiStyleConfig.definePartsStyle({
balance: {
fontSize: "sm",
lineHeight: "sm",
Expand All @@ -60,7 +59,7 @@ const sizeSm = definePartsStyle({
},
})

const sizeMd = definePartsStyle({
const sizeMd = multiStyleConfig.definePartsStyle({
balance: {
fontSize: "md",
lineHeight: "md",
Expand All @@ -71,7 +70,7 @@ const sizeMd = definePartsStyle({
},
})

const sizeLg = definePartsStyle({
const sizeLg = multiStyleConfig.definePartsStyle({
balance: {
fontSize: "lg",
lineHeight: "lg",
Expand All @@ -82,7 +81,7 @@ const sizeLg = definePartsStyle({
},
})

const sizeXl = definePartsStyle({
const sizeXl = multiStyleConfig.definePartsStyle({
balance: {
fontSize: "xl",
lineHeight: "xl",
Expand All @@ -101,7 +100,7 @@ const sizes = {
xl: sizeXl,
}

export const currencyBalanceTheme = defineMultiStyleConfig({
export const currencyBalanceTheme = multiStyleConfig.defineMultiStyleConfig({
baseStyle,
variants,
sizes,
Expand Down
11 changes: 6 additions & 5 deletions dapp/src/theme/Drawer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { drawerAnatomy as parts } from "@chakra-ui/anatomy"
import { createMultiStyleConfigHelpers, defineStyle } from "@chakra-ui/react"

const { defineMultiStyleConfig, definePartsStyle } =
createMultiStyleConfigHelpers(parts.keys)

const baseStyleDialogContainer = defineStyle({
zIndex: "drawer",
})
Expand All @@ -23,10 +20,14 @@ const baseStyleOverlay = defineStyle({
backdropBlur: "8px",
})

const baseStyle = definePartsStyle({
const multiStyleConfig = createMultiStyleConfigHelpers(parts.keys)

const baseStyle = multiStyleConfig.definePartsStyle({
dialogContainer: baseStyleDialogContainer,
dialog: baseStyleDialog,
overlay: baseStyleOverlay,
})

export const drawerTheme = defineMultiStyleConfig({ baseStyle })
export const drawerTheme = multiStyleConfig.defineMultiStyleConfig({
baseStyle,
})
9 changes: 4 additions & 5 deletions dapp/src/theme/Form.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { formAnatomy as parts } from "@chakra-ui/anatomy"
import { createMultiStyleConfigHelpers, defineStyle } from "@chakra-ui/react"

const { defineMultiStyleConfig, definePartsStyle } =
createMultiStyleConfigHelpers(parts.keys)

const baseStyleHelperText = defineStyle({
display: "flex",
alignItems: "center",
Expand All @@ -12,8 +9,10 @@ const baseStyleHelperText = defineStyle({
color: "grey.500",
})

const baseStyle = definePartsStyle({
const multiStyleConfig = createMultiStyleConfigHelpers(parts.keys)

const baseStyle = multiStyleConfig.definePartsStyle({
helperText: baseStyleHelperText,
})

export const formTheme = defineMultiStyleConfig({ baseStyle })
export const formTheme = multiStyleConfig.defineMultiStyleConfig({ baseStyle })
11 changes: 6 additions & 5 deletions dapp/src/theme/FormError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { defineStyle, createMultiStyleConfigHelpers } from "@chakra-ui/react"

import { formErrorAnatomy as parts } from "@chakra-ui/anatomy"

const { defineMultiStyleConfig, definePartsStyle } =
createMultiStyleConfigHelpers(parts.keys)

const baseStyleText = defineStyle({
fontWeight: "medium",
color: "red.400",
})

const baseStyle = definePartsStyle({
const multiStyleConfig = createMultiStyleConfigHelpers(parts.keys)

const baseStyle = multiStyleConfig.definePartsStyle({
text: baseStyleText,
})

export const formErrorTheme = defineMultiStyleConfig({ baseStyle })
export const formErrorTheme = multiStyleConfig.defineMultiStyleConfig({
baseStyle,
})
Loading