Skip to content

Commit

Permalink
added async waits to fulareadiness check
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Nov 26, 2024
1 parent 83271b8 commit edfab49
Show file tree
Hide file tree
Showing 5 changed files with 403 additions and 304 deletions.
2 changes: 1 addition & 1 deletion apps/box/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "box",
"version": "1.6.24",
"version": "1.6.25",
"private": true,
"dependencies": {
"@functionland/fula-sec": "*",
Expand Down
21 changes: 14 additions & 7 deletions apps/box/src/screens/Blox/Blox.screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ export const BloxScreen = () => {
);
const navigation = useNavigation();
const logger = useLogger();
const [earnings, getEarnings, fulaIsReady] = useUserProfileStore((state) => [
state.earnings,
state.getEarnings,
state.fulaIsReady,
]);
const [earnings, getEarnings, fulaIsReady, checkFulaReadiness] =
useUserProfileStore((state) => [
state.earnings,
state.getEarnings,
state.fulaIsReady,
state.checkFulaReadiness,
]);

const [
bloxs,
Expand Down Expand Up @@ -99,7 +101,7 @@ export const BloxScreen = () => {
state.getPools,
]);

const updateBloxAccount = async () => {
const updateBloxAccount = async (retried = false) => {
try {
if (fulaIsReady) {
const connectionStatus = await checkBloxConnection();
Expand All @@ -110,7 +112,12 @@ export const BloxScreen = () => {
setBloxAccountId('Not Connected to blox');
}
} else {
setBloxAccountId('Fula is not ready');
if (retried === false) {
await checkFulaReadiness();
updateBloxAccount(true);
} else {
setBloxAccountId('Fula is not ready');
}
}
} catch (e) {
console.error('Error updating blox account:', e);
Expand Down
29 changes: 16 additions & 13 deletions apps/box/src/screens/InitialSetup/SetupComplete.screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,7 @@ export const SetupCompleteScreen = ({ route }: Props) => {
}, [initialWaitForInternet]);

useEffect(() => {
if (
internetStatus !== 'CONNECTED' &&
inetInfo.isInternetReachable &&
inetInfo?.type === NetInfoStateType.wifi
) {
setInternetStatus('CONNECTED');
setInitialWaitForInternet(false);
}
checkInternetStatus();
}, [inetInfo]);

// Initiate fula
Expand Down Expand Up @@ -196,7 +189,7 @@ export const SetupCompleteScreen = ({ route }: Props) => {
const checkHotspotConnection = async () => {
try {
// Attempt to reach the specified URL
await axios.get('http://10.42.0.1:3500/properties');
await axios?.get('http://10.42.0.1:3500/properties');
// If successful, navigate back
navigation.pop();
} catch (error) {
Expand All @@ -211,10 +204,14 @@ export const SetupCompleteScreen = ({ route }: Props) => {

const checkInternetStatus = async () => {
try {
const network = await NetInfo.fetch();
const pingResponse = await axios?.head('https://google.com', {
timeout: 5000, // 5 seconds timeout
});
const network = await NetInfo?.fetch();
if (
network.isInternetReachable // &&
network?.isInternetReachable || // &&
//network?.type === NetInfoStateType.wifi
pingResponse?.status === 200
) {
setInternetStatus('CONNECTED');
setInitialWaitForInternet(false);
Expand Down Expand Up @@ -443,7 +440,12 @@ export const SetupCompleteScreen = ({ route }: Props) => {
Check internet connectivity
</FxButton>
<FxSpacer height={10} />
<FxButton marginBottom="16" variant="inverted" size="large" onPress={handleHome}>
<FxButton
marginBottom="16"
variant="inverted"
size="large"
onPress={handleHome}
>
Home
</FxButton>
<FxSpacer height={10} />
Expand Down Expand Up @@ -509,7 +511,8 @@ export const SetupCompleteScreen = ({ route }: Props) => {
</FxButton>
</>
)}
{currentBloxPeerId && bloxsConnectionStatus[currentBloxPeerId] === 'DISCONNECTED' &&
{currentBloxPeerId &&
bloxsConnectionStatus[currentBloxPeerId] === 'DISCONNECTED' &&
internetStatus === 'CONNECTED' &&
setupStatus === 'NOTCOMPLETED' && (
<FxButton size="large" onPress={handleReconnectBlox}>
Expand Down
Loading

0 comments on commit edfab49

Please sign in to comment.