Skip to content

Commit

Permalink
Merge pull request #356 from bob-collective/refactor/status
Browse files Browse the repository at this point in the history
refactor: better order status
  • Loading branch information
gregdhill authored Sep 19, 2024
2 parents 393056d + fb3d73b commit a60d60a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
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

0 comments on commit a60d60a

Please sign in to comment.