mirror of
https://github.com/selfxyz/self.git
synced 2026-01-07 22:04:03 -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,
|
||||
usePassport,
|
||||
} from '@/providers/passportDataProvider';
|
||||
import { getPointsAddress } from '@/services/points';
|
||||
import {
|
||||
getPointsAddress,
|
||||
getWhiteListedDisclosureAddresses,
|
||||
} from '@/services/points';
|
||||
import { useProofHistoryStore } from '@/stores/proofHistoryStore';
|
||||
import { ProofStatus } from '@/stores/proofTypes';
|
||||
import {
|
||||
@@ -64,6 +67,7 @@ const ProveScreen: React.FC = () => {
|
||||
const { useProvingStore, useSelfAppStore } = selfClient;
|
||||
const selectedApp = useSelfAppStore(state => state.selfApp);
|
||||
const selectedAppRef = useRef<typeof selectedApp>(null);
|
||||
const processedSessionsRef = useRef<Set<string>>(new Set());
|
||||
|
||||
const [hasScrolledToBottom, setHasScrolledToBottom] = useState(false);
|
||||
const [scrollViewContentHeight, setScrollViewContentHeight] = useState(0);
|
||||
@@ -167,16 +171,41 @@ const ProveScreen: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const enhanceApp = async () => {
|
||||
const address = await getPointsAddress();
|
||||
const sessionId = selectedApp.sessionId;
|
||||
|
||||
// Only update if still the same session
|
||||
if (selectedAppRef.current?.sessionId === selectedApp.sessionId) {
|
||||
console.log('enhancing app with points address', address);
|
||||
selfClient.getSelfAppState().setSelfApp({
|
||||
...selectedApp,
|
||||
selfDefinedData: address.toLowerCase(),
|
||||
});
|
||||
if (processedSessionsRef.current.has(sessionId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const enhanceApp = async () => {
|
||||
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