]> git.digitality.be Git - pdw25-26/commitdiff
"Mobile : Mis en place fichier api (toujours en mocks pour le moment)"
authorThibaud Moustier <thibaudmoustier0@gmail.com>
Fri, 27 Feb 2026 21:34:00 +0000 (22:34 +0100)
committerThibaud Moustier <thibaudmoustier0@gmail.com>
Fri, 27 Feb 2026 21:34:00 +0000 (22:34 +0100)
Wallette/mobile/src/config/api.ts [new file with mode: 0644]
Wallette/mobile/src/config/env.ts
Wallette/mobile/src/services/api/alertsApi.ts [new file with mode: 0644]
Wallette/mobile/src/services/api/authApi.ts [new file with mode: 0644]
Wallette/mobile/src/services/api/priceApi.ts [new file with mode: 0644]
Wallette/mobile/src/services/api/signalApi.ts [new file with mode: 0644]
Wallette/mobile/src/services/api/strategyApi.ts [new file with mode: 0644]

diff --git a/Wallette/mobile/src/config/api.ts b/Wallette/mobile/src/config/api.ts
new file mode 100644 (file)
index 0000000..19f8d94
--- /dev/null
@@ -0,0 +1,41 @@
+import { Platform } from "react-native";
+
+/**
+ * API Gateway (microservices)
+ * ---------------------------
+ * - Téléphone physique : utiliser l'IP du PC sur le réseau local
+ * - Android émulateur : 10.0.2.2
+ * - iOS simulateur : localhost (souvent OK)
+ *
+ * IMPORTANT : le mobile doit appeler UNIQUEMENT le gateway:
+ *   http://<HOST>:3000/api/...
+ * Socket.IO passe aussi via le gateway:
+ *   http://<HOST>:3000   (proxy /socket.io/*)
+ */
+
+// ✅ Change uniquement cette valeur pour ton PC
+const DEV_LAN_IP = "192.168.129.121";
+
+export function getGatewayHost(): string {
+  if (__DEV__) {
+    // Téléphone physique / LAN
+    return DEV_LAN_IP;
+  }
+  // En prod (ou build), tu mettras un vrai domaine/IP si nécessaire
+  return DEV_LAN_IP;
+}
+
+export function getGatewayBaseUrl(): string {
+  const host =
+    Platform.OS === "android" && !__DEV__
+      ? "10.0.2.2"
+      : getGatewayHost();
+
+  return `http://${host}:3000`;
+}
+
+// REST base
+export const API_BASE_URL = `${getGatewayBaseUrl()}/api`;
+
+// Socket base (pas /api)
+export const SOCKET_BASE_URL = `${getGatewayBaseUrl()}`;
\ No newline at end of file
index 36a9d9a6cb7ed054187e118e8374bce18a5e640e..e394a9ba3e90d26318efd6c22ef74920439c9a77 100644 (file)
@@ -1,3 +1,37 @@
-// ⚠️ En dev téléphone réel : URL = IP du PC sur le même réseau
-export const SERVER_URL = "http://192.168.129.121:3000";
-export const WS_URL = "ws://192.168.129.121:3000"; // optionnel, Socket.IO peut aussi utiliser http(s)
\ No newline at end of file
+import { Platform } from "react-native";
+
+/**
+ * env.ts
+ * ------
+ * Objectif : centraliser les URLs réseau pour le mobile.
+ *
+ * IMPORTANT (microservices + gateway) :
+ * - Le mobile parle UNIQUEMENT au gateway : http://<HOST>:3000
+ * - REST = http://<HOST>:3000/api/...
+ * - Socket.IO = http://<HOST>:3000  (proxy /socket.io/* via gateway)
+ *
+ * Téléphone physique :
+ * - <HOST> = IP du PC sur le Wi-Fi (ex: 192.168.x.x)
+ *
+ * Émulateurs (si un jour) :
+ * - Android: 10.0.2.2
+ * - iOS: localhost
+ */
+
+const DEV_LAN_IP = "192.168.129.121";
+
+function resolveHost(): string {
+  // On part sur téléphone physique (ton cas).
+  // Si un jour tu testes sur émulateur Android, tu peux mettre une condition:
+  // if (Platform.OS === "android" && __DEV__ && isEmulator) return "10.0.2.2";
+  return DEV_LAN_IP;
+}
+
+// Base gateway (HTTP)
+export const GATEWAY_BASE_URL = `http://${resolveHost()}:3000`;
+
+// REST (via gateway)
+export const API_BASE_URL = `${GATEWAY_BASE_URL}/api`;
+
+// Socket.IO (via gateway)
+export const SERVER_URL = GATEWAY_BASE_URL;
\ No newline at end of file
diff --git a/Wallette/mobile/src/services/api/alertsApi.ts b/Wallette/mobile/src/services/api/alertsApi.ts
new file mode 100644 (file)
index 0000000..3c9e7d2
--- /dev/null
@@ -0,0 +1,21 @@
+import type { Alert } from "../../types/Alert";
+import { alertStore } from "../alertStore";
+
+/**
+ * alertsApi
+ * ---------
+ * Contrat futur (gateway):
+ * - GET /api/alerts/events?userId=...&limit=10
+ * - POST /api/alerts
+ * - POST /api/alerts/:id/toggle
+ *
+ * Pour l'instant : on lit ce qu'on a en local (alertStore alimenté par Socket).
+ */
+export async function getRecentAlerts(limit = 10): Promise<Alert[]> {
+  const all = alertStore.getAll?.() ?? [];
+  return all.slice(0, limit);
+}
+
+export async function clearLocalAlerts(): Promise<void> {
+  alertStore.clear?.();
+}
\ No newline at end of file
diff --git a/Wallette/mobile/src/services/api/authApi.ts b/Wallette/mobile/src/services/api/authApi.ts
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/Wallette/mobile/src/services/api/priceApi.ts b/Wallette/mobile/src/services/api/priceApi.ts
new file mode 100644 (file)
index 0000000..224660d
--- /dev/null
@@ -0,0 +1,15 @@
+import type { DashboardSummary } from "../../types/DashboardSummary";
+import { fetchDashboardSummary } from "../dashboardService";
+
+/**
+ * priceApi
+ * --------
+ * Contrat futur (gateway):
+ * - GET /api/price/current?pair=BTC/EUR
+ *
+ * Pour l'instant : on renvoie la donnée mock déjà utilisée par le Dashboard.
+ */
+export async function getCurrentPriceForDashboard(): Promise<Pick<DashboardSummary, "pair" | "price" | "timestamp">> {
+  const d = await fetchDashboardSummary();
+  return { pair: d.pair, price: d.price, timestamp: d.timestamp };
+}
\ No newline at end of file
diff --git a/Wallette/mobile/src/services/api/signalApi.ts b/Wallette/mobile/src/services/api/signalApi.ts
new file mode 100644 (file)
index 0000000..8a2d075
--- /dev/null
@@ -0,0 +1,15 @@
+import type { Signal } from "../../types/Signal";
+import { fetchRecentSignals } from "../signalService";
+
+/**
+ * signalApi
+ * ---------
+ * Contrat futur (gateway):
+ * - GET /api/signal/current?userId=...&pair=BTC/EUR
+ * - (option) GET /api/signal/recent?userId=...&limit=20
+ *
+ * Pour l'instant : on utilise les mocks existants.
+ */
+export async function getRecentSignals(limit = 20): Promise<Signal[]> {
+  return await fetchRecentSignals(limit);
+}
\ No newline at end of file
diff --git a/Wallette/mobile/src/services/api/strategyApi.ts b/Wallette/mobile/src/services/api/strategyApi.ts
new file mode 100644 (file)
index 0000000..5f5b366
--- /dev/null
@@ -0,0 +1,17 @@
+import { loadSettings, saveSettings } from "../../utils/settingsStorage";
+import type { UserSettings } from "../../models/UserSettings";
+
+/**
+ * strategyApi
+ * -----------
+ * Contrat futur (gateway):
+ * - POST /api/strategy/select   { userId, pair, strategyKey, params... }
+ *
+ * Pour l'instant : on sauvegarde localement dans settingsStorage.
+ */
+export async function selectStrategy(strategyKey: string): Promise<UserSettings> {
+  const s = await loadSettings();
+  const next: UserSettings = { ...s, selectedStrategyKey: strategyKey };
+  await saveSettings(next);
+  return next;
+}
\ No newline at end of file