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 ;
12using System . Threading . Tasks ;
23
34namespace Thirdweb . Pay
@@ -18,8 +19,16 @@ public static async Task<string> BuyWithCrypto(BuyWithCryptoQuoteResult buyWithC
1819 {
1920 ThirdwebDebug . Log ( "Approving ERC20..." ) ;
2021 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+ }
2332 }
2433
2534 ThirdwebDebug . Log ( "Sending swap transaction..." ) ;
You can’t perform that action at this time.
0 commit comments