Skip to content

Commit a7c82d4

Browse files
committed
feat: enable using chain object with status
1 parent 8a12f32 commit a7c82d4

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

packages/thirdweb/src/bridge/Status.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, it } from "vitest";
22
import { TEST_CLIENT } from "~test/test-clients.js";
33
import { status } from "./Status.js";
4+
import { defineChain } from "../chains/utils.js";
45

56
describe.runIf(process.env.TW_SECRET_KEY)("Bridge.status", () => {
67
it("should handle successful status", async () => {
@@ -35,4 +36,16 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.status", () => {
3536
}
3637
`);
3738
});
39+
40+
it("should handle successfull status with chain", async () => {
41+
const result = await status({
42+
transactionHash:
43+
"0xe199ef82a0b6215221536e18ec512813c1aa10b4f5ed0d4dfdfcd703578da56d",
44+
chain: defineChain(8453),
45+
client: TEST_CLIENT,
46+
});
47+
48+
expect(result).toBeDefined();
49+
expect(result.status).toBe("COMPLETED");
50+
});
3851
});

packages/thirdweb/src/bridge/Status.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ThirdwebClient } from "../client/client.js";
33
import { getClientFetch } from "../utils/fetch.js";
44
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
55
import type { Status } from "./types/Status.js";
6+
import type { Chain } from "../chains/types.js";
67

78
/**
89
* Retrieves a Universal Bridge quote for the provided sell intent. The quote will specify the expected `destinationAmount` that will be received in exchange for the specified `originAmount`, which is specified with the `sellAmountWei` option.
@@ -100,7 +101,8 @@ import type { Status } from "./types/Status.js";
100101
* @beta
101102
*/
102103
export async function status(options: status.Options): Promise<status.Result> {
103-
const { transactionHash, chainId, client } = options;
104+
const { transactionHash, client } = options;
105+
const chainId = "chainId" in options ? options.chainId : options.chain.id;
104106

105107
const clientFetch = getClientFetch(client);
106108
const url = new URL(`${UNIVERSAL_BRIDGE_URL}/status`);
@@ -153,11 +155,17 @@ export async function status(options: status.Options): Promise<status.Result> {
153155
}
154156

155157
export declare namespace status {
156-
type Options = {
157-
transactionHash: ox__Hex.Hex;
158-
chainId: number;
159-
client: ThirdwebClient;
160-
};
158+
type Options =
159+
| {
160+
transactionHash: ox__Hex.Hex;
161+
chainId: number;
162+
client: ThirdwebClient;
163+
}
164+
| {
165+
transactionHash: ox__Hex.Hex;
166+
chain: Chain;
167+
client: ThirdwebClient;
168+
};
161169

162170
type Result = Status;
163171
}

packages/thirdweb/src/bridge/types/Quote.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import type {
2-
Hex as ox__Hex,
3-
TransactionEnvelopeEip1559 as ox__TransactionEnvelopeEip1559,
4-
} from "ox";
1+
import type { Hex as ox__Hex } from "ox";
52
import type { Chain } from "../../chains/types.js";
63
import type { ThirdwebClient } from "../../client/client.js";
74

@@ -36,23 +33,20 @@ export type PreparedQuote = Quote & {
3633
/**
3734
* A series of [ox](https://oxlib.sh) EIP-1559 transactions that must be executed in sequential order to fulfill the complete route.
3835
*/
39-
transactions: Array<
40-
ox__TransactionEnvelopeEip1559.TransactionEnvelopeEip1559<
41-
false,
42-
bigint,
43-
number,
44-
"eip1559"
45-
> & {
46-
/**
47-
* The action this transaction performs. This can be "approval", "transfer", "buy", or "sell".
48-
*/
49-
action: "approval" | "transfer" | "buy" | "sell";
50-
/**
51-
* The transaction ID, used for tracking purposes.
52-
*/
53-
id: ox__Hex.Hex;
54-
client: ThirdwebClient;
55-
chain: Chain;
56-
}
57-
>;
36+
transactions: Array<{
37+
data: ox__Hex.Hex;
38+
to: ox__Hex.Hex;
39+
value?: bigint | undefined;
40+
chainId: number;
41+
/**
42+
* The action this transaction performs. This can be "approval", "transfer", "buy", or "sell".
43+
*/
44+
action: "approval" | "transfer" | "buy" | "sell";
45+
/**
46+
* The transaction ID, used for tracking purposes.
47+
*/
48+
id: ox__Hex.Hex;
49+
client: ThirdwebClient;
50+
chain: Chain;
51+
}>;
5852
};

0 commit comments

Comments
 (0)