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

feat: ActionInfo component #642

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions packages/curve-ui-kit/src/shared/ui/ActionInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { useState } from 'react'
import { useTheme } from '@mui/material/styles'
import { Stack } from '@mui/material'
import Snackbar from '@mui/material/Snackbar'
import Alert from '@mui/material/Alert'
import AlertTitle from '@mui/material/AlertTitle'
import IconButton from '@mui/material/IconButton'
import Icon from 'ui/src/Icon'
import Typography from '@mui/material/Typography'
import Link from '@mui/material/Link'
import { Duration } from '../../themes/design/0_primitives'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can use @ui-kit if you want to instead of relative files.

import { shortenTokenAddress } from 'ui/src/utils/'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh shit didn't know this existed, now we have a somewhat duplicate implementation with curve-ui-kit\src\utils\address.ts. Should probably consolidate that some time.

import { t } from 'i18next'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wait what's this, aren't we using import { t } from '@lingui/macro'?

import { SizesAndSpaces } from '../../themes/design/1_sizes_spaces'

const { Spacing } = SizesAndSpaces

type ComponentSize = 'S' | 'M' | 'L'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type ComponentSize = 'S' | 'M' | 'L'
type ComponentSize = 'small' | 'medium' | 'large'


type ActionInfoProps = {
label: string
address: string
linkAddress: string
size?: ComponentSize
}

const labelSize: Record<ComponentSize, 'bodyXsRegular' | 'bodyMRegular'> = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could just use TypographyVariantKey in the future if you ever want to keep your options open, but this works regardless.

S: 'bodyXsRegular',
M: 'bodyMRegular',
L: 'bodyMRegular',
}

const addressSize: Record<ComponentSize, 'bodyXsBold' | 'highlightM' | 'headingSBold'> = {
S: 'bodyXsBold',
M: 'highlightM',
L: 'headingSBold',
}

const ActionInfo = ({ label, address, linkAddress, size = 'S' }: ActionInfoProps) => {
const {
design: { Button },
} = useTheme()
const [openCopyAlert, setOpenCopyAlert] = useState(false)
OnlyJousting marked this conversation as resolved.
Show resolved Hide resolved

const copyValue = () => {
navigator.clipboard.writeText(address)
setOpenCopyAlert(true)
}

return (
<Stack direction="row" alignItems="center" justifyContent="space-between">
<Typography variant={labelSize[size]} color="textTertiary">
{label}
</Typography>
<Stack direction="row" alignItems="center">
<Typography variant={addressSize[size]} color="textPrimary" sx={{ marginRight: Spacing.sm }}>
{shortenTokenAddress(address)}
</Typography>
<IconButton size="small" onClick={copyValue} sx={{ svg: { color: Button.Primary.Default.Fill } }}>
OnlyJousting marked this conversation as resolved.
Show resolved Hide resolved
<Icon name="Copy" size={24} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Check out SizesAndSpaces.IconSize

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it returns values in 'rem' and the Icon component requires number 🤔

</IconButton>
<IconButton
component={Link}
href={linkAddress}
target="_blank"
rel="noopener"
size="small"
sx={{ svg: { color: Button.Primary.Default.Fill } }}
>
<Icon name="ArrowUpRight" size={24} />
</IconButton>
</Stack>

<Snackbar open={openCopyAlert} onClose={() => setOpenCopyAlert(false)} autoHideDuration={Duration.Snackbar}>
<Alert variant="filled" severity="success">
<AlertTitle>{t`Copied to clipboard!`}</AlertTitle>
{address}
</Alert>
</Snackbar>
</Stack>
)
}

export default ActionInfo
Loading