@@ -6,12 +6,18 @@ import type { ThirdwebClient } from "../../../../../../../client/client.js";
66import { NATIVE_TOKEN_ADDRESS } from "../../../../../../../constants/addresses.js" ;
77import { getContract } from "../../../../../../../contract/contract.js" ;
88import { allowance } from "../../../../../../../extensions/erc20/__generated__/IERC20/read/allowance.js" ;
9+ import {
10+ type GetCurrencyMetadataResult ,
11+ getCurrencyMetadata ,
12+ } from "../../../../../../../extensions/erc20/read/getCurrencyMetadata.js" ;
913import { approve } from "../../../../../../../extensions/erc20/write/approve.js" ;
1014import { transfer } from "../../../../../../../extensions/erc20/write/transfer.js" ;
15+ import type { BuyWithCryptoStatus } from "../../../../../../../pay/buyWithCrypto/getStatus.js" ;
1116import { getBuyWithCryptoTransfer } from "../../../../../../../pay/buyWithCrypto/getTransfer.js" ;
1217import { sendAndConfirmTransaction } from "../../../../../../../transaction/actions/send-and-confirm-transaction.js" ;
1318import { sendTransaction } from "../../../../../../../transaction/actions/send-transaction.js" ;
1419import { prepareTransaction } from "../../../../../../../transaction/prepare-transaction.js" ;
20+ import type { TransactionReceipt } from "../../../../../../../transaction/types.js" ;
1521import type { Address } from "../../../../../../../utils/address.js" ;
1622import { toWei } from "../../../../../../../utils/units.js" ;
1723import { iconSize } from "../../../../../../core/design-system/index.js" ;
@@ -42,6 +48,7 @@ type TransferConfirmationScreenProps = {
4248 tokenAmount : string ;
4349 transactionMode ?: boolean ;
4450 payOptions ?: PayUIOptions ;
51+ onSuccess : ( ( status : BuyWithCryptoStatus ) => void ) | undefined ;
4552} ;
4653
4754export function TransferConfirmationScreen (
@@ -202,10 +209,33 @@ export function TransferConfirmationScreen(
202209 to : receiverAddress ,
203210 amount : tokenAmount ,
204211 } ) ;
205- await sendAndConfirmTransaction ( {
206- account : props . payer . account ,
207- transaction,
208- } ) ;
212+ const [ txResult , tokenMetadata ] = await Promise . all ( [
213+ sendAndConfirmTransaction ( {
214+ account : props . payer . account ,
215+ transaction,
216+ } ) ,
217+ getCurrencyMetadata ( {
218+ contract : getContract ( {
219+ address : isNativeToken ( token )
220+ ? NATIVE_TOKEN_ADDRESS
221+ : token . address ,
222+ chain : chain ,
223+ client : client ,
224+ } ) ,
225+ } ) ,
226+ ] ) ;
227+ // its the last step before the transaction, so propagate onPurchaseSuccess here
228+ props . onSuccess ?.(
229+ transferBuyWithCryptoQuote ( {
230+ token,
231+ chain,
232+ tokenMetadata,
233+ tokenAmount,
234+ fromAddress : payer . account . address ,
235+ toAddress : receiverAddress ,
236+ transaction : txResult ,
237+ } ) ,
238+ ) ;
209239 // switch to execute step
210240 setStep ( "execute" ) ;
211241 setStatus ( { id : "idle" } ) ;
@@ -299,3 +329,85 @@ export function TransferConfirmationScreen(
299329 </ Container >
300330 ) ;
301331}
332+
333+ function transferBuyWithCryptoQuote ( args : {
334+ token : ERC20OrNativeToken ;
335+ chain : Chain ;
336+ tokenMetadata : GetCurrencyMetadataResult ;
337+ tokenAmount : string ;
338+ fromAddress : string ;
339+ toAddress : string ;
340+ transaction : TransactionReceipt ;
341+ } ) : BuyWithCryptoStatus {
342+ const {
343+ token,
344+ chain,
345+ tokenMetadata,
346+ tokenAmount,
347+ fromAddress,
348+ toAddress,
349+ transaction,
350+ } = args ;
351+ return {
352+ status : "COMPLETED" ,
353+ subStatus : "SUCCESS" ,
354+ swapType : "TRANSFER" ,
355+ quote : {
356+ createdAt : new Date ( ) . toISOString ( ) ,
357+ fromToken : {
358+ chainId : chain . id ,
359+ tokenAddress : isNativeToken ( token )
360+ ? NATIVE_TOKEN_ADDRESS
361+ : token . address ,
362+ decimals : tokenMetadata . decimals ,
363+ symbol : tokenMetadata . symbol ,
364+ name : tokenMetadata . name ,
365+ priceUSDCents : 0 ,
366+ } ,
367+ toToken : {
368+ chainId : chain . id ,
369+ tokenAddress : isNativeToken ( token )
370+ ? NATIVE_TOKEN_ADDRESS
371+ : token . address ,
372+ decimals : tokenMetadata . decimals ,
373+ symbol : tokenMetadata . symbol ,
374+ name : tokenMetadata . name ,
375+ priceUSDCents : 0 ,
376+ } ,
377+ fromAmountWei : toWei ( tokenAmount ) . toString ( ) ,
378+ fromAmount : tokenAmount ,
379+ toAmountWei : toWei ( tokenAmount ) . toString ( ) ,
380+ toAmount : tokenAmount ,
381+ toAmountMin : tokenAmount ,
382+ toAmountMinWei : toWei ( tokenAmount ) . toString ( ) ,
383+ estimated : {
384+ feesUSDCents : 0 ,
385+ gasCostUSDCents : 0 ,
386+ slippageBPS : 0 ,
387+ toAmountMinUSDCents : 0 ,
388+ toAmountUSDCents : 0 ,
389+ fromAmountUSDCents : 0 ,
390+ durationSeconds : 0 ,
391+ } ,
392+ } ,
393+ fromAddress,
394+ toAddress,
395+ source : {
396+ transactionHash : transaction . transactionHash ,
397+ amount : tokenAmount ,
398+ amountWei : toWei ( tokenAmount ) . toString ( ) ,
399+ amountUSDCents : 0 ,
400+ completedAt : new Date ( ) . toISOString ( ) ,
401+ token : {
402+ chainId : chain . id ,
403+ tokenAddress : isNativeToken ( token )
404+ ? NATIVE_TOKEN_ADDRESS
405+ : token . address ,
406+ decimals : tokenMetadata . decimals ,
407+ symbol : tokenMetadata . symbol ,
408+ name : tokenMetadata . name ,
409+ priceUSDCents : 0 ,
410+ } ,
411+ } ,
412+ } ;
413+ }
0 commit comments