Skip to content

Commit

Permalink
fix: cache region
Browse files Browse the repository at this point in the history
  • Loading branch information
zhbhun committed Nov 12, 2023
1 parent c626e8f commit c901e6d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/common/src/uitls/intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ export function getRegion(): Promise<string> {
if (pendingRegionRequest) {
return pendingRegionRequest
}
const region = localStorage.getItem('region')
if (region) {
return Promise.resolve(region)
}
pendingRegionRequest = fetch('https://api.country.is')
.then((res) => res.json())
.then((data) => data.country)
.then((data) => {
const region = data.country
if (region) {
localStorage.setItem('region', region)
}
return region
})
return pendingRegionRequest
}

0 comments on commit c901e6d

Please sign in to comment.