(feat): added version render script for apps like obtainium #7
1 changed files with 36 additions and 6 deletions
commit
9e3a6040e3
|
|
@ -191,6 +191,7 @@ export function Provider(props: {
|
||||||
typeof createTransportClient<Schemas>
|
typeof createTransportClient<Schemas>
|
||||||
> | null>(null);
|
> | null>(null);
|
||||||
const identificationStartedRef = useRef(false);
|
const identificationStartedRef = useRef(false);
|
||||||
|
const identificationCancelRef = useRef(false);
|
||||||
|
|
||||||
// Load ttp url
|
// Load ttp url
|
||||||
const [ttpUrl, setTtpUrl] = useState<string | null>(null);
|
const [ttpUrl, setTtpUrl] = useState<string | null>(null);
|
||||||
|
|
@ -242,6 +243,23 @@ export function Provider(props: {
|
||||||
return client.subscribePush(handler);
|
return client.subscribePush(handler);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Check for error_no_iota
|
||||||
|
useEffect(() => {
|
||||||
|
if (!connected) return;
|
||||||
|
|
||||||
|
return subscribePush((message) => {
|
||||||
|
if (message.type !== "error_no_iota") return;
|
||||||
|
|
||||||
|
identificationCancelRef.current = true;
|
||||||
|
setIdentified(false);
|
||||||
|
setIdentifying(false);
|
||||||
|
setError("We couldn't reach your Iota");
|
||||||
|
setErrorDescription(
|
||||||
|
"You could try to restart your Iota, check for updates or check your network connection.",
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}, [connected, subscribePush]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!connected || !identified) {
|
if (!connected || !identified) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -363,6 +381,7 @@ export function Provider(props: {
|
||||||
clearReconnectTimer();
|
clearReconnectTimer();
|
||||||
scheduleReconnectReset();
|
scheduleReconnectReset();
|
||||||
identificationStartedRef.current = false;
|
identificationStartedRef.current = false;
|
||||||
|
identificationCancelRef.current = false;
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
setIdentified(false);
|
setIdentified(false);
|
||||||
setError("");
|
setError("");
|
||||||
|
|
@ -483,6 +502,11 @@ export function Provider(props: {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (identificationCancelRef.current) {
|
||||||
|
identificationStartedRef.current = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (identificationStartedRef.current) {
|
if (identificationStartedRef.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -551,10 +575,12 @@ export function Provider(props: {
|
||||||
const finalResponse = await send("challenge_response", {
|
const finalResponse = await send("challenge_response", {
|
||||||
challenge: decryptedChallenge,
|
challenge: decryptedChallenge,
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
|
if (!identificationCancelRef.current) {
|
||||||
setError("Identification Failed");
|
setError("Identification Failed");
|
||||||
setErrorDescription(
|
setErrorDescription(
|
||||||
"Unable to complete secure identification. Please verify your credentials and try again.",
|
"Unable to complete secure identification. Please verify your credentials and try again.",
|
||||||
);
|
);
|
||||||
|
}
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -562,7 +588,7 @@ export function Provider(props: {
|
||||||
setFreshContacts(finalResponse.data.contacts);
|
setFreshContacts(finalResponse.data.contacts);
|
||||||
setFreshCommunities(finalResponse.data.communities);
|
setFreshCommunities(finalResponse.data.communities);
|
||||||
setFreshCalls(finalResponse.data.calls);
|
setFreshCalls(finalResponse.data.calls);
|
||||||
if (cancelled) {
|
if (cancelled || identificationCancelRef.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -574,6 +600,10 @@ export function Provider(props: {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (identificationCancelRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isStopSendingError(identificationError)) {
|
if (isStopSendingError(identificationError)) {
|
||||||
setError("Connection closed");
|
setError("Connection closed");
|
||||||
setErrorDescription(
|
setErrorDescription(
|
||||||
|
|
@ -604,7 +634,7 @@ export function Provider(props: {
|
||||||
: "Unable to complete secure identification because the transport request failed.",
|
: "Unable to complete secure identification because the transport request failed.",
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
if (!cancelled) {
|
if (!cancelled && !identificationCancelRef.current) {
|
||||||
setIdentifying(false);
|
setIdentifying(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue