-
Notifications
You must be signed in to change notification settings - Fork 877
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 #26442 from brave/feat-wallet-zcash-text-memo
feat(wallet): ZCash Text Memo
- Loading branch information
Showing
12 changed files
with
227 additions
and
7 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
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
14 changes: 14 additions & 0 deletions
14
components/brave_wallet_ui/page/screens/send/components/add_memo/add_memo.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,14 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
import styled from 'styled-components' | ||
import Input from '@brave/leo/react/input' | ||
|
||
export const MemoInput = styled(Input)` | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
gap: 4px; | ||
` |
97 changes: 97 additions & 0 deletions
97
components/brave_wallet_ui/page/screens/send/components/add_memo/add_memo.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,97 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
import * as React from 'react' | ||
import Button from '@brave/leo/react/button' | ||
import Icon from '@brave/leo/react/icon' | ||
|
||
// Constants | ||
import { MAX_ZCASH_MEMO_LENGTH } from '../../constants/magics' | ||
|
||
// Utils | ||
import { getLocale } from '../../../../../../common/locale' | ||
|
||
// Styled Components | ||
import { Column, Text } from '../../../../../components/shared/style' | ||
import { MemoInput } from './add_memo.style' | ||
|
||
interface Props { | ||
memoText: string | ||
onUpdateMemoText: (value: string) => void | ||
} | ||
|
||
export const AddMemo = (props: Props) => { | ||
const { memoText, onUpdateMemoText } = props | ||
|
||
// State | ||
const [showMemoTextInput, setShowMemoTextInput] = | ||
React.useState<boolean>(false) | ||
|
||
// Memos | ||
const memoTextLength = React.useMemo(() => { | ||
return memoText.length | ||
}, [memoText]) | ||
|
||
// Methods | ||
const onAddOrRemoveTextMemo = React.useCallback(() => { | ||
if (showMemoTextInput) { | ||
onUpdateMemoText('') | ||
setShowMemoTextInput(false) | ||
return | ||
} | ||
setShowMemoTextInput(true) | ||
}, [showMemoTextInput, onUpdateMemoText]) | ||
|
||
return ( | ||
<Column | ||
fullWidth={true} | ||
alignItems='flex-start' | ||
gap='8px' | ||
padding='16px 0px 0px 0px' | ||
> | ||
{showMemoTextInput && ( | ||
<MemoInput | ||
value={memoText} | ||
onInput={(e) => onUpdateMemoText(e.value)} | ||
placeholder={getLocale('braveWalletEnterAMessage')} | ||
showErrors={memoText.length > MAX_ZCASH_MEMO_LENGTH} | ||
> | ||
<Text | ||
textSize='12px' | ||
isBold={true} | ||
textColor='primary' | ||
> | ||
{getLocale('braveWalletMessageOptional')} | ||
</Text> | ||
<span slot='extra'> | ||
{memoTextLength}/{MAX_ZCASH_MEMO_LENGTH} | ||
</span> | ||
<Text | ||
textSize='12px' | ||
isBold={true} | ||
textColor='error' | ||
slot='errors' | ||
textAlign='left' | ||
> | ||
{getLocale('braveWalletMemoLengthError')} | ||
</Text> | ||
</MemoInput> | ||
)} | ||
<Button | ||
kind='plain' | ||
size='medium' | ||
onClick={onAddOrRemoveTextMemo} | ||
> | ||
<Icon | ||
name={showMemoTextInput ? 'trash' : 'plus-add'} | ||
slot='icon-before' | ||
/> | ||
{showMemoTextInput | ||
? getLocale('braveWalletRemoveMemo') | ||
: getLocale('braveWalletAddMemo')} | ||
</Button> | ||
</Column> | ||
) | ||
} |
6 changes: 6 additions & 0 deletions
6
components/brave_wallet_ui/page/screens/send/constants/magics.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,6 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
export const MAX_ZCASH_MEMO_LENGTH = 512 |
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