@@ -7,12 +7,10 @@ import { Form } from '@/components/ui/form';
77import { OperationsInputField } from '@/components/operations/operations-input-field' ;
88import { OperationsSubmitButton } from '@/components/operations/operations-submit-button' ;
99import BigNumber from 'bignumber.js' ;
10- import { ESDTType , useConfig , useTokenTransfer } from '@useelven/core' ;
11- import { transfersOperationsGasLimit } from '@/components/operations/constants' ;
10+ import { ESDTType , useTokenTransfer } from '@useelven/core' ;
1211import { OperationsTokenIdAmountInput } from '@/components/operations/operations-tokenid-amount-input' ;
13- import { ExternalToast , toast } from 'sonner' ;
14- import { useEffect , useRef } from 'react' ;
15- import { Spinner } from '@/components/ui/spinner' ;
12+ import { OperationInfoBox } from '@/components/operation-info-box' ;
13+ import { useTxStatus } from '@/hooks/use-tx-status' ;
1614
1715const formSchema = z . object ( {
1816 tokenId : z . string ( ) . min ( 1 , 'The field is required' ) ,
@@ -28,9 +26,6 @@ const formSchema = z.object({
2826export const Send = ( ) => {
2927 const { transfer, transaction, txResult, error, pending } =
3028 useTokenTransfer ( ) ;
31- const { explorerAddress } = useConfig ( ) ;
32-
33- const toastId = useRef < string | number > ( ) ;
3429
3530 const form = useForm < z . infer < typeof formSchema > > ( {
3631 resolver : zodResolver ( formSchema ) ,
@@ -41,77 +36,58 @@ export const Send = () => {
4136 } ,
4237 } ) ;
4338
44- // TODO: move to separate hook
45- // TODO: make custom contents for toasters or display more data about the transactions somewhere
46- // TODO: add information where to confirm signing process
47- useEffect ( ( ) => {
48- const pendingHash = transaction ?. getHash ( ) . toString ( ) ;
49- const successHash = txResult ?. hash ;
50- const toasterOptions : ExternalToast = {
51- id : toastId ?. current ,
52- position : 'top-right' ,
53- ...( explorerAddress
54- ? {
55- action : (
56- < a
57- className = "flex items-center justify-between gap-2 text-xs underline"
58- href = { `${ explorerAddress } /transactions/${ pendingHash || successHash } ` }
59- >
60- { pending && < Spinner size = { 20 } /> } { ' ' }
61- < span > Check in the Explorer!</ span >
62- </ a >
63- ) ,
64- }
65- : { } ) ,
66- } ;
67- if ( pending ) {
68- toastId . current = toast . info ( 'Transaction is pending' , toasterOptions ) ;
69- } else if ( successHash ) {
70- toast . success ( 'Transaction success' , toasterOptions ) ;
71- } else if ( error ) {
72- toast . error ( 'Transaction error' , toasterOptions ) ;
73- }
74- } , [ txResult ?. hash , transaction , error , explorerAddress , pending ] ) ;
39+ useTxStatus ( {
40+ successHash : txResult ?. hash ,
41+ pendingHash : transaction ?. getHash ( ) ?. toString ( ) ,
42+ error,
43+ pending,
44+ } ) ;
7545
7646 const onSubmit = async ( {
7747 tokenId,
7848 address,
7949 amount,
8050 } : z . infer < typeof formSchema > ) => {
8151 transfer ?.( {
82- type : ESDTType . FungibleESDT ,
83- tokenId : tokenId . trim ( ) ,
52+ tokens : [
53+ {
54+ type : ESDTType . FungibleESDT ,
55+ amount : amount . trim ( ) ,
56+ tokenId : tokenId . trim ( ) ,
57+ } ,
58+ ] ,
8459 receiver : address . trim ( ) ,
85- amount : amount . trim ( ) ,
86- gasLimit : transfersOperationsGasLimit ,
8760 } ) ;
8861
8962 form . reset ( ) ;
9063 } ;
9164
9265 return (
93- < Form { ...form } >
94- < form onSubmit = { form . handleSubmit ( onSubmit ) } className = "space-y-8" >
95- < div className = "flex-1 overflow-auto p-1" >
96- < OperationsTokenIdAmountInput
97- tokenType = "fungible"
98- onlyOwner = { false }
99- />
100- < OperationsInputField
101- name = "address"
102- label = "Address"
103- placeholder = "Example: erd1..."
104- description = "Please provide the address to where the amount will be send"
105- />
106- < OperationsInputField
107- name = "amount"
108- label = "Amount"
109- placeholder = "Example: 22.5"
110- description = "Please provide the amount of ESDT to send (ex. 22.5 is 22.5 amount of an ESDT token. Don't worry about the decimal places here)."
111- />
112- </ div >
113- < OperationsSubmitButton pending = { pending } />
114- </ form >
115- </ Form >
66+ < >
67+ < OperationInfoBox error = { error } message = { '' } txHash = { txResult ?. hash } />
68+ < Form { ...form } >
69+ < form onSubmit = { form . handleSubmit ( onSubmit ) } className = "space-y-8" >
70+ < div className = "flex-1 overflow-auto p-1" >
71+ < OperationsTokenIdAmountInput
72+ tokenType = "fungible"
73+ onlyOwner = { false }
74+ />
75+ < OperationsInputField
76+ name = "address"
77+ label = "Address"
78+ placeholder = "Example: erd1..."
79+ description = "Please provide the address to where the amount will be send"
80+ />
81+ < OperationsInputField
82+ name = "amount"
83+ label = "Amount"
84+ placeholder = "Example: 22.5"
85+ description = "Please provide the amount of ESDT to send (ex. 22.5 is 22.5 amount of an ESDT token. Don't worry about the decimal places here)."
86+ />
87+ </ div >
88+ < OperationsSubmitButton pending = { pending } />
89+ </ form >
90+ </ Form >
91+ </ >
11692 ) ;
11793} ;
0 commit comments