// Copyright 2019-2023 @polkadot/extension-ui authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { ThemeProps } from '../types.js'; import { faUsb } from '@fortawesome/free-brands-svg-icons'; import { faCodeBranch, faFileExport, faFileUpload, faKey, faPlusCircle, faQrcode } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import React, { useCallback, useContext } from 'react'; import { AccountContext, Link, MediaContext, Menu, MenuDivider, MenuItem } from '../components/index.js'; import useIsPopup from '../hooks/useIsPopup.js'; import { useLedger } from '../hooks/useLedger.js'; import useTranslation from '../hooks/useTranslation.js'; import { windowOpen } from '../messaging.js'; import { styled } from '../styled.js'; interface Props extends ThemeProps { className?: string; reference: React.MutableRefObject; } const jsonPath = '/account/restore-json'; const ledgerPath = '/account/import-ledger'; function MenuAdd ({ className, reference }: Props): React.ReactElement { const { t } = useTranslation(); const { master } = useContext(AccountContext); const mediaAllowed = useContext(MediaContext); const { isLedgerCapable, isLedgerEnabled } = useLedger(); const isPopup = useIsPopup(); const _openJson = useCallback( (): void => { windowOpen(jsonPath).catch(console.error); }, [] ); const _onOpenLedgerConnect = useCallback( (): void => { windowOpen(ledgerPath).catch(console.error); }, [] ); return ( { t('Create new account')} {!!master && ( <> {t('Derive from an account')} )} {t('Export all accounts')} {t('Import account from pre-existing seed')} {t('Restore account from backup JSON file')} ('Camera access must be first enabled in the settings') : '' } to='/account/import-qr' > {t('Attach external QR-signer account')} {isLedgerEnabled ? ( ('Ledger devices can only be connected with Chrome browser')) || ''} to={ledgerPath} > { t('Attach ledger account')} ) : ( { t('Connect Ledger device')} ) } ); } export default React.memo(styled(MenuAdd)(({ theme }: Props) => ` margin-top: 50px; right: 50px; // 24 + 18 + 8 user-select: none; .menuItem { span:first-child { height: 20px; margin-right: 8px; opacity: 0.5; width: 20px; } span { vertical-align: middle; } .svg-inline--fa { color: ${theme.iconNeutralColor}; margin-right: 0.3rem; width: 0.875em; } } `));