Skip to content

Commit

Permalink
Refactor formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljscript committed Oct 25, 2024
1 parent 399ae52 commit 4a7d903
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {Notification, Notifications} from '@jamsinclair/react-native-notificatio
import {mountAsyncStorage} from '@yoroi/common'
import {Notifications as NotificationTypes} from '@yoroi/types'

import {getCurrencySymbol} from '../../../Settings/useCases/changeAppSettings/Currency/CurrencyContext'
import {configCurrencies} from '../../../../kernel/constants'

Check failure on line 5 in apps/wallet-mobile/src/features/Notifications/useCases/common/notifications.ts

View workflow job for this annotation

GitHub Actions / check

'configCurrencies' is defined but never used. Allowed unused vars must match /^_/u
import {formatCurrency, getCurrencySymbol} from '../../../Settings/useCases/changeAppSettings/Currency/CurrencyContext'

export const generateNotificationId = (): number => {
return generateRandomInteger(0, Number.MAX_SAFE_INTEGER)
Expand All @@ -28,11 +29,11 @@ export const displayNotificationEvent = async (notificationEvent: NotificationTy
if (notificationEvent.trigger === NotificationTypes.Trigger.PrimaryTokenPriceChanged) {
const appStorage = mountAsyncStorage({path: '/'})
const currencyCode = await getCurrencySymbol(appStorage)
const newPrice = `${notificationEvent.metadata.nextPrice.toFixed(2)}${currencyCode}`
const newPrice = formatCurrency(notificationEvent.metadata.nextPrice, currencyCode)

sendNotification({
title: 'Primary token price changed',
body: `The price of the primary token has changed to ${newPrice}`,
body: `The price of the primary token has changed to ${newPrice}.`,
id: notificationEvent.id,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export const getCurrencySymbol = async (storage: App.Storage) => {
return defaultCurrency
}

export const formatCurrency = (value: number, currency: CurrencySymbol) => {
return `${value.toFixed(configCurrencies[currency].decimals)} ${currency}`
}

const useSaveCurrency = ({onSuccess, ...options}: UseMutationOptions<void, Error, CurrencySymbol> = {}) => {
const queryClient = useQueryClient()
const storage = useAsyncStorage()
Expand Down

0 comments on commit 4a7d903

Please sign in to comment.