mirror of
https://github.com/status-im/nft-faucet.git
synced 2025-02-22 11:38:26 +00:00
Fix balance overflow when balance is too big
This commit is contained in:
parent
a45575bda2
commit
401e3fed76
@ -1,7 +1,9 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace NftFaucet.Models;
|
||||
|
||||
public class Balance
|
||||
{
|
||||
public decimal Amount { get; set; }
|
||||
public BigInteger Amount { get; set; }
|
||||
public string Currency { get; set; }
|
||||
}
|
||||
|
@ -50,6 +50,10 @@ else if (State == MintingState.CheckingNetwork)
|
||||
{
|
||||
@(Balance.Amount + " " + Balance.Currency)
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(GetBalanceError))
|
||||
{
|
||||
@GetBalanceError
|
||||
}
|
||||
else
|
||||
{
|
||||
@:<unknown>
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Numerics;
|
||||
using NftFaucet.Components;
|
||||
using NftFaucet.Models;
|
||||
using NftFaucet.Plugins.NetworkPlugins;
|
||||
@ -15,6 +16,7 @@ public partial class MintDialog : BasicComponent
|
||||
private string SourceAddress { get; set; }
|
||||
private Balance Balance { get; set; }
|
||||
private string TransactionHash { get; set; }
|
||||
private string GetBalanceError { get; set; }
|
||||
private string SendTransactionError { get; set; }
|
||||
|
||||
protected override Task OnInitializedAsync()
|
||||
@ -89,9 +91,14 @@ public partial class MintDialog : BasicComponent
|
||||
return task1.Result;
|
||||
});
|
||||
Balance = balanceResult.IsSuccess ? balanceResult.Value : null;
|
||||
var amount = Math.Max(Balance?.Amount ?? 0, 0);
|
||||
GetBalanceError = balanceResult.IsFailure ? balanceResult.Error : null;
|
||||
var amount = Balance?.Amount ?? BigInteger.Zero;
|
||||
if (amount < BigInteger.Zero)
|
||||
{
|
||||
amount = BigInteger.Zero;
|
||||
}
|
||||
|
||||
if (amount != 0)
|
||||
if (amount != BigInteger.Zero)
|
||||
{
|
||||
SendTransaction();
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class EthereumKeygenProvider : IProvider
|
||||
|
||||
var web3 = new Web3(network.PublicRpcUrl.OriginalString);
|
||||
var hexBalance = await web3.Eth.GetBalance.SendRequestAsync(Key.Address);
|
||||
var balance = (long) hexBalance.Value;
|
||||
var balance = hexBalance.Value;
|
||||
return new Balance
|
||||
{
|
||||
Amount = balance,
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using CSharpFunctionalExtensions;
|
||||
using NftFaucet.Components.CardList;
|
||||
@ -111,7 +112,7 @@ public class SolanaKeygenProvider : IProvider
|
||||
if (!balanceResult.WasSuccessful || balanceResult.Result == null)
|
||||
return null;
|
||||
|
||||
var balance = (long) balanceResult.Result.Value;
|
||||
var balance = new BigInteger(balanceResult.Result.Value);
|
||||
return new Balance
|
||||
{
|
||||
Amount = balance,
|
||||
|
@ -137,7 +137,7 @@ public class MetamaskProvider : IProvider
|
||||
if (!IsConfigured)
|
||||
return null;
|
||||
|
||||
var balance = (long) await MetaMaskService.GetBalanceAsync();
|
||||
var balance = await MetaMaskService.GetBalanceAsync();
|
||||
return new Balance
|
||||
{
|
||||
Amount = balance,
|
||||
|
Loading…
x
Reference in New Issue
Block a user