forked from decred/decrediton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReceivePage.jsx
158 lines (152 loc) · 5.01 KB
/
ReceivePage.jsx
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { useState, useRef } from "react";
import copy from "clipboard-copy";
import { FormattedMessage as T, injectIntl, defineMessages } from "react-intl";
import { ReceiveAccountsSelect, DcrInput } from "inputs";
import { Subtitle } from "shared";
import { KeyBlueButton, SmallButton } from "buttons";
import QRCodeModal from "./QRCodeModal";
import { classNames, Tooltip, TextHighlighted } from "pi-ui";
import style from "./ReceivePage.module.css";
const messages = defineMessages({
amountPlaceholder: {
id: "receive.amountPlaceholder",
defaultMessage: "Amount"
},
amountLabel: {
id: "receive.requestedAmountLabel",
defaultMessage: "Requested Amount"
}
});
const ReceivePage = ({
nextAddress,
onRequestAddress,
amountAtomValue,
amount,
error,
intl,
onValidateAmount
}) => {
const [modal, setModal] = useState(false);
const [tooltip, setTooltip] = useState(false);
const [tooltipText, setTooltipText] = useState(false);
const timeout = useRef();
function showTooltip() {
clearTimeout(timeout.current);
setTooltip(true);
timeout.current = setTimeout(() => {
setTooltip(false);
}, 1000);
}
return (
<>
{modal && <QRCodeModal {...{ amount, nextAddress, setModal }} />}
<Subtitle title={<T id="receive.subtitle" m="Receive DCR" />} />
<div className={style.receiveContent}>
<div className={style.inputs}>
<div className={style.inputWrapper}>
<label htmlFor="receiveAccountSelect">
<T id="receive.accountLabel" m="This address is for" />
</label>
{
// `selectWithBigFont` className is
// temp solution to skinning from ReactSelectGlobal.css.
// When react-select will be replaced by the `pi-ui` component,
// this className can be deleted.
}
<ReceiveAccountsSelect
id="receiveAccountSelect"
showAccountsButton
className={classNames(
style.receiveSelectAccountSelect,
"selectWithBigFont"
)}
selectClassName={style.receiveSelectAccountSelectInput}
/>
</div>
<div
className={classNames(
style.inputWrapper,
style.amountInputWrapper
)}>
<div className={style.receiveSelectAmountInput}>
<DcrInput
newBiggerFontStyle
id="amountInput"
label={intl.formatMessage(messages.amountLabel)}
className={style.requestedAmountInput}
required={false}
showErrors={error && error.amount}
invalid={error && error.amount}
invalidMessage={error && error.amount}
amount={amountAtomValue}
placeholder={intl.formatMessage(messages.amountPlaceholder)}
onChangeAmount={(e) => onValidateAmount(e)}
/>
</div>
</div>
</div>
<div className={style.line}>
<TextHighlighted
truncate={false}
className={classNames(style.receiveContentNestQR)}>
{nextAddress}
<div
className={classNames(
style.receiveContentNestCopyQR,
tooltip && style.opacity
)}>
<div className={style.receiveContentNestCopyQRArrow} />
<div className={style.receiveContentNestCopyQRText}>
{tooltipText ? (
<T
id="receive.tooltipGenerated"
m="+ New Address Generated"
/>
) : (
<T
id="receive.tooltipCopied"
m="✓ Copied to Clipboard"
/>
)}
</div>
</div>
</TextHighlighted>
<div>
<Tooltip content={<T id="receiveTab.copy" m="Copy" />}>
<SmallButton
className={style.receiveContentCopyButton}
onClick={() => {
copy(nextAddress);
setTooltipText(false);
showTooltip();
}}
/>
</Tooltip>
</div>
<div>
<Tooltip content={<T id="receiveTab.QRCode" m="QR code" />}>
<SmallButton
className={style.receiveContentQRButton}
onClick={() => setModal(true)}
/>
</Tooltip>
</div>
</div>
</div>
<div className={style.generateButton}>
<KeyBlueButton
size="large"
block={false}
className={style.blueButton}
onClick={() => {
setTooltipText(true);
showTooltip();
onRequestAddress();
}}>
<T id="receive.newAddressBtn" m="Generate new address" />
</KeyBlueButton>
</div>
</>
);
};
export default injectIntl(ReceivePage);