Skip to content

Commit

Permalink
add: support global enabled for goodid feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Dec 23, 2024
1 parent 1157324 commit 7b2a886
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ const FaceVerification = ({ screenProps, navigation }) => {
const userStorage = useUserStorage()
const { account, isFVFlow } = useContext(FVFlowContext)
const payload = useFlagWithPayload('uat-goodid-flow')
const { countries, whitelist } = payload ?? {}
const [isEligible] = usePromise(() => supportedCountries(countries, whitelist, account))
const { enabled = false, countries = '', whitelist = [] } = payload ?? {}
const [isEligible] = usePromise(
() => supportedCountries(countries, whitelist, account, enabled),
[countries, whitelist, account, enabled],
)

const { faceIdentifier: enrollmentIdentifier, chainId, v1FaceIdentifier: fvSigner } = useEnrollmentIdentifier()

Expand Down
12 changes: 8 additions & 4 deletions src/lib/utils/supportedCountries.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { retry } from './async'

export const supportedCountries = async (supportedCountries = '', whitelist = [], account) => {
export const supportedCountries = async (supportedCountries = '', whitelist = [], account, enabled) => {
if (enabled || whitelist?.includes(account)) {
return true
}
if (!supportedCountries) {
return false
}
const country = await retry(async () => (await fetch('https://get.geojs.io/v1/ip/country.json')).json(), 3, 2000)
.then(data => data.country)
.catch(() => false)

const isEligible = supportedCountries?.split(',')?.includes(country) || whitelist?.includes(account)

return isEligible
return supportedCountries?.split(',')?.includes(country)
}
6 changes: 3 additions & 3 deletions src/lib/wallet/GoodWalletProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ export const GoodWalletProvider = ({ children, disableLoginAndWatch = false }) =
const [hasGoodIdEnabled, setHasGoodIdEnabled] = useState(false)
const [shouldLoginAndWatch] = usePropsRefs([disableLoginAndWatch === false])
const posthog = usePostHog()
const { countries, whitelist } = useFlagWithPayload('uat-goodid-flow') ?? {}
const { enabled = false, countries = '', whitelist = [] } = useFlagWithPayload('uat-goodid-flow') ?? {}
const [isEligible] = usePromise(
() => supportedCountries(countries, whitelist, goodWallet?.account),
[countries, whitelist, goodWallet?.account],
() => supportedCountries(countries, whitelist, goodWallet?.account, enabled),
[countries, whitelist, goodWallet?.account, enabled],
)

const db = getDB()
Expand Down

0 comments on commit 7b2a886

Please sign in to comment.