on master help sign in
Confirmed walletconnect working with L2
commitae5855b7ad300c9b3fe9cf3139aa3169129aae57 authorWill Galebach <willbach@gmail.com> dateWed 1 Dec 2021, 20:29 (5 years ago) parent065d894
8 files changed+49−29
src/components/L2/Headers/L2BackHeader.tsx+1−3 src/lib/useRoller.ts+12−10 src/lib/utils/notifications.ts+5 src/lib/utils/roller.ts+1−1 src/store/lib/useControlledPointsStore.js+1−1 src/views/Ops/Ops.tsx+24−7 src/views/Point/MigrateL2.tsx+4−6 src/views/UrbitID/Home.tsx+1−1
src/components/L2/Headers/L2BackHeader.tsx+1−3
@@ -55,9 +55,7 @@ const L2BackHeader = ({
5555 }
5656 };
5757
58− if (currentL2) {
59− getEthBalance();
60− }
58+ getEthBalance();
6159 }, [currentL2, setEthBalance, wallet, web3]);
6260
6361 const hasBalance = Number(ethBalance.toString()) !== 0;
src/lib/useRoller.ts+12−10
@@ -33,6 +33,7 @@ import {
3333 adopt,
3434 detach,
3535 reject,
36+ isL2Spawn,
3637} from './utils/roller';
3738import { ETH_ZERO_ADDR, ROLLER_HOSTS, TEN_SECONDS } from './constants';
3839
@@ -51,6 +52,7 @@ import { useTimerStore } from 'store/timerStore';
5152import { ReticketParams, SendL2Params } from './types/L2Transaction';
5253import { L1Point } from './types/L1Point';
5354import { ddmmmYYYY } from './utils/date';
55+import { showNotification } from './utils/notifications';
5456import { useWalletConnect } from './useWalletConnect';
5557
5658const ONE_SECOND = 1000;
@@ -190,10 +192,9 @@ export default function useRoller() {
190192 const pointNum = Number(point);
191193 try {
192194 const rawDetails = await api.getPoint(pointNum);
193− const l2Quota =
194− rawDetails?.dominion === 'l2'
195− ? await api.getRemainingQuota(pointNum)
196− : 0;
195+ const l2Quota = isL2Spawn(rawDetails?.dominion)
196+ ? await api.getRemainingQuota(pointNum)
197+ : 0;
197198 const details = toL1Details(rawDetails);
198199
199200 return new Point({
@@ -246,8 +247,8 @@ export default function useRoller() {
246247 if (!updatedPoint.isPlaceholder && changedField) {
247248 updatePoint(updatedPoint);
248249 clearInterval(interval);
249− if (Notification?.permission === 'granted' && notify) {
250− new Notification(
250+ if (notify) {
251+ showNotification(
251252 `${message || getUpdatedPointMessage(updatedPoint, changedField)}`
252253 );
253254 }
@@ -530,6 +531,9 @@ export default function useRoller() {
530531
531532 setStoredInvites(ls, invites);
532533 getInvites();
534+ showNotification(
535+ `Your invite${invites.length > 1 ? 's have' : ' has'} been generated!`
536+ );
533537 },
534538 [
535539 api,
@@ -996,7 +1000,7 @@ export default function useRoller() {
9961000 }, [config, fetchConfig]);
9971001
9981002 useEffect(() => {
999− const time = isDevelopment ? 10000 : ONE_SECOND;
1003+ const time = ONE_SECOND;
10001004
10011005 const interval = setInterval(() => {
10021006 const nextRoll = getTimeToNextBatch(nextBatchTime, new Date().getTime());
@@ -1010,10 +1014,8 @@ export default function useRoller() {
10101014 getPendingTransactions();
10111015
10121016 setTimeout(() => {
1013− getPendingTransactions();
1014−
10151017 if (!point.isDefault) {
1016− getInvites();
1018+ getInvites(); // This will also get pending txns
10171019 }
10181020 }, TEN_SECONDS); // Should this be more like a minute?
10191021 }
src/lib/utils/notifications.tsnew file+5
@@ -0,0 +1,5 @@
1+export const showNotification = (message: string) => {
2+ if (Notification?.permission === 'granted') {
3+ new Notification(message);
4+ }
5+};
src/lib/utils/roller.ts+1−1
@@ -44,7 +44,7 @@ export const getTimeToNextBatch = (nextBatch: number, now: number) => {
4444
4545export const isL2 = (dom?: string) => dom === 'l2';
4646
47−export const isL2Spawn = (dom?: string) => dom === 'spawn';
47+export const isL2Spawn = (dom?: string) => dom === 'l2' || dom === 'spawn';
4848
4949export const generateInviteWallet = async (point: number, seed: string) => {
5050 const ticket = makeDeterministicTicket(point, seed);
src/store/lib/useControlledPointsStore.js+1−1
@@ -67,7 +67,7 @@ export default function useControlledPointsStore() {
6767 Just(Result.Error('Failed to read the blockchain.'))
6868 );
6969 } else {
70− getPointsDetails(
70+ await getPointsDetails(
7171 (ownedPointsL1 || []).concat(ownedPointsL2 || []).filter(onlyUnique),
7272 (incomingPointsL1 || [])
7373 .concat(incomingPointsL2 || [])
src/views/Ops/Ops.tsx+24−7
@@ -17,7 +17,7 @@ import L2BackHeader from 'components/L2/Headers/L2BackHeader';
1717import './Ops.scss';
1818
1919export const Ops = () => {
20− const { pop, push, names }: any = useLocalRouter();
20+ const { pop, push, popAndPush, names }: any = useLocalRouter();
2121 const { pointCursor }: any = usePointCursor();
2222 const { point } = useRollerStore();
2323 const _point = need.point(pointCursor);
@@ -29,6 +29,28 @@ export const Ops = () => {
2929 names.ISSUE_CHILD,
3030 push,
3131 ]);
32+ const goUrbitOS = useCallback(() => popAndPush(names.URBIT_OS), [
33+ names.URBIT_OS,
34+ popAndPush,
35+ ]);
36+
37+ const getButtonContent = () => {
38+ if (!point.canSpawn) {
39+ return null;
40+ } else if (point.networkKeysSet) {
41+ return (
42+ <Button onClick={goIssuePoint} className="header-button">
43+ <Icon icon="Node" /> &nbsp;Spawn&nbsp;
44+ {isGalaxy(_point) ? 'Stars' : 'Planets'}
45+ </Button>
46+ );
47+ }
48+ return (
49+ <Button onClick={goUrbitOS} className="header-button">
50+ Set Network Keys
51+ </Button>
52+ );
53+ };
3254
3355 return (
3456 <View
@@ -41,12 +63,7 @@ export const Ops = () => {
4163 <HeaderPane>
4264 <Row className="header-row">
4365 <h5>{isGalaxy(_point) ? 'Galaxy' : 'Star'} Ops</h5>
44− {point.networkKeysSet && (
45− <Button onClick={goIssuePoint} className="header-button">
46− <Icon icon="Node" /> &nbsp;Spawn&nbsp;
47− {isGalaxy(_point) ? 'Stars' : 'Planets'}
48− </Button>
49− )}
66+ {getButtonContent()}
5067 </Row>
5168 </HeaderPane>
5269 <BodyPane>
src/views/Point/MigrateL2.tsx+4−6
@@ -128,12 +128,10 @@ export default function MigrateL2() {
128128
129129 useEffect(() => {
130130 if (completed) {
131− checkForUpdates(
132− selectedPoint.value,
133− `${selectedPoint.patp} has been migrated to Layer 2!`,
134− true,
135− PointField.layer
136− );
131+ const message = transfer
132+ ? `${selectedPoint.patp} has been migrated to Layer 2!`
133+ : `${selectedPoint.patp}'s spawn proxy has been set to Layer 2!`;
134+ checkForUpdates(selectedPoint.value, message, true, PointField.layer);
137135 pop();
138136 }
139137 }, [completed, pop]); // eslint-disable-line react-hooks/exhaustive-deps
src/views/UrbitID/Home.tsx+1−1
@@ -118,7 +118,7 @@ export default function UrbitIDHome() {
118118 </Row>
119119 )}
120120
121− {point.isParent && networkRevision !== 0 && (
121+ {point.isParent && (
122122 <Row className="between-row management">
123123 <Box>
124124 <Box>Spawn Proxy Address</Box>