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

refactor: better order status #356

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gobob/bob-sdk",
"version": "2.3.3",
"version": "2.3.4",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
Expand Down
22 changes: 10 additions & 12 deletions sdk/src/gateway/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
EvmAddress,
GatewayTokensInfo,
OrderStatus,
OrderStatusType,
} from "./types";
import { SYMBOL_LOOKUP, ADDRESS_LOOKUP } from "./tokens";
import { createBitcoinPsbt } from "../wallet";
Expand Down Expand Up @@ -299,17 +298,16 @@ export class GatewayApiClient {
async getStatus(esploraClient: EsploraClient, latestHeight?: number): Promise<OrderStatus> {
const confirmations = await getConfirmations(esploraClient, latestHeight);
const hasEnoughConfirmations = confirmations >= order.txProofDifficultyFactor;
const data = {
confirmations,
confirmed: hasEnoughConfirmations
};
return order.status
? order.strategyAddress
? order.outputTokenAddress
? { status: OrderStatusType.Success, data }
: { status: OrderStatusType.Failed, data }
: { status: OrderStatusType.Success, data }
: { status: OrderStatusType.Pending, data };
const data = { confirmations };
return !hasEnoughConfirmations
? { confirmed: false, data }
: order.status
? order.strategyAddress
? order.outputTokenAddress
? { success: true, data }
: { success: false, data }
: { success: true, data }
: { pending: true, data };
},
};
});
Expand Down
1 change: 0 additions & 1 deletion sdk/src/gateway/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ export {
GatewayQuote,
GatewayOrder,
GatewayStrategyContract,
OrderStatusType,
OrderStatus,
} from "./types";
56 changes: 31 additions & 25 deletions sdk/src/gateway/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,6 @@ export type GatewayCreateOrderRequest = {
satoshis: number;
};

export type OrderStatusData = {
confirmations: number;
confirmed: boolean;
};

export enum OrderStatusType {
Success = "Success",
Failed = "Failed",
Pending = "Pending",
}

export type OrderStatus =
| { status: OrderStatusType.Success; data: OrderStatusData }
| { status: OrderStatusType.Failed; data: OrderStatusData }
| { status: OrderStatusType.Pending; data: OrderStatusData };

export interface GatewayOrderResponse {
/** @description The gateway address */
gatewayAddress: EvmAddress;
Expand Down Expand Up @@ -236,6 +220,37 @@ export interface GatewayOrderResponse {
outputTokenAmount?: string;
/** @description The tx hash on the EVM chain */
txHash?: string;
};

export type OrderStatusData = {
confirmations: number;
};

export type OrderStatus = {
confirmed: false;
pending?: never;
success?: never;
data: OrderStatusData;
} | {
confirmed?: never;
pending: true;
success?: never;
data: OrderStatusData;
} | {
confirmed?: never;
pending?: never;
success: boolean;
data: OrderStatusData;
};;

/** Order given by the Gateway API once the bitcoin tx is submitted */
export type GatewayOrder = Omit<
GatewayOrderResponse & {
/** @description The gas refill in satoshis */
gasRefill: number;
},
"satsToConvertToEth"
> & {
/** @description Get the actual token address received */
getTokenAddress(): string | undefined;
/** @description Get the actual token received */
Expand All @@ -248,15 +263,6 @@ export interface GatewayOrderResponse {
getStatus(esploraClient: EsploraClient, latestHeight?: number): Promise<OrderStatus>;
};

/** Order given by the Gateway API once the bitcoin tx is submitted */
export type GatewayOrder = Omit<
GatewayOrderResponse & {
/** @description The gas refill in satoshis */
gasRefill: number;
},
"satsToConvertToEth"
>;

export type GatewayTokensInfo = {
/** @description The base token (e.g. wBTC or tBTC) */
baseToken: Token,
Expand Down
Loading