Skip to content

Commit 731ef80

Browse files
authored
fix: blind vote deeplink bug (#335)
1 parent 650aad0 commit 731ef80

File tree

9 files changed

+598
-310
lines changed

9 files changed

+598
-310
lines changed
1.53 KB
Binary file not shown.
1.44 KB
Binary file not shown.
15.7 MB
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"version": 3,
3+
"artifactType": {
4+
"type": "APK",
5+
"kind": "Directory"
6+
},
7+
"applicationId": "foundation.metastate.eid_wallet",
8+
"variantName": "arm64Release",
9+
"elements": [
10+
{
11+
"type": "SINGLE",
12+
"filters": [],
13+
"attributes": [],
14+
"versionCode": 2,
15+
"versionName": "0.1.8",
16+
"outputFile": "app-arm64-release.apk"
17+
}
18+
],
19+
"elementType": "File",
20+
"baselineProfiles": [
21+
{
22+
"minApi": 28,
23+
"maxApi": 30,
24+
"baselineProfiles": [
25+
"baselineProfiles/1/app-arm64-release.dm"
26+
]
27+
},
28+
{
29+
"minApi": 31,
30+
"maxApi": 2147483647,
31+
"baselineProfiles": [
32+
"baselineProfiles/0/app-arm64-release.dm"
33+
]
34+
}
35+
],
36+
"minSdkVersionForDexing": 24
37+
}

infrastructure/eid-wallet/src/routes/(app)/scan-qr/+page.svelte

Lines changed: 107 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,14 @@
374374
"🔍 DEBUG: Is poll request?",
375375
!!(signingData?.pollId && signingData?.voteData),
376376
);
377+
378+
// Only set signing modal for regular signing requests (not blind voting)
379+
isSigningRequest = true;
380+
signingDrawerOpen = true;
377381
} catch (error) {
378382
console.error("Error decoding signing data:", error);
379383
return;
380384
}
381-
382-
isSigningRequest = true;
383-
signingDrawerOpen = true;
384385
} catch (error) {
385386
console.error("Error parsing signing request:", error);
386387
}
@@ -597,6 +598,15 @@
597598
blindVoteError = null; // Clear any previous errors
598599
599600
console.log("✅ Blind voting request set up successfully");
601+
console.log("🔍 DEBUG: State after setup:");
602+
console.log(" - isBlindVotingRequest:", isBlindVotingRequest);
603+
console.log(" - signingDrawerOpen:", signingDrawerOpen);
604+
console.log(" - signingData:", signingData);
605+
console.log(" - signingData.pollId:", signingData?.pollId);
606+
console.log(
607+
" - signingData.pollDetails:",
608+
!!signingData?.pollDetails,
609+
);
600610
} catch (error) {
601611
console.error("❌ Error handling blind voting request:", error);
602612
}
@@ -953,7 +963,7 @@
953963
console.log("Scan QR page mounted, checking for deep link data...");
954964
955965
// Function to handle deep link data
956-
function handleDeepLinkData(data: any) {
966+
async function handleDeepLinkData(data: any) {
957967
console.log("Handling deep link data:", data);
958968
console.log("Data type:", data.type);
959969
console.log("Platform:", data.platform);
@@ -999,24 +1009,91 @@
9991009
const decodedString = atob(base64Data);
10001010
signingData = JSON.parse(decodedString);
10011011
console.log("Decoded signing data:", signingData);
1012+
1013+
// Check if this is actually a blind voting request
1014+
if (signingData.type === "blind-vote") {
1015+
console.log(
1016+
"🔍 Blind voting request detected in sign deep link",
1017+
);
1018+
1019+
// Set up blind voting state
1020+
isBlindVotingRequest = true;
1021+
selectedBlindVoteOption = null;
1022+
signingDrawerOpen = true;
1023+
blindVoteError = null;
1024+
1025+
// Extract platform URL from the data
1026+
const platformUrl =
1027+
signingData.platformUrl ||
1028+
"http://192.168.0.225:7777";
1029+
1030+
// Set up signingData for blind voting UI
1031+
signingData = {
1032+
pollId: signingData.pollId,
1033+
sessionId: signingData.sessionId,
1034+
platform_url: platformUrl,
1035+
redirect: redirectUri, // Add the redirect URI from the deep link
1036+
// We'll need to fetch poll details, but for now set a placeholder
1037+
pollDetails: {
1038+
title: "Loading poll details...",
1039+
creatorName: "Loading...",
1040+
options: ["Loading..."],
1041+
},
1042+
};
1043+
1044+
// Fetch poll details in the background
1045+
try {
1046+
const pollResponse = await fetch(
1047+
`${platformUrl}/api/polls/${signingData.pollId}`,
1048+
);
1049+
if (pollResponse.ok) {
1050+
const pollDetails =
1051+
await pollResponse.json();
1052+
signingData.pollDetails = pollDetails;
1053+
console.log(
1054+
"✅ Poll details fetched:",
1055+
pollDetails,
1056+
);
1057+
}
1058+
} catch (error) {
1059+
console.error(
1060+
"Failed to fetch poll details:",
1061+
error,
1062+
);
1063+
blindVoteError = "Failed to load poll details";
1064+
}
1065+
1066+
return;
1067+
}
1068+
1069+
// Regular signing request
1070+
isSigningRequest = true;
1071+
signingDrawerOpen = true;
1072+
console.log("Signing modal should now be open");
10021073
} catch (error) {
10031074
console.error("Error decoding signing data:", error);
10041075
return;
10051076
}
1006-
isSigningRequest = true;
1007-
signingDrawerOpen = true;
1008-
console.log("Signing modal should now be open");
10091077
}
1010-
}
1011-
// Handle blind voting requests
1012-
if (data.type === "blind-vote") {
1013-
console.log("🔍 Blind voting request detected");
1014-
isBlindVotingRequest = true;
1015-
selectedBlindVoteOption = null;
1016-
signingData = data;
1017-
signingDrawerOpen = true;
1018-
blindVoteError = null; // Clear any previous errors
1019-
return;
1078+
} else if (data.type === "reveal") {
1079+
console.log("Handling reveal deep link");
1080+
// Handle reveal deep link
1081+
const pollId = data.pollId;
1082+
1083+
if (pollId) {
1084+
console.log("🔍 Reveal request for poll:", pollId);
1085+
1086+
// Set up reveal state
1087+
revealPollId = pollId;
1088+
isRevealRequest = true;
1089+
1090+
console.log("✅ Reveal request set up successfully");
1091+
console.log("🔍 DEBUG: State after setup:");
1092+
console.log(" - revealPollId:", revealPollId);
1093+
console.log(" - isRevealRequest:", isRevealRequest);
1094+
} else {
1095+
console.error("Missing pollId in reveal request");
1096+
}
10201097
}
10211098
}
10221099
@@ -1032,7 +1109,7 @@
10321109
try {
10331110
const data = JSON.parse(deepLinkData);
10341111
console.log("Parsed deep link data:", data);
1035-
handleDeepLinkData(data);
1112+
await handleDeepLinkData(data);
10361113
// Clear both storage keys to be safe
10371114
sessionStorage.removeItem("deepLinkData");
10381115
sessionStorage.removeItem("pendingDeepLink");
@@ -1048,40 +1125,36 @@
10481125
}
10491126
10501127
// Listen for deep link events when already on the page
1051-
const handleAuthEvent = (event: CustomEvent) => {
1128+
const handleAuthEvent = async (event: CustomEvent) => {
10521129
console.log("Received deepLinkAuth event:", event.detail);
1053-
handleDeepLinkData({
1130+
await handleDeepLinkData({
10541131
type: "auth",
10551132
...event.detail,
10561133
});
10571134
};
10581135
1059-
const handleSignEvent = (event: CustomEvent) => {
1136+
const handleSignEvent = async (event: CustomEvent) => {
10601137
console.log("Received deepLinkSign event:", event.detail);
1061-
handleDeepLinkData({
1138+
await handleDeepLinkData({
10621139
type: "sign",
10631140
...event.detail,
10641141
});
10651142
};
10661143
1067-
window.addEventListener(
1068-
"deepLinkAuth",
1069-
handleAuthEvent as EventListener,
1144+
window.addEventListener("deepLinkAuth", (event) =>
1145+
handleAuthEvent(event as CustomEvent),
10701146
);
1071-
window.addEventListener(
1072-
"deepLinkSign",
1073-
handleSignEvent as EventListener,
1147+
window.addEventListener("deepLinkSign", (event) =>
1148+
handleSignEvent(event as CustomEvent),
10741149
);
10751150
10761151
// Cleanup event listeners
10771152
onDestroy(() => {
1078-
window.removeEventListener(
1079-
"deepLinkAuth",
1080-
handleAuthEvent as EventListener,
1153+
window.removeEventListener("deepLinkAuth", (event) =>
1154+
handleAuthEvent(event as CustomEvent),
10811155
);
1082-
window.removeEventListener(
1083-
"deepLinkSign",
1084-
handleSignEvent as EventListener,
1156+
window.removeEventListener("deepLinkSign", (event) =>
1157+
handleSignEvent(event as CustomEvent),
10851158
);
10861159
});
10871160
});

0 commit comments

Comments
 (0)