/
WalletRow.js
130 lines (119 loc) · 4.25 KB
/
WalletRow.js
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// @flow
import { Component } from 'react'
import type { Node } from 'react';
import styles from './WalletRow.scss'
import WalletAccountIcon from '../../topbar/WalletAccountIcon';
import type { WalletChecksum } from '@emurgo/cip4-js';
import type { PublicDeriverCache } from '../../../../chrome/extension/ergo-connector/types';
import type { TokenLookupKey } from '../../../api/common/lib/MultiToken';
import type { TokenRow } from '../../../api/ada/lib/storage/database/primitives/tables';
import { getTokenName } from '../../../stores/stateless/tokenHelpers';
import { hiddenAmount } from '../../../utils/strings';
import DeleteIcon from '../../../assets/images/dapp-connector/delete.inline.svg';
import NoDappImage from '../../../assets/images/dapp-connector/no-dapp.inline.svg';
import WalletType from '../../widgets/WalletType';
import NavPlate from '../../topbar/NavPlate'
import type { ConceptualWalletSettingsCache } from '../../../stores/toplevel/WalletSettingsStore';
import { intlShape, defineMessages } from 'react-intl';
import type { $npm$ReactIntl$IntlFormat } from 'react-intl';
const messages = defineMessages({
active: {
id: 'connector.connect.connectedWallets.active',
defaultMessage: '!!!Active',
}
});
type Props = {|
+url: ?string,
+protocol: ?string,
+isActiveSite: boolean,
+shouldHideBalance: boolean,
+onRemoveWallet: {| url: ?string, protocol: ?string |} => void,
+getTokenInfo: $ReadOnly<Inexact<TokenLookupKey>> => $ReadOnly<TokenRow>,
+settingsCache: ConceptualWalletSettingsCache | null,
+websiteIcon: string,
|};
type State = {|
showDeleteIcon: boolean,
|}
export default class WalletRow extends Component<Props, State> {
static contextTypes: {| intl: $npm$ReactIntl$IntlFormat |} = {
intl: intlShape.isRequired,
};
state: State = {
showDeleteIcon: false,
}
showDeleteIcon: void => void = () => {
this.setState({ showDeleteIcon: true })
}
hideDeleteIcon: void => void = () => {
this.setState({ showDeleteIcon: false })
}
render(): Node {
const {
isActiveSite,
url,
protocol,
plate,
onRemoveWallet,
balance,
shouldHideBalance,
getTokenInfo,
settingsCache,
websiteIcon
} = this.props;
const { showDeleteIcon } = this.state
const { intl } = this.context;
const defaultEntry = balance.getDefaultEntry();
const tokenInfo = getTokenInfo(defaultEntry);
const shiftedAmount = defaultEntry.amount
.shiftedBy(-tokenInfo.Metadata.numberOfDecimals);
return (
<div>
<div
onMouseEnter={this.showDeleteIcon}
onMouseLeave={this.hideDeleteIcon}
className={styles.component}
>
<p className={styles.name}>
{settingsCache.conceptualWalletName}
{settingsCache && <span> · <WalletType wallet={settingsCache} /></span>}
</p>
<div className={styles.rowWrapper}>
<div>
<div className={styles.card}>
<div className={styles.avatar}>
<NavPlate plate={plate} wallet={settingsCache} />
</div>
<p className={styles.balance}>
{shouldHideBalance ? hiddenAmount : shiftedAmount.toString()}{' '}
<span>{getTokenName(tokenInfo)}</span>
</p>
</div>
</div>
<div className={styles.dapp}>
<div className={styles.websiteIcon}>
{websiteIcon ?
<img src={websiteIcon} alt={url} />:
<NoDappImage />
}
</div>
<div>
<p className={styles.url}>{url}</p>
{isActiveSite &&
<p className={styles.status}>
{intl.formatMessage(messages.active)}
</p>}
</div>
</div>
<div className={styles.delete}>
{showDeleteIcon &&
<button onClick={() => onRemoveWallet({ url, protocol })} type='button'>
<DeleteIcon />
</button>}
</div>
</div>
</div>
</div>
)
}
}