mirror of
https://github.com/status-im/nft-faucet.git
synced 2025-02-23 03:58:23 +00:00
Fixed network selection and add retry on balance
This commit is contained in:
parent
ea5406ba82
commit
b203ce0f9a
@ -22,6 +22,7 @@ public class Step1Component : BasicComponent
|
|||||||
protected void OnSolanaSelected()
|
protected void OnSolanaSelected()
|
||||||
{
|
{
|
||||||
AppState.Storage.NetworkType = NetworkType.Solana;
|
AppState.Storage.NetworkType = NetworkType.Solana;
|
||||||
|
AppState.Storage.Network = EthereumNetwork.SolanaDevnet;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void OnNetworkChange(EnumWrapper<EthereumNetwork> network)
|
protected void OnNetworkChange(EnumWrapper<EthereumNetwork> network)
|
||||||
|
@ -38,19 +38,25 @@ public class SolanaTransactionService : ISolanaTransactionService
|
|||||||
ulong tokenPrice = 20000000; // 0.02 SOL
|
ulong tokenPrice = 20000000; // 0.02 SOL
|
||||||
|
|
||||||
var airdropSig = await client.RequestAirdropAsync(wallet.Account.PublicKey, 50000000);
|
var airdropSig = await client.RequestAirdropAsync(wallet.Account.PublicKey, 50000000);
|
||||||
|
Console.WriteLine(airdropSig.Result);
|
||||||
|
|
||||||
var airDropCompleted = false;
|
await RepeatAsync(async () =>
|
||||||
do
|
|
||||||
{
|
{
|
||||||
var transaction = await client.GetTransactionAsync(airdropSig.Result);
|
var transaction = await client.GetTransactionAsync(airdropSig.Result);
|
||||||
|
|
||||||
airDropCompleted = transaction.WasRequestSuccessfullyHandled && transaction.ErrorData == null;
|
return transaction.WasRequestSuccessfullyHandled && transaction.ErrorData == null;
|
||||||
await Task.Delay(1000);
|
}, TimeSpan.FromSeconds(1), 100);
|
||||||
} while (!airDropCompleted);
|
|
||||||
|
|
||||||
var walletAddress = wallet.Account.PublicKey;
|
var walletAddress = wallet.Account.PublicKey;
|
||||||
|
|
||||||
|
await RepeatAsync(async () =>
|
||||||
|
{
|
||||||
var balanceRes = await client.GetBalanceAsync(walletAddress);
|
var balanceRes = await client.GetBalanceAsync(walletAddress);
|
||||||
|
|
||||||
|
return balanceRes.Result.Value > 0;
|
||||||
|
}, TimeSpan.FromSeconds(1), 5);
|
||||||
|
|
||||||
|
|
||||||
var rentExemption = await client.GetMinimumBalanceForRentExemptionAsync(
|
var rentExemption = await client.GetMinimumBalanceForRentExemptionAsync(
|
||||||
TokenProgram.MintAccountDataSize,
|
TokenProgram.MintAccountDataSize,
|
||||||
Solnet.Rpc.Types.Commitment.Confirmed
|
Solnet.Rpc.Types.Commitment.Confirmed
|
||||||
@ -97,7 +103,7 @@ public class SolanaTransactionService : ISolanaTransactionService
|
|||||||
|
|
||||||
if (!isSimulationSuccessful)
|
if (!isSimulationSuccessful)
|
||||||
{
|
{
|
||||||
return string.Empty;
|
throw new Exception("Transaction simulation failed. Try again.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var txResult = await client.SendTransactionAsync(tx);
|
var txResult = await client.SendTransactionAsync(tx);
|
||||||
@ -111,6 +117,26 @@ public class SolanaTransactionService : ISolanaTransactionService
|
|||||||
return new Wallet(newMnemonic);
|
return new Wallet(newMnemonic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task RepeatAsync(Func<Task<bool>> work, TimeSpan retryInterval, int maxExecutionCount = 3)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < maxExecutionCount; ++i)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await work();
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.Delay(retryInterval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private PublicKey GetMetadataAddress(PublicKey mintAddress)
|
private PublicKey GetMetadataAddress(PublicKey mintAddress)
|
||||||
{
|
{
|
||||||
// PDA METADATA
|
// PDA METADATA
|
||||||
|
Loading…
x
Reference in New Issue
Block a user