on master help sign in
Merge pull request #482 from urbit/lf/bridge-cleanup
f1db829Fang
src/components/MaybeSigil.js+2−1
@@ -10,7 +10,8 @@ import AspectRatio from './AspectRatio';
10export default function MaybeSigil({ className, patp, size, ...rest }) {
10export default function MaybeSigil({ className, patp, size, ...rest }) {
11 const validPatp = patp.matchWith({
11 const validPatp = patp.matchWith({
12 Nothing: () => null,
12 Nothing: () => null,
13+ Just: p =>
13− Just: p => (ob.isValidPatp(p.value) ? p.value : null),
14+ ob.isValidPatp(p.value) && p.value.length < 15 ? p.value : null,
14 });
15 });
15
16
16 return validPatp ? (
17 return validPatp ? (
src/lib/metamask.js+8−7
@@ -1,3 +1,5 @@
1+import { toHex } from 'web3-utils';
2+
1export function MetamaskWallet(address) {
3export function MetamaskWallet(address) {
2 this.address = address;
4 this.address = address;
3}
5}
@@ -14,13 +16,12 @@ export function FakeMetamaskTransaction(txnData) {
14// Sign it actually when sending
16// Sign it actually when sending
15export const metamaskSignTransaction = async (txn, from) => {
17export const metamaskSignTransaction = async (txn, from) => {
16 const metamaskFormattedTxn = {
18 const metamaskFormattedTxn = {
17− to: txn.to.toString('hex'),
18− value: txn.value.toString('hex'),
19− data: txn.data.toString('hex'),
19+ data: txn.data,
20− gasLimit: txn.gasLimit.toString('hex'),
20+ gasLimit: txn.gasLimit,
21− gasPrice: txn.gasPrice.toString('hex'),
21+ gasPrice: txn.gasPrice,
22− nonce: txn.nonce.length === 0 ? '00' : txn.nonce.toString('hex'),
22+ nonce: txn.nonce,
23+ to: toHex(txn.to),
23− from: from,
24+ from: toHex(from),
24 };
25 };
25
26
26 return new FakeMetamaskTransaction(metamaskFormattedTxn);
27 return new FakeMetamaskTransaction(metamaskFormattedTxn);
src/lib/txn.js+11−18
@@ -92,7 +92,7 @@ const signTransaction = async ({
92 } else if (walletType === WALLET_TYPES.TREZOR) {
92 } else if (walletType === WALLET_TYPES.TREZOR) {
93 await trezorSignTransaction(stx, walletHdPath);
93 await trezorSignTransaction(stx, walletHdPath);
94 } else if (walletType === WALLET_TYPES.METAMASK) {
94 } else if (walletType === WALLET_TYPES.METAMASK) {
95− return metamaskSignTransaction(stx, wallet.address);
95+ return metamaskSignTransaction(utx, wallet.address);
96 } else {
96 } else {
97 stx.sign(wallet.privateKey);
97 stx.sign(wallet.privateKey);
98 }
98 }
@@ -102,24 +102,16 @@ const signTransaction = async ({
102
102
103const sendSignedTransaction = (web3, stx, doubtNonceError) => {
103const sendSignedTransaction = (web3, stx, doubtNonceError) => {
104 // Handle fake metamask transaction
104 // Handle fake metamask transaction
105+ let eventEmitter;
106+ let rawTx;
105 if (stx instanceof FakeMetamaskTransaction) {
107 if (stx instanceof FakeMetamaskTransaction) {
106− const { ethereum } = window;
108+ eventEmitter = web3.eth.sendTransaction(stx.txnData);
107− const sendTxs = {
109+ } else {
108− method: 'eth_sendTransaction',
110+ eventEmitter = web3.eth.sendSignedTransaction(rawTx);
109− params: [stx.txnData],
111+ rawTx = hexify(stx.serialize());
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− );
117 }
112 }
118− const rawTx = hexify(stx.serialize());
119−
120 return new Promise(async (resolve, reject) => {
113 return new Promise(async (resolve, reject) => {
121− web3.eth
114+ eventEmitter
122− .sendSignedTransaction(rawTx)
123 .on('transactionHash', hash => {
115 .on('transactionHash', hash => {
124 resolve(hash);
116 resolve(hash);
125 })
117 })
@@ -132,7 +124,7 @@ const sendSignedTransaction = (web3, stx, doubtNonceError) => {
132 const isNonceError =
124 const isNonceError =
133 message.includes("the tx doesn't have the correct nonce.") ||
125 message.includes("the tx doesn't have the correct nonce.") ||
134 message.includes('nonce too low');
126 message.includes('nonce too low');
135− if (isKnownError || (doubtNonceError && isNonceError)) {
127+ if (rawTx && (isKnownError || (doubtNonceError && isNonceError))) {
136 console.log(
128 console.log(
137 'tx send error likely from gas tank submission, ignoring:',
129 'tx send error likely from gas tank submission, ignoring:',
138 message
130 message
@@ -141,7 +133,8 @@ const sendSignedTransaction = (web3, stx, doubtNonceError) => {
141 resolve(txHash);
133 resolve(txHash);
142 } else {
134 } else {
143 console.error(err);
135 console.error(err);
144− reject(err.message || 'Transaction sending failed!');
136+ const wrappedErr = err instanceof Error ? err : new Error(message);
137+ reject(wrappedErr);
145 }
138 }
146 });
139 });
147 });
140 });
src/lib/useRouter.js+2−2
@@ -1,5 +1,5 @@
1import { useCallback, useMemo, useState, useRef, useEffect } from 'react';
1import { 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';
3
3
4const NULL_DATA = {};
4const NULL_DATA = {};
5
5
@@ -89,7 +89,7 @@ export default function useRouter({
89 routes,
89 routes,
90 ]);
90 ]);
91 const data = useMemo(() => {
91 const data = useMemo(() => {
92− return last(routes).data || NULL_DATA;
92+ return get(last(routes), 'data', NULL_DATA);
93 }, [routes]);
93 }, [routes]);
94 const Route = useMemo(() => views[peek().key], [views, peek]);
94 const Route = useMemo(() => views[peek().key], [views, peek]);
95
95
src/views/Residents.js+4−1
@@ -158,6 +158,7 @@ export default function Residents() {
158 const point = need.point(pointCursor);
158 const point = need.point(pointCursor);
159 const { getResidents, syncResidents } = usePointCache();
159 const { getResidents, syncResidents } = usePointCache();
160
160
161+ const goBack = useCallback(() => pop(), [pop]);
161 useEffect(() => {
162 useEffect(() => {
162 syncResidents(point);
163 syncResidents(point);
163 }, [syncResidents, point]);
164 }, [syncResidents, point]);
@@ -202,7 +203,9 @@ export default function Residents() {
202 return (
203 return (
203 <View pop={pop} inset>
204 <View pop={pop} inset>
204 <NavHeader>
205 <NavHeader>
206+ <Crumbs
205− <Crumbs routes={[{ text: name, action: pop }, { text: 'Residents' }]} />
207+ routes={[{ text: name, action: goBack }, { text: 'Residents' }]}
208+ />
206 </NavHeader>
209 </NavHeader>
207 <Grid>
210 <Grid>
208 <Grid.Item full as={H4} className="mt4">
211 <Grid.Item full as={H4} className="mt4">
src/views/UrbitOS/Home.js+6−4
@@ -180,14 +180,16 @@ function Hosting({ manualNetworkSeed }) {
180 }
180 }
181 }, [
181 }, [
182 localRunning,
182 localRunning,
183− ship.missing,
184 ship.running,
183 ship.running,
184+ ship.missing,
185 ship.pending,
185 ship.pending,
186− bootProgress,
186+ localUrl,
187− bootMessage,
187+ code,
188+ url,
188 keyfile,
189 keyfile,
189 createShip,
190 createShip,
190− url,
191+ bootProgress,
192+ bootMessage,
191 ]);
193 ]);
192
194
193 const renderDetails = useCallback(() => {
195 const renderDetails = useCallback(() => {