11import { type Status , status as bridgeStatus } from "../../bridge/index.js" ;
2+ import type { Token } from "../../bridge/types/Token.js" ;
23import type { ThirdwebClient } from "../../client/client.js" ;
34import type { Hex } from "../../utils/encoding/hex.js" ;
5+ import { toTokens } from "../../utils/units.js" ;
46import 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