From de723a5d8ab4d97fec00445f56b0d076893b4f49 Mon Sep 17 00:00:00 2001 From: David Westgate Date: Sun, 9 Mar 2025 16:35:02 -0700 Subject: [PATCH] add warning mechanism --- components/ChipDistributionSummary.tsx | 25 +++++++++++++++---- .../ChipDistributionSummary.test.tsx | 7 ++++++ i18n/en.json | 4 ++- i18n/es.json | 4 ++- styles/styles.ts | 2 +- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/components/ChipDistributionSummary.tsx b/components/ChipDistributionSummary.tsx index 4b8ce1a..c2a4a38 100644 --- a/components/ChipDistributionSummary.tsx +++ b/components/ChipDistributionSummary.tsx @@ -1,8 +1,9 @@ import React, { useCallback, useEffect, useMemo, useState } from "react"; -import { View, Text } from "react-native"; +import { View, Text, Alert } from "react-native"; import { ColorValue } from "react-native"; import i18n from "@/i18n/i18n"; -import styles from "@/styles/styles"; +import styles, { COLORS } from "@/styles/styles"; +import { MaterialIcons } from "@expo/vector-icons"; interface ChipDistributionSummaryProps { playerCount: number; @@ -27,6 +28,10 @@ const ChipDistributionSummary = ({ const [denominations, setDenominations] = useState([]); const [distributions, setDistributions] = useState([]); + const showAlert = () => { + Alert.alert(i18n.t("warning"), i18n.t("chip_value_warn")); + }; + type validDenomination = | 0.05 | 0.1 @@ -171,9 +176,19 @@ const ChipDistributionSummary = ({ })} - - {i18n.t("total_value")}: {selectedCurrency} {round(totalValue)} - + + + {i18n.t("total_value")}: {selectedCurrency} {round(totalValue)}{" "} + + {round(totalValue) !== buyInAmount && ( + + )} + {selectedCurrency} {potValue} {i18n.t("pot")} diff --git a/components/__tests__/ChipDistributionSummary.test.tsx b/components/__tests__/ChipDistributionSummary.test.tsx index 936d7f8..f0ce2cb 100644 --- a/components/__tests__/ChipDistributionSummary.test.tsx +++ b/components/__tests__/ChipDistributionSummary.test.tsx @@ -2,6 +2,13 @@ import React from "react"; import { render } from "@testing-library/react-native"; import ChipDistributionSummary from "../ChipDistributionSummary"; +jest.mock("@expo/vector-icons", () => { + const { Text } = require("react-native"); + return { + MaterialIcons: () => TestIcon, + }; +}); + describe("ChipDistributionSummary Component", () => { test("renders correctly with valid data", () => { const playerCount = 4; diff --git a/i18n/en.json b/i18n/en.json index da31ef9..c7033e3 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -36,6 +36,7 @@ "failed_to_save_state": "Failed to save state.", "state_loaded_from": "State loaded from", "info": "Info", + "warning": "Warning", "no_saved_state_found": "No saved state found.", "automatic_chip_detection": "Automatic Chip Detection", "manual_chip_adjustment": "Manual Chip Adjustment", @@ -44,6 +45,7 @@ "save_slot_2": "Save\nSlot 2", "load_slot_1": "Load\nSlot 1", "load_slot_2": "Load\nSlot 2", - "please_select_valid_buyin": "Please select a valid buy-in amount" + "please_select_valid_buyin": "Please select a valid buy-in amount", + "chip_value_warn": "Be advised that the value of the distributed chips does not equal the buy-in for these inputs.\n\nHowever, results shown are fair to all players" } } diff --git a/i18n/es.json b/i18n/es.json index c39c4aa..6395e86 100644 --- a/i18n/es.json +++ b/i18n/es.json @@ -37,6 +37,7 @@ "failed_to_save_state": "No se pudo guardar el estado.", "state_loaded_from": "Estado cargado desde", "info": "Información", + "warning": "Advertencia", "no_saved_state_found": "No se encontró estado guardado.", "automatic_chip_detection": "Detección automática de fichas", "manual_chip_adjustment": "Ajuste manual de fichas", @@ -45,6 +46,7 @@ "save_slot_2": "Guardar\nSlot 2", "load_slot_1": "Cargar\nSlot 1", "load_slot_2": "Cargar\nSlot 2", - "please_select_valid_buyin": "Por favor seleccione una cantidad de buy-in válida" + "please_select_valid_buyin": "Por favor seleccione una cantidad de buy-in válida", + "chip_value_warn": "Tenga en cuenta que el valor de las fichas distribuidas no es igual al buy-in para estas entradas.\n\nSin embargo, los resultados que se muestran son justos para todos los jugadores." } } diff --git a/styles/styles.ts b/styles/styles.ts index 8ae1a57..dc5376f 100644 --- a/styles/styles.ts +++ b/styles/styles.ts @@ -5,7 +5,7 @@ export const COLORS = { SECONDARY: "#6c757d", SUCCESS: "#28a745", DANGER: "#dc3545", - WARNING: "#ffc107", + WARNING: "#c79c28", }; const lightStyles = StyleSheet.create({});