Fix Native requests (#375)

* fix-android-maker

* test
This commit is contained in:
Reckless_Satoshi 2023-03-04 12:54:06 +00:00 committed by GitHub
parent cee6ffbf45
commit 8d4301a0c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 12 deletions

View File

@ -43,9 +43,11 @@ const RobotPage = (): JSX.Element => {
setInputToken(robot.token); setInputToken(robot.token);
} }
if (robot.nickname == null && robot.token) { if (robot.nickname == null && robot.token) {
fetchRobot({ action: 'generate', setBadRequest }); if (window.NativeRobosats === undefined || torStatus == '"Done"') {
fetchRobot({ action: 'generate', setBadRequest });
}
} }
}, []); }, [torStatus]);
const getGenerateRobot = (token: string, slot?: number) => { const getGenerateRobot = (token: string, slot?: number) => {
setInputToken(token); setInputToken(token);

View File

@ -18,6 +18,7 @@ import {
} from '../models'; } from '../models';
import { apiClient } from '../services/api'; import { apiClient } from '../services/api';
import { systemClient } from '../services/System';
import { checkVer, getHost, tokenStrength } from '../utils'; import { checkVer, getHost, tokenStrength } from '../utils';
import { sha256 } from 'js-sha256'; import { sha256 } from 'js-sha256';
@ -252,7 +253,7 @@ export const AppContextProvider = ({
useEffect(() => { useEffect(() => {
window.addEventListener('torStatus', (event) => { window.addEventListener('torStatus', (event) => {
// UX improv: delay the "Conencted" status by 10 secs to avoid long waits for first requests // UX improv: delay the "Conencted" status by 10 secs to avoid long waits for first requests
setTimeout(() => setTorStatus(event?.detail), event?.detail === '"Done"' ? 10000 : 0); setTimeout(() => setTorStatus(event?.detail), event?.detail === '"Done"' ? 5000 : 0);
}); });
}, []); }, []);
@ -465,6 +466,7 @@ export const AppContextProvider = ({
setRobot(newRobot); setRobot(newRobot);
garage.updateRobot(newRobot, targetSlot); garage.updateRobot(newRobot, targetSlot);
setCurrentSlot(targetSlot); setCurrentSlot(targetSlot);
systemClient.setItem('robot_token', token);
} }
}); });
}; };

View File

@ -10,16 +10,19 @@ class ApiNativeClient implements ApiClient {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}; };
const sessionid = systemClient.getCookie('sessionid'); const robotToken = systemClient.getItem('robot_token');
const csrftoken = systemClient.getCookie('csrftoken'); if (robotToken) {
const sessionid = systemClient.getCookie('sessionid');
const csrftoken = systemClient.getCookie('csrftoken');
headers = { headers = {
...headers, ...headers,
...{ ...{
'X-CSRFToken': csrftoken, 'X-CSRFToken': csrftoken,
Cookie: `sessionid=${sessionid};token=${csrftoken}`, Cookie: `sessionid=${sessionid};csrftoken=${csrftoken}`,
}, },
}; };
}
return headers; return headers;
}; };

View File

@ -45,6 +45,7 @@ const App = () => {
EncryptedStorage.removeItem('sessionid'); EncryptedStorage.removeItem('sessionid');
EncryptedStorage.removeItem('csrftoken'); EncryptedStorage.removeItem('csrftoken');
loadCookie('robot_token');
loadCookie('settings_fontsize_basic'); loadCookie('settings_fontsize_basic');
loadCookie('settings_language'); loadCookie('settings_language');
loadCookie('settings_mode'); loadCookie('settings_mode');