diff --git a/src/cheatcodes/pages/others/CheatcodesScreenNewCaledonia.tsx b/src/cheatcodes/pages/others/CheatcodesScreenNewCaledonia.tsx
index c036b2d6728..acfcdfa2ffb 100644
--- a/src/cheatcodes/pages/others/CheatcodesScreenNewCaledonia.tsx
+++ b/src/cheatcodes/pages/others/CheatcodesScreenNewCaledonia.tsx
@@ -55,10 +55,10 @@ export const CheatcodesScreenNewCaledonia = () => {
Devise affichée à l’utilisateur :
{currency}
- Taux de change sur Firestore :
+ Taux de change depuis le backend :
{pacificFrancToEuroRate}
- Taux de change dans le code :
+ Taux de change par défaut côté frontend :
{DEFAULT_PACIFIC_FRANC_TO_EURO_RATE}
{
- it('should call the right firestore document "exchangeRates"', () => {
- getExchangeRates()
-
- expect(collection).toHaveBeenCalledWith('root')
- expect(collection('root').doc).toHaveBeenCalledWith(RemoteStoreDocuments.EXCHANGE_RATES)
- })
-
- it('should call captureMonitoringError when Firestore throws an error', async () => {
- mockGet.mockRejectedValueOnce(new Error('Firestore error'))
- getExchangeRates()
-
- await waitFor(() => {
- expect(captureMonitoringError).toHaveBeenCalledWith(
- 'Firestore error',
- 'firestore_not_available'
- )
- })
- })
-})
diff --git a/src/libs/firebase/firestore/exchangeRates/getExchangeRates.ts b/src/libs/firebase/firestore/exchangeRates/getExchangeRates.ts
deleted file mode 100644
index d3614a47a89..00000000000
--- a/src/libs/firebase/firestore/exchangeRates/getExchangeRates.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { firestoreRemoteStore } from 'libs/firebase/firestore/client'
-import { DEFAULT_PACIFIC_FRANC_TO_EURO_RATE } from 'libs/firebase/firestore/exchangeRates/useGetPacificFrancToEuroRate'
-import {
- FIRESTORE_ROOT_COLLECTION,
- RemoteStoreDocuments,
- RemoteStoreExchangeRates,
-} from 'libs/firebase/firestore/types'
-import { captureMonitoringError } from 'libs/monitoring'
-import { getErrorMessage } from 'shared/getErrorMessage/getErrorMessage'
-
-export const getExchangeRates = async (): Promise => {
- try {
- const docSnapshot = await firestoreRemoteStore
- .collection(FIRESTORE_ROOT_COLLECTION)
- .doc(RemoteStoreDocuments.EXCHANGE_RATES)
- .get()
-
- if (!docSnapshot.exists) return DEFAULT_PACIFIC_FRANC_TO_EURO_RATE
-
- return docSnapshot.get(RemoteStoreExchangeRates.PACIFIC_FRANC_TO_EURO_RATE)
- } catch (error) {
- captureMonitoringError(getErrorMessage(error), 'firestore_not_available')
- return DEFAULT_PACIFIC_FRANC_TO_EURO_RATE
- }
-}
diff --git a/src/libs/firebase/firestore/exchangeRates/useGetPacificFrancToEuroRate.native.test.ts b/src/libs/firebase/firestore/exchangeRates/useGetPacificFrancToEuroRate.native.test.ts
index c54f3101e1f..20c00b22faa 100644
--- a/src/libs/firebase/firestore/exchangeRates/useGetPacificFrancToEuroRate.native.test.ts
+++ b/src/libs/firebase/firestore/exchangeRates/useGetPacificFrancToEuroRate.native.test.ts
@@ -1,6 +1,4 @@
-import { onlineManager } from 'react-query'
-
-import { getExchangeRates } from 'libs/firebase/firestore/exchangeRates/getExchangeRates'
+import { defaultSettings } from 'features/auth/fixtures/fixtures'
import {
DEFAULT_PACIFIC_FRANC_TO_EURO_RATE,
useGetPacificFrancToEuroRate,
@@ -8,17 +6,16 @@ import {
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, renderHook } from 'tests/utils'
-jest.mock('@react-native-firebase/firestore')
-jest.mock('libs/firebase/firestore/exchangeRates/getExchangeRates')
-const mockGetExchangeRates = getExchangeRates as jest.Mock
+const mockSettings = jest.fn().mockReturnValue({ data: defaultSettings })
+jest.mock('features/auth/context/SettingsContext', () => ({
+ useSettingsContext: jest.fn(() => mockSettings()),
+}))
describe('useGetPacificFrancToEuroRate', () => {
- beforeEach(() => {
- jest.clearAllMocks()
- })
+ beforeEach(() => jest.clearAllMocks())
it('should initialize with the default rate', async () => {
- mockGetExchangeRates.mockReturnValueOnce(undefined)
+ mockSettings.mockReturnValueOnce({ data: undefined })
const { result } = renderUseGetPacificFrancToEuroRate()
await act(async () => {})
@@ -26,23 +23,16 @@ describe('useGetPacificFrancToEuroRate', () => {
expect(result.current).toEqual(DEFAULT_PACIFIC_FRANC_TO_EURO_RATE)
})
- it('should return remote exchange rate from firestore', async () => {
- mockGetExchangeRates.mockReturnValueOnce(0.05)
+ it('should return exchange rate from backend', async () => {
+ mockSettings.mockReturnValueOnce({
+ data: { ...defaultSettings, rates: { pacificFrancToEuro: 0.05 } },
+ })
const { result } = renderUseGetPacificFrancToEuroRate()
await act(async () => {})
expect(result.current).toEqual(0.05)
})
-
- it('should return default rate when connection is disabled', () => {
- onlineManager.setOnline(false)
- mockGetExchangeRates.mockReturnValueOnce(0.05)
-
- const { result } = renderUseGetPacificFrancToEuroRate()
-
- expect(result.current).toEqual(DEFAULT_PACIFIC_FRANC_TO_EURO_RATE)
- })
})
const renderUseGetPacificFrancToEuroRate = () =>
diff --git a/src/libs/firebase/firestore/exchangeRates/useGetPacificFrancToEuroRate.ts b/src/libs/firebase/firestore/exchangeRates/useGetPacificFrancToEuroRate.ts
index dcdcd9fddf7..5464df86b98 100644
--- a/src/libs/firebase/firestore/exchangeRates/useGetPacificFrancToEuroRate.ts
+++ b/src/libs/firebase/firestore/exchangeRates/useGetPacificFrancToEuroRate.ts
@@ -1,16 +1,8 @@
-import { onlineManager, useQuery } from 'react-query'
-
-import { getExchangeRates } from 'libs/firebase/firestore/exchangeRates/getExchangeRates'
-import { QueryKeys } from 'libs/queryKeys'
+import { useSettingsContext } from 'features/auth/context/SettingsContext'
export const DEFAULT_PACIFIC_FRANC_TO_EURO_RATE = 0.00838
export const useGetPacificFrancToEuroRate = (): number => {
- const { data: pacificFrancToEuroRate } = useQuery(QueryKeys.EXCHANGE_RATES, getExchangeRates, {
- staleTime: 1000 * 30,
- cacheTime: 1000 * 30,
- enabled: onlineManager.isOnline(),
- })
-
- return pacificFrancToEuroRate ?? DEFAULT_PACIFIC_FRANC_TO_EURO_RATE
+ const { data: settings } = useSettingsContext()
+ return settings?.rates?.pacificFrancToEuro ?? DEFAULT_PACIFIC_FRANC_TO_EURO_RATE
}
diff --git a/src/libs/firebase/firestore/types.ts b/src/libs/firebase/firestore/types.ts
index ab986e28e30..04aa7ee133d 100644
--- a/src/libs/firebase/firestore/types.ts
+++ b/src/libs/firebase/firestore/types.ts
@@ -3,7 +3,6 @@ export const FIRESTORE_ROOT_COLLECTION = 'root'
export enum RemoteStoreDocuments {
APPLICATION_VERSIONS = 'applicationVersions',
COOKIES_LAST_UPDATE = 'cookiesLastUpdate',
- EXCHANGE_RATES = 'exchangeRates',
FEATURE_FLAGS = 'featureFlags',
MAINTENANCE = 'maintenance',
UBBLE = 'ubble',
diff --git a/src/libs/queryKeys.ts b/src/libs/queryKeys.ts
index d8d57080b8a..78c6e394cdb 100644
--- a/src/libs/queryKeys.ts
+++ b/src/libs/queryKeys.ts
@@ -17,7 +17,6 @@ export enum QueryKeys {
EMAIL_UPDATE_STATUS = 'emailUpdateStatus',
EMAIL_UPDATE_STATUS_V2 = 'emailUpdateStatusV2',
EMAIL_VALIDATION_REMAINING_ATTEMPTS = 'emailValidationRemainingAttempts',
- EXCHANGE_RATES = 'exchangeRates',
ERROR_ASYNC = 'errorAsync',
FAVORITES = 'favorites',
FAVORITES_COUNT = 'favoritesCount',