From 146a5c46aed78dd71aaa3b0cb4f168652df02e47 Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Sun, 29 Nov 2026 13:25:39 +0100 Subject: [PATCH] Bind Rihla receipts to settled facts when recovering pending cash --- .../main/java/com/dunerealms/menus/AtmMenu.java | 17 +++++++++-------- .../main/java/com/dunerealms/menus/Backend.java | 8 ++++++-- .../com/dunerealms/menus/JarvisBackend.java | 11 +++++++---- .../com/dunerealms/menus/RihlaReceiptTest.java | 14 ++++++++++++++ docs/RIHLA-ATM-SCREENS-20261129.md | 2 +- 5 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 DuneMenus/src/test/java/com/dunerealms/menus/RihlaReceiptTest.java diff --git a/DuneMenus/src/main/java/com/dunerealms/menus/AtmMenu.java b/DuneMenus/src/main/java/com/dunerealms/menus/AtmMenu.java index d869aaae..bc207a97 100644 --- a/DuneMenus/src/main/java/com/dunerealms/menus/AtmMenu.java +++ b/DuneMenus/src/main/java/com/dunerealms/menus/AtmMenu.java @@ -24,7 +24,7 @@ final class AtmMenu extends Menu { private final List selected = new ArrayList<>(); private String entered; // RIA ID typed on the Redeem tab private String receiptOperation,receiptReference,receiptMessage; - private long receiptAmount; + private Long receiptAmount; AtmMenu(DuneMenusPlugin plugin, Player p, Menu parent, Tab tab) { super(plugin, p, parent); this.tab = tab; } String id() { return switch(tab){case WITHDRAW->"withdraw";case DEPOSIT->"deposit";case REDEEM->"redeem";case RECEIPT->"receipt";default->"atm";}; } @@ -66,7 +66,7 @@ final class AtmMenu extends Menu { put(36,Ui.item(Material.ARROW,"Back"),c->{tab=Tab.HOME;selected.clear();redraw();}); if(tab==Tab.RECEIPT){ put(13,Ui.item(Material.PAPER,""+receiptOperation, - "Amount: "+Ui.dm(receiptAmount),""+receiptMessage)); + receiptAmount==null?""+receiptMessage:"Amount: "+Ui.dm(receiptAmount),""+receiptMessage)); if(receiptReference!=null&&!receiptReference.isBlank())put(29,Ui.item(Material.NAME_TAG,"RIA ID",""+receiptReference)); return; } @@ -91,20 +91,21 @@ final class AtmMenu extends Menu { if (dep) load(backend().atmCreateRia(player, pieces), r -> { say(new Backend.Result(r.ok(), r.message())); - if (r.ok()) { receipt("Cash deposit",minor,r.riaId(),r.message()); } + if (r.ok()) { receipt("Cash deposit",r.receipt(),r.message()); } else redraw(); }); else load(backend().bankWithdraw(player, pieces), r -> { say(r); - if (r.ok()) receipt("Cash withdrawal",minor,null,r.message()); + if (r.ok()) receipt("Cash withdrawal",r.receipt(),r.message()); else redraw(); }); }); } - private void receipt(String operation,long amount,String reference,String message){ - receiptOperation=operation;receiptAmount=amount;receiptReference=reference;receiptMessage=message; + private void receipt(String operation,Backend.CashReceipt facts,String message){ + receiptOperation=facts!=null&&facts.recovered()?"Recovered Rihla transaction":operation; + receiptAmount=facts==null?null:facts.amountMinor();receiptReference=facts==null?null:facts.riaId();receiptMessage=message; selected.clear();tab=Tab.RECEIPT;redraw(); } @@ -123,9 +124,9 @@ final class AtmMenu extends Menu { if (v == null) { put(22, Ui.item(Material.BARRIER, "RIA ID not found")); return; } put(22, Ui.glow(Ui.item(Material.GOLD_BLOCK, "" + Ui.dm(v.amountMinor()), "From: " + v.fromName()))); put(24, Ui.glow(Ui.item(Material.GOLD_INGOT, "Take as cash", "Bills and coins in your inventory")), - c -> load(backend().atmRedeem(player, v, false), r -> { say(r); if (r.ok()) {entered = null;receipt("RIA payout · Cash",v.amountMinor(),id,r.message());} else redraw(); })); + c -> load(backend().atmRedeem(player, v, false), r -> { say(r); if (r.ok()) {entered = null;receipt("RIA payout · Cash",r.receipt(),r.message());} else redraw(); })); put(26, Ui.glow(Ui.item(Material.ENDER_CHEST, "Send to my bank", "Credited to your account")), - c -> load(backend().atmRedeem(player, v, true), r -> { say(r); if (r.ok()) {entered = null;receipt("RIA payout · Bank",v.amountMinor(),id,r.message());} else redraw(); })); + c -> load(backend().atmRedeem(player, v, true), r -> { say(r); if (r.ok()) {entered = null;receipt("RIA payout · Bank",r.receipt(),r.message());} else redraw(); })); }); } } diff --git a/DuneMenus/src/main/java/com/dunerealms/menus/Backend.java b/DuneMenus/src/main/java/com/dunerealms/menus/Backend.java index 69aa0716..2edbd610 100644 --- a/DuneMenus/src/main/java/com/dunerealms/menus/Backend.java +++ b/DuneMenus/src/main/java/com/dunerealms/menus/Backend.java @@ -20,7 +20,9 @@ public interface Backend { /** Complete a future exceptionally with this to mean "this feature is not wired yet". */ final class Unavailable extends RuntimeException { public Unavailable() { super("not wired", null, false, false); } } - record Result(boolean ok, String message) { + record CashReceipt(long amountMinor,String riaId,boolean recovered) {} + record Result(boolean ok, String message, CashReceipt receipt) { + public Result(boolean ok,String message){this(ok,message,null);} public static Result yes(String m) { return new Result(true, m); } public static Result no(String m) { return new Result(false, m); } } @@ -96,7 +98,9 @@ public interface Backend { // receives the full amount and collects it in-game; cancelling releases the reservation. default CompletableFuture bankAccount(Player p) { return na(); } /** ATM, tab 1. The player taps bills and coins; the menu sends the total. Backend takes the cash and CREATES a new RIA ID worth that amount. */ - record Issued(boolean ok, String message, String riaId) {} + record Issued(boolean ok, String message, String riaId, CashReceipt receipt) { + public Issued(boolean ok,String message,String riaId){this(ok,message,riaId,null);} + } default CompletableFuture atmCreateRia(Player p, List pieces) { return na(); } /** ATM, tab 2. Look an RIA ID up so the menu can show the amount before payout. Return null/exceptional if unknown. */ record Voucher(String riaId, long amountMinor, String fromName) {} diff --git a/DuneMenus/src/main/java/com/dunerealms/menus/JarvisBackend.java b/DuneMenus/src/main/java/com/dunerealms/menus/JarvisBackend.java index 2c5ef1b2..acd4af1f 100644 --- a/DuneMenus/src/main/java/com/dunerealms/menus/JarvisBackend.java +++ b/DuneMenus/src/main/java/com/dunerealms/menus/JarvisBackend.java @@ -97,7 +97,8 @@ final class JarvisBackend implements Backend, Listener { } return cashAction(player,request).thenApply(row->{ String voucher=number(row,"voucher"); - return new Issued(!voucher.isEmpty(),voucher.isEmpty()?cashResult(row).message():"Rihla voucher created.",voucher); + var result=cashResult(row); + return new Issued(result.ok()&&!voucher.isEmpty(),result.message(),voucher,result.receipt()); }); } @@ -133,7 +134,8 @@ final class JarvisBackend implements Backend, Listener { request.addProperty("voucher",voucher.riaId()); request.addProperty("requestId",UUID.randomUUID().toString()); var row=accepted(jarvis.requestRihla(actor,request)); - return Result.yes("Credited "+Ui.dm(money(row,"amountMinor"))+" to your Postbank account."); + long amount=money(row,"amountMinor"); + return new Result(true,"Credited "+Ui.dm(amount)+" to your Postbank account.",new CashReceipt(amount,voucher.riaId(),false)); })); } var pieces=change(voucher.amountMinor()); @@ -192,13 +194,14 @@ final class JarvisBackend implements Backend, Listener { return List.copyOf(result); } - private static Result cashResult(JsonObject result) { + static Result cashResult(JsonObject result) { if(result.has("localError"))return Result.no(text(result,"localError")); if(text(result,"state").equals("aborted"))return Result.no("The previous unfinished Rihla cash action was released. Select your cash again."); if(!text(result,"state").equals("committed"))return Result.no("Rihla cash was not settled."); String voucher=number(result,"voucher"); String prefix=yes(result,"recovered")?"Previous Rihla cash action recovered · ":"Rihla cash settled · "; - return Result.yes(prefix+Ui.dm(money(result,"amountMinor"))+(voucher.isEmpty()?".":" · "+voucher+".")); + long amount=money(result,"amountMinor"); + return new Result(true,prefix+Ui.dm(amount)+(voucher.isEmpty()?".":" · "+voucher+"."),new CashReceipt(amount,voucher,yes(result,"recovered"))); } private static String number(JsonObject row,String key){ diff --git a/DuneMenus/src/test/java/com/dunerealms/menus/RihlaReceiptTest.java b/DuneMenus/src/test/java/com/dunerealms/menus/RihlaReceiptTest.java new file mode 100644 index 00000000..4ba55d4a --- /dev/null +++ b/DuneMenus/src/test/java/com/dunerealms/menus/RihlaReceiptTest.java @@ -0,0 +1,14 @@ +package com.dunerealms.menus; +import com.google.gson.JsonObject; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +class RihlaReceiptTest { + @Test void recoveredReceiptUsesSettledFactsInsteadOfNewSelection(){ + var row=new JsonObject();row.addProperty("state","committed");row.addProperty("amountMinor",2000);row.addProperty("voucher","RIA-0123456789ABCDEF0123456789ABCDEF");row.addProperty("recovered",true); + var result=JarvisBackend.cashResult(row); + assertTrue(result.ok());assertEquals(2000,result.receipt().amountMinor());assertTrue(result.receipt().recovered());assertEquals(row.get("voucher").getAsString(),result.receipt().riaId()); + } + @Test void nonCommittedResultsDoNotProduceSuccessfulReceipts(){ + for(String state:new String[]{"aborted","prepared","queued"}){var row=new JsonObject();row.addProperty("state",state);row.addProperty("amountMinor",5000);var result=JarvisBackend.cashResult(row);assertFalse(result.ok());assertNull(result.receipt());} + } +} diff --git a/docs/RIHLA-ATM-SCREENS-20261129.md b/docs/RIHLA-ATM-SCREENS-20261129.md index 11bdbfd1..f76dc36e 100644 --- a/docs/RIHLA-ATM-SCREENS-20261129.md +++ b/docs/RIHLA-ATM-SCREENS-20261129.md @@ -10,7 +10,7 @@ Make the cash flow discoverable from the Imperial Codex and separate operation s - ATM home offers Deposit cash, Redeem RIA ID and Withdraw cash. Back returns to the Codex. - Deposit/Withdraw show actual denomination artwork and selectors, one amount-labelled transaction action and Back. The action is above the denomination grid and visible in the initial viewport. There are no repeated operation tabs or a second lookalike Withdraw tile. Selecting a denomination still only selects it; the existing final action performs the transaction. No new confirmation step is added. - Redeem offers reference entry, then the existing verified voucher amount and payout destinations. Reference entry uses a native Minecraft anvil text window because pinned MCGUI 0.8.6 has no editable text-field API. It is not an editable HTML form. Input is normalized and validated, never sent through chat. Closing the entry window returns to Redeem. All input items and clicks are isolated and cleared on completion, close, quit and disable. -- A successful bank response opens the transaction receipt. It displays the actual operation, selected amount, backend result and RIA ID when the backend supplies one. It invents neither a withdrawal RIA ID nor fees, zero-cost claims or settlement status. Existing backend errors remain errors, not successful receipts. Back returns to ATM home. +- A successful bank response opens the transaction receipt. It displays the actual operation, bank-returned amount, backend result and RIA ID when the backend supplies one. It invents neither a withdrawal RIA ID nor fees, zero-cost claims or settlement status. Recovered cash operations use the earlier settled amount/reference and an explicit recovered-transaction label, never the current selection. Existing backend errors remain errors, not successful receipts. Back returns to ATM home. The canonical `rihla-brand-v1.png` artwork is packaged locally and proportionally displayed using its existing top-logo region. No remote image fetch occurs when opening the screen. Currency artwork and the published resource pack are unchanged.