-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12386 from brave/encryption-key-panel
feat(wallet): Built Out Encryption Key Panel UI
- Loading branch information
Showing
11 changed files
with
391 additions
and
4 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
117 changes: 117 additions & 0 deletions
117
components/brave_wallet_ui/components/extension/encryption-key-panel/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,117 @@ | ||
import * as React from 'react' | ||
|
||
// Types | ||
import { BraveWallet, WalletAccountType } from '../../../constants/types' | ||
|
||
// Utils | ||
import { reduceAccountDisplayName } from '../../../utils/reduce-account-name' | ||
import { getLocale } from '../../../../common/locale' | ||
|
||
// Components | ||
import { create } from 'ethereum-blockies' | ||
import { NavButton, PanelTab } from '..' | ||
|
||
// Styled Components | ||
import { | ||
StyledWrapper, | ||
AccountCircle, | ||
AccountNameText, | ||
TopRow, | ||
NetworkText, | ||
PanelTitle, | ||
MessageBox, | ||
MessageText, | ||
ButtonRow, | ||
DecryptButton | ||
} from './style' | ||
|
||
import { TabRow } from '../shared-panel-styles' | ||
|
||
export interface Props { | ||
panelType: 'request' | 'read' | ||
accounts: WalletAccountType[] | ||
selectedNetwork: BraveWallet.EthereumChain | ||
encryptionKeyPayload: BraveWallet.EncryptionKeyRequest | ||
onProvideOrAllow: () => void | ||
onCancel: () => void | ||
} | ||
|
||
function EncryptionKeyPanel (props: Props) { | ||
const { | ||
panelType, | ||
accounts, | ||
selectedNetwork, | ||
encryptionKeyPayload, | ||
onProvideOrAllow, | ||
onCancel | ||
} = props | ||
const [isDecrypted, setIsDecrypted] = React.useState<boolean>(false) | ||
|
||
const foundAccountName = React.useMemo(() => { | ||
return accounts.find((account) => account.address.toLowerCase() === encryptionKeyPayload.address.toLowerCase())?.name | ||
}, [encryptionKeyPayload]) | ||
|
||
const orb = React.useMemo(() => { | ||
return create({ seed: encryptionKeyPayload.address.toLowerCase(), size: 8, scale: 16 }).toDataURL() | ||
}, [encryptionKeyPayload]) | ||
|
||
const onDecryptMessage = () => { | ||
setIsDecrypted(true) | ||
} | ||
|
||
return ( | ||
<StyledWrapper> | ||
<TopRow> | ||
<NetworkText>{selectedNetwork.chainName}</NetworkText> | ||
</TopRow> | ||
<AccountCircle orb={orb} /> | ||
<AccountNameText>{reduceAccountDisplayName(foundAccountName ?? '', 14)}</AccountNameText> | ||
<PanelTitle> | ||
{panelType === 'request' | ||
? getLocale('braveWalletProvideEncryptionKeyTitle') | ||
: getLocale('braveWalletReadEncryptedMessageTitle').replace('$1', encryptionKeyPayload.origin)} | ||
</PanelTitle> | ||
<TabRow> | ||
<PanelTab | ||
isSelected={true} | ||
text={getLocale('braveWalletSignTransactionMessageTitle')} | ||
/> | ||
</TabRow> | ||
<MessageBox | ||
needsCenterAlignment={panelType === 'read' && !isDecrypted} | ||
> | ||
{panelType === 'read' && !isDecrypted ? ( | ||
<DecryptButton | ||
onClick={onDecryptMessage} | ||
> | ||
{getLocale('braveWalletReadEncryptedMessageDecryptButton')} | ||
</DecryptButton> | ||
) : ( | ||
<MessageText> | ||
{panelType === 'request' | ||
? getLocale('braveWalletProvideEncryptionKeyDescription').replace('$1', encryptionKeyPayload.origin) | ||
: encryptionKeyPayload.message} | ||
</MessageText> | ||
)} | ||
</MessageBox> | ||
<ButtonRow> | ||
<NavButton | ||
buttonType='secondary' | ||
text={getLocale('braveWalletBackupButtonCancel')} | ||
onSubmit={onCancel} | ||
/> | ||
<NavButton | ||
buttonType='primary' | ||
text={ | ||
panelType === 'request' | ||
? getLocale('braveWalletProvideEncryptionKeyButton') | ||
: getLocale('braveWalletReadEncryptedMessageButton') | ||
} | ||
onSubmit={onProvideOrAllow} | ||
/> | ||
</ButtonRow> | ||
</StyledWrapper> | ||
) | ||
} | ||
|
||
export default EncryptionKeyPanel |
117 changes: 117 additions & 0 deletions
117
components/brave_wallet_ui/components/extension/encryption-key-panel/style.ts
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,117 @@ | ||
import styled from 'styled-components' | ||
import { WalletButton } from '../../shared/style' | ||
|
||
interface StyleProps { | ||
orb: string | ||
needsCenterAlignment: boolean | ||
} | ||
|
||
export const StyledWrapper = styled.div` | ||
display: flex; | ||
height: 100%; | ||
width: 100%; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: space-between; | ||
background-color: ${(p) => p.theme.color.background01}; | ||
` | ||
|
||
export const TopRow = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
flex-direction: row; | ||
width: 100%; | ||
padding: 15px 15px 0px 15px; | ||
` | ||
|
||
export const AccountCircle = styled.div<Partial<StyleProps>>` | ||
width: 54px; | ||
height: 54px; | ||
border-radius: 100%; | ||
background-image: url(${(p) => p.orb}); | ||
background-size: cover; | ||
margin-bottom: 13px; | ||
` | ||
|
||
export const AccountNameText = styled.span` | ||
font-family: Poppins; | ||
font-size: 13px; | ||
line-height: 20px; | ||
font-weight: 600; | ||
letter-spacing: 0.01em; | ||
line-height: 20px; | ||
color: ${(p) => p.theme.color.text02}; | ||
margin-bottom: 2px; | ||
` | ||
|
||
export const NetworkText = styled.span` | ||
font-family: Poppins; | ||
font-size: 12px; | ||
line-height: 18px; | ||
letter-spacing: 0.01em; | ||
color: ${(p) => p.theme.color.text03}; | ||
` | ||
|
||
export const PanelTitle = styled.span` | ||
width: 80%; | ||
font-family: Poppins; | ||
font-size: 18px; | ||
line-height: 26px; | ||
letter-spacing: 0.02em; | ||
text-align: center; | ||
color: ${(p) => p.theme.color.text01}; | ||
font-weight: 600; | ||
margin-bottom: 15px; | ||
` | ||
|
||
export const MessageBox = styled.div<Partial<StyleProps>>` | ||
display: flex; | ||
align-items: ${(p) => p.needsCenterAlignment ? 'center' : 'flex-start'}; | ||
justify-content: ${(p) => p.needsCenterAlignment ? 'center' : 'flex-start'}; | ||
flex-direction: column; | ||
border: 1px solid ${(p) => p.theme.color.divider01}; | ||
box-sizing: border-box; | ||
border-radius: 4px; | ||
width: 255px; | ||
height: 140px; | ||
padding: 8px 14px; | ||
margin-bottom: 14px; | ||
overflow-x: hidden; | ||
overflow-y: scroll; | ||
` | ||
|
||
export const MessageText = styled.span` | ||
font-family: Poppins; | ||
font-size: 12px; | ||
line-height: 18px; | ||
letter-spacing: 0.01em; | ||
text-align: left; | ||
color: ${(p) => p.theme.color.text02}; | ||
word-break: break-word; | ||
` | ||
|
||
export const ButtonRow = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: row; | ||
width: 100%; | ||
margin-bottom: 14px; | ||
` | ||
|
||
export const DecryptButton = styled(WalletButton)` | ||
cursor: pointer; | ||
outline: none; | ||
border: none; | ||
font-weight: 600; | ||
font-family: Poppins; | ||
font-size: 12px; | ||
line-height: 18px; | ||
letter-spacing: 0.01em; | ||
background: none; | ||
color: ${(p) => p.theme.color.interactive05}; | ||
@media (prefers-color-scheme: dark) { | ||
color: ${(p) => p.theme.palette.blurple300}; | ||
} | ||
` |
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
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
Oops, something went wrong.