Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Promise, async, await - Boolean returns false but if condition still gets called

$
0
0

Context

I have this piece of code to force app update, that checks whether an update is needed and is supposed to return true or false depending on the version number of the user's app vs the App Store version. This seems to be working correctly when the version number of the user's app is lower, because it stores the right url in the website variable:

  let website = ''  const isLatestVersion = async (): Promise<boolean> => {    await VersionCheck.needUpdate({      packageName: 'com.tfp.numberbomb',    }).then((res) => {      if (res.isNeeded) {        website = res.storeUrl        return true // open store if update is needed.      } else return false    })  }

Problem

It doesn't work correctly when the version number of the user's app is equal/higher. This is the function where I am using the function from above. For some reason, the logic executes showPopup() even if the response from the function is false. What am I doing wrong?:

  const handleBiometricLogin = async () => {    if (!(await isLatestVersion())) {      await showPopup()      return    }    ... // rest of the logic that doesn't run even when it's supposed to because of the return statement

Additional info

showPopup() function just for reference:

const showPopup = async () => {    Alert.alert(      translations['errors.login.update.title'] ?? 'Download Available',      translations['errors.login.update.body'] ??'There is a new download available on the app store. Please update to gain access',      [        { text: translations['form.no-answer'] ?? 'No' },        {          text: translations['form.yes-answer'] ?? 'Yes',          onPress: () => handleOpenLink(website, translations),        },      ],    )  }

I feel like I am doing the async and await stuff correctly, and I tried to search for possible duplicates but it's difficult to find anything


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>