1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/ui/update-nickname-popover/update-nickname-popover.js

127 lines
3.2 KiB
JavaScript
Raw Normal View History

import React, { useCallback, useContext, useState } from 'react';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import Popover from '../popover';
import Button from '../button';
import TextField from '../text-field';
import { I18nContext } from '../../../contexts/i18n';
import Identicon from '../identicon';
import { getTokenList } from '../../../selectors';
export default function UpdateNicknamePopover({
address,
2022-06-08 23:21:53 +02:00
nickname = '',
memo = '',
onAdd,
onClose,
}) {
const t = useContext(I18nContext);
2022-06-08 01:04:59 +02:00
const [nicknameInput, setNicknameInput] = useState(
nickname === null ? '' : nickname,
);
const [memoInput, setMemoInput] = useState(memo === null ? '' : memo);
const handleNicknameChange = (event) => {
setNicknameInput(event.target.value);
};
const handleMemoChange = (event) => {
setMemoInput(event.target.value);
};
const closePopover = useCallback(() => {
onClose();
}, [onClose]);
const onCancel = () => {
onClose();
};
const onSubmit = () => {
onAdd(address, nicknameInput, memoInput);
onClose();
};
const tokenList = useSelector(getTokenList);
return (
<Popover
Feature: Transaction Insights (#12881) * integration for tx decoding confirmation and history view * upgrading @truffle/decoder to latest release 5.1.0 * Update acorn and colors patches * feat: remove redundant styling * feat: basic integration for nickname components * feat: wiring functionality of adding new nickname * feat: wire functionality of showing nickname modal * feat: link the nickname popover with add/update popover * feat: moving forward with address nicknames integration * feat: fixing a bug related to passing chainId in addressBook * feat: populating memo prop in addressbook entry * feat: add explorer link * feat: bug fixing update nickname component * feat: fix proptypes * feat: adding tooltip for copying nickname address * featL fix styling for tx-details page * feat: optimize code for error handling * feat: limiting transaction decoding to tx with data * feat: remove tree UI component * feat: adding request to check for tx decoding supported networks * feat: showing data hex component * feat: fix react warnings * feat: remove extra margin in tx decoding * Remove unused package @truffle/source-map-utils * Ensure messages get translated * feat: link tx-decoding addresses with nicknames * Omit value for boolean attributes * Fix props reading in CopyRawData * fix: fixing issue with transaltion * Fix lint errors in TransactionDecoding - Remove unused import - Reorder imports - Address conflict between caught `error` and error state flag by renaming state flag to `hasError` - Fix requestUrl identifier casing and use of template string - Ensure `useEffect` gets passed the deps it needs - Add scope braces around case statement where it's needed - Omit literal `true` for boolean jsx attribute - Refactor nested ternary as `if` statements * fix: revert fetchWithCache modifications * Fix linting for TransactionListItemDetails - Remove unused import - Fix import spacing - Remove unused prop dereference - Fix string interpolation for translated From/To * Moving to popover pattern * fix: sass color variable * Omit value for boolean attribute * Remove changes from modal.js * fix: refactor nickname popovers * Ensure const gets declared before it's used * Fix linting for ConfirmTransactionBase - Remove unused prop chainId - Stop destructuring an unused field * fix: refactor usage of nicknames popovers in send-content-container * fix: remove extra prop updateAccountNicknameModal * fix: refactor code for address.component * fix: remove extra tooltip * Ensure NicknamePopovers always returns component * Fix linting for NicknamePopover component - Fix useCallback deps - Switch ternary to logical-or * Fix linting for SenderToRecipient ... by fixing import order * Remove unused addressCopied state * Delete empty file * fix: remove sender-to-recipient.container * fix: refactor usage of nickname popovers in confirm-page-container * fix: bug related to state variable * Stylelint fix * Lint fix * Change "Total Amount" to "Total" * Lint fix locales * Update address-book.spec.js * e2e test update * Update e2e tests * Fix issue where absence of function params in data hex tab would result in rendering a string * Fix border radius, and width and height in small notification windows, of the update-nickname-popover * Remove fake await * Clean up * Clean up Co-authored-by: Alaa Hadad <alaahd@Alaas-MacBook-M1-Pro-14-inch.local> Co-authored-by: Dan Miller <danjm.com@gmail.com> Co-authored-by: g. nicholas d'andrea <gnidan@trufflesuite.com>
2021-12-01 18:22:08 +01:00
title={nickname ? t('editAddressNickname') : t('addANickname')}
onClose={closePopover}
className="update-nickname__wrapper"
footer={
<>
<Button
className="update-nickname__cancel"
type="secondary"
onClick={onCancel}
>
{t('cancel')}
</Button>
Feature: Transaction Insights (#12881) * integration for tx decoding confirmation and history view * upgrading @truffle/decoder to latest release 5.1.0 * Update acorn and colors patches * feat: remove redundant styling * feat: basic integration for nickname components * feat: wiring functionality of adding new nickname * feat: wire functionality of showing nickname modal * feat: link the nickname popover with add/update popover * feat: moving forward with address nicknames integration * feat: fixing a bug related to passing chainId in addressBook * feat: populating memo prop in addressbook entry * feat: add explorer link * feat: bug fixing update nickname component * feat: fix proptypes * feat: adding tooltip for copying nickname address * featL fix styling for tx-details page * feat: optimize code for error handling * feat: limiting transaction decoding to tx with data * feat: remove tree UI component * feat: adding request to check for tx decoding supported networks * feat: showing data hex component * feat: fix react warnings * feat: remove extra margin in tx decoding * Remove unused package @truffle/source-map-utils * Ensure messages get translated * feat: link tx-decoding addresses with nicknames * Omit value for boolean attributes * Fix props reading in CopyRawData * fix: fixing issue with transaltion * Fix lint errors in TransactionDecoding - Remove unused import - Reorder imports - Address conflict between caught `error` and error state flag by renaming state flag to `hasError` - Fix requestUrl identifier casing and use of template string - Ensure `useEffect` gets passed the deps it needs - Add scope braces around case statement where it's needed - Omit literal `true` for boolean jsx attribute - Refactor nested ternary as `if` statements * fix: revert fetchWithCache modifications * Fix linting for TransactionListItemDetails - Remove unused import - Fix import spacing - Remove unused prop dereference - Fix string interpolation for translated From/To * Moving to popover pattern * fix: sass color variable * Omit value for boolean attribute * Remove changes from modal.js * fix: refactor nickname popovers * Ensure const gets declared before it's used * Fix linting for ConfirmTransactionBase - Remove unused prop chainId - Stop destructuring an unused field * fix: refactor usage of nicknames popovers in send-content-container * fix: remove extra prop updateAccountNicknameModal * fix: refactor code for address.component * fix: remove extra tooltip * Ensure NicknamePopovers always returns component * Fix linting for NicknamePopover component - Fix useCallback deps - Switch ternary to logical-or * Fix linting for SenderToRecipient ... by fixing import order * Remove unused addressCopied state * Delete empty file * fix: remove sender-to-recipient.container * fix: refactor usage of nickname popovers in confirm-page-container * fix: bug related to state variable * Stylelint fix * Lint fix * Change "Total Amount" to "Total" * Lint fix locales * Update address-book.spec.js * e2e test update * Update e2e tests * Fix issue where absence of function params in data hex tab would result in rendering a string * Fix border radius, and width and height in small notification windows, of the update-nickname-popover * Remove fake await * Clean up * Clean up Co-authored-by: Alaa Hadad <alaahd@Alaas-MacBook-M1-Pro-14-inch.local> Co-authored-by: Dan Miller <danjm.com@gmail.com> Co-authored-by: g. nicholas d'andrea <gnidan@trufflesuite.com>
2021-12-01 18:22:08 +01:00
<Button
className="update-nickname__save"
type="primary"
onClick={onSubmit}
disabled={!nicknameInput}
>
{t('save')}
</Button>
</>
}
>
<div className="update-nickname__content">
<Identicon
className="update-nickname__content__indenticon"
address={address}
diameter={36}
image={tokenList[address.toLowerCase()]?.iconUrl}
/>
<label className="update-nickname__content__label--capitalized">
{t('address')}
</label>
<div className="update-nickname__content__address">{address}</div>
<div className="update-nickname__content__nickname-label">
{t('nickname')}
</div>
<TextField
className="update-nickname__content__text-field"
value={nicknameInput}
onChange={handleNicknameChange}
placeholder={t('addANickname')}
fullWidth
/>
<div className="update-nickname__content__label--capitalized">
{t('memo')}
</div>
<TextField
type="text"
id="memo"
value={memoInput}
onChange={handleMemoChange}
placeholder={t('addMemo')}
fullWidth
margin="dense"
multiline
rows={3}
classes={{
inputMultiline: 'update-nickname__content__text-area',
inputRoot: 'update-nickname__content__text-area-wrapper',
}}
/>
</div>
</Popover>
);
}
UpdateNicknamePopover.propTypes = {
nickname: PropTypes.string,
address: PropTypes.string,
memo: PropTypes.string,
onAdd: PropTypes.func,
onClose: PropTypes.func,
};