Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@turnkey/http: add withAsyncPolling(...) helper #23

Merged
merged 8 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move TurnkeyActivityError to @turnkey/http
  • Loading branch information
keyz-tk committed Apr 11, 2023
commit 18ba3556d0fd564e4d12214d2b7e8972d416b816
37 changes: 7 additions & 30 deletions packages/ethers/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
import { ethers, type UnsignedTransaction, type Bytes } from "ethers";
import { PublicApiService, init as httpInit } from "@turnkey/http";

type TActivity = PublicApiService.TPostGetActivityResponse["activity"];
type TActivityId = TActivity["id"];
type TActivityStatus = TActivity["status"];
type TActivityType = TActivity["type"];

export class TurnkeyActivityError extends Error {
activityId: TActivityId | null;
activityStatus: TActivityStatus | null;
activityType: TActivityType | null;
cause: Error | null;

constructor(input: {
message: string;
cause?: Error | null;
activityId?: TActivityId | null;
activityStatus?: TActivityStatus | null;
activityType?: TActivityType | null;
}) {
const { message, cause, activityId, activityStatus, activityType } = input;
super(message);

this.name = "TurnkeyActivityError";
this.activityId = activityId ?? null;
this.activityStatus = activityStatus ?? null;
this.activityType = activityType ?? null;
this.cause = cause ?? null;
}
}
import {
PublicApiService,
TurnkeyActivityError,
init as httpInit,
} from "@turnkey/http";

type TConfig = {
apiPublicKey: string;
Expand Down Expand Up @@ -226,6 +201,8 @@ export class TurnkeySigner extends ethers.Signer {
}
}

export { TurnkeyActivityError };

function assertNonNull<T>(input: T | null | undefined): T {
if (input == null) {
throw new Error(`Got unexpected ${JSON.stringify(input)}`);
Expand Down
7 changes: 1 addition & 6 deletions packages/http/src/async.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { PublicApiService } from "./__generated__/barrel";
import type { definitions } from "./__generated__/services/coordinator/public/v1/public_api.types";
import type { TActivity, TActivityResponse } from "./shared";

const DEFAULT_REFRESH_INTERVAL_MS = 500;

type TActivity = definitions["v1Activity"];
type TActivityResponse = definitions["v1ActivityResponse"];
// type TActivityType = definitions["v1ActivityType"];
// type TActivityId = TActivity["id"];

/**
* TODO: document this helper
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export * from "./__generated__/barrel";

export { init } from "./config";

export { TurnkeyActivityError } from "./shared";

export { withAsyncPolling } from "./async";
31 changes: 31 additions & 0 deletions packages/http/src/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { definitions } from "./__generated__/services/coordinator/public/v1/public_api.types";

export type TActivity = definitions["v1Activity"];
export type TActivityResponse = definitions["v1ActivityResponse"];
export type TActivityId = TActivity["id"];
export type TActivityStatus = TActivity["status"];
export type TActivityType = TActivity["type"];

export class TurnkeyActivityError extends Error {
activityId: TActivityId | null;
activityStatus: TActivityStatus | null;
activityType: TActivityType | null;
cause: Error | null;

constructor(input: {
message: string;
cause?: Error | null;
activityId?: TActivityId | null;
activityStatus?: TActivityStatus | null;
activityType?: TActivityType | null;
}) {
const { message, cause, activityId, activityStatus, activityType } = input;
super(message);

this.name = "TurnkeyActivityError";
this.activityId = activityId ?? null;
this.activityStatus = activityStatus ?? null;
this.activityType = activityType ?? null;
this.cause = cause ?? null;
}
}