Skip to content

Commit

Permalink
Rename CandidService to CanisterAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Jan 31, 2025
1 parent caa3e3f commit 5c4e52a
Show file tree
Hide file tree
Showing 31 changed files with 68 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Packer = new Packr({
largeBigIntToString: true,
} as unknown as Options);

export abstract class CandidService {
export abstract class CanisterAgent {
protected createServiceClient<T>(factory: IDL.InterfaceFactory): T {
return Actor.createActor<T>(factory, {
agent: this.agent,
Expand All @@ -55,7 +55,7 @@ export abstract class CandidService {
requestValidator: In,
responseValidator: Resp,
): Promise<Out> {
const payload = CandidService.prepareMsgpackArgs(args, requestValidator);
const payload = CanisterAgent.prepareMsgpackArgs(args, requestValidator);

return await this.handleQueryResponse(
() =>
Expand All @@ -66,7 +66,7 @@ export abstract class CandidService {
(resp) => {
if (resp.status === "replied") {
return Promise.resolve(
CandidService.processMsgpackResponse(
CanisterAgent.processMsgpackResponse(
resp.reply.arg,
mapper,
responseValidator,
Expand All @@ -92,7 +92,7 @@ export abstract class CandidService {
responseValidator: Resp,
onRequestAccepted?: () => void,
): Promise<Out> {
const payload = CandidService.prepareMsgpackArgs(args, requestValidator);
const payload = CanisterAgent.prepareMsgpackArgs(args, requestValidator);

try {
const { requestId, response } = await this.sendRequestToCanister(() =>
Expand Down Expand Up @@ -122,7 +122,7 @@ export abstract class CandidService {
const reply = lookupResultToBuffer(certificate.lookup([...path, "reply"]));
if (reply) {
return Promise.resolve(
CandidService.processMsgpackResponse(
CanisterAgent.processMsgpackResponse(
reply,
mapper,
responseValidator,
Expand Down Expand Up @@ -154,7 +154,7 @@ export abstract class CandidService {
),
);
return Promise.resolve(
CandidService.processMsgpackResponse(reply, mapper, responseValidator),
CanisterAgent.processMsgpackResponse(reply, mapper, responseValidator),
);
} else {
throw new UpdateCallRejectedError(
Expand Down Expand Up @@ -254,7 +254,7 @@ export abstract class CandidService {
value: Static<T>,
validator: T,
): ArrayBuffer {
const validated = CandidService.validate(value, validator);
const validated = CanisterAgent.validate(value, validator);
return Packer.pack(validated);
}

Expand All @@ -265,7 +265,7 @@ export abstract class CandidService {
): Out {
const response = Packer.unpack(new Uint8Array(responseBytes));
try {
const validated = CandidService.validate(response, validator);
const validated = CanisterAgent.validate(response, validator);
return mapper(validated);
} catch (err) {
console.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import type { HttpAgent, Identity } from "@dfinity/agent";
import { Principal } from "@dfinity/principal";
import type { UpdateBtcBalanceResponse } from "openchat-shared";
import { idlFactory, type CkbtcMinterService } from "./candid/idl";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import { updateBtcBalanceResponse } from "./mappers";
import { apiOptional } from "../common/chatMappers";

const CKBTC_MINTER_CANISTER_ID = "mqygn-kiaaa-aaaar-qaadq-cai";

export class CkbtcMinterClient extends CandidService {
export class CkbtcMinterClient extends CanisterAgent {
private service: CkbtcMinterService;

constructor(identity: Identity, agent: HttpAgent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { HttpAgent, Identity } from "@dfinity/agent";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import {
apiOptionUpdateV2,
identity,
Expand Down Expand Up @@ -299,7 +299,7 @@ import {
CommunityGenerateBotApiKeyResponse,
} from "../../typebox";

export class CommunityClient extends CandidService {
export class CommunityClient extends CanisterAgent {
constructor(
identity: Identity,
agent: HttpAgent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import { idlFactory, type IcpSwapIndexService } from "./candid/idl";
import { CandidService } from "../../../candidService";
import { CanisterAgent } from "../../../canisterAgent";
import type { TokenSwapPool } from "openchat-shared";
import { getPoolsResponse } from "./mappers";
import type { SwapIndexClient, SwapPoolClient } from "../../index";
import { IcpSwapPoolClient } from "../pool/icpSwap.pool.client";

const ICPSWAP_INDEX_CANISTER_ID = "4mmnk-kiaaa-aaaag-qbllq-cai";

export class IcpSwapIndexClient extends CandidService implements SwapIndexClient {
export class IcpSwapIndexClient extends CanisterAgent implements SwapIndexClient {
private service: IcpSwapIndexService;

constructor(identity: Identity, agent: HttpAgent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import { idlFactory, type IcpSwapPoolService } from "./candid/idl";
import { CandidService } from "../../../candidService";
import { CanisterAgent } from "../../../canisterAgent";
import { quoteResponse } from "./mappers";
import type { SwapPoolClient } from "../../index";

export class IcpSwapPoolClient extends CandidService implements SwapPoolClient {
export class IcpSwapPoolClient extends CanisterAgent implements SwapPoolClient {
private service: IcpSwapPoolService;

constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import { idlFactory, type KongSwapService } from "./candid/idl";
import { CandidService } from "../../candidService";
import { CanisterAgent } from "../../canisterAgent";
import type { TokenSwapPool } from "openchat-shared";
import { swapAmountsResponse, tokensResponse } from "./mappers";
import type { SwapIndexClient, SwapPoolClient } from "../index";
import type { CryptocurrencyDetails } from "openchat-shared/lib/domain/crypto";

const KONG_SWAP_CANISTER_ID = "2ipq2-uqaaa-aaaar-qailq-cai";

export class KongSwapClient extends CandidService implements SwapIndexClient, SwapPoolClient {
export class KongSwapClient extends CanisterAgent implements SwapIndexClient, SwapPoolClient {
private service: KongSwapService;
private icrc2Tokens: Set<string>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import { idlFactory, type SonicSwapsService } from "./candid/idl";
import { CandidService } from "../../../candidService";
import { CanisterAgent } from "../../../canisterAgent";
import type { TokenSwapPool } from "openchat-shared";
import { getAllPairsResponse, getPairResponse } from "./mappers";
import { Principal } from "@dfinity/principal";
import type { SwapIndexClient, SwapPoolClient } from "../..";

const SONIC_INDEX_CANISTER_ID = "3xwpq-ziaaa-aaaah-qcn4a-cai";

export class SonicSwapsClient extends CandidService implements SwapIndexClient, SwapPoolClient {
export class SonicSwapsClient extends CanisterAgent implements SwapIndexClient, SwapPoolClient {
private service: SonicSwapsService;

constructor(identity: Identity, agent: HttpAgent) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/openchat-agent/src/services/group/group.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import {
MAX_MESSAGES,
MAX_MISSING,
} from "openchat-shared";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import {
apiRole,
getEventsResponse,
Expand Down Expand Up @@ -235,7 +235,7 @@ import {
GroupGenerateBotApiKeyResponse,
} from "../../typebox";

export class GroupClient extends CandidService {
export class GroupClient extends CanisterAgent {
constructor(
identity: Identity,
agent: HttpAgent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
FreezeCommunityResponse,
UnfreezeCommunityResponse,
} from "openchat-shared";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import {
addHotGroupExclusionResponse,
deleteFrozenGroupResponse,
Expand Down Expand Up @@ -70,7 +70,7 @@ import {
} from "../../typebox";
import { principalStringToBytes } from "../../utils/mapping";

export class GroupIndexClient extends CandidService {
export class GroupIndexClient extends CanisterAgent {
constructor(identity: Identity, agent: HttpAgent, canisterId: string) {
super(identity, agent, canisterId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import { idlFactory, type IcpLedgerIndexService } from "./candid/idl";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import { Principal } from "@dfinity/principal";
import { accountTransactions } from "./mappers";
import type { AccountTransactionResult } from "openchat-shared";
import { apiOptional } from "../common/chatMappers";
import { identity } from "../../utils/mapping";

export class IcpLedgerIndexClient extends CandidService {
export class IcpLedgerIndexClient extends CanisterAgent {
private service: IcpLedgerIndexService;

constructor(identity: Identity, agent: HttpAgent, canisterId: string) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/openchat-agent/src/services/icpSwap/icpSwapClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import type { CryptocurrencyDetails, TokenExchangeRates } from "openchat-shared";
import { idlFactory, type ICPSwapService } from "./candid/idl";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import { getAllTokensResponse } from "./mappers";
import type { ExchangeRateClient } from "../openchatAgent";

const ICPSWAP_CANISTER_ID = "ggzvv-5qaaa-aaaag-qck7a-cai";

export class IcpSwapClient extends CandidService implements ExchangeRateClient {
export class IcpSwapClient extends CanisterAgent implements ExchangeRateClient {
private service: ICPSwapService;

constructor(identity: Identity, agent: HttpAgent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import type { CryptocurrencyDetails, TokenExchangeRates } from "openchat-shared";
import { idlFactory, type ICPCoinsService } from "./candid/idl";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import { getLatestResponse } from "./mappers";
import type { ExchangeRateClient } from "../openchatAgent";

const ICPCOINS_CANISTER_ID = "u45jl-liaaa-aaaam-abppa-cai";

export class IcpCoinsClient extends CandidService implements ExchangeRateClient {
export class IcpCoinsClient extends CanisterAgent implements ExchangeRateClient {
private service: ICPCoinsService;

constructor(identity: Identity, agent: HttpAgent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { HttpAgent, Identity, SignIdentity } from "@dfinity/agent";
import { idlFactory, type IdentityService } from "./candid/idl";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import type {
ApproveIdentityLinkResponse,
AuthenticationPrincipalsResponse,
Expand Down Expand Up @@ -31,7 +31,7 @@ import { Principal } from "@dfinity/principal";
import type { DelegationIdentity } from "@dfinity/identity";
import { signedDelegation } from "../../utils/id";

export class IdentityClient extends CandidService {
export class IdentityClient extends CanisterAgent {
private service: IdentityService;

constructor(identity: Identity, agent: HttpAgent, identityCanister: string) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/openchat-agent/src/services/ledger/ledger.client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import { idlFactory, type LedgerService } from "./candid/idl";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import { Principal } from "@dfinity/principal";

export class LedgerClient extends CandidService {
export class LedgerClient extends CanisterAgent {
private service: LedgerService;

constructor(identity: Identity, agent: HttpAgent, canisterId: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import { idlFactory, type LedgerIndexService } from "./candid/idl";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import { Principal } from "@dfinity/principal";
import { accountTransactions } from "./mappers";
import type { AccountTransactionResult } from "openchat-shared";
import { apiOptional } from "../common/chatMappers";
import { identity } from "../../utils/mapping";

export class LedgerIndexClient extends CandidService {
export class LedgerIndexClient extends CanisterAgent {
private service: LedgerIndexService;

constructor(identity: Identity, agent: HttpAgent, canisterId: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
ExternalBotPermissions,
VerifiedCredentialArgs,
} from "openchat-shared";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import {
accessTokenResponse,
apiAccessTokenType,
Expand Down Expand Up @@ -83,7 +83,7 @@ import {
LocalUserIndexWithdrawFromIcpswapResponse,
} from "../../typebox";

export class LocalUserIndexClient extends CandidService {
export class LocalUserIndexClient extends CanisterAgent {
constructor(
identity: Identity,
agent: HttpAgent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import type { UpdateMarketMakerConfigArgs, UpdateMarketMakerConfigResponse } from "openchat-shared";
import { idlFactory, type MarketMakerService } from "./candid/idl";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import { updateConfigResponse } from "./mappers";
import { apiOptional } from "../common/chatMappers";
import { identity } from "../../utils/mapping";

export class MarketMakerClient extends CandidService {
export class MarketMakerClient extends CanisterAgent {
private service: MarketMakerService;

constructor(identity: Identity, agent: HttpAgent, canisterId: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import type { ManageNeuronResponse, ProposalVoteDetails } from "openchat-shared";
import { idlFactory, type NnsGovernanceService } from "./candid/idl";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import { getProposalVoteDetails, manageNeuronResponse } from "./mappers";
import { apiOptional, apiProposalVote } from "../common/chatMappers";
import { identity } from "../../utils/mapping";

export class NnsGovernanceClient extends CandidService {
export class NnsGovernanceClient extends CanisterAgent {
private service: NnsGovernanceService;

constructor(identity: Identity, agent: HttpAgent, canisterId: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { HttpAgent, Identity } from "@dfinity/agent";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import { subscriptionExistsResponse } from "./mappers";
import { toVoid } from "../../utils/mapping";
import {
Expand All @@ -12,7 +12,7 @@ import {
NotificationsIndexSubscriptionExistsResponse,
} from "../../typebox";

export class NotificationsClient extends CandidService {
export class NotificationsClient extends CanisterAgent {
constructor(identity: Identity, agent: HttpAgent, canisterId: string) {
super(identity, agent, canisterId);
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/openchat-agent/src/services/online/online.client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import { principalStringToBytes, toVoid } from "../../utils/mapping";
import { lastOnlineResponse } from "./mappers";
import {
Expand All @@ -9,7 +9,7 @@ import {
OnlineUsersMarkAsOnlineResponse,
} from "../../typebox";

export class OnlineClient extends CandidService {
export class OnlineClient extends CanisterAgent {
constructor(identity: Identity, agent: HttpAgent, canisterId: string) {
super(identity, agent, canisterId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HttpAgent, Identity } from "@dfinity/agent";
import { CandidService } from "../candidService";
import { CanisterAgent } from "../canisterAgent";
import {
type CandidateProposal,
nowNanos,
Expand All @@ -24,7 +24,7 @@ import {
} from "../../typebox";
import { apiToken, principalToIcrcAccount } from "../common/chatMappersV2";

export class ProposalsBotClient extends CandidService {
export class ProposalsBotClient extends CanisterAgent {
constructor(identity: Identity, agent: HttpAgent, canisterId: string) {
super(identity, agent, canisterId);
}
Expand Down
Loading

0 comments on commit 5c4e52a

Please sign in to comment.