Skip to content

Commit

Permalink
feat: add address and copy button to wallets (#378)
Browse files Browse the repository at this point in the history
* feat: add address and copy button to wallets

* feat: move header to left margin

* feat: add pointer style
  • Loading branch information
braianj authored Jun 7, 2024
1 parent c997d29 commit abefce1
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/Notifications/Notifications.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const Container = styled('div')({
maxWidth: '660px'
})

export const Header = styled('div')({ marginLeft: '24px', marginTop: '14px' })
export const Header = styled('div')({ marginTop: '14px' })

export const Wrapper = styled('div')({
marginTop: '16px'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { NetworkGatewayType, gatewaysNames } from 'decentraland-ui'
import { Deposit, TransactionStatus, TransactionType, Transfer, Withdrawal, WithdrawalStatus } from '../../../../../modules/mana/types'
import { getStatusMessage, isPendingAccountTransaction } from '../../../../../modules/mana/utils'
import { shortening } from '../../../../../modules/wallet/utils'
import { Props } from './AccountTransaction.types'

import './AccountTransaction.css'
Expand All @@ -21,8 +22,6 @@ const AccountTransaction = ({ transaction, onTransactionDetail, onPendingWithdra
}
}, [now])

const shortening = (address: string): string => (address ? `${address.slice(0, 4)}...${address.slice(-4)}` : '')

let data: any = null
let description = ''
if (type === TransactionType.DEPOSIT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
flex-direction: row;
flex-wrap: wrap;
padding-right: 50px;
margin-top: 16px;
}
@media (max-width: 991px) {
.AccountCardContainer {
Expand Down
4 changes: 3 additions & 1 deletion src/components/Wallets/Wallets.container.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { connect } from 'react-redux'
import { getAddress } from 'decentraland-dapps/dist/modules/wallet/selectors'
import { getTransactionByNetwork, getWalletDeposits, getWalletWithdrawals } from '../../modules/mana/selectors'
import { RootState } from '../../modules/reducer'
import Wallets from './Wallets'
Expand All @@ -8,7 +9,8 @@ const mapState = (state: RootState): MapStateProps => {
return {
transactionsByNetwork: getTransactionByNetwork(state),
withdrawals: getWalletWithdrawals(state),
deposits: getWalletDeposits(state)
deposits: getWalletDeposits(state),
address: getAddress(state)!
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/components/Wallets/Wallets.styled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import styled from '@emotion/styled'
import ContentCopyRoundedIconMui from '@mui/icons-material/ContentCopyRounded'
import { Typography as TypographyMui } from 'decentraland-ui2'
import { Description as DescriptionGlobal } from '../Typography'

export const Header = styled('div')({ marginTop: '14px' })

export const Description = styled(DescriptionGlobal)({ display: 'flex', alignItems: 'center' })

export const Address = styled(TypographyMui)({
color: '#fcfcfc99',
fontSize: '14px',
lineHeight: '24px',
fontWeight: 500,
marginLeft: '8px',
marginRight: '8px'
})

export const ContentCopyRoundedIcon = styled(ContentCopyRoundedIconMui)({
cursor: 'pointer'
})
47 changes: 45 additions & 2 deletions src/components/Wallets/Wallets.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,64 @@
import React from 'react'
import React, { useCallback, useState } from 'react'
import { Network } from '@dcl/schemas'
import AccountBalanceWalletRoundedIcon from '@mui/icons-material/AccountBalanceWalletRounded'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { Tooltip } from 'decentraland-ui2'
import { DepositStatus, WithdrawalStatus } from '../../modules/mana/types'
import { shortening } from '../../modules/wallet/utils'
import DepositTooltip from '../Tooltips/DepositTooltip'
import WithdrawalTooltip from '../Tooltips/WithdrawalTooltip'
import { Title } from '../Typography'
import { AccountCard } from './AccountCard'
import AccountCardContainer from './AccountCardContainer/AccountCardContainer'
import { Address, ContentCopyRoundedIcon, Description, Header } from './Wallets.styled'
import { Props } from './Wallets.types'

const Wallets: React.FC<Props> = ({ withdrawals, deposits, transactionsByNetwork }) => {
const Wallets: React.FC<Props> = props => {
const { withdrawals, deposits, transactionsByNetwork, address } = props
const [openTooltip, setOpenTooltip] = useState(false)
const ethereumTransactions = transactionsByNetwork[Network.ETHEREUM]
const maticTransactions = transactionsByNetwork[Network.MATIC]

const isFirstWithdrawal = withdrawals.length === 1 && withdrawals[0].status === WithdrawalStatus.PENDING
const isFirstDeposits = deposits.length === 1 && deposits[0].status === DepositStatus.PENDING

const handleCopyAddres = useCallback(() => {
setOpenTooltip(true)
navigator.clipboard.writeText(address)
setTimeout(() => {
setOpenTooltip(false)
}, 1200)
}, [address])

const handleTooltipClose = useCallback(() => {
setOpenTooltip(false)
}, [])

return (
<>
<Header>
<Title variant="h3">{t('main_page.wallets')}</Title>
<Description variant="subtitle1">
<AccountBalanceWalletRoundedIcon />
<Address>{shortening(address)}</Address>
<Tooltip
PopperProps={{
disablePortal: true
}}
onClose={handleTooltipClose}
open={openTooltip}
disableFocusListener
disableHoverListener
disableTouchListener
title={t('main_page.copied')}
leaveDelay={1200}
placement="right"
arrow
>
<ContentCopyRoundedIcon onClick={handleCopyAddres} />
</Tooltip>
</Description>
</Header>
<AccountCardContainer>
<AccountCard network={Network.ETHEREUM} title="Ethereum MANA" transactions={ethereumTransactions} />
<AccountCard network={Network.MATIC} title="Polygon MANA" transactions={maticTransactions} />
Expand Down
3 changes: 2 additions & 1 deletion src/components/Wallets/Wallets.types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export type Props = {
transactionsByNetwork: Record<Network, Transaction[]>
withdrawals: Withdrawal[]
deposits: Deposit[]
address: string
}
export type MapStateProps = Pick<Props, 'transactionsByNetwork' | 'withdrawals' | 'deposits'>
export type MapStateProps = Pick<Props, 'transactionsByNetwork' | 'withdrawals' | 'deposits' | 'address'>
export type MapDispatchProps = {}
export type MapDispatch = Dispatch
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"main_page": {
"wallets": "Wallets",
"email_notifications": "Email Notifications",
"title": "Account Settings"
"title": "Account Settings",
"copied": "Copied!"
},
"account_header": {
"actions": {
Expand Down
3 changes: 2 additions & 1 deletion src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"main_page": {
"wallets": "Wallets",
"email_notifications": "Notificaciones",
"title": "Configuración de la cuenta"
"title": "Configuración de la cuenta",
"copied": "Copiado!"
},
"account_header": {
"actions": {
Expand Down
3 changes: 2 additions & 1 deletion src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"main_page": {
"wallets": "錢包",
"email_notifications": "電子郵件通知",
"title": "帳戶設定"
"title": "帳戶設定",
"copied": "已复制!"
},
"account_header": {
"actions": {
Expand Down
3 changes: 3 additions & 0 deletions src/modules/wallet/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function shortening(address: string): string {
return address ? `${address.slice(0, 4)}...${address.slice(-4)}` : ''
}

0 comments on commit abefce1

Please sign in to comment.