Skip to content

Commit

Permalink
treaty: subscribe for treaties to prevent race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
pkova committed Apr 3, 2024
1 parent 9e8258e commit 39e959e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions desk/app/treaty.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ~)
==
--
Expand Down
7 changes: 6 additions & 1 deletion ui/src/state/docket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,14 @@ export function useAllyTreaties(ship: string) {
// [ship]
// )
// );
const { data: treatyData, isLoading } = useReactQueryScry<TreatyUpdateIni>({

const { data: treatyData, isLoading } = useReactQuerySubscription<
TreatyUpdateIni
>({
queryKey: ['treaty', 'treaties', ship],
app: 'treaty',
path: `/treaties/${ship}`,
scry: `/treaties/${ship}`,
options: {
enabled: isAllied,
},
Expand All @@ -238,6 +242,7 @@ export function useAllyTreaties(ship: string) {
}
return normalizeDockets(treatyData.ini);
}, [treatyData]);

const status = getAllyTreatyStatus(
treaties,
isLoading,
Expand Down

0 comments on commit 39e959e

Please sign in to comment.