-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: geofence transak in uk (#2598)
* feat: geofence transak in uk Co-authored-by: Jean Ribeiro <[email protected]> * fix: updateCountryCode condition --------- Co-authored-by: Jean Ribeiro <[email protected]>
- Loading branch information
1 parent
ec3e96b
commit 4789d91
Showing
14 changed files
with
109 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/shared/src/lib/auxiliary/country/actions/getAndUpdateCountryCode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { CountryApi } from '../api' | ||
import { updateCountryCode } from '../stores' | ||
|
||
export async function getAndUpdateCountryCode(): Promise<void> { | ||
const api = new CountryApi() | ||
const countryCode = await api.getCountryCode() | ||
updateCountryCode(countryCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './getAndUpdateCountryCode' |
42 changes: 42 additions & 0 deletions
42
packages/shared/src/lib/auxiliary/country/api/country.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { BaseApi } from '@core/utils' | ||
|
||
interface IIpApiResponse { | ||
ip: string | ||
network: string | ||
version: string | ||
city: string | ||
region: string | ||
region_code: string | ||
country: string | ||
country_name: string | ||
country_code: string | ||
country_code_iso3: string | ||
country_capital: string | ||
country_tld: string | ||
continent_code: string | ||
in_eu: boolean | ||
postal: string | ||
latitude: number | ||
longitude: number | ||
timezone: string | ||
utc_offset: string | ||
country_calling_code: string | ||
currency: string | ||
currency_name: string | ||
languages: string | ||
country_area: number | ||
country_population: number | ||
asn: string | ||
org: string | ||
} | ||
|
||
export class CountryApi extends BaseApi { | ||
constructor() { | ||
super('https://ipapi.co') | ||
} | ||
|
||
async getCountryCode(): Promise<string | undefined> { | ||
const ipData = await this.get<IIpApiResponse>('json') | ||
return ipData?.country_code | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './country.api' |
Empty file.
9 changes: 9 additions & 0 deletions
9
packages/shared/src/lib/auxiliary/country/stores/country-code.store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { writable } from 'svelte/store' | ||
|
||
export const countryCode = writable<string | undefined>(undefined) | ||
|
||
export function updateCountryCode(_countryCode: string | undefined): void { | ||
if (_countryCode) { | ||
countryCode?.set(_countryCode) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './country-code.store' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,7 @@ export interface IAppParameters { | |
allowlists: { | ||
urls: string[] | ||
} | ||
geoFence: { | ||
buySell: string[] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,8 @@ | |
}, | ||
"allowlists": { | ||
"urls": ["https://tideprotocol.infura-ipfs.io"] | ||
}, | ||
"geoFence": { | ||
"buySell": ["GB"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './isFeatureEnabled' | ||
export * from './isFeatureGeoFenced' |
21 changes: 21 additions & 0 deletions
21
packages/shared/src/lib/features/utils/isFeatureGeoFenced.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { countryCode } from '@auxiliary/country/stores' | ||
import { appParameters } from '@core/app/stores' | ||
import { get } from 'svelte/store' | ||
|
||
export function isFeatureNotGeoFenced(featureString: string): boolean { | ||
const currentCountryCode = get(countryCode) | ||
const featurePathToCheck = featureString.split('.') | ||
const geoFence = get(appParameters)?.geoFence | ||
let previousFeatures = geoFence | ||
for (let i = 0; i < featurePathToCheck.length; i++) { | ||
const currentFeature = previousFeatures?.[featurePathToCheck[i]] | ||
if (!currentFeature) { | ||
return true | ||
} | ||
if (i === featurePathToCheck.length - 1) { | ||
return !currentFeature?.some((blockedCountry) => blockedCountry === currentCountryCode) | ||
} | ||
previousFeatures = currentFeature | ||
} | ||
return true | ||
} |