Skip to content

Commit 197d85b

Browse files
update status endpoint
1 parent 6d8d185 commit 197d85b

File tree

5 files changed

+92
-32
lines changed

5 files changed

+92
-32
lines changed

packages/thirdweb/src/bridge/Status.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export async function status(options: status.Options): Promise<status.Result> {
124124
if (data.status === "FAILED") {
125125
return {
126126
status: "FAILED",
127+
paymentId: data.paymentId,
127128
transactions: data.transactions,
128129
};
129130
}
@@ -137,12 +138,19 @@ export async function status(options: status.Options): Promise<status.Result> {
137138
originTokenAddress: data.originTokenAddress,
138139
destinationTokenAddress: data.destinationTokenAddress,
139140
transactions: data.transactions,
141+
originToken: data.originToken,
142+
destinationToken: data.destinationToken,
143+
sender: data.sender,
144+
receiver: data.receiver,
145+
paymentId: data.paymentId,
146+
purchaseData: data.purchaseData,
140147
};
141148
}
142149

143150
if (data.status === "NOT_FOUND") {
144151
return {
145152
status: "NOT_FOUND",
153+
paymentId: data.paymentId,
146154
transactions: [],
147155
};
148156
}
@@ -156,6 +164,11 @@ export async function status(options: status.Options): Promise<status.Result> {
156164
originTokenAddress: data.originTokenAddress,
157165
destinationTokenAddress: data.destinationTokenAddress,
158166
transactions: data.transactions,
167+
originToken: data.originToken,
168+
destinationToken: data.destinationToken,
169+
sender: data.sender,
170+
receiver: data.receiver,
171+
paymentId: data.paymentId,
159172
purchaseData: data.purchaseData,
160173
};
161174
}
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
import type { Address as ox__Address } from "ox";
1+
import type { Token } from "./Token.js";
22

33
export type Route = {
4-
originToken: {
5-
chainId: number;
6-
address: ox__Address.Address;
7-
decimals: number;
8-
symbol: string;
9-
name: string;
10-
iconUri?: string;
11-
};
12-
destinationToken: {
13-
chainId: number;
14-
address: string;
15-
decimals: number;
16-
symbol: string;
17-
name: string;
18-
iconUri?: string;
19-
};
4+
originToken: Token;
5+
destinationToken: Token;
206
};
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import type { Address as ox__Address, Hex as ox__Hex } from "ox";
2-
2+
import type { Token } from "./Token.js";
33
export type Status =
44
| {
55
status: "COMPLETED";
6+
paymentId: string;
67
originAmount: bigint;
78
destinationAmount: bigint;
89
originChainId: number;
910
destinationChainId: number;
1011
originTokenAddress: ox__Address.Address;
1112
destinationTokenAddress: ox__Address.Address;
13+
originToken: Token;
14+
destinationToken: Token;
15+
sender: ox__Address.Address;
16+
receiver: ox__Address.Address;
1217
transactions: Array<{
1318
chainId: number;
1419
transactionHash: ox__Hex.Hex;
@@ -17,24 +22,33 @@ export type Status =
1722
}
1823
| {
1924
status: "PENDING";
25+
paymentId: string;
2026
originAmount: bigint;
2127
originChainId: number;
2228
destinationChainId: number;
2329
originTokenAddress: ox__Address.Address;
2430
destinationTokenAddress: ox__Address.Address;
31+
originToken: Token;
32+
destinationToken: Token;
33+
sender: ox__Address.Address;
34+
receiver: ox__Address.Address;
2535
transactions: Array<{
2636
chainId: number;
2737
transactionHash: ox__Hex.Hex;
2838
}>;
39+
purchaseData?: unknown;
2940
}
3041
| {
3142
status: "FAILED";
43+
paymentId: string;
3244
transactions: Array<{
3345
chainId: number;
3446
transactionHash: ox__Hex.Hex;
3547
}>;
48+
purchaseData?: unknown;
3649
}
3750
| {
3851
status: "NOT_FOUND";
52+
paymentId: string;
3953
transactions: [];
4054
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Address as ox__Address } from "ox";
2+
3+
export type Token = {
4+
chainId: number;
5+
address: ox__Address.Address;
6+
decimals: number;
7+
symbol: string;
8+
name: string;
9+
iconUri?: string;
10+
};

packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { type Status, status as bridgeStatus } from "../../bridge/index.js";
2+
import type { Token } from "../../bridge/types/Token.js";
23
import type { ThirdwebClient } from "../../client/client.js";
34
import type { Hex } from "../../utils/encoding/hex.js";
5+
import { toTokens } from "../../utils/units.js";
46
import type {
57
PayOnChainTransactionDetails,
68
PayTokenInfo,
@@ -158,6 +160,11 @@ export async function getBuyWithCryptoStatus(
158160
originChainId: result.originChainId,
159161
destinationChainId: result.destinationChainId,
160162
status: result.status,
163+
sender: result.sender,
164+
receiver: result.receiver,
165+
paymentId: result.paymentId,
166+
originToken: result.originToken,
167+
destinationToken: result.destinationToken,
161168
purchaseData: result.purchaseData as object | undefined,
162169
});
163170
}
@@ -169,6 +176,12 @@ export async function getBuyWithCryptoStatus(
169176
originChainId: result.originChainId,
170177
destinationChainId: result.destinationChainId,
171178
status: result.status,
179+
sender: result.sender,
180+
receiver: result.receiver,
181+
paymentId: result.paymentId,
182+
originToken: result.originToken,
183+
destinationToken: result.destinationToken,
184+
purchaseData: result.purchaseData as object | undefined,
172185
});
173186
}
174187
case "FAILED": {
@@ -182,12 +195,17 @@ export async function getBuyWithCryptoStatus(
182195
originTransaction,
183196
destinationTransaction,
184197
originAmount: BigInt(0), // TODO: get from API
185-
destinationAmount: BigInt(0), // TODO: get from API
186198
originTokenAddress: "", // TODO: get from API
187199
destinationTokenAddress: "", // TODO: get from API
188200
originChainId: 0, // TODO: get from API
189201
destinationChainId: 0, // TODO: get from API
190202
status: result.status,
203+
sender: "",
204+
receiver: "",
205+
paymentId: "",
206+
originToken: undefined,
207+
destinationToken: undefined,
208+
purchaseData: result.purchaseData as object | undefined,
191209
});
192210
}
193211
default: {
@@ -213,6 +231,11 @@ function toBuyWithCryptoStatus(args: {
213231
destinationChainId: number;
214232
status: Status["status"];
215233
purchaseData?: object;
234+
sender: string;
235+
receiver: string;
236+
paymentId: string;
237+
originToken?: Token;
238+
destinationToken?: Token;
216239
}): BuyWithCryptoStatus {
217240
const {
218241
originTransaction,
@@ -225,10 +248,14 @@ function toBuyWithCryptoStatus(args: {
225248
destinationTokenAddress,
226249
originChainId,
227250
destinationChainId,
251+
sender,
252+
receiver,
253+
originToken,
254+
destinationToken,
228255
} = args;
229256
return {
230-
fromAddress: "", // TODO: get from API
231-
toAddress: "",
257+
fromAddress: sender,
258+
toAddress: receiver,
232259
quote: {
233260
createdAt: new Date().toISOString(),
234261
estimated: {
@@ -240,26 +267,36 @@ function toBuyWithCryptoStatus(args: {
240267
gasCostUSDCents: 0,
241268
durationSeconds: 0,
242269
},
243-
fromAmount: originAmount.toString(), // TODO: get from API
270+
fromAmount: originToken
271+
? toTokens(originAmount, originToken.decimals).toString()
272+
: "",
244273
fromAmountWei: originAmount.toString(),
245-
toAmount: destinationAmount?.toString() ?? "", // TODO: get from API
246-
toAmountWei: destinationAmount?.toString() ?? "",
247-
toAmountMin: destinationAmount?.toString() ?? "", // TODO: get from API
248-
toAmountMinWei: destinationAmount?.toString() ?? "",
274+
toAmount:
275+
destinationToken && destinationAmount
276+
? toTokens(destinationAmount, destinationToken.decimals).toString()
277+
: "", // TODO: get from API
278+
toAmountWei: destinationAmount ? destinationAmount.toString() : "",
279+
toAmountMin: destinationToken
280+
? toTokens(
281+
destinationAmount ?? BigInt(0),
282+
destinationToken.decimals,
283+
).toString()
284+
: "", // TODO: get from API
285+
toAmountMinWei: destinationAmount ? destinationAmount.toString() : "",
249286
fromToken: {
250287
tokenAddress: originTokenAddress,
251288
chainId: originChainId,
252-
decimals: 18,
253-
name: "",
254-
symbol: "",
289+
decimals: originToken?.decimals ?? 18,
290+
name: originToken?.name ?? "",
291+
symbol: originToken?.symbol ?? "",
255292
priceUSDCents: 0,
256293
},
257294
toToken: {
258295
tokenAddress: destinationTokenAddress,
259296
chainId: destinationChainId,
260-
decimals: 18,
261-
name: "",
262-
symbol: "",
297+
decimals: destinationToken?.decimals ?? 18,
298+
name: destinationToken?.name ?? "",
299+
symbol: destinationToken?.symbol ?? "",
263300
priceUSDCents: 0,
264301
},
265302
},

0 commit comments

Comments
 (0)