From cf320119768d27ba7a6098183bc8a91b769d3848 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 4 May 2020 15:39:56 +0200 Subject: [PATCH] Ledger confim address (#2686) --- .../page-accounts/src/Accounts/Account.tsx | 23 ++++++++++++++++++- packages/react-hooks/src/types.ts | 1 + packages/react-hooks/src/useAccountInfo.ts | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/page-accounts/src/Accounts/Account.tsx b/packages/page-accounts/src/Accounts/Account.tsx index d287347e5f..486dba0bff 100644 --- a/packages/page-accounts/src/Accounts/Account.tsx +++ b/packages/page-accounts/src/Accounts/Account.tsx @@ -10,6 +10,7 @@ import { SortedAccount } from './types'; import BN from 'bn.js'; import React, { useCallback, useState, useEffect } from 'react'; import styled from 'styled-components'; +import { getLedger } from '@polkadot/react-api'; import { AddressInfo, AddressMini, AddressSmall, Badge, Button, ChainLock, CryptoType, Forget, Icon, IdentityIcon, LinkExternal, Menu, Popup, Tag } from '@polkadot/react-components'; import { useAccountInfo, useApi, useCall, useIncrement, useToggle } from '@polkadot/react-hooks'; import { Option, StorageKey } from '@polkadot/types'; @@ -59,7 +60,7 @@ function Account ({ account: { address, meta }, className, filter, isFavorite, s .filter(([, opt]) => opt.isSome) .map(([key, opt]) => [key.args[1] as H256, opt.unwrap()]) }); - const { flags: { isDevelopment, isExternal, isInjected, isMultisig }, genesisHash, name: accName, onSetGenesisHash, tags } = useAccountInfo(address); + const { flags: { isDevelopment, isExternal, isHardware, isInjected, isMultisig }, genesisHash, name: accName, onSetGenesisHash, tags } = useAccountInfo(address); const [isVisible, setIsVisible] = useState(true); const [isBackupOpen, toggleBackup] = useToggle(); const [isDeriveOpen, toggleDerive] = useToggle(); @@ -118,6 +119,19 @@ function Account ({ account: { address, meta }, className, filter, isFavorite, s [refreshMulti, toggleMultisig] ); + const _showOnHardware = useCallback( + (): void => { + // TODO: we should check the hardwareType from metadata here as well, + // for now we are always assuming hardwareType === 'ledger' + getLedger() + .getAddress(true) + .catch((error): void => { + console.error(`ledger: ${error.message}`); + }); + }, + [] + ); + if (!isVisible) { return null; } @@ -307,6 +321,13 @@ function Account ({ account: { address, meta }, className, filter, isFavorite, s > {t('Derive account via derivation path')} + {isHardware && ( + + {t('Show address on hardware device')} + + )} +