on master help sign in
reskin InlineEthereumTransaction
commit97de700a4f53a230d201c90b087a32394b1e797b authorLiam Fitzgerald <liam@urizen.co> dateFri 28 Feb 2020, 12:40 (7 years ago) parent83e8ca4
5 files changed+93−29
src/assets/info.svg+3 src/components/InlineEthereumTransaction.js+84−24 src/lib/useEthereumTransaction.js+4−2 src/views/UrbitOS/Home.js+1−2 src/views/UrbitOS/NetworkingKeys.js+1−1
src/assets/info.svgnew file+3
@@ -0,0 +1,3 @@
1+<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
2+<path d="M6 -5.24537e-07C2.68503 -8.1434e-07 8.1434e-07 2.68503 5.24537e-07 6C2.34733e-07 9.31497 2.68503 12 6 12C9.31497 12 12 9.31497 12 6C12 2.68503 9.31497 -2.34733e-07 6 -5.24537e-07ZM6 0.723491C8.91892 0.723491 11.2765 3.08732 11.2765 6C11.2765 8.91892 8.91892 11.2765 6 11.2765C3.08108 11.2765 0.723492 8.91892 0.723492 6C0.723492 3.08732 3.08108 0.723491 6 0.723491ZM5.57588 9.19335L6.42412 9.19335L6.42 5.22L5.58 5.22L5.57588 9.19335ZM6 2.75676C5.69127 2.75676 5.43867 3.00935 5.43867 3.31809C5.43867 3.62682 5.69127 3.87942 6 3.87942C6.30873 3.87942 6.56133 3.62682 6.56133 3.31809C6.56133 3.00936 6.30873 2.75676 6 2.75676Z" fill="#B1B2B3"/>
3+</svg>
src/components/InlineEthereumTransaction.js+84−24
@@ -1,4 +1,4 @@
1−import React, { useMemo, useCallback } from 'react';
1+import React, { useMemo, useCallback, useState } from 'react';
22import cn from 'classnames';
33import {
44 Grid,
@@ -8,11 +8,16 @@ import {
88 LinkButton,
99 H5,
1010 Text,
11+ IconButton,
1112} from 'indigo-react';
13+import { toBN } from 'web3-utils';
14+
15+import { ReactComponent as InfoIcon } from 'assets/info.svg';
1216
1317import { useExploreTxUrls } from 'lib/explorer';
1418import { hexify } from 'lib/txn';
1519import pluralize from 'lib/pluralize';
20+import { safeFromWei, safeToWei } from 'lib/lib';
1621
1722import { composeValidator, buildCheckboxValidator } from 'form/validators';
1823import BridgeForm from 'form/BridgeForm';
@@ -45,6 +50,8 @@ export default function InlineEthereumTransaction({
4550 needFunds,
4651 signedTransactions,
4752 confirmationProgress,
53+ gasLimit,
54+ unsignedTransactions,
4855
4956 // additional from parent
5057 label = 'Generate & Sign Transaction',
@@ -52,7 +59,11 @@ export default function InlineEthereumTransaction({
5259 onReturn,
5360}) {
5461 // show receipt after successful broadcast
55− const showReceipt = broadcasted || confirmed || completed;
62+ const [showReceipt, setShowReceipt] = useState(false);
63+ const toggleShowReceipt = useCallback(() => setShowReceipt(!showReceipt), [
64+ setShowReceipt,
65+ showReceipt,
66+ ]);
5667 // show configure controls pre-broadcast
5768 const showConfigureInput = !(signed || broadcasted || confirmed || completed);
5869 // show the send/loading button while signed, broadcasting, or confirme
@@ -62,6 +73,12 @@ export default function InlineEthereumTransaction({
6273 // show signed tx only when signing (for offline usage)
6374 const showSignedTx = signed;
6475
76+ const [showGasDetails, _setShowGasDetails] = useState(false);
77+ const toggleGasDetails = useCallback(
78+ () => _setShowGasDetails(!showGasDetails),
79+ [_setShowGasDetails, showGasDetails]
80+ );
81+
6582 const validate = useMemo(
6683 () =>
6784 composeValidator({
@@ -88,11 +105,7 @@ export default function InlineEthereumTransaction({
88105 </Grid.Item>
89106 );
90107 } else if (completed) {
91− return (
92− <Grid.Item full className="pv4 black f5">
93− Transaction Complete
94− </Grid.Item>
95− );
108+ return undefined;
96109 } else if (showBroadcastButton) {
97110 return (
98111 <Grid.Item
@@ -137,6 +150,29 @@ export default function InlineEthereumTransaction({
137150 [signedTransactions]
138151 );
139152
153+ const numTxs = useMemo(() => (unsignedTransactions || []).length || 1, [
154+ unsignedTransactions,
155+ ]);
156+ const maxCost = useMemo(
157+ () =>
158+ safeFromWei(
159+ safeToWei(
160+ toBN(gasLimit)
161+ .mul(toBN(gasPrice))
162+ .mul(toBN(numTxs)),
163+ 'gwei'
164+ )
165+ ),
166+ [gasLimit, gasPrice, numTxs]
167+ );
168+
169+ const gasInfo = useMemo(() => {
170+ const extra = numTxs === 1 ? '' : `* ${numTxs} TXN`;
171+ return showGasDetails
172+ ? `${gasPrice} Gwei * ${gasLimit} ${extra} = ${maxCost} ETH`
173+ : `${maxCost} ETH`;
174+ }, [showGasDetails, maxCost, gasPrice, gasLimit, numTxs]);
175+
140176 return (
141177 <Grid className={cn(className, 'mt1')}>
142178 <BridgeForm validate={validate} onValues={onValues}>
@@ -172,6 +208,7 @@ export default function InlineEthereumTransaction({
172208 />
173209
174210 <Condition when="useAdvanced" is={true}>
211+ <Grid.Item full className="mb2"></Grid.Item>
175212 <Grid.Divider />
176213 <Grid.Item
177214 full
@@ -180,8 +217,16 @@ export default function InlineEthereumTransaction({
180217 justify="between"
181218 className="mt2">
182219 <Flex.Item as={H5}>Gas Price</Flex.Item>
183− <Flex.Item as={H5}>{gasPrice} Gwei</Flex.Item>
220+
221+ <Flex.Item as={H5}>
222+ {gasInfo}{' '}
223+ <InfoIcon
224+ className="pointer"
225+ onClick={toggleGasDetails}
226+ />
227+ </Flex.Item>
184228 </Grid.Item>
229+
185230 {/* TODO(shrugs): move to indigo/RangeInput */}
186231 <Grid.Item
187232 full
@@ -228,21 +273,28 @@ export default function InlineEthereumTransaction({
228273 </>
229274 )}
230275
231− {showReceipt && (
232− <>
233− <Grid.Divider />
234− <HashReceiptList txHashes={txHashes} />
235−
236− <Grid.Divider />
237− </>
238− )}
239−
240276 {completed && (
241277 <>
242278 <Grid.Item full as={RestartButton} onClick={onReturn}>
243279 Return
244280 </Grid.Item>
245281 <Grid.Divider />
282+ {showReceipt && (
283+ <TransactionReceipt
284+ txHashes={txHashes}
285+ maxCost={maxCost}
286+ onClose={toggleShowReceipt}
287+ />
288+ )}
289+
290+ {!showReceipt && (
291+ <Grid.Item
292+ className="underline mv2 pointer"
293+ full
294+ onClick={toggleShowReceipt}>
295+ View Receipt
296+ </Grid.Item>
297+ )}
246298 </>
247299 )}
248300 </>
@@ -278,34 +330,42 @@ function SignedTransactionList({ serializedTxsHex, nonce, gasPrice }) {
278330 ));
279331}
280332
281−function HashReceiptList({ txHashes }) {
333+function TransactionReceipt({ txHashes, maxCost, onClose }) {
282334 const txUrls = useExploreTxUrls(txHashes);
283− const header = pluralize(txHashes.length, 'Hash', 'Hashes');
284335 return (
285336 <>
337+ <Grid.Item full as={Flex} justify="between" className="pv2 black f5">
338+ <Flex.Item>Receipt</Flex.Item>
339+ <Flex.Item onClick={onClose} className="underline pointer">
340+ Close
341+ </Flex.Item>
342+ </Grid.Item>
343+ <Grid.Item full as={Flex} justify="between" className="pv2 black f5">
344+ <Flex.Item>Gas Price</Flex.Item>
345+ <Flex.Item className="mono">{maxCost} ETH</Flex.Item>
346+ </Grid.Item>
286347 <Grid.Divider />
287348 <Grid.Item full as={Flex} col className="pv4">
288− <Flex.Item as={H5}>Transaction {header}</Flex.Item>
349+ <Flex.Item as={H5}>Receipt</Flex.Item>
289350
290351 {txHashes &&
291352 txHashes.map((txHash, i) => (
292− <Flex.Item as={Flex}>
353+ <Flex.Item as={Flex} className="mv3">
293354 <>
294355 <Flex.Item
295356 key={i}
296357 flex
297358 as="code"
298− className="f6 mono gray4 wrap">
359+ className="f6 mono gray4 wrap ">
299360 {txHash}
300361 </Flex.Item>
301− <Flex.Item as={LinkButton} href={txUrls[i]}>
362+ <Flex.Item className="ml8" as={LinkButton} href={txUrls[i]}>
302363 Etherscan↗
303364 </Flex.Item>
304365 </>
305366 </Flex.Item>
306367 ))}
307368 </Grid.Item>
308− <Grid.Divider />
309369 </>
310370 );
311371}
src/lib/useEthereumTransaction.js+4−2
@@ -1,4 +1,4 @@
1−import { useCallback, useEffect, useState } from 'react';
1+import { useCallback, useEffect, useState, useMemo } from 'react';
22import { Just } from 'folktale/maybe';
33import { toBN } from 'web3-utils';
44
@@ -22,7 +22,7 @@ import { ensureFundsFor } from 'lib/tank';
2222import useDeepEqualReference from 'lib/useDeepEqualReference';
2323import useGasPrice from 'lib/useGasPrice';
2424import timeout from 'lib/timeout';
25−import { safeToWei } from 'lib/lib';
25+import { safeToWei, safeFromWei } from 'lib/lib';
2626
2727const STATE = {
2828 NONE: 'NONE',
@@ -312,6 +312,8 @@ export default function useEthereumTransaction(
312312 nonce,
313313 chainId,
314314 needFunds,
315+ gasLimit,
316+ unsignedTransactions,
315317 });
316318
317319 return { ...values, bind: values };
src/views/UrbitOS/Home.js+1−2
@@ -60,9 +60,9 @@ export default function UrbitOSHome() {
6060 <Grid.Item full className="mv7 f5">
6161 Network
6262 </Grid.Item>
63− <Grid.Divider />
6463 {showSponsor && (
6564 <>
65+ <Grid.Divider />
6666 <Grid.Item
6767 full
6868 as={ForwardButton}
@@ -72,7 +72,6 @@ export default function UrbitOSHome() {
7272 <span className="mono">{sponsor}</span>
7373 <span className="f7 bg-black white p1 ml2 r4">SPONSOR</span>
7474 </Grid.Item>
75− <Grid.Divider />
7675 </>
7776 )}
7877
src/views/UrbitOS/NetworkingKeys.js+1−1
@@ -210,7 +210,7 @@ export default function UrbitOSNetworkingKeys() {
210210 <>
211211 <Grid.Item
212212 full
213− className="mb3"
213+ className="mv3"
214214 as={DownloadKeyfileButton}
215215 solid
216216 {...keyfileBind}