-
Notifications
You must be signed in to change notification settings - Fork 295
/
TopBar.tsx
115 lines (107 loc) · 3.34 KB
/
TopBar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// @flow
import React, { Component } from 'react';
import SVGInline from 'react-svg-inline';
import type { Node } from 'react';
import classNames from 'classnames';
import { observer } from 'mobx-react';
import { IS_BYRON_WALLET_MIGRATION_ENABLED } from '../../config/walletsConfig';
import LegacyBadge, { LEGACY_BADGE_MODES } from '../notifications/LegacyBadge';
import LegacyNotification from '../notifications/LegacyNotification';
import Wallet from '../../domains/Wallet';
import styles from './TopBar.scss';
import headerLogo from '../../assets/images/header-logo.inline.svg';
import { DiscreetWalletAmount } from '../../features/discreet-mode';
type Props = {
onLeftIconClick?: ?Function,
leftIcon?: ?string,
children?: ?Node,
activeWallet?: ?Wallet,
onTransferFunds?: Function,
onWalletAdd?: Function,
hasRewardsWallets?: boolean,
onLearnMore?: Function,
isShelleyActivated: boolean,
};
@observer
export default class TopBar extends Component<Props> {
render() {
const {
onLeftIconClick,
leftIcon,
activeWallet,
children,
hasRewardsWallets,
onTransferFunds,
onWalletAdd,
onLearnMore,
isShelleyActivated,
} = this.props;
const topBarStyles = classNames([
styles.topBar,
activeWallet ? styles.withWallet : styles.withoutWallet,
]);
const hasLegacyNotification =
activeWallet &&
activeWallet.isLegacy &&
isShelleyActivated &&
activeWallet.amount.gt(0) &&
!activeWallet.isRestoring &&
((hasRewardsWallets && onTransferFunds) || onWalletAdd);
const onTransferFundsFn =
onTransferFunds && activeWallet
? () => onTransferFunds(activeWallet.id)
: () => {};
const isRestoreActive = activeWallet ? activeWallet.isRestoring : false;
const topBarTitle = activeWallet ? (
<span className={styles.walletInfo}>
<span className={styles.walletName}>
{activeWallet.name}
{activeWallet.isLegacy && (
<LegacyBadge mode={LEGACY_BADGE_MODES.NATURAL} />
)}
</span>
<span className={styles.walletAmount}>
{
// show currency and use long format
isRestoreActive ? (
'-'
) : (
<DiscreetWalletAmount amount={activeWallet.amount} />
)
}
</span>
</span>
) : null;
const leftIconSVG = leftIcon && (
<SVGInline svg={leftIcon} className={styles.sidebarIcon} />
);
return (
<header>
<div className={topBarStyles}>
{leftIcon && (
<button className={styles.leftIcon} onClick={onLeftIconClick}>
{leftIconSVG}
</button>
)}
{activeWallet ? (
<div className={styles.topBarTitle}>{topBarTitle}</div>
) : (
<SVGInline svg={headerLogo} className={styles.headerLogo} />
)}
{children}
</div>
{IS_BYRON_WALLET_MIGRATION_ENABLED &&
hasLegacyNotification &&
activeWallet && (
<LegacyNotification
activeWalletName={activeWallet.name}
onLearnMore={onLearnMore}
onTransferFunds={onTransferFundsFn}
hasRewardsWallets={hasRewardsWallets}
onWalletAdd={onWalletAdd}
/>
)}
</header>
);
}
}