File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Assets/Thirdweb/Core/Scripts/Pay Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change
1
+ using System . Numerics ;
1
2
using System . Threading . Tasks ;
2
3
3
4
namespace Thirdweb . Pay
@@ -18,8 +19,16 @@ public static async Task<string> BuyWithCrypto(BuyWithCryptoQuoteResult buyWithC
18
19
{
19
20
ThirdwebDebug . Log ( "Approving ERC20..." ) ;
20
21
var erc20ToApprove = sdk . GetContract ( buyWithCryptoQuote . Approval . TokenAddress ) ;
21
- var approvalRes = await erc20ToApprove . ERC20 . SetAllowance ( buyWithCryptoQuote . Approval . SpenderAddress , buyWithCryptoQuote . Approval . AmountWei . ToEth ( ) ) ;
22
- ThirdwebDebug . Log ( $ "Approval transaction receipt: { approvalRes } ") ;
22
+ var currentAllowance = await erc20ToApprove . ERC20 . Allowance ( buyWithCryptoQuote . Approval . SpenderAddress ) ;
23
+ if ( BigInteger . Parse ( currentAllowance . value ) >= BigInteger . Parse ( buyWithCryptoQuote . Approval . AmountWei ) )
24
+ {
25
+ ThirdwebDebug . Log ( "Already approved" ) ;
26
+ }
27
+ else
28
+ {
29
+ var approvalRes = await erc20ToApprove . ERC20 . SetAllowance ( buyWithCryptoQuote . Approval . SpenderAddress , buyWithCryptoQuote . Approval . AmountWei . ToEth ( ) ) ;
30
+ ThirdwebDebug . Log ( $ "Approval transaction receipt: { approvalRes } ") ;
31
+ }
23
32
}
24
33
25
34
ThirdwebDebug . Log ( "Sending swap transaction..." ) ;
You can’t perform that action at this time.
0 commit comments