From 39e959ea2a60b934512d378d2e7d3769c09e4c24 Mon Sep 17 00:00:00 2001 From: pkova Date: Wed, 3 Apr 2024 13:30:50 +0300 Subject: [PATCH] treaty: subscribe for treaties to prevent race condition --- desk/app/treaty.hoon | 13 +++++++++++++ ui/src/state/docket.ts | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/desk/app/treaty.hoon b/desk/app/treaty.hoon index 0b040cac..37c2f579 100644 --- a/desk/app/treaty.hoon +++ b/desk/app/treaty.hoon @@ -111,6 +111,17 @@ ::NOTE this assumes that all treaties in sovereign are also :: present in the treaties map (fact-init:io (treaty-update:cg:cc %ini treaties))^~ + :: + [%treaties @ ~] + :_ this + =/ =ship (slav %p i.t.path) + =/ alliance (~(get ju allies) ship) + =/ allied + %- ~(gas by *(map [^ship desk] treaty)) + %+ skim ~(tap by treaties) + |= [ref=[^ship desk] =treaty] + (~(has in alliance) ref) + (fact-init:io (treaty-update:cg:ca:cc %ini allied))^~ :: [%alliance ~] :_ this @@ -308,12 +319,14 @@ ++ gone ^- (list card) :~ (fact:io (treaty-update:cg %del ship desk) /treaties ~) + (fact:io (treaty-update:cg %del ship desk) /treaties/[(scot %p ship)] ~) (kick-only:io our.bowl path ~) == ++ give ^- (list card) =/ t=treaty (~(got by treaties) ship desk) :~ (fact:io (treaty-update:cg %add t) /treaties ~) + (fact:io (treaty-update:cg %add t) /treaties/[(scot %p ship)] ~) (fact:io (treaty:cg t) path ~) == -- diff --git a/ui/src/state/docket.ts b/ui/src/state/docket.ts index c5a51d29..bea92f4c 100644 --- a/ui/src/state/docket.ts +++ b/ui/src/state/docket.ts @@ -223,10 +223,14 @@ export function useAllyTreaties(ship: string) { // [ship] // ) // ); - const { data: treatyData, isLoading } = useReactQueryScry({ + + const { data: treatyData, isLoading } = useReactQuerySubscription< + TreatyUpdateIni + >({ queryKey: ['treaty', 'treaties', ship], app: 'treaty', path: `/treaties/${ship}`, + scry: `/treaties/${ship}`, options: { enabled: isAllied, }, @@ -238,6 +242,7 @@ export function useAllyTreaties(ship: string) { } return normalizeDockets(treatyData.ini); }, [treatyData]); + const status = getAllyTreatyStatus( treaties, isLoading,