on master help sign in
Merge pull request #1052 from pkova/master
74f0aa6tomholford
src/lib/useRoller.ts+12−9
@@ -44,7 +44,7 @@ import { useRollerOptions } from './useRollerOptions';
44import { useTimerStore } from 'store/timerStore';
44import { useTimerStore } from 'store/timerStore';
45
45
46interface UpdateParams {
46interface UpdateParams {
47− point: number;
47+ point?: Point | number;
48 message?: string;
48 message?: string;
49 notify?: boolean;
49 notify?: boolean;
50 field?: PointField;
50 field?: PointField;
@@ -140,7 +140,7 @@ export default function useRoller() {
140 }, [nextQuotaTime, point, setModalText]);
140 }, [nextQuotaTime, point, setModalText]);
141
141
142 const initPoint = useCallback(
142 const initPoint = useCallback(
143− async (point: string | number) => {
143+ async (point: string | number): Promise<Point> => {
144 const _wallet = wallet.getOrElse(null);
144 const _wallet = wallet.getOrElse(null);
145 const _contracts = contracts.getOrElse(null);
145 const _contracts = contracts.getOrElse(null);
146
146
@@ -211,21 +211,24 @@ export default function useRoller() {
211 l1Txn,
211 l1Txn,
212 intervalTime = TEN_SECONDS,
212 intervalTime = TEN_SECONDS,
213 }: UpdateParams) => {
213 }: UpdateParams) => {
214+
215+
216+ const p = (typeof point === 'number' ? await initPoint(point) : point) as Point
217+
214 if (l1Txn) storePendingL1Txn(l1Txn);
218 if (l1Txn) storePendingL1Txn(l1Txn);
215
219
216 let interval: any;
220 let interval: any;
217 const check = async () => {
221 const check = async () => {
218− const updatedPoint = await initPoint(point);
219− const changedField = !points[point]
222+ const changedField = !points[p.value]
220 ? 'newPoint'
223 ? 'newPoint'
221− : updatedPoint.getChangedField(points[point], field);
224+ : p.getChangedField(points[p.value], field);
222
225
223 if (isDevelopment) {
226 if (isDevelopment) {
224− console.log(`CHECKING FOR ${changedField} UPDATES:`, updatedPoint);
227+ console.log(`CHECKING FOR ${changedField} UPDATES:`, p.patp);
225 }
228 }
226
229
227− if (!updatedPoint.isPlaceholder && changedField) {
230+ if (!p.isPlaceholder && changedField) {
228− updatePoint(updatedPoint);
231+ updatePoint(p);
229 if (interval) {
232 if (interval) {
230 clearInterval(interval);
233 clearInterval(interval);
231 }
234 }
@@ -233,7 +236,7 @@ export default function useRoller() {
233 if (l1Txn) deletePendingL1Txn(l1Txn);
236 if (l1Txn) deletePendingL1Txn(l1Txn);
234 if (notify) {
237 if (notify) {
235 showNotification(
238 showNotification(
236− `${message || getUpdatedPointMessage(updatedPoint, changedField)}`
239+ `${message || getUpdatedPointMessage(p, changedField)}`
237 );
240 );
238 }
241 }
239 }
242 }
src/store/pointCache.js+2−1
@@ -1,5 +1,6 @@
1import React, { createContext, forwardRef, useContext } from 'react';
1import React, { createContext, forwardRef, useContext } from 'react';
2
2
3+import useDeepEqualReference from 'lib/useDeepEqualReference';
3import usePointStore from './lib/usePointStore';
4import usePointStore from './lib/usePointStore';
4
5
5export const PointCacheContext = createContext(null);
6export const PointCacheContext = createContext(null);
@@ -8,7 +9,7 @@ export function PointCacheProvider({ children }) {
8 const cache = usePointStore();
9 const cache = usePointStore();
9
10
10 return (
11 return (
11− <PointCacheContext.Provider value={cache}>
12+ <PointCacheContext.Provider value={useDeepEqualReference(cache)}>
12 {children}
13 {children}
13 </PointCacheContext.Provider>
14 </PointCacheContext.Provider>
14 );
15 );
src/views/AcceptTransfer.tsx+3−3
@@ -53,7 +53,7 @@ function useAcceptTransfer() {
53 ),
53 ),
54 useCallback(
54 useCallback(
55 () => Promise.all([syncExtras(_point), syncControlledPoints()]),
55 () => Promise.all([syncExtras(_point), syncControlledPoints()]),
56− [_point, syncControlledPoints, syncExtras]
56+ [_point]
57 ),
57 ),
58 GAS_LIMITS.TRANSFER
58 GAS_LIMITS.TRANSFER
59 );
59 );
@@ -89,7 +89,7 @@ export default function AcceptTransfer() {
89 // Update this one
89 // Update this one
90 if (completed) {
90 if (completed) {
91 checkForUpdates({
91 checkForUpdates({
92− point: point.value,
92+ point: point,
93 message: `${point.patp} has been transferred to you!`,
93 message: `${point.patp} has been transferred to you!`,
94 l1Txn: {
94 l1Txn: {
95 id: `accept-transfer-${point.value}`,
95 id: `accept-transfer-${point.value}`,
@@ -129,7 +129,7 @@ export default function AcceptTransfer() {
129 transferring.current = true;
129 transferring.current = true;
130 await transferPoint(_address, reset);
130 await transferPoint(_address, reset);
131 await checkForUpdates({
131 await checkForUpdates({
132− point: point.value,
132+ point: point,
133 message: `${point.patp} has been transferred to you!`,
133 message: `${point.patp} has been transferred to you!`,
134 });
134 });
135
135
src/views/CancelTransfer.tsx+2−2
@@ -68,7 +68,7 @@ function AdminCancelTransfer() {
68 useEffect(() => {
68 useEffect(() => {
69 if (completed) {
69 if (completed) {
70 checkForUpdates({
70 checkForUpdates({
71− point: point.value,
71+ point: point,
72 message: `${point.patp} transfer cancelled`,
72 message: `${point.patp} transfer cancelled`,
73 l1Txn: {
73 l1Txn: {
74 id: `cancel-${point.value}`,
74 id: `cancel-${point.value}`,
@@ -89,7 +89,7 @@ function AdminCancelTransfer() {
89 const cancelTransfer = useCallback(async () => {
89 const cancelTransfer = useCallback(async () => {
90 await setProxyAddress('transfer', ETH_ZERO_ADDR);
90 await setProxyAddress('transfer', ETH_ZERO_ADDR);
91 await checkForUpdates({
91 await checkForUpdates({
92− point: point.value,
92+ point: point,
93 message: `${point.patp} transfer cancelled`,
93 message: `${point.patp} transfer cancelled`,
94 });
94 });
95 goBack();
95 goBack();
src/views/Point/MigrateL2.tsx+1−1
@@ -135,7 +135,7 @@ export default function MigrateL2() {
135 : `${selectedPoint.patp}'s spawn proxy has been set to Layer 2!`;
135 : `${selectedPoint.patp}'s spawn proxy has been set to Layer 2!`;
136
136
137 checkForUpdates({
137 checkForUpdates({
138− point: selectedPoint.value,
138+ point: selectedPoint,
139 message,
139 message,
140 notify: true,
140 notify: true,
141 field: PointField.layer,
141 field: PointField.layer,
src/views/UrbitID/SetProxy.js+2−2
@@ -165,7 +165,7 @@ export default function SetProxy() {
165 await setProxyAddress(getL2ProxyName(data.proxyType), newAddress);
165 await setProxyAddress(getL2ProxyName(data.proxyType), newAddress);
166
166
167 checkForUpdates({
167 checkForUpdates({
168− point: point.value,
168+ point: point,
169 message: `${point.patp}'s ${humanProxyType} proxy has been set!`,
169 message: `${point.patp}'s ${humanProxyType} proxy has been set!`,
170 });
170 });
171
171
@@ -191,7 +191,7 @@ export default function SetProxy() {
191 useEffect(() => {
191 useEffect(() => {
192 if (completed) {
192 if (completed) {
193 checkForUpdates({
193 checkForUpdates({
194− point: point.value,
194+ point: point,
195 message: `${point.patp}'s ${humanProxyType} proxy has been set!`,
195 message: `${point.patp}'s ${humanProxyType} proxy has been set!`,
196 l1Txn: {
196 l1Txn: {
197 id: `${newAddress}-${point.value}`,
197 id: `${newAddress}-${point.value}`,
src/views/UrbitID/Transfer.tsx+2−2
@@ -80,7 +80,7 @@ export default function AdminTransfer() {
80 // Update this one
80 // Update this one
81 if (completed) {
81 if (completed) {
82 checkForUpdates({
82 checkForUpdates({
83− point: point.value,
83+ point: point,
84 message: `${point.patp}'s transfer proxy has been set!`,
84 message: `${point.patp}'s transfer proxy has been set!`,
85 l1Txn: {
85 l1Txn: {
86 id: `set-transfer-proxy-${point.value}`,
86 id: `set-transfer-proxy-${point.value}`,
@@ -105,7 +105,7 @@ export default function AdminTransfer() {
105 await setProxyAddress('transfer', owner);
105 await setProxyAddress('transfer', owner);
106 getPendingTransactions();
106 getPendingTransactions();
107 checkForUpdates({
107 checkForUpdates({
108− point: point.value,
108+ point: point,
109 message: `${point.patp}'s transfer proxy has been set!`,
109 message: `${point.patp}'s transfer proxy has been set!`,
110 });
110 });
111 pop();
111 pop();
src/views/UrbitOS/ChangeSponsor.tsx+2−2
@@ -63,7 +63,7 @@ function ChangeSponsor({ onDone }: { onDone: Function }) {
63 setLoading(true);
63 setLoading(true);
64 await changeSponsor(newSponsor!);
64 await changeSponsor(newSponsor!);
65 checkForUpdates({
65 checkForUpdates({
66− point: point.value,
66+ point: point,
67 message: `${point.patp} has requested ${ob.patp(
67 message: `${point.patp} has requested ${ob.patp(
68 newSponsor
68 newSponsor
69 )} as a sponsor`,
69 )} as a sponsor`,
@@ -210,7 +210,7 @@ function CurrentEscape({ onDone }: { onDone: Function }) {
210 setLoading(true);
210 setLoading(true);
211 await cancelEscape();
211 await cancelEscape();
212 checkForUpdates({
212 checkForUpdates({
213− point: point.value,
213+ point: point,
214 message: `${point.patp}'s sponsor change cancelled`,
214 message: `${point.patp}'s sponsor change cancelled`,
215 });
215 });
216 setLoading(false);
216 setLoading(false);
src/views/UrbitOS/NetworkKeys.tsx+2−2
@@ -176,7 +176,7 @@ export default function UrbitOSNetworkKeys({
176 useEffect(() => {
176 useEffect(() => {
177 if (completed) {
177 if (completed) {
178 checkForUpdates({
178 checkForUpdates({
179− point: point.value,
179+ point: point,
180 message: `${point.patp}'s Network Keys have been set!`,
180 message: `${point.patp}'s Network Keys have been set!`,
181 l1Txn: {
181 l1Txn: {
182 id: `${point.keyRevisionNumber}-network-keys-${point.value}`,
182 id: `${point.keyRevisionNumber}-network-keys-${point.value}`,
@@ -252,7 +252,7 @@ export default function UrbitOSNetworkKeys({
252 // we could inspect if there's a changeKeys in the local list of pending txs,...
252 // we could inspect if there's a changeKeys in the local list of pending txs,...
253 //
253 //
254 checkForUpdates({
254 checkForUpdates({
255− point: point.value,
255+ point: point,
256 message: `${point.patp}'s Network Keys have been set!`,
256 message: `${point.patp}'s Network Keys have been set!`,
257 intervalTime: ONE_SECOND,
257 intervalTime: ONE_SECOND,
258 });
258 });