Skip to content

Commit

Permalink
Merge pull request #4793 from LiskHQ/4769-add-hw-status-to-top-bar
Browse files Browse the repository at this point in the history
Add hardware wallet status to top bar
  • Loading branch information
eniolam1000752 authored Feb 9, 2023
2 parents 9ecc236 + cde3a54 commit ea62b14
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 51 deletions.
6 changes: 6 additions & 0 deletions libs/hwServer/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ export const FUNCTION_TYPES = {
[IPC_MESSAGES.SIGN_TRANSACTION]: 'signTransaction',
[IPC_MESSAGES.SIGN_MSG]: 'signMessage',
};

export const HW_CONNECTION_STATUS = {
STAND_BY: 'standby',
DISCONNECTED: 'disconnected',
CONNECTED: 'connected',
};
7 changes: 7 additions & 0 deletions setup/react/app/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ or "warn/action" ineastd of "red/green"
--color-ufo-green: #00a04b;
--color-deep-green: #00d563;
--color-jade-green: #2bd67b;
--color-jade-green-border: #2bd67b33;
--color-jade-green-background: #2bd67b0d;
--color-pale-pink: #ffd0d1;
--color-silver: #eef0f7;
--color-black: #000;
Expand All @@ -133,6 +135,8 @@ or "warn/action" ineastd of "red/green"
--color-constant-white: #fff;
--color-danger: #ff7721;
--color-red: #ff4557;
--color-red-border: #ff455733;
--color-red-background: #ff45570d;
--color-content: #19224d;
--color-content-light: #0c152e;
--color-primary-very-light: #e8f0fa;
Expand Down Expand Up @@ -180,6 +184,8 @@ or "warn/action" ineastd of "red/green"
--color-tooltip-bg: rgb(255, 255, 255, 0.7);
--color-tooltip-arrow: rgb(255, 255, 255, 0.7);
--color-warning-border: #f7e36d;
--color-warning-border-transparent: #f7e36d33;
--color-warning-border-background-transparent: #f7e36d19;
--color-warning-bg: #fffce8;
--color-tx-priority-btn-bg: var(--color-ink-blue);
--color-tx-priority-btn-default: var(--color-maastricht-blue);
Expand All @@ -199,6 +205,7 @@ or "warn/action" ineastd of "red/green"
--color-token-card-shadow: #eaeaea5c;
--color-stakes-available: #4070f41a;
--color-search-bar-background: #2e3855;
--color-success: #25ca95;
--color-edit-button-background: var(--color-ghost-white);
--color-edit-button-border: var(--color-very-light-gray);

Expand Down
3 changes: 3 additions & 0 deletions setup/react/assets/images/icons/hardware-wallet-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
"Got it, thanks!": "Got it, thanks!",
"Great! Your account is now created": "Great! Your account is now created",
"Group": "Group",
"Hardware wallet details": "Hardware wallet details",
"Height": "Height",
"Help": "Help",
"Help improve Lisk by sending anonymous usage data.": "Help improve Lisk by sending anonymous usage data.",
Expand Down
140 changes: 140 additions & 0 deletions src/modules/common/components/bars/topBar/hardwareWallet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
@import '../../../../../../setup/react/app/mixins.css';

.wrapper {
margin-right: 16px;
position: relative;
display: flex;
flex-direction: column;
justify-content: center;

& .hwIcon {
width: 20px;
height: 100% !important;
background-color: transparent;
padding: 0px 6px !important;
max-width: fit-content;
min-width: fit-content;
position: relative;

&.connected::after {
background-color: var(--color-jade-green);
}

&.standby::after {
background-color: var(--color-warning-border);
}

&::after {
width: 6px;
height: 6px;
border-radius: 50%;
content: "";
display: block;
position: absolute;
margin-top: -25px;
margin-left: 14px;
}

& > img {
margin-top: 5px;
}
}

& > button ~ div {
margin-right: -23px;
margin-top: -18px;
width: 229px;
}
}

.dropdown {
width: 200px;
padding: 24px 16px 17px 16px;
border-radius: var(--border-radius-box);

& h6 {
font-family: var(--heading-font) !important;
font-size: var(--font-size-h6) !important;
color: var(--color-content-light) !important;
padding: 0px !important;
margin: 0px;

&:hover {
background-color: transparent !important;
}
}

& h6 ~ ul {
padding: 0px !important;
font-size: var(--paragraph-font-size-s) !important;
margin: 6px 0px 0px 0px;

&:hover {
background-color: transparent !important;
color: var(--color-slate-gray);
}

& > li {
display: flex;
flex-direction: row;
margin-top: 10px;
}

& > li > div {
width: 35%;
color: var(--color-slate-gray);
}

& > li > div:nth-child(2) {
width: 65%;
color: var(--color-content-light);
}
}
}

.statusWrapper {
border-radius: 5px;
border: 1px solid transparent;
display: flex;
align-items: center;
font-size: var(--button-font-size-s);
width: fit-content;
padding: 0px 8px;
text-transform: capitalize;

&::before {
width: 6px;
height: 6px;
border-radius: 50%;
content: "";
display: block;
margin-right: 8px;
}

&.standby {
border-color: var(--color-warning-border-transparent);
background-color: var(--color-warning-border-background-transparent);
color: var(--color-warning-border) !important;

&::before {
background-color: var(--color-warning-border);
}
}

&.connected {
border-color: var(--color-jade-green-border);
background-color: var(--color-jade-green-background);
color: var(--color-jade-green) !important;

&::before {
background-color: var(--color-jade-green);
}
}
}

.hwStatusTooltip {
width: fit-content;
padding: 0px;
transform: translate(30px, -6px) !important;
background-color: var(--color-white);
}
58 changes: 58 additions & 0 deletions src/modules/common/components/bars/topBar/hardwareWallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import Tooltip from 'src/theme/Tooltip';
import { useTranslation } from 'react-i18next';
import Icon from 'src/theme/Icon';
import { HW_CONNECTION_STATUS } from '@libs/hwServer/constants';
import styles from './hardwareWallet.css';

const Status = ({ status }) => (
<div className={`${styles.statusWrapper} ${styles[status]}`}>
<b>{status}</b>
</div>
);

const HardwareWallet = () => {
const { t } = useTranslation();

/** @TODO:
* actual values should be replaced when the useHWStatus hook is integrated by issue #4768
* Also this component should return null when there is no current device connected.
*/
const status = HW_CONNECTION_STATUS.STAND_BY;
const hwStatusInfo = [
{ label: 'Brand :', value: 'Ledger' },
{ label: 'Model :', value: 'Nano S' },
{ label: 'ID :', value: '23233' },
{ label: 'Status :', value: <Status status={status} /> },
];

return (
<section className={styles.wrapper}>
<Tooltip
tooltipClassName={`${styles.hwStatusTooltip}`}
position="bottom left"
content={
<div className={`${styles.hwIcon} ${styles[status]}`}>
<Icon name="hardwareWalletIcon" />
</div>
}
>
<div className={styles.dropdown}>
<h6>
<b>{t('Hardware wallet details')}</b>
</h6>
<ul>
{hwStatusInfo.map(({ label, value }) => (
<li key={label}>
<div>{label}</div>
<div>{value}</div>
</li>
))}
</ul>
</div>
</Tooltip>
</section>
);
};

export default HardwareWallet;
18 changes: 18 additions & 0 deletions src/modules/common/components/bars/topBar/hardwareWallet.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import HardwareWallet from './hardwareWallet';

describe('hardwareWallet', () => {
beforeEach(() => {
render(<HardwareWallet />);
});

// @TODO: we should update test when the useHWStatus hook has been integrated
it('should render hardware wallet icon', () => {
expect(screen.getByAltText('hardwareWalletIcon')).toBeTruthy();
expect(screen.getByText('Brand :')).toBeTruthy();
expect(screen.getByText('Model :')).toBeTruthy();
expect(screen.getByText('ID :')).toBeTruthy();
expect(screen.getByText('Status :')).toBeTruthy();
});
});
2 changes: 2 additions & 0 deletions src/modules/common/components/bars/topBar/topBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { isEmpty } from 'src/utils/helpers';
import NavigationButtons from '@common/components/bars/topBar/navigationButtons';
import styles from './topBar.css';
import Network from './networkName';
import HardwareWallet from './hardwareWallet';

const TopBar = ({ stakeCount, location, history }) => {
const disabled = location.pathname === routes.reclaim.path;
Expand All @@ -39,6 +40,7 @@ const TopBar = ({ stakeCount, location, history }) => {
<SearchBar className={styles.searchBarProp} />
</div>
<div className={styles.group}>
<HardwareWallet />
<Tooltip
className={styles.tooltipWrapper}
size="maxContent"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/transaction/utils/hwManager/hwManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as communication from '@libs/hwServer/communication';
// import accounts from '@tests/constants/wallets';
import { signTransactionByHW } from '.';

jest.mock('@libs/hwManager/communication', () => ({
jest.mock('@libs/hwServer/communication', () => ({
signTransaction: jest.fn(),
}));

Expand Down
2 changes: 1 addition & 1 deletion src/modules/wallet/utils/hwManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getAccountsFromDevice, signMessageByHW, getNewAccountByIndex } from './

const address = 'lskdxc4ta5j43jp9ro3f8zqbxta9fn6jwzjucw7yt';

jest.mock('@libs/hwManager/communication', () => ({
jest.mock('@libs/hwServer/communication', () => ({
getPublicKey: jest.fn(),
signTransaction: jest.fn(),
signMessage: jest.fn(),
Expand Down
2 changes: 2 additions & 0 deletions src/theme/Icon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ import receivedTransactionIcon from '@setup/react/assets/images/icons/received_t
import sentTransactionIcon from '@setup/react/assets/images/icons/sent_transaction_icon.svg';
import commissionsIcon from '@setup/react/assets/images/icons/commissions.svg';
import editActiveIcon from '@setup/react/assets/images/icons/editActive.svg';
import hardwareWalletIcon from '@setup/react/assets/images/icons/hardware-wallet-icon.svg';

export const icons = {
academy,
Expand Down Expand Up @@ -468,6 +469,7 @@ export const icons = {
arrowBlueRight,
multisigKeys,
multisigKeysDark,
hardwareWalletIcon,
};

const Icon = ({ name, noTheme, ...props }) => {
Expand Down
Loading

0 comments on commit ea62b14

Please sign in to comment.