Skip to content
Open
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
14 changes: 11 additions & 3 deletions src/actions/AccountReferralActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -208,8 +208,16 @@ export const getCountryCodeByIp = async (): Promise<string | undefined> => {
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
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/types/TweakTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ export const asPluginTweak = asObject<PluginTweak>({
export const asIpApi = asObject({
countryCode: asString
})

export const asIp2LocationIo = asObject({
countryCode: asString
})