From e8c1dc17f9c074e261dfa531a7c6970abd8375e1 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com> Date: Mon, 25 Jan 2021 19:40:46 +0100 Subject: [PATCH] allow giving a name to ledger (#630) --- .../extension-ui/src/Popup/ImportLedger.tsx | 20 +++++++++++++------ .../extension-ui/src/components/Dropdown.tsx | 4 +++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/extension-ui/src/Popup/ImportLedger.tsx b/packages/extension-ui/src/Popup/ImportLedger.tsx index 5a6474bd..d50cc909 100644 --- a/packages/extension-ui/src/Popup/ImportLedger.tsx +++ b/packages/extension-ui/src/Popup/ImportLedger.tsx @@ -3,7 +3,7 @@ import { faSync } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'; +import React, { useCallback, useContext, useEffect, useRef, useState } from 'react'; import styled from 'styled-components'; import settings from '@polkadot/ui-settings'; @@ -12,7 +12,7 @@ import { ActionContext, Address, Button, ButtonArea, Dropdown, VerticalSpace, Wa import { useLedger } from '../hooks/useLedger'; import useTranslation from '../hooks/useTranslation'; import { createAccountHardware } from '../messaging'; -import { Header } from '../partials'; +import { Header, Name } from '../partials'; import { ThemeProps } from '../types'; import ledgerChains from '../util/legerChains'; @@ -40,7 +40,7 @@ function ImportLedger ({ className }: Props): React.ReactElement { const [isBusy, setIsBusy] = useState(false); const [genesis, setGenesis] = useState(null); const onAction = useContext(ActionContext); - const name = useMemo(() => `ledger ${accountIndex}/${addressOffset}`, [accountIndex, addressOffset]); + const [name, setName] = useState(null); const { address, error: ledgerError, isLoading: ledgerLoading, isLocked: ledgerLocked, refresh, warning: ledgerWarning } = useLedger(genesis, accountIndex, addressOffset); useEffect(() => { @@ -72,7 +72,7 @@ function ImportLedger ({ className }: Props): React.ReactElement { const _onSave = useCallback( () => { - if (address && genesis) { + if (address && genesis && name) { setIsBusy(true); createAccountHardware(address, 'ledger', accountIndex, addressOffset, name, genesis) @@ -104,7 +104,7 @@ function ImportLedger ({ className }: Props): React.ReactElement { genesisHash={genesis} isExternal isHardware - name={address ? name : ''} + name={name} /> - {genesis && address && !ledgerError && ( + { !!genesis && !!address && !ledgerError && ( + + )} + { !!name && ( <> ('account type')} onChange={_onSetAccountIndex} options={accOps.current} @@ -124,6 +131,7 @@ function ImportLedger ({ className }: Props): React.ReactElement { /> ('address index')} onChange={_onSetAddressOffset} options={addOps.current} diff --git a/packages/extension-ui/src/components/Dropdown.tsx b/packages/extension-ui/src/components/Dropdown.tsx index 2a5315c6..803e82d9 100644 --- a/packages/extension-ui/src/components/Dropdown.tsx +++ b/packages/extension-ui/src/components/Dropdown.tsx @@ -17,6 +17,7 @@ interface DropdownOption { interface Props extends ThemeProps { className?: string; defaultValue?: string | null; + isDisabled?: boolean isError?: boolean; isFocussed?: boolean; label: string; @@ -26,7 +27,7 @@ interface Props extends ThemeProps { value?: string; } -function Dropdown ({ className, defaultValue, isFocussed, label, onBlur, onChange, options, value }: Props): React.ReactElement { +function Dropdown ({ className, defaultValue, isDisabled, isFocussed, label, onBlur, onChange, options, value }: Props): React.ReactElement { const _onChange = ({ target: { value } }: React.ChangeEvent): void => { onChange && onChange(value.trim()); }; @@ -40,6 +41,7 @@ function Dropdown ({ className, defaultValue, isFocussed, label, onBlur, onChang