-
Notifications
You must be signed in to change notification settings - Fork 295
/
AddressSequential.tsx
93 lines (88 loc) · 2.37 KB
/
AddressSequential.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
// @flow
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import classnames from 'classnames';
import AddressActions from './AddressActions';
import styles from './AddressSequential.scss';
import WalletAddress from '../../../domains/WalletAddress';
type Props = {
address: WalletAddress,
onShareAddress: Function,
onCopyAddress: Function,
shouldRegisterAddressElement: boolean,
onRegisterHTMLElements: Function,
addressSlice: number,
};
@observer
export default class AddressSequential extends Component<Props> {
addressElement: ?HTMLElement;
addressContainerElement: ?HTMLElement;
componentDidMount() {
if (this.props.shouldRegisterAddressElement) {
this.props.onRegisterHTMLElements(
this.addressElement,
this.addressContainerElement
);
}
}
get rawAddress() {
return this.props.address.id;
}
get renderAddress() {
const { rawAddress } = this;
const { addressSlice } = this.props;
if (!addressSlice) return rawAddress;
const addressBegin = rawAddress.slice(0, addressSlice);
const addressEnd = rawAddress.slice(-addressSlice);
return `${addressBegin}…${addressEnd}`;
}
render() {
const {
address,
onShareAddress,
onCopyAddress,
shouldRegisterAddressElement,
} = this.props;
const { renderAddress, rawAddress } = this;
const addressClasses = classnames([
'Address',
`receiveAddress-${rawAddress}`,
styles.component,
address.used ? styles.usedWalletAddress : null,
]);
return (
<div
className={addressClasses}
onClick={() => onShareAddress(address)}
role="link"
aria-hidden
>
<div
className={styles.addressId}
ref={(ref) => {
this.addressContainerElement = ref;
}}
id={`address-${rawAddress}`}
>
{renderAddress}
{shouldRegisterAddressElement && (
<span
ref={(ref) => {
this.addressElement = ref;
}}
className={styles.addressElement}
>
{rawAddress}
</span>
)}
</div>
<AddressActions
address={address}
onShareAddress={onShareAddress}
onCopyAddress={onCopyAddress}
type="share"
/>
</div>
);
}
}