Skip to content

Commit

Permalink
feat: #1301 - simplify location in offer columns
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladivo committed Nov 5, 2024
1 parent f9a4c00 commit 44bbdcc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
25 changes: 24 additions & 1 deletion apps/location-service/src/utils/googleMapsApi/geocode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import {
type GetGeocodedCoordinatesRequest,
} from '@vexl-next/rest-api/src/services/location/contracts'
import axios from 'axios'
import {Effect} from 'effect'
import {Array, Effect, Option, pipe} from 'effect'

interface GoogleGeocodeResponse {
results: Array<{
place_id: string
formatted_address: string
address_components: Array<{
long_name: string
short_name: string
types: string[]
}>
geometry: {
location: {
lat: number
Expand All @@ -31,6 +36,24 @@ interface GoogleGeocodeResponse {
}>
}

// Just keep this just in case. Might be useful
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const findTypeInAddressComponents = (
type: string,
components: Array<{
long_name: string
short_name: string
types: string[]
}>
): string | undefined =>
pipe(
Array.findFirst(components, (oneComponent) =>
oneComponent.types.includes(type)
),
Option.map((one) => one.long_name),
Option.getOrElse(() => undefined)
)

export const googleGeocode =
(apiKey: string) =>
({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
PriceBigger,
PriceText,
} from '../columnsStyles'
import {formatLocationForColumns} from '../utils'

interface Props {
offer: OfferInfo
Expand Down Expand Up @@ -114,9 +115,7 @@ function BtcOfferColumns({offer}: Props): JSX.Element {
{offer.publicPart.paymentMethod
.map((method) => {
if (method === 'CASH') {
return offer.publicPart.location
.map((one) => one.shortAddress)
.join(', ')
return formatLocationForColumns(offer.publicPart.location)
}
if (method === 'REVOLUT') {
return t('offer.revolut')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import pickupSvg from '../../images/pickupSvg'
import spokenLanguagesSvg from '../../images/spokenLanguagesSvg'
import mapTagSvg from '../../InsideRouter/components/MarketplaceScreen/images/mapTagSvg'
import {InfoDivider, InfoItemContainer, InfoText} from '../columnsStyles'
import {formatLocationForColumns} from '../utils'
import FiatOrSats from './FiatOrSats'

interface Props {
Expand Down Expand Up @@ -78,9 +79,7 @@ function ProductAndOtherOfferColumns({offer}: Props): JSX.Element {
<SvgImage source={mapTagSvg} />
</Stack>
<InfoText>
{offer.publicPart.location
.map((one) => one.shortAddress)
.join(', ')}
{formatLocationForColumns(offer.publicPart.location)}
</InfoText>
</InfoItemContainer>
</>
Expand Down
14 changes: 14 additions & 0 deletions apps/mobile/src/components/OfferInfoPreview/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {type OfferLocation} from '@vexl-next/domain/src/general/offers'

export const formatLocationForColumns = (
location: readonly OfferLocation[]
): string =>
location
.map((one) =>
one.address
.split(', ')
.slice(0, 2)
.map((one) => one.replace(/\d+/g, '').trim())
.join(', ')
)
.join('; ')

0 comments on commit 44bbdcc

Please sign in to comment.