-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
chore: MMI adds note to trader support to the new Tx confirmation view #27214
Changes from all commits
d345de1
036414f
64d3700
39d1b9f
897c60d
665691e
48a9838
6dd7f18
2a69cba
f400a6a
b5abc19
635886a
0134a80
6cd04c3
a8b3b0f
fbb5252
72e82cf
a013c49
e0d4931
a6d6b98
8bd8283
28ebb05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import { | ||
Display, | ||
FlexDirection, | ||
JustifyContent, | ||
} from '../../../helpers/constants/design-system'; | ||
import { Label, Box, Text } from '../../component-library'; | ||
|
||
type NoteToTraderProps = { | ||
placeholder: string; | ||
maxLength: number; | ||
onChange: (value: string) => void; | ||
noteText: string; | ||
labelText: string; | ||
}; | ||
|
||
const TabbedNoteToTrader: React.FC<NoteToTraderProps> = ({ | ||
placeholder, | ||
maxLength, | ||
onChange, | ||
noteText, | ||
labelText, | ||
}) => { | ||
return ( | ||
<Box className="confirm-page-container-content__data"> | ||
<Box | ||
display={Display.Flex} | ||
flexDirection={FlexDirection.Column} | ||
padding={4} | ||
> | ||
<Box | ||
className="note-header" | ||
display={Display.Flex} | ||
justifyContent={JustifyContent.spaceBetween} | ||
> | ||
<Label htmlFor="transaction-note">{labelText}</Label> | ||
<Text className="note-header__counter"> | ||
{noteText.length}/{maxLength} | ||
</Text> | ||
</Box> | ||
<Box | ||
display={Display.Flex} | ||
flexDirection={FlexDirection.Column} | ||
className="note-field" | ||
> | ||
<textarea | ||
id="transaction-note" | ||
data-testid="transaction-note" | ||
onChange={({ target: { value } }) => onChange(value)} | ||
autoFocus | ||
maxLength={maxLength} | ||
placeholder={placeholder} | ||
value={noteText} | ||
/> | ||
</Box> | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default TabbedNoteToTrader; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,54 @@ | ||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { | ||
BackgroundColor, | ||
BlockSize, | ||
BorderRadius, | ||
Display, | ||
FlexDirection, | ||
JustifyContent, | ||
} from '../../../helpers/constants/design-system'; | ||
import { Label, Box, Text } from '../../component-library'; | ||
import { Textarea } from '../../component-library/textarea'; | ||
import { setNoteToTraderMessage } from '../../../store/institutional/institution-background'; | ||
import { | ||
getIsNoteToTraderSupported, | ||
State, | ||
} from '../../../selectors/institutional/selectors'; | ||
import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; | ||
import { useConfirmContext } from '../../../pages/confirmations/context/confirm'; | ||
import { getConfirmationSender } from '../../../pages/confirmations/components/confirm/utils'; | ||
import { useI18nContext } from '../../../hooks/useI18nContext'; | ||
import { isSignatureTransactionType } from '../../../pages/confirmations/utils'; | ||
|
||
type NoteToTraderProps = { | ||
placeholder: string; | ||
maxLength: number; | ||
onChange: (value: string) => void; | ||
noteText: string; | ||
labelText: string; | ||
}; | ||
const NoteToTrader: React.FC = () => { | ||
const dispatch = useDispatch(); | ||
const t = useI18nContext(); | ||
const [noteText, setNoteText] = useState(''); | ||
|
||
const { currentConfirmation } = useConfirmContext(); | ||
const isSignature = isSignatureTransactionType(currentConfirmation); | ||
const { from } = getConfirmationSender(currentConfirmation); | ||
const fromChecksumHexAddress = toChecksumHexAddress(from || ''); | ||
const isNoteToTraderSupported = useSelector((state: State) => | ||
getIsNoteToTraderSupported(state, fromChecksumHexAddress), | ||
); | ||
|
||
const NoteToTrader: React.FC<NoteToTraderProps> = ({ | ||
placeholder, | ||
maxLength, | ||
onChange, | ||
noteText, | ||
labelText, | ||
}) => { | ||
return ( | ||
<Box className="confirm-page-container-content__data"> | ||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
dispatch(setNoteToTraderMessage(noteText)); | ||
}, 700); | ||
|
||
return () => clearTimeout(timer); | ||
}, [noteText]); | ||
|
||
return isNoteToTraderSupported && !isSignature ? ( | ||
<Box | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit]: Can instead be expressed with an early return which is arguably more readable: if (!isNotToTraderSupported || isSignature) {
return null
} |
||
backgroundColor={BackgroundColor.backgroundDefault} | ||
borderRadius={BorderRadius.MD} | ||
padding={0} | ||
marginBottom={4} | ||
> | ||
<Box | ||
display={Display.Flex} | ||
flexDirection={FlexDirection.Column} | ||
|
@@ -33,29 +59,31 @@ const NoteToTrader: React.FC<NoteToTraderProps> = ({ | |
display={Display.Flex} | ||
justifyContent={JustifyContent.spaceBetween} | ||
> | ||
<Label htmlFor="transaction-note">{labelText}</Label> | ||
<Label htmlFor="transaction-note">{t('transactionNote')}</Label> | ||
<Text className="note-header__counter"> | ||
{noteText.length}/{maxLength} | ||
{noteText.length}/{280} | ||
</Text> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what's the intended behaviour with this, but do we want to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the 280 is the max length. I'll assign it to a const in a next PR I have open 👍🏼 |
||
</Box> | ||
<Box | ||
display={Display.Flex} | ||
flexDirection={FlexDirection.Column} | ||
className="note-field" | ||
> | ||
<textarea | ||
<Textarea | ||
id="transaction-note" | ||
data-testid="transaction-note" | ||
onChange={({ target: { value } }) => onChange(value)} | ||
autoFocus | ||
maxLength={maxLength} | ||
placeholder={placeholder} | ||
onChange={({ target: { value } }) => setNoteText(value)} | ||
value={noteText} | ||
height={BlockSize.Full} | ||
width={BlockSize.Full} | ||
maxLength={280} | ||
placeholder={t('notePlaceholder')} | ||
padding={2} | ||
/> | ||
</Box> | ||
</Box> | ||
</Box> | ||
); | ||
) : null; | ||
}; | ||
|
||
export default NoteToTrader; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be removed towards the end of the year.