Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #402 from admin-ch/bugfix/eu-national-rules
Browse files Browse the repository at this point in the history
Check for CH only valid certificates
  • Loading branch information
benz-ubique authored Apr 7, 2022
2 parents d26b93d + 3678322 commit 21325e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ class CertificateDetailFragment : Fragment() {
binding.certificateDetailButtonReverify.showAnimated()
}

val isSuccessState = it.state is VerificationState.SUCCESS
val isOnlyNationalRulesInvalid = it.state.isOnlyNationalRulesInvalid()
binding.certificateForeignValidityButton.isVisible =
currentConfig?.foreignRulesCheckEnabled == true && (isSuccessState || isOnlyNationalRulesInvalid)
val isFeatureEnabled = currentConfig?.foreignRulesCheckEnabled == true
val isNotInvalid = it.state is VerificationState.SUCCESS || it.state.isOnlyNationalRulesInvalid()
val isValidOnlyInSwitzerland = it.state.isValidOnlyInSwitzerland()
binding.certificateForeignValidityButton.isVisible = isFeatureEnabled && isNotInvalid && !isValidOnlyInSwitzerland

updateStatusInfo(it.state)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import androidx.annotation.ColorRes
import ch.admin.bag.covidcertificate.common.util.addBoldDate
import ch.admin.bag.covidcertificate.common.util.makeSubStringBold
import ch.admin.bag.covidcertificate.sdk.core.data.ErrorCodes
import ch.admin.bag.covidcertificate.sdk.core.models.state.CheckNationalRulesState
import ch.admin.bag.covidcertificate.sdk.core.models.state.CheckRevocationState
import ch.admin.bag.covidcertificate.sdk.core.models.state.CheckSignatureState
import ch.admin.bag.covidcertificate.sdk.core.models.state.VerificationState
import ch.admin.bag.covidcertificate.sdk.core.models.state.*
import ch.admin.bag.covidcertificate.wallet.R

const val DATE_REPLACEMENT_STRING = "{DATE}"
Expand Down Expand Up @@ -69,6 +66,19 @@ fun VerificationState.getNameDobColor(): Int {
}
}

/**
* @return True if this is a successful (wallet) verification state and the certificate is only valid in switzerland
*/
fun VerificationState.isValidOnlyInSwitzerland(): Boolean {
return when (this) {
is VerificationState.SUCCESS -> {
val walletSuccessState = this.successState as? SuccessState.WalletSuccessState
walletSuccessState?.isValidOnlyInSwitzerland ?: false
}
else -> false
}
}

/**
* @return True if this is an invalid verification state and only the national rules check failed (signature and revocation must be valid)
*/
Expand Down

0 comments on commit 21325e4

Please sign in to comment.