Skip to content

Commit

Permalink
Pull nervous system details from the Registry (#4571)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Oct 12, 2023
1 parent c8aa2dc commit 0a97250
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 13 deletions.
11 changes: 9 additions & 2 deletions frontend/openchat-agent/src/services/openchatAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { LedgerClient } from "./ledger/ledger.client";
import { GroupIndexClient } from "./groupIndex/groupIndex.client";
import { MarketMakerClient } from "./marketMaker/marketMaker.client";
import { RegistryClient } from "./registry/registry.client";
import { toRecord } from "../utils/list";
import { distinctBy, toRecord } from "../utils/list";
import { measure } from "./common/profiling";
import {
buildBlobUrl,
Expand Down Expand Up @@ -2484,7 +2484,14 @@ export class OpenChatAgent extends EventTarget {
if (updates.kind === "success" && updates.tokenDetails !== undefined) {
const updated = {
lastUpdated: updates.lastUpdated,
tokenDetails: updates.tokenDetails,
tokenDetails: distinctBy(
[...updates.tokenDetails, ...(current?.tokenDetails ?? [])],
(t) => t.ledgerCanisterId,
),
nervousSystemDetails: distinctBy(
[...updates.nervousSystemDetails, ...(current?.nervousSystemDetails ?? [])],
(ns) => ns.governanceCanisterId,
),
};
setCachedRegistry(updated);
return updated;
Expand Down
8 changes: 8 additions & 0 deletions frontend/openchat-agent/src/services/registry/candid/idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ export const idlFactory = ({ IDL }) => {
'symbol' : IDL.Text,
'transaction_url_format' : IDL.Text,
});
const NervousSystemSummary = IDL.Record({
'submitting_proposals_enabled' : IDL.Bool,
'is_nns' : IDL.Bool,
'governance_canister_id' : CanisterId,
'proposal_rejection_fee' : IDL.Nat64,
'ledger_canister_id' : CanisterId,
});
const UpdatesResponse = IDL.Variant({
'Success' : IDL.Record({
'last_updated' : TimestampMillis,
'token_details' : IDL.Opt(IDL.Vec(TokenDetails)),
'nervous_system_details' : IDL.Vec(NervousSystemSummary),
}),
'SuccessNoUpdates' : IDL.Null,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,13 @@ export interface MessagesSuccessResult {
export type Milliseconds = bigint;
export type MultiUserChat = { 'Group' : ChatId } |
{ 'Channel' : [CommunityId, ChannelId] };
export interface NervousSystemSummary {
'submitting_proposals_enabled' : boolean,
'is_nns' : boolean,
'governance_canister_id' : CanisterId,
'proposal_rejection_fee' : bigint,
'ledger_canister_id' : CanisterId,
}
export interface NnsCompletedCryptoTransaction {
'to' : NnsCryptoAccount,
'fee' : Tokens,
Expand Down Expand Up @@ -1206,6 +1213,7 @@ export type UpdatesResponse = {
'Success' : {
'last_updated' : TimestampMillis,
'token_details' : [] | [Array<TokenDetails>],
'nervous_system_details' : Array<NervousSystemSummary>,
}
} |
{ 'SuccessNoUpdates' : null };
Expand Down
9 changes: 8 additions & 1 deletion frontend/openchat-agent/src/services/registry/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ export function updatesResponse(candid: ApiUpdatesResponse): RegistryUpdatesResp
return {
kind: "success",
lastUpdated: candid.Success.last_updated,
tokenDetails: optional(candid.Success.token_details, (t) => t.map(tokenDetails)),
tokenDetails: optional(candid.Success.token_details, (t) => t.map(tokenDetails)) ?? [],
nervousSystemDetails: candid.Success.nervous_system_details.map((ns) => ({
governanceCanisterId: ns.governance_canister_id.toString(),
ledgerCanisterId: ns.ledger_canister_id.toString(),
isNns: ns.is_nns,
proposalRejectionFee: ns.proposal_rejection_fee,
submittingProposalsEnabled: ns.submitting_proposals_enabled,
})),
};
}
if ("SuccessNoUpdates" in candid) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/openchat-agent/src/utils/registryCache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { openDB, type DBSchema, type IDBPDatabase } from "idb";
import type { RegistryValue } from "openchat-shared";

const CACHE_VERSION = 1;
const CACHE_VERSION = 2;
const KEY = "registry";

let db: RegistryDatabase | undefined;
Expand Down
1 change: 1 addition & 0 deletions frontend/openchat-client/src/utils/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ export function mergeSendMessageResponse(
token: msg.content.transfer.token,
endDate: msg.content.endDate,
caption: msg.content.caption,
diamondOnly: msg.content.diamondOnly,
} as PrizeContent;
break;
}
Expand Down
30 changes: 21 additions & 9 deletions frontend/openchat-shared/src/domain/registry/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
export type RegistryUpdatesResponse = RegistryUpdatesResponseSuccess | RegistryUpdatesResponseSuccessNoUpdates;
export type RegistryUpdatesResponse =
| RegistryUpdatesResponseSuccess
| RegistryUpdatesResponseSuccessNoUpdates;

export type RegistryValue = {
lastUpdated: bigint;
tokenDetails: TokenDetails[],
}
tokenDetails: TokenDetails[];
nervousSystemDetails: NervousSystemSummary[];
};

export type RegistryUpdatesResponseSuccess = {
kind: "success";
lastUpdated: bigint;
tokenDetails?: TokenDetails[];
}
tokenDetails: TokenDetails[];
nervousSystemDetails: NervousSystemSummary[];
};

export type RegistryUpdatesResponseSuccessNoUpdates = {
kind: "success_no_updates";
}
};

export type TokenDetails = {
ledgerCanisterId: string;
Expand All @@ -23,12 +27,20 @@ export type TokenDetails = {
fee: bigint;
logo: string;
nervousSystem?: {
root: string
governance: string
root: string;
governance: string;
};
infoUrl: string;
howToBuyUrl: string;
transactionUrlFormat: string;
added: bigint;
lastUpdated: bigint;
}
};

export type NervousSystemSummary = {
governanceCanisterId: string;
ledgerCanisterId: string;
isNns: boolean;
proposalRejectionFee: bigint;
submittingProposalsEnabled: boolean;
};

0 comments on commit 0a97250

Please sign in to comment.