-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor changeThresholdReview screen (#4212)
- Loading branch information
1 parent
03ae506
commit d12bf6f
Showing
7 changed files
with
152 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createContext } from 'react' | ||
|
||
export const ChangeThresholdReviewContext = createContext({ | ||
newThreshold: 0, | ||
}) |
33 changes: 33 additions & 0 deletions
33
src/components/tx/confirmation-views/ChangeThreshold/ChangeThreshold.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { Paper } from '@mui/material' | ||
import { StoreDecorator } from '@/stories/storeDecorator' | ||
import ChangeThreshold from './index' | ||
import { ChangeThresholdReviewContext } from '@/components/tx-flow/flows/ChangeThreshold/context' | ||
|
||
const meta = { | ||
component: ChangeThreshold, | ||
parameters: { | ||
layout: 'centered', | ||
newThreshold: 1, | ||
}, | ||
decorators: [ | ||
(Story, { parameters }) => { | ||
return ( | ||
<StoreDecorator initialState={{}}> | ||
<ChangeThresholdReviewContext.Provider value={{ newThreshold: parameters.newThreshold }}> | ||
<Paper sx={{ padding: 2 }}> | ||
<Story /> | ||
</Paper> | ||
</ChangeThresholdReviewContext.Provider> | ||
</StoreDecorator> | ||
) | ||
}, | ||
], | ||
|
||
tags: ['autodocs'], | ||
} satisfies Meta<typeof ChangeThreshold> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = {} |
31 changes: 31 additions & 0 deletions
31
src/components/tx/confirmation-views/ChangeThreshold/ChangeThreshold.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { render } from '@/tests/test-utils' | ||
import ChangeThreshold from '.' | ||
import { ChangeThresholdReviewContext } from '@/components/tx-flow/flows/ChangeThreshold/context' | ||
import * as useSafeInfo from '@/hooks/useSafeInfo' | ||
import { extendedSafeInfoBuilder } from '@/tests/builders/safe' | ||
|
||
const extendedSafeInfo = extendedSafeInfoBuilder().build() | ||
|
||
jest.spyOn(useSafeInfo, 'default').mockImplementation(() => ({ | ||
safeAddress: 'eth:0xA77DE01e157f9f57C7c4A326eeE9C4874D0598b6', | ||
safe: { | ||
...extendedSafeInfo, | ||
owners: [extendedSafeInfo.owners[0]], | ||
}, | ||
safeError: undefined, | ||
safeLoading: false, | ||
safeLoaded: true, | ||
})) | ||
|
||
describe('ChangeThreshold', () => { | ||
it('should display the ChangeThreshold component with the new threshold range', () => { | ||
const { container, getByLabelText } = render( | ||
<ChangeThresholdReviewContext.Provider value={{ newThreshold: 3 }}> | ||
<ChangeThreshold /> | ||
</ChangeThresholdReviewContext.Provider>, | ||
) | ||
|
||
expect(container).toMatchSnapshot() | ||
expect(getByLabelText('threshold')).toHaveTextContent('3 out of 1 signer(s)') | ||
}) | ||
}) |
33 changes: 33 additions & 0 deletions
33
...ponents/tx/confirmation-views/ChangeThreshold/__snapshots__/ChangeThreshold.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ChangeThreshold should display the ChangeThreshold component with the new threshold range 1`] = ` | ||
<div> | ||
<div> | ||
<p | ||
class="MuiTypography-root MuiTypography-body2 css-1bcmoup-MuiTypography-root" | ||
> | ||
Any transaction will require the confirmation of: | ||
</p> | ||
<p | ||
aria-label="threshold" | ||
class="MuiTypography-root MuiTypography-body1 css-1pqjor9-MuiTypography-root" | ||
> | ||
<b> | ||
3 | ||
</b> | ||
out of | ||
<b> | ||
1 | ||
signer(s) | ||
</b> | ||
</p> | ||
</div> | ||
<div | ||
class="MuiBox-root css-1xlzx9v" | ||
> | ||
<hr | ||
class="MuiDivider-root MuiDivider-fullWidth nestedDivider css-da8pia-MuiDivider-root" | ||
/> | ||
</div> | ||
</div> | ||
`; |
30 changes: 30 additions & 0 deletions
30
src/components/tx/confirmation-views/ChangeThreshold/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Box, Divider, Typography } from '@mui/material' | ||
import React, { useContext } from 'react' | ||
|
||
import commonCss from '@/components/tx-flow/common/styles.module.css' | ||
import useSafeInfo from '@/hooks/useSafeInfo' | ||
import { ChangeThresholdReviewContext } from '@/components/tx-flow/flows/ChangeThreshold/context' | ||
|
||
function ChangeThreshold() { | ||
const { safe } = useSafeInfo() | ||
const { newThreshold } = useContext(ChangeThresholdReviewContext) | ||
|
||
return ( | ||
<> | ||
<div> | ||
<Typography variant="body2" color="text.secondary" mb={0.5}> | ||
Any transaction will require the confirmation of: | ||
</Typography> | ||
|
||
<Typography aria-label="threshold"> | ||
<b>{newThreshold}</b> out of <b>{safe.owners.length} signer(s)</b> | ||
</Typography> | ||
</div> | ||
<Box my={1}> | ||
<Divider className={commonCss.nestedDivider} /> | ||
</Box> | ||
</> | ||
) | ||
} | ||
|
||
export default ChangeThreshold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters