Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/epic/multichain-safes' into feat…
Browse files Browse the repository at this point in the history
…/cached-safe-overviews
  • Loading branch information
schmanu committed Sep 25, 2024
2 parents 2496bbd + 3ff63d4 commit 3a3294a
Show file tree
Hide file tree
Showing 74 changed files with 271 additions and 646 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
"plugin:storybook/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.json"]
},
"rules": {
"@next/next/no-img-element": "off",
"@next/next/google-font-display": "off",
"@next/next/google-font-preconnect": "off",
"@next/next/no-page-custom-font": "off",
"unused-imports/no-unused-imports-ts": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/await-thenable": "error",
"no-constant-condition": "warn",
"no-unused-vars": ["error", { "varsIgnorePattern": "^_" }],
"react-hooks/exhaustive-deps": [
"warn",
{
Expand All @@ -28,7 +33,9 @@
"ignorePatterns": [
"node_modules/",
".next/",
".github/"
".github/",
"cypress/",
"src/types/contracts/"
],
"plugins": [
"unused-imports",
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ concurrency:

jobs:
test:
permissions:
contents: write
checks: write
pull-requests: write

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/yarn

- name: Annotations and coverage report
uses: ArtiomTr/jest-coverage-report-action@v2
uses: ArtiomTr/jest-coverage-report-action@v2.3.1
with:
skip-step: install
annotations: failed-tests
Expand Down
15 changes: 8 additions & 7 deletions src/components/address-book/EntryDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import ModalDialog from '@/components/common/ModalDialog'
import NameInput from '@/components/common/NameInput'
import useChainId from '@/hooks/useChainId'
import { useAppDispatch } from '@/store'
import { upsertAddressBookEntry, upsertMultichainAddressBookEntry } from '@/store/addressBookSlice'
import madProps from '@/utils/mad-props'
import { upsertAddressBookEntries } from '@/store/addressBookSlice'

export type AddressEntry = {
name: string
Expand Down Expand Up @@ -41,11 +41,7 @@ function EntryDialog({
const { handleSubmit, formState } = methods

const submitCallback = handleSubmit((data: AddressEntry) => {
if (chainIds) {
dispatch(upsertMultichainAddressBookEntry({ ...data, chainIds }))
} else {
dispatch(upsertAddressBookEntry({ ...data, chainId: currentChainId }))
}
dispatch(upsertAddressBookEntries({ ...data, chainIds: chainIds ?? [currentChainId] }))
handleClose()
})

Expand All @@ -55,7 +51,12 @@ function EntryDialog({
}

return (
<ModalDialog open onClose={handleClose} dialogTitle={defaultValues.name ? 'Edit entry' : 'Create entry'}>
<ModalDialog
open
onClose={handleClose}
dialogTitle={defaultValues.name ? 'Edit entry' : 'Create entry'}
hideChainIndicator={chainIds && chainIds.length > 1}
>
<FormProvider {...methods}>
<form onSubmit={onSubmit}>
<DialogContent>
Expand Down
6 changes: 3 additions & 3 deletions src/components/address-book/ImportDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { ParseResult } from 'papaparse'
import { type ReactElement, useState, type MouseEvent, useMemo } from 'react'

import ModalDialog from '@/components/common/ModalDialog'
import { upsertAddressBookEntry } from '@/store/addressBookSlice'
import { upsertAddressBookEntries } from '@/store/addressBookSlice'
import { useAppDispatch } from '@/store'

import css from './styles.module.css'
Expand Down Expand Up @@ -60,7 +60,7 @@ const ImportDialog = ({ handleClose }: { handleClose: () => void }): ReactElemen

for (const entry of entries) {
const [address, name, chainId] = entry
dispatch(upsertAddressBookEntry({ address, name, chainId: chainId.trim() }))
dispatch(upsertAddressBookEntries({ address, name, chainIds: [chainId.trim()] }))
}

trackEvent({ ...ADDRESS_BOOK_EVENTS.IMPORT, label: entries.length })
Expand Down Expand Up @@ -114,7 +114,7 @@ const ImportDialog = ({ handleClose }: { handleClose: () => void }): ReactElemen
}}
>
{/* https://github.com/Bunlong/react-papaparse/blob/master/src/useCSVReader.tsx */}
{({ getRootProps, acceptedFile, ProgressBar, getRemoveFileProps, Remove }: any) => {
{({ getRootProps, acceptedFile, getRemoveFileProps }: any) => {
const { onClick } = getRemoveFileProps()

const onRemove = (e: MouseEvent<HTMLSpanElement>) => {
Expand Down
26 changes: 14 additions & 12 deletions src/components/common/AddressBookInput/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, fireEvent, render, waitFor } from '@/tests/test-utils'
import { act } from 'react'
import { fireEvent, render, waitFor } from '@/tests/test-utils'
import { FormProvider, useForm } from 'react-hook-form'
import AddressBookInput from '.'
import type { AddressInputProps } from '../AddressInput'
Expand Down Expand Up @@ -147,20 +148,21 @@ describe('AddressBookInput', () => {

expect(input).toHaveAttribute('aria-expanded', 'false')

await act(() => {
act(() => {
fireEvent.mouseDown(input)
fireEvent.mouseUp(input)
})

await act(() => {
act(() => {
fireEvent.change(input, { target: { value: invalidAddress } })
jest.advanceTimersByTime(1000)
})

await waitFor(() => expect(utils.getByLabelText(validationError, { exact: false })).toBeDefined())

const address = checksumAddress(faker.finance.ethereumAddress())
await act(() => {

act(() => {
fireEvent.change(input, { target: { value: address } })
jest.advanceTimersByTime(1000)
})
Expand All @@ -187,14 +189,14 @@ describe('AddressBookInput', () => {

expect(input).toHaveAttribute('aria-expanded', 'false')

await act(() => {
act(() => {
fireEvent.mouseDown(input)
fireEvent.mouseUp(input)
})

expect(input).toHaveAttribute('aria-expanded', 'true')

await act(() => {
act(() => {
fireEvent.click(utils.getByText('InvalidAddress'))
fireEvent.blur(input)
jest.advanceTimersByTime(1000)
Expand All @@ -206,7 +208,7 @@ describe('AddressBookInput', () => {
})

// Clear the input by clicking on the readonly input
await act(() => {
act(() => {
// first click clears input
fireEvent.click(utils.getByLabelText(validationError, { exact: false }))
})
Expand All @@ -215,13 +217,13 @@ describe('AddressBookInput', () => {
const newInput = utils.getByLabelText(validationError, { exact: false })
expect(newInput).toBeVisible()

await act(() => {
act(() => {
// mousedown opens autocompletion again
fireEvent.mouseDown(newInput)
fireEvent.mouseUp(newInput)
})

await act(() => {
act(() => {
fireEvent.click(utils.getByText('ValidAddress'))
fireEvent.blur(newInput)

Expand All @@ -239,7 +241,7 @@ describe('AddressBookInput', () => {
const { input, utils } = setup('', {}, undefined, true)

const newAddress = checksumAddress(faker.finance.ethereumAddress())
await act(() => {
act(() => {
fireEvent.change(input, { target: { value: newAddress } })
jest.advanceTimersByTime(1000)
})
Expand All @@ -253,7 +255,7 @@ describe('AddressBookInput', () => {
})

const nameInput = utils.getByLabelText('Name', { exact: false })
await act(() => {
act(() => {
fireEvent.change(nameInput, { target: { value: 'Tim Testermann' } })
fireEvent.submit(nameInput)
})
Expand All @@ -265,7 +267,7 @@ describe('AddressBookInput', () => {
const { input, utils } = setup('', {}, undefined, false)

const newAddress = checksumAddress(faker.finance.ethereumAddress())
await act(() => {
act(() => {
fireEvent.change(input, { target: { value: newAddress } })
jest.advanceTimersByTime(1000)
})
Expand Down
3 changes: 2 additions & 1 deletion src/components/common/AddressBookInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const AddressBookInput = ({ name, canAdd, ...props }: AddressInputProps & { canA
<Controller
name={name}
control={control}
render={({ field: { ref, ...field }, fieldState: { error } }) => (
// eslint-disable-next-line
render={({ field: { ref, ...field } }) => (
<Autocomplete
{...field}
className={inputCss.input}
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/CheckWallet/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('CheckWallet', () => {
;(useIsSafeOwner as jest.MockedFunction<typeof useIsSafeOwner>).mockReturnValueOnce(true)

const renderButtonWithNetworkCheck = () =>
render(<CheckWallet checkNetwork={true}>{(isOk) => <button disabled={true}></button>}</CheckWallet>)
render(<CheckWallet checkNetwork={true}>{(isOk) => <button disabled={!isOk}></button>}</CheckWallet>)

const { container } = renderButtonWithNetworkCheck()

Expand Down
1 change: 0 additions & 1 deletion src/components/common/CookieAndTermBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export const CookieAndTermBanner = ({

const CookieBannerPopup = (): ReactElement | null => {
const cookiePopup = useAppSelector(selectCookieBanner)
const cookies = useAppSelector(selectCookies)
const dispatch = useAppDispatch()

const hasAccepted = useAppSelector(hasAcceptedTerms)
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/DatePickerInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const DatePickerInput = ({
inputFormat="dd/MM/yyyy"
{...field}
disableFuture={disableFuture}
renderInput={({ label, error: _, ...params }) => (
renderInput={({ label, ...params }) => (
<TextField label={fieldState.error?.message || label} {...params} fullWidth error={!!fieldState.error} />
)}
PaperProps={{
Expand Down
6 changes: 2 additions & 4 deletions src/components/common/DateTime/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ describe('DateTime', () => {

date.setDate(date.getDate() - days)

const { queryByText } = render(<DateTime value={date.getTime()} />, {
const { getByText } = render(<DateTime value={date.getTime()} />, {
routerProps: { pathname: '/transactions/history' },
})

const expected = formatDateTime(date.getTime())

expect(queryByText('3 days ago')).toBeInTheDocument()
expect(getByText('3 days ago')).toBeInTheDocument()
})

it('should render the full date and time after threshold on the filter', () => {
Expand Down
13 changes: 7 additions & 6 deletions src/components/common/EthHashInfo/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { blo } from 'blo'
import { act } from 'react'
import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'

import { act, fireEvent, render, waitFor } from '@/tests/test-utils'
import { fireEvent, render, waitFor } from '@/tests/test-utils'
import * as useAllAddressBooks from '@/hooks/useAllAddressBooks'
import * as useChainId from '@/hooks/useChainId'
import * as store from '@/store'
Expand Down Expand Up @@ -258,7 +259,7 @@ describe('EthHashInfo', () => {

const button = container.querySelector('button')

await act(() => {
act(() => {
fireEvent.click(button!)
})

Expand Down Expand Up @@ -288,7 +289,7 @@ describe('EthHashInfo', () => {

const button = container.querySelector('button')

await act(() => {
act(() => {
fireEvent.click(button!)
})

Expand Down Expand Up @@ -320,7 +321,7 @@ describe('EthHashInfo', () => {

const button = container.querySelector('button')

await act(() => {
act(() => {
fireEvent.click(button!)
})

Expand Down Expand Up @@ -349,7 +350,7 @@ describe('EthHashInfo', () => {

const button = container.querySelector('button')

await act(() => {
act(() => {
fireEvent.click(button!)
})

Expand All @@ -375,7 +376,7 @@ describe('EthHashInfo', () => {

const button = container.querySelector('button')

await act(() => {
act(() => {
fireEvent.click(button!)
})

Expand Down
4 changes: 1 addition & 3 deletions src/components/common/NameInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import type { TextFieldProps } from '@mui/material'
import { TextField } from '@mui/material'
import get from 'lodash/get'
import { type FieldError, type Validate, useFormContext } from 'react-hook-form'
import { type FieldError, useFormContext } from 'react-hook-form'
import inputCss from '@/styles/inputs.module.css'

const NameInput = ({
name,
validate,
required = false,
...props
}: Omit<TextFieldProps, 'error' | 'variant' | 'ref' | 'fullWidth'> & {
name: string
validate?: Validate<string>
required?: boolean
}) => {
const { register, formState } = useFormContext() || {}
Expand Down
3 changes: 2 additions & 1 deletion src/components/common/NetworkInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const NetworkInput = ({
name={name}
rules={{ required }}
control={control}
render={({ field: { ref, ...field }, fieldState: { error } }) => (
// eslint-disable-next-line
render={({ field: { ref, ...field } }) => (
<FormControl fullWidth>
<InputLabel id="network-input-label">Network</InputLabel>
<Select
Expand Down
9 changes: 1 addition & 8 deletions src/components/common/TxModalDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@ import type { ReactElement } from 'react'
import CloseIcon from '@mui/icons-material/Close'
import css from './styles.module.css'

interface ModalDialogProps extends DialogProps {
dialogTitle?: React.ReactNode
hideChainIndicator?: boolean
}

const TxModalDialog = ({
dialogTitle,
hideChainIndicator,
children,
onClose,
fullScreen = false,
fullWidth = false,
...restProps
}: ModalDialogProps): ReactElement => {
}: DialogProps): ReactElement => {
return (
<Dialog
{...restProps}
Expand Down
4 changes: 3 additions & 1 deletion src/components/dashboard/ActivityRewardsSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ const ActivityRewardsSection = () => {
<Step title="Get activity points" active />
<Step title="Receive rewards" active={false} />
</div>
<ExternalLink href="https://safe.global/pass">Learn more</ExternalLink>
<ExternalLink onClick={onLearnMore} href="https://safe.global/pass">
Learn more
</ExternalLink>
</Grid>
<Grid item xs={12}>
<Box className={css.links} gap={2}>
Expand Down
Loading

0 comments on commit 3a3294a

Please sign in to comment.