on master help sign in
Merge pull request #482 from urbit/lf/bridge-cleanup

various bridge cleanup

commitf1db829c5a8ee0642931b2143d6c7d0e64aec01b authorFang <git@fang.io> dateWed 15 Jul 2020, 12:21 (6 years ago) parent968a3ecc5754a6
6 files changed+33−33
src/components/MaybeSigil.js+2−1 src/lib/metamask.js+8−7 src/lib/txn.js+11−18 src/lib/useRouter.js+2−2 src/views/Residents.js+4−1 src/views/UrbitOS/Home.js+6−4
src/components/MaybeSigil.js+2−1
@@ -10,7 +10,8 @@ import AspectRatio from './AspectRatio';
1010export default function MaybeSigil({ className, patp, size, ...rest }) {
1111 const validPatp = patp.matchWith({
1212 Nothing: () => null,
13− Just: p => (ob.isValidPatp(p.value) ? p.value : null),
13+ Just: p =>
14+ ob.isValidPatp(p.value) && p.value.length < 15 ? p.value : null,
1415 });
1516
1617 return validPatp ? (
src/lib/metamask.js+8−7
@@ -1,3 +1,5 @@
1+import { toHex } from 'web3-utils';
2+
13export function MetamaskWallet(address) {
24 this.address = address;
35}
@@ -14,13 +16,12 @@ export function FakeMetamaskTransaction(txnData) {
1416// Sign it actually when sending
1517export const metamaskSignTransaction = async (txn, from) => {
1618 const metamaskFormattedTxn = {
17− to: txn.to.toString('hex'),
18− value: txn.value.toString('hex'),
19− data: txn.data.toString('hex'),
20− gasLimit: txn.gasLimit.toString('hex'),
21− gasPrice: txn.gasPrice.toString('hex'),
22− nonce: txn.nonce.length === 0 ? '00' : txn.nonce.toString('hex'),
23− from: from,
19+ data: txn.data,
20+ gasLimit: txn.gasLimit,
21+ gasPrice: txn.gasPrice,
22+ nonce: txn.nonce,
23+ to: toHex(txn.to),
24+ from: toHex(from),
2425 };
2526
2627 return new FakeMetamaskTransaction(metamaskFormattedTxn);
src/lib/txn.js+11−18
@@ -92,7 +92,7 @@ const signTransaction = async ({
9292 } else if (walletType === WALLET_TYPES.TREZOR) {
9393 await trezorSignTransaction(stx, walletHdPath);
9494 } else if (walletType === WALLET_TYPES.METAMASK) {
95− return metamaskSignTransaction(stx, wallet.address);
95+ return metamaskSignTransaction(utx, wallet.address);
9696 } else {
9797 stx.sign(wallet.privateKey);
9898 }
@@ -102,24 +102,16 @@ const signTransaction = async ({
102102
103103const sendSignedTransaction = (web3, stx, doubtNonceError) => {
104104 // Handle fake metamask transaction
105+ let eventEmitter;
106+ let rawTx;
105107 if (stx instanceof FakeMetamaskTransaction) {
106− const { ethereum } = window;
107− const sendTxs = {
108− method: 'eth_sendTransaction',
109− params: [stx.txnData],
110− from: stx.txnData.from,
111− };
112− return new Promise((resolve, reject) =>
113− ethereum.sendAsync(sendTxs, (err, data) =>
114− err ? reject(err) : resolve(data.result)
115− )
116− );
108+ eventEmitter = web3.eth.sendTransaction(stx.txnData);
109+ } else {
110+ eventEmitter = web3.eth.sendSignedTransaction(rawTx);
111+ rawTx = hexify(stx.serialize());
117112 }
118− const rawTx = hexify(stx.serialize());
119−
120113 return new Promise(async (resolve, reject) => {
121− web3.eth
122− .sendSignedTransaction(rawTx)
114+ eventEmitter
123115 .on('transactionHash', hash => {
124116 resolve(hash);
125117 })
@@ -132,7 +124,7 @@ const sendSignedTransaction = (web3, stx, doubtNonceError) => {
132124 const isNonceError =
133125 message.includes("the tx doesn't have the correct nonce.") ||
134126 message.includes('nonce too low');
135− if (isKnownError || (doubtNonceError && isNonceError)) {
127+ if (rawTx && (isKnownError || (doubtNonceError && isNonceError))) {
136128 console.log(
137129 'tx send error likely from gas tank submission, ignoring:',
138130 message
@@ -141,7 +133,8 @@ const sendSignedTransaction = (web3, stx, doubtNonceError) => {
141133 resolve(txHash);
142134 } else {
143135 console.error(err);
144− reject(err.message || 'Transaction sending failed!');
136+ const wrappedErr = err instanceof Error ? err : new Error(message);
137+ reject(wrappedErr);
145138 }
146139 });
147140 });
src/lib/useRouter.js+2−2
@@ -1,5 +1,5 @@
11import { useCallback, useMemo, useState, useRef, useEffect } from 'react';
2−import { last, includes as _includes, findIndex } from 'lodash';
2+import { last, includes as _includes, findIndex, get } from 'lodash';
33
44const NULL_DATA = {};
55
@@ -89,7 +89,7 @@ export default function useRouter({
8989 routes,
9090 ]);
9191 const data = useMemo(() => {
92− return last(routes).data || NULL_DATA;
92+ return get(last(routes), 'data', NULL_DATA);
9393 }, [routes]);
9494 const Route = useMemo(() => views[peek().key], [views, peek]);
9595
src/views/Residents.js+4−1
@@ -158,6 +158,7 @@ export default function Residents() {
158158 const point = need.point(pointCursor);
159159 const { getResidents, syncResidents } = usePointCache();
160160
161+ const goBack = useCallback(() => pop(), [pop]);
161162 useEffect(() => {
162163 syncResidents(point);
163164 }, [syncResidents, point]);
@@ -202,7 +203,9 @@ export default function Residents() {
202203 return (
203204 <View pop={pop} inset>
204205 <NavHeader>
205− <Crumbs routes={[{ text: name, action: pop }, { text: 'Residents' }]} />
206+ <Crumbs
207+ routes={[{ text: name, action: goBack }, { text: 'Residents' }]}
208+ />
206209 </NavHeader>
207210 <Grid>
208211 <Grid.Item full as={H4} className="mt4">
src/views/UrbitOS/Home.js+6−4
@@ -180,14 +180,16 @@ function Hosting({ manualNetworkSeed }) {
180180 }
181181 }, [
182182 localRunning,
183− ship.missing,
184183 ship.running,
184+ ship.missing,
185185 ship.pending,
186− bootProgress,
187− bootMessage,
186+ localUrl,
187+ code,
188+ url,
188189 keyfile,
189190 createShip,
190− url,
191+ bootProgress,
192+ bootMessage,
191193 ]);
192194
193195 const renderDetails = useCallback(() => {