Skip to content

Commit

Permalink
feat: price formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelfimov authored and jade-smith-rs46 committed Jun 4, 2024
1 parent 8e34b61 commit 8a7eace
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 7 deletions.
226 changes: 226 additions & 0 deletions rn-demo-app/app/android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
{
"project_info": {
"project_number": "605730184710",
"project_id": "rees46-com",
"storage_bucket": "rees46-com.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:605730184710:android:6c640baac4dda9e05b6d87",
"android_client_info": {
"package_name": "com.demoapp"
}
},
"oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAMI5DiiCqeZ2JV2m6r0Be520N39WKh_TA"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "605730184710-33itje7rfcbadqg1j9bh98iip5h02nju.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "Avsi.TestPushSDK1"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:605730184710:android:7b6eb053665460b55b6d87",
"android_client_info": {
"package_name": "com.example.rees46_java_app"
}
},
"oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAMI5DiiCqeZ2JV2m6r0Be520N39WKh_TA"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "605730184710-33itje7rfcbadqg1j9bh98iip5h02nju.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "Avsi.TestPushSDK1"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:605730184710:android:198526dca19b16ec5b6d87",
"android_client_info": {
"package_name": "com.personaclick.sample"
}
},
"oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAMI5DiiCqeZ2JV2m6r0Be520N39WKh_TA"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "605730184710-33itje7rfcbadqg1j9bh98iip5h02nju.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "Avsi.TestPushSDK1"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:605730184710:android:e3fd667d60c9bdb75b6d87",
"android_client_info": {
"package_name": "com.personalizatio.sample"
}
},
"oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAMI5DiiCqeZ2JV2m6r0Be520N39WKh_TA"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "605730184710-33itje7rfcbadqg1j9bh98iip5h02nju.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "Avsi.TestPushSDK1"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:605730184710:android:75abe9965c01c1c45b6d87",
"android_client_info": {
"package_name": "com.rees46.sample"
}
},
"oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAMI5DiiCqeZ2JV2m6r0Be520N39WKh_TA"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "605730184710-33itje7rfcbadqg1j9bh98iip5h02nju.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "Avsi.TestPushSDK1"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:605730184710:android:9f9c2bc678183a005b6d87",
"android_client_info": {
"package_name": "com.sdkdev"
}
},
"oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAMI5DiiCqeZ2JV2m6r0Be520N39WKh_TA"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "605730184710-0t1ptvsobvg8pu3v4in9vb0u2lm855kb.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "605730184710-33itje7rfcbadqg1j9bh98iip5h02nju.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "Avsi.TestPushSDK1"
}
}
]
}
}
}
],
"configuration_version": "1"
}
5 changes: 4 additions & 1 deletion rn-demo-app/app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"
android:maxSdkVersion="32"/>
<uses-permission android:name="android.permission.USE_EXACT_ALARM"
android:minSdkVersion="33"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
Expand Down
2 changes: 2 additions & 0 deletions rn-demo-app/app/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ buildscript {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
classpath("com.google.gms:google-services:4.4.2")
}
}

apply plugin: "com.facebook.react.rootproject"
apply plugin: "com.google.gms.google-services"
1 change: 1 addition & 0 deletions rn-demo-app/fragments/product-info/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@globals/api-service": "workspace:0.0.1",
"@globals/constants": "workspace:0.0.1",
"@navigations/constants": "workspace:0.0.1",
"@shared/utils": "workspace:*",
"@stores/rn-sdk": "workspace:0.0.1",
"@ui/button": "workspace:0.0.1",
"@ui/condition": "workspace:0.0.1",
Expand Down
14 changes: 9 additions & 5 deletions rn-demo-app/fragments/product-info/src/product-info.fragment.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import { memo } from 'react'
import { useEffect } from 'react'
import { priceFormatter } from '@shared/utils'
import React from 'react'
import { memo } from 'react'
import { useEffect } from 'react'

import { SHOP_ID } from '@globals/constants'
import { ProductType } from '@globals/types'
Expand Down Expand Up @@ -45,6 +46,9 @@ export const ProductInfo = memo(({ id }: ProductInfoProps) => {
return null
}

const price = priceFormatter(product.price)
const oldPrice = priceFormatter(product?.oldprice)

return (
<>
<Row>
Expand Down Expand Up @@ -93,11 +97,11 @@ export const ProductInfo = memo(({ id }: ProductInfoProps) => {
fontSize='smallTitle'
fontColor='gray'
lineTrough
>{`${product?.oldprice} ${product!.currency}`}</TextComponent>
>{`${oldPrice} ${product!.currency}`}</TextComponent>
<Spacer height={4} />
</Condition>
<TextComponent fontWeight='semibold' fontSize='title' lineHeight={1}>
{`${product!.price} ${product!.currency}`}
{`${price} ${product!.currency}`}
</TextComponent>
</Box>
<Spacer space={16} />
Expand Down
1 change: 1 addition & 0 deletions rn-demo-app/shared/utils/src/formatters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './price.formatter'
23 changes: 23 additions & 0 deletions rn-demo-app/shared/utils/src/formatters/price.formatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const priceFormatter = (value: string | undefined): string => {
if (!value) return ''

let result = ''

if (value.includes('.')
) {
const priceSplit = value.split('.')

const majors = priceSplit[0]
result += majors

const minors = priceSplit[1]

if (minors.length > 0) {
if (minors !== '0' && minors !== '00') {
result += minors.length > 1 ? `.${minors.slice(0, 2)}` : `.${minors}0`
}
}
}

return result
}
1 change: 1 addition & 0 deletions rn-demo-app/shared/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './hooks'
export * from './formatters'
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,7 @@ __metadata:
"@globals/constants": "workspace:0.0.1"
"@globals/types": "workspace:0.0.1"
"@navigations/constants": "workspace:0.0.1"
"@shared/utils": "workspace:*"
"@stores/rn-sdk": "workspace:0.0.1"
"@types/react": "npm:^18.2.6"
"@ui/button": "workspace:0.0.1"
Expand Down Expand Up @@ -3813,7 +3814,7 @@ __metadata:
languageName: unknown
linkType: soft

"@shared/utils@workspace:0.0.1, @shared/utils@workspace:rn-demo-app/shared/utils":
"@shared/utils@workspace:*, @shared/utils@workspace:0.0.1, @shared/utils@workspace:rn-demo-app/shared/utils":
version: 0.0.0-use.local
resolution: "@shared/utils@workspace:rn-demo-app/shared/utils"
dependencies:
Expand Down

0 comments on commit 8a7eace

Please sign in to comment.