diff --git a/src/actions/AccountReferralActions.ts b/src/actions/AccountReferralActions.ts index 45926c5f370..8b381648296 100644 --- a/src/actions/AccountReferralActions.ts +++ b/src/actions/AccountReferralActions.ts @@ -5,7 +5,7 @@ import { EdgeAccount } from 'edge-core-js/types' import { ENV } from '../env' import { RootState, ThunkAction } from '../types/reduxTypes' import { AccountReferral, Promotion, ReferralCache } from '../types/ReferralTypes' -import { asCurrencyCode, asIpApi, asMessageTweak, asPluginTweak } from '../types/TweakTypes' +import { asCurrencyCode, asIp2LocationIo, asIpApi, asMessageTweak, asPluginTweak } from '../types/TweakTypes' import { fetchReferral } from '../util/network' import { lockStartDates, TweakSource } from '../util/ReferralHelpers' import { logEvent } from '../util/tracking' @@ -208,8 +208,16 @@ export const getCountryCodeByIp = async (): Promise => { const { countryCode } = asIpApi(await reply.json()) return countryCode } catch (e: any) { - console.warn(`getCountryCodeByIp() failed: ${String(e)}`) - return undefined + try { + const reply2 = await fetch(`https://api.ip2location.io`) + let json2 = await reply2.json() + json2 = json2.replace(`country_code`, `countryCode`) + const { countryCode } = asIp2LocationIo(json2) + return countryCode + } catch (e: any) { + console.warn(`getCountryCodeByIp() failed: ${String(e)}`) + return undefined + } } } diff --git a/src/types/TweakTypes.ts b/src/types/TweakTypes.ts index 7e0fa687dad..4282d37cffc 100644 --- a/src/types/TweakTypes.ts +++ b/src/types/TweakTypes.ts @@ -80,3 +80,7 @@ export const asPluginTweak = asObject({ export const asIpApi = asObject({ countryCode: asString }) + +export const asIp2LocationIo = asObject({ + countryCode: asString +})