Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fetch country code #225

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/constants/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const appConfig = {
CF_TEMPLATE: getEnv("VITE_AWS_CF_TEMPLATE"),
APPLE_APP_STORE_LINK: getEnv("VITE_APPLE_APP_STORE_LINK"),
GOOGLE_PLAY_STORE_LINK: getEnv("VITE_GOOGLE_PLAY_STORE_LINK"),
COUNTRY_EVALUATION_URL: import.meta.env.DEV ? "/doNotDelete.txt" : "assets/doNotDelete.txt",
COUNTRY_EVALUATION_URL: "/doNotDelete.txt",
APP_VERSION: getEnv("VITE_APP_VERSION"),
NL_BASE_URL: getEnv("VITE_NL_BASE_URL"),
NL_API_KEY: getEnv("VITE_NL_API_KEY"),
Expand Down
3 changes: 3 additions & 0 deletions src/utils/analyticsUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. */
/* SPDX-License-Identifier: MIT-0 */

import {
Event,
GetEndpointCommand,
Expand Down
11 changes: 10 additions & 1 deletion src/utils/countryUtil.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. */
/* SPDX-License-Identifier: MIT-0 */

import { appConfig } from "@demo/core/constants";

import sleep from "./sleep";

let failCount = 0;
let countryCode = "";

const {
ENV: { COUNTRY_EVALUATION_URL }
} = appConfig;

export const getCountryCode: () => Promise<string | undefined> = async () => {
try {
if (countryCode) {
return countryCode === "Unknown" ? undefined : countryCode;
}

const response = await fetch(COUNTRY_EVALUATION_URL);
const country = response.headers.get("x-country");
countryCode = country || "Unknown";

failCount = 0;

Expand All @@ -22,7 +31,7 @@ export const getCountryCode: () => Promise<string | undefined> = async () => {
}
} catch (error) {
failCount++;
console.log("error: ", error);
console.error("error: ", error);

// try three times before failing
if (failCount === 3) {
Expand Down
Loading