mirror of
https://github.com/selfxyz/self.git
synced 2026-01-09 14:48:06 -05:00
fix Race condition in setting selfDefinedData (#1531)
* fix racecondition in setting selfDefinedData * fixes
This commit is contained in:
@@ -46,7 +46,10 @@ import {
|
|||||||
setDefaultDocumentTypeIfNeeded,
|
setDefaultDocumentTypeIfNeeded,
|
||||||
usePassport,
|
usePassport,
|
||||||
} from '@/providers/passportDataProvider';
|
} from '@/providers/passportDataProvider';
|
||||||
import { getPointsAddress } from '@/services/points';
|
import {
|
||||||
|
getPointsAddress,
|
||||||
|
getWhiteListedDisclosureAddresses,
|
||||||
|
} from '@/services/points';
|
||||||
import { useProofHistoryStore } from '@/stores/proofHistoryStore';
|
import { useProofHistoryStore } from '@/stores/proofHistoryStore';
|
||||||
import { ProofStatus } from '@/stores/proofTypes';
|
import { ProofStatus } from '@/stores/proofTypes';
|
||||||
import {
|
import {
|
||||||
@@ -64,6 +67,7 @@ const ProveScreen: React.FC = () => {
|
|||||||
const { useProvingStore, useSelfAppStore } = selfClient;
|
const { useProvingStore, useSelfAppStore } = selfClient;
|
||||||
const selectedApp = useSelfAppStore(state => state.selfApp);
|
const selectedApp = useSelfAppStore(state => state.selfApp);
|
||||||
const selectedAppRef = useRef<typeof selectedApp>(null);
|
const selectedAppRef = useRef<typeof selectedApp>(null);
|
||||||
|
const processedSessionsRef = useRef<Set<string>>(new Set());
|
||||||
|
|
||||||
const [hasScrolledToBottom, setHasScrolledToBottom] = useState(false);
|
const [hasScrolledToBottom, setHasScrolledToBottom] = useState(false);
|
||||||
const [scrollViewContentHeight, setScrollViewContentHeight] = useState(0);
|
const [scrollViewContentHeight, setScrollViewContentHeight] = useState(0);
|
||||||
@@ -167,16 +171,41 @@ const ProveScreen: React.FC = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const enhanceApp = async () => {
|
const sessionId = selectedApp.sessionId;
|
||||||
const address = await getPointsAddress();
|
|
||||||
|
|
||||||
// Only update if still the same session
|
if (processedSessionsRef.current.has(sessionId)) {
|
||||||
if (selectedAppRef.current?.sessionId === selectedApp.sessionId) {
|
return;
|
||||||
console.log('enhancing app with points address', address);
|
}
|
||||||
selfClient.getSelfAppState().setSelfApp({
|
|
||||||
...selectedApp,
|
const enhanceApp = async () => {
|
||||||
selfDefinedData: address.toLowerCase(),
|
const currentSessionId = sessionId;
|
||||||
});
|
|
||||||
|
try {
|
||||||
|
const address = await getPointsAddress();
|
||||||
|
const whitelistedAddresses = await getWhiteListedDisclosureAddresses();
|
||||||
|
|
||||||
|
const isWhitelisted = whitelistedAddresses.some(
|
||||||
|
contract =>
|
||||||
|
contract.contract_address.toLowerCase() === address.toLowerCase(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const currentApp = selfClient.getSelfAppState().selfApp;
|
||||||
|
if (currentApp?.sessionId === currentSessionId) {
|
||||||
|
if (isWhitelisted) {
|
||||||
|
console.log(
|
||||||
|
'enhancing app with whitelisted points address',
|
||||||
|
address,
|
||||||
|
);
|
||||||
|
selfClient.getSelfAppState().setSelfApp({
|
||||||
|
...currentApp,
|
||||||
|
selfDefinedData: address.toLowerCase(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processedSessionsRef.current.add(currentSessionId);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed enhancing app:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user