diff --git a/src/miniapps/fairshare/ResourceTiles.test.tsx b/src/miniapps/fairshare/ResourceTiles.test.tsx
index 6170705..1ddf3d9 100644
--- a/src/miniapps/fairshare/ResourceTiles.test.tsx
+++ b/src/miniapps/fairshare/ResourceTiles.test.tsx
@@ -1,6 +1,6 @@
// @vitest-environment happy-dom
import "@testing-library/jest-dom/vitest";
-import { cleanup, render, screen, waitFor } from "@testing-library/react";
+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { db } from "../../lib/db";
import { append, readAll } from "../../lib/eventlog";
@@ -361,6 +361,65 @@ describe("ResourceTiles (allocation display formatting - coherence audit)", () =
await waitForAllocationCycleCount("power", 1);
await waitForAllocationCycleCount("cooling", 1);
});
+
+ it("formats a fractional wallet balance to 2 decimals instead of echoing its raw precision", async () => {
+ await init();
+ const accountId = toAccountId(await getPublicKey());
+
+ // A wallet.issue amount is just a number - nothing requires it to be a
+ // whole number, and the project's own convention elsewhere (e.g.
+ // Farms' harvest forecast) issues genuinely fractional amounts.
+ await append({ type: "wallet.issue", account: accountId, amount: 123.456789 });
+
+ render();
+
+ await waitFor(() => {
+ const text = screen.getByTestId("fairshare-balance").textContent ?? "";
+ expect(text).toMatch(/^\d+\.\d\d$/);
+ expect(text).toBe((123.456789).toFixed(2));
+ });
+ });
+
+ it("formats a fractional resource supply (e.g. Farms' real LP/GDD forecast feeding food) to 2 decimals", async () => {
+ await init();
+ const accountId = toAccountId(await getPublicKey());
+
+ // Mirrors the real cross-app chain: Farms' settleFarmsForecast credits
+ // food via a seed.resource.food event carrying the LP optimizer's real
+ // (frequently non-round) totalForecastYieldKg - this is not a
+ // contrived fixture, it is exactly how the food supply pool is
+ // populated in production.
+ await append({ type: "seed.resource.food", resource: "food", value: 187.654321 });
+ await append({ type: "fairshare.need", agent: accountId, resource: "food", value: 1 });
+
+ render();
+
+ await waitFor(() => {
+ const text = screen.getByTestId("tile-food").textContent ?? "";
+ expect(text).toContain((187.654321).toFixed(2));
+ expect(text).not.toContain("187.654321");
+ });
+ });
+
+ it("formats the echoed need amount in the submit-status message to 2 decimals, even if a resident types more precision", async () => {
+ await init();
+
+ render();
+
+ await waitFor(() => {
+ expect(screen.getByTestId("fairshare-need-resource")).toBeInTheDocument();
+ });
+ fireEvent.change(screen.getByTestId("fairshare-need-amount"), {
+ target: { value: "9.123456789" },
+ });
+ fireEvent.submit(screen.getByRole("form", { name: "Report your need" }));
+
+ await waitFor(() => {
+ const text = screen.getByTestId("fairshare-need-status").textContent ?? "";
+ expect(text).toContain((9.123456789).toFixed(2));
+ expect(text).not.toContain("9.123456789");
+ });
+ });
});
describe("ResourceTiles (failure path - no ledger balance yet)", () => {
diff --git a/src/miniapps/fairshare/ResourceTiles.tsx b/src/miniapps/fairshare/ResourceTiles.tsx
index 1e0dfe6..df37dcc 100644
--- a/src/miniapps/fairshare/ResourceTiles.tsx
+++ b/src/miniapps/fairshare/ResourceTiles.tsx
@@ -132,7 +132,7 @@ export function ResourceTiles() {
}
try {
await postFairshareNeed(accountId, needResource, value);
- setNeedStatus(`Reported a need of ${value} for ${needResource}.`);
+ setNeedStatus(`Reported a need of ${value.toFixed(2)} for ${needResource}.`);
setNeedAmount("");
} catch (err) {
setNeedStatus(err instanceof Error ? err.message : String(err));
@@ -148,7 +148,7 @@ export function ResourceTiles() {
? "--"
: balance === undefined
? "No balance yet"
- : balance}
+ : balance.toFixed(2)}
@@ -187,7 +187,7 @@ export function ResourceTiles() {
>
{hasAllocation ? qty!.toFixed(2) : "No allocation yet"}
- of {supply} pool
+ of {supply.toFixed(2)} pool
);