on master help sign in
Signing transactions with Metamask
commit31860d32f6a14cdbe5144b5dfa421995ba913c16 authorWill Galebach <willbach@gmail.com> dateThu 11 Nov 2021, 20:33 (5 years ago) parentf181773
8 files changed+55−31
src/components/L2/Dropdowns/AccountsDropdown.tsx+3−2 src/components/L2/Dropdowns/Dropdown.scss+8 src/components/L2/Dropdowns/Dropdown.tsx+1 src/lib/useRoller.ts+11−13 src/lib/utils/roller.ts+4−3 src/views/Point/Point.tsx+25−5 src/views/Points.js+3−7 src/views/UrbitOS/NetworkingKeys.js−1
src/components/L2/Dropdowns/AccountsDropdown.tsx+3−2
@@ -54,11 +54,12 @@ const AccountsDropdown = ({ showMigrate = false }: AccountsDropdownProps) => {
5454
5555 const selectPoint = useCallback(
5656 (point: number) => () => {
57+ popTo(names.POINTS);
5758 setPointCursor(Just(point));
5859 push(names.POINT);
5960 setOpen(false);
6061 },
61− [push, names.POINT, setOpen, setPointCursor]
62+ [push, popTo, names, setOpen, setPointCursor]
6263 );
6364
6465 const goHome = useCallback(() => popTo(names.POINTS), [names, popTo]);
@@ -137,7 +138,7 @@ const AccountsDropdown = ({ showMigrate = false }: AccountsDropdownProps) => {
137138 )}
138139 {isParent && canSpawn && (
139140 <Row className="entry" onClick={goIssuePoint}>
140− <Box>Spawn{isStar ? ' Planets' : ' Stars'}</Box>
141+ <Box>{isStar ? 'Generate Invites' : 'Spawn Stars'}</Box>
141142 <Icon icon="Plus" />
142143 </Row>
143144 )}
src/components/L2/Dropdowns/Dropdown.scss+8
@@ -4,6 +4,14 @@
44 font-size: 14px;
55 position: relative;
66
7+ .close-background {
8+ position: fixed;
9+ top: 0;
10+ bottom: 0;
11+ right: 0;
12+ left: 0;
13+ }
14+
715 .selector {
816 background-color: $washed-gray;
917 padding: 8px;
src/components/L2/Dropdowns/Dropdown.tsx+1
@@ -20,6 +20,7 @@ const Dropdown = ({
2020}: DropdownProps) => {
2121 return (
2222 <Box className={`dropdown ${className}`}>
23+ {open && <Box className="close-background" onClick={toggleOpen} />}
2324 <Box className={`selector ${open ? 'open' : ''}`} onClick={toggleOpen}>
2425 {value}
2526 <Icon icon="ChevronSouth" />
src/lib/useRoller.ts+11−13
@@ -336,10 +336,6 @@ export default function useRoller() {
336336 outgoingPoints.filter((p: number) => !spawnedPoints.includes(p))
337337 );
338338
339− if (isDevelopment) {
340− console.log('INVITED PLANETS', invitePlanets);
341− }
342−
343339 const newInvites: Invite[] = [];
344340 // Iterate over all of the stored invites, generating wallet info as necessary
345341 const storedInvites = getStoredInvites(ls);
@@ -409,7 +405,7 @@ export default function useRoller() {
409405 const _contracts = contracts.getOrElse(null);
410406
411407 if (_authToken && _contracts) {
412− let invitePoints = isL2 ? await api.getSpawned(curPoint) : [];
408+ let spawnedPoints = isL2 ? await api.getSpawned(curPoint) : [];
413409
414410 const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
415411 _contracts,
@@ -424,14 +420,16 @@ export default function useRoller() {
424420 getDetails
425421 ).filter((p: number) => isPlanet(p) && availablePoints.includes(p));
426422
423+ const invitePoints = spawnedPoints
424+ .concat(
425+ outgoingPoints.filter((p: number) => !spawnedPoints.includes(p))
426+ )
427+ .filter((p: number) => !pendingSpawns.has(p));
428+
427429 setPendingTransactions(newPending);
428− setInvitePoints(
429− invitePoints
430− .concat(
431− outgoingPoints.filter((p: number) => !invitePoints.includes(p))
432− )
433− .filter((p: number) => !pendingSpawns.has(p))
434− );
430+ setInvitePoints(invitePoints);
431+
432+ return invitePoints;
435433 }
436434 } catch (e) {
437435 if (isDevelopment) {
@@ -695,7 +693,7 @@ export default function useRoller() {
695693 getNumInvites(currentL2);
696694 });
697695 }
698− }, 1000);
696+ }, 10000000);
699697
700698 return () => clearInterval(interval);
701699 }, [nextBatchTime, getPendingTransactions, currentL2]); // eslint-disable-line react-hooks/exhaustive-deps
src/lib/utils/roller.ts+4−3
@@ -63,12 +63,13 @@ export const generateHashAndSign = async (
6363 web3: any
6464) => {
6565 if (walletType === WALLET_TYPES.METAMASK) {
66− const hash = await api.getUnsignedTx(nonce, from, type, data);
66+ const hash = await api.prepareForSigning(nonce, from, type, data);
6767 const sig = await web3.eth.personal.sign(hash, wallet.address, '');
6868 return sig;
6969 } else {
70− const hash = await api.hashTransaction(nonce, from, type, data);
71− return signTransactionHash(hash, wallet.privateKey);
70+ const hash = await api.getUnsignedTx(nonce, from, type, data);
71+ const sig = await signTransactionHash(hash, wallet.privateKey);
72+ return sig;
7273 }
7374};
7475
src/views/Point/Point.tsx+25−5
@@ -1,4 +1,4 @@
1−import { useCallback, useEffect, useState } from 'react';
1+import { useCallback, useEffect, useState, useRef } from 'react';
22import { Just } from 'folktale/maybe';
33import { Grid, Flex } from 'indigo-react';
44import { Box, Icon, Row, Button, Checkbox } from '@tlon/indigo-react';
@@ -30,13 +30,16 @@ import Modal from 'components/L2/Modal';
3030import { isPlanet, isStar } from 'lib/utils/point';
3131import { useHasNetworkKeysSet } from 'lib/useHasNetworkKeysSet';
3232import { InviteForm } from './InviteForm';
33+import LoadingOverlay from 'components/L2/LoadingOverlay';
3334
3435export default function Point() {
3536 const { pop, push, names }: any = useLocalRouter();
3637 const { wallet }: any = useWallet();
3738 const { pointCursor }: any = usePointCursor();
3839 const point = need.point(pointCursor);
40+ const networkKeysSet = useHasNetworkKeysSet();
3941 const { syncExtras }: any = usePointCache();
42+
4043 const { api, getNumInvites, getPendingTransactions } = useRoller();
4144 const {
4245 pendingTransactions,
@@ -45,10 +48,13 @@ export default function Point() {
4548 setCurrentPoint,
4649 setInvites,
4750 } = useRollerStore();
48− const networkKeysSet = useHasNetworkKeysSet();
51+
4952 const [seenMissingKeys, setSeenMissingKeys] = useSeenMissingKeys();
5053 const [showModal, setShowModal] = useState(false);
5154 const [hideMessage, setHideMessage] = useState(false);
55+ const [loading, setLoading] = useState(false);
56+
57+ const pointRef = useRef<number | null>(null);
5258
5359 const hideModal = useCallback(() => {
5460 if (hideMessage) {
@@ -59,8 +65,11 @@ export default function Point() {
5965 }, [hideMessage, setShowModal, setSeenMissingKeys]);
6066
6167 useEffect(() => {
62− setShowModal(!networkKeysSet && !seenMissingKeys);
63− }, [networkKeysSet, seenMissingKeys]);
68+ if (pointRef.current !== point) {
69+ pointRef.current = point;
70+ setShowModal(!networkKeysSet && !seenMissingKeys);
71+ }
72+ }, [networkKeysSet, seenMissingKeys, point]);
6473
6574 const loadL1Info = useCallback(async () => {
6675 await syncExtras(point);
@@ -68,6 +77,7 @@ export default function Point() {
6877
6978 const loadL2Info = useCallback(async () => {
7079 const getTransactions = async () => {
80+ setLoading(true);
7181 const pointInfo = await api.getPoint(Number(point));
7282
7383 if (isDevelopment) {
@@ -76,10 +86,19 @@ export default function Point() {
7686 getPendingTransactions();
7787 setCurrentPoint(pointInfo);
7888 getNumInvites(isL2(pointInfo.dominion));
89+
90+ setTimeout(() => setLoading(false), 100);
7991 };
8092
8193 await getTransactions();
82− }, [api, point, getNumInvites, setCurrentPoint, getPendingTransactions]);
94+ }, [
95+ api,
96+ point,
97+ getNumInvites,
98+ setCurrentPoint,
99+ getPendingTransactions,
100+ setLoading,
101+ ]);
83102
84103 useEffect(() => {
85104 loadL1Info();
@@ -277,6 +296,7 @@ export default function Point() {
277296 </Row>
278297 </Box>
279298 </Modal>
299+ <LoadingOverlay loading={loading} />
280300 </View>
281301 );
282302}
src/views/Points.js+3−7
@@ -8,6 +8,7 @@ import { useWallet } from 'store/wallet';
88import { usePointCache } from 'store/pointCache';
99import { usePointCursor } from 'store/pointCursor';
1010import { useStarReleaseCache } from 'store/starRelease';
11+import { useNetwork } from 'store/network';
1112
1213import * as need from 'lib/need';
1314import { isZeroAddress, abbreviateAddress } from 'lib/utils/address';
@@ -18,7 +19,6 @@ import { pluralize } from 'lib/pluralize';
1819import newGithubIssueUrl from 'new-github-issue-url';
1920
2021import View from 'components/View';
21−import Blinky from 'components/Blinky';
2222import Passport from 'components/Passport';
2323import Footer from 'components/Footer';
2424import { ForwardButton } from 'components/Buttons';
@@ -26,7 +26,7 @@ import CopiableAddress from 'components/copiable/CopiableAddress';
2626import NavHeader from 'components/NavHeader';
2727import L2PointHeader from 'components/L2/Headers/L2PointHeader';
2828import IncomingPoint from 'components/L2/Points/IncomingPoint';
29−import { useNetwork } from 'store/network';
29+import LoadingOverlay from 'components/L2/LoadingOverlay';
3030
3131export const maybeGetResult = (obj, key, defaultValue) =>
3232 obj.matchWith({
@@ -307,11 +307,7 @@ export default function Points() {
307307 ) {
308308 return (
309309 <View inset>
310− <Grid>
311− <Grid.Item full as={HelpText} className="mt8 t-center">
312− <Blinky /> Loading...
313− </Grid.Item>
314− </Grid>
310+ <LoadingOverlay loading />
315311 </View>
316312 );
317313 }
src/views/UrbitOS/NetworkingKeys.js−1
@@ -212,7 +212,6 @@ export default function UrbitOSNetworkingKeys({
212212
213213 const setNetworkingKeys = useCallback(async () => {
214214 // setLoading(true);
215− console.log(breach, manualNetworkSeed);
216215 try {
217216 const txHash = await configureNetworkingKeys({
218217 breach,