@@ -20,7 +20,7 @@ import {
20
20
useBalance ,
21
21
} from "wagmi" ;
22
22
import { parseEther , parseUnits } from "viem" ;
23
- import { normalize } from ' viem/ens'
23
+ import { normalize } from " viem/ens" ;
24
24
import { isUndefined } from "utils/index" ;
25
25
import { wrapWithToast } from "utils/wrapWithToast" ;
26
26
import { ethAddressPattern } from "utils/validateAddress" ;
@@ -70,23 +70,23 @@ const DepositPaymentButton: React.FC = () => {
70
70
const finalRecipientAddress = ensResult . data || sellerAddress ;
71
71
72
72
const { data : nativeBalance } = useBalance ( {
73
- address : isNativeTransaction ? address as `0x${string } ` : undefined ,
73
+ address : isNativeTransaction ? ( address as `0x${string } `) : undefined ,
74
74
} ) ;
75
75
76
76
const { data : tokenBalance } = useReadContract ( {
77
- address : ! isNativeTransaction ? sendingToken ?. address as `0x${string } ` : undefined ,
77
+ address : ! isNativeTransaction ? ( sendingToken ?. address as `0x${string } `) : undefined ,
78
78
abi : erc20Abi ,
79
- functionName : ' balanceOf' ,
79
+ functionName : " balanceOf" ,
80
80
args : [ address as `0x${string } `] ,
81
81
} ) ;
82
-
82
+
83
83
const insufficientBalance = useMemo ( ( ) => {
84
84
if ( isUndefined ( sendingQuantity ) ) return true ;
85
-
85
+
86
86
if ( isNativeTransaction ) {
87
87
return nativeBalance ? parseFloat ( sendingQuantity ) > parseFloat ( nativeBalance . value . toString ( ) ) : true ;
88
88
}
89
-
89
+
90
90
return isUndefined ( tokenBalance ) ? true : parseFloat ( sendingQuantity ) > parseFloat ( tokenBalance . toString ( ) ) ;
91
91
} , [ sendingQuantity , tokenBalance , nativeBalance , isNativeTransaction ] ) ;
92
92
@@ -129,7 +129,13 @@ const DepositPaymentButton: React.FC = () => {
129
129
ethAddressPattern . test ( finalRecipientAddress ) &&
130
130
! insufficientBalance ,
131
131
} ,
132
- args : [ transactionValue , sendingToken ?. address as `0x${string } `, deadlineTimestamp , transactionUri , finalRecipientAddress as `0x${string } `] ,
132
+ args : [
133
+ transactionValue ,
134
+ sendingToken ?. address as `0x${string } `,
135
+ deadlineTimestamp ,
136
+ transactionUri ,
137
+ finalRecipientAddress as `0x${string } `,
138
+ ] ,
133
139
} ) ;
134
140
135
141
const { writeContractAsync : createNativeTransaction } =
@@ -191,7 +197,7 @@ const DepositPaymentButton: React.FC = () => {
191
197
return (
192
198
< div >
193
199
< StyledButton
194
- isLoading = { isSending || isLoadingNativeConfig || isLoadingERC20Config }
200
+ isLoading = { ! insufficientBalance && ( isSending || isLoadingNativeConfig || isLoadingERC20Config ) }
195
201
disabled = {
196
202
isSending ||
197
203
insufficientBalance ||
0 commit comments