From 77c1cc8182c8216db8b479ec3201ac6077813a4e Mon Sep 17 00:00:00 2001 From: pkova Date: Wed, 3 Apr 2024 13:30:50 +0300 Subject: [PATCH 1/3] treaty: subscribe for treaties to prevent race condition --- desk/app/treaty.hoon | 13 +++++++++++++ ui/src/state/docket.ts | 8 +++++++- 2 files changed, 20 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..90cda359 100644 --- a/ui/src/state/docket.ts +++ b/ui/src/state/docket.ts @@ -223,10 +223,15 @@ export function useAllyTreaties(ship: string) { // [ship] // ) // ); - const { data: treatyData, isLoading } = useReactQueryScry({ + + const { data: treatyData, isLoading } = useReactQuerySubscription< + TreatyUpdateIni, + TreatyUpdate + >({ queryKey: ['treaty', 'treaties', ship], app: 'treaty', path: `/treaties/${ship}`, + scry: `/treaties/${ship}`, options: { enabled: isAllied, }, @@ -238,6 +243,7 @@ export function useAllyTreaties(ship: string) { } return normalizeDockets(treatyData.ini); }, [treatyData]); + const status = getAllyTreatyStatus( treaties, isLoading, From 83e4372c6837ae09b279e94fa38d75c8b4b314a0 Mon Sep 17 00:00:00 2001 From: pkova Date: Thu, 4 Apr 2024 18:02:35 +0300 Subject: [PATCH 2/3] treaty: fix resubscribe no-op if already subscribed --- desk/app/treaty.hoon | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/desk/app/treaty.hoon b/desk/app/treaty.hoon index 37c2f579..4ada3507 100644 --- a/desk/app/treaty.hoon +++ b/desk/app/treaty.hoon @@ -4,6 +4,7 @@ ++ default-ally ~dister-dozzod-dozzod :: +$ card card:agent:gall ++$ state-1 [%1 state-0] +$ state-0 $: treaties=(map [=ship =desk] treaty) sovereign=(map desk treaty) @@ -15,7 +16,7 @@ ^- agent:gall %+ verb | %- agent:dbug -=| state-0 +=| state-1 =* state - =< |_ =bowl:gall @@ -30,8 +31,19 @@ ++ on-save !>(state) ++ on-load |= =vase + ?: =(%1 -.q.vase) + =+ !<(old=state-1 vase) + `this(state old) =+ !<(old=state-0 vase) - `this(state old) + :_ this(state [%1 old]) + %- zing + ^- (list (list card)) + %+ turn ~(tap by allies.old) + |= [=ship s=(set *)] + ^- (list card) + =* al ~(. al:cc ship) + ?^ s ~ + ~[leave:al watch:al] :: ++ on-poke |= [=mark =vase] @@ -59,7 +71,7 @@ ?< =(ship our.bowl) =* al ~(. al:cc ship.update) ?- -.update - %add [~[watch:al] this(allies (~(put by allies) ship *alliance))] + %add [~[leave:al watch:al] this(allies (~(put by allies) ship *alliance))] %del [~[leave:al] this(allies (~(del by allies) ship))] == :: From df231040b1629bb95be0228825b44d96370b1eba Mon Sep 17 00:00:00 2001 From: Pyry Kovanen Date: Thu, 4 Apr 2024 18:12:51 +0300 Subject: [PATCH 3/3] treaty: use singular fact:io for subscription update Co-authored-by: fang --- desk/app/treaty.hoon | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/desk/app/treaty.hoon b/desk/app/treaty.hoon index 4ada3507..cb4af4e0 100644 --- a/desk/app/treaty.hoon +++ b/desk/app/treaty.hoon @@ -330,8 +330,7 @@ ++ leave (leave:pass dock) ++ gone ^- (list card) - :~ (fact:io (treaty-update:cg %del ship desk) /treaties ~) - (fact:io (treaty-update:cg %del ship desk) /treaties/[(scot %p ship)] ~) + :~ (fact:io (treaty-update:cg %del ship desk) /treaties /treaties/[(scot %p ship)] ~) (kick-only:io our.bowl path ~) == ++ give