2022-09-20 22:24:05 -05:00
|
|
|
using CSharpFunctionalExtensions;
|
2022-09-18 22:15:59 -05:00
|
|
|
using NftFaucetRadzen.Components;
|
2022-09-20 21:05:08 -05:00
|
|
|
using NftFaucetRadzen.Models;
|
2022-09-20 22:24:05 -05:00
|
|
|
using NftFaucetRadzen.Utils;
|
2022-09-20 21:13:34 -05:00
|
|
|
using Radzen;
|
2022-09-18 22:15:59 -05:00
|
|
|
|
|
|
|
namespace NftFaucetRadzen.Pages;
|
|
|
|
|
|
|
|
public partial class MintPage : BasicComponent
|
|
|
|
{
|
2022-09-20 22:24:05 -05:00
|
|
|
private string SourceAddress { get; set; }
|
2022-09-20 21:41:53 -05:00
|
|
|
private bool NetworkMatches { get; set; }
|
2022-09-20 22:24:05 -05:00
|
|
|
private bool BalanceIsZero { get; set; } = true;
|
2022-09-18 22:15:59 -05:00
|
|
|
private bool IsReadyToMint => AppState != null &&
|
|
|
|
AppState.SelectedNetwork != null &&
|
|
|
|
AppState.SelectedProvider != null &&
|
|
|
|
AppState.SelectedProvider.IsConfigured &&
|
|
|
|
AppState.SelectedContract != null &&
|
|
|
|
AppState.SelectedToken != null &&
|
2022-09-20 21:41:53 -05:00
|
|
|
AppState.SelectedUploadLocation != null &&
|
2022-09-20 22:24:05 -05:00
|
|
|
!string.IsNullOrEmpty(SourceAddress) &&
|
|
|
|
NetworkMatches &&
|
|
|
|
!BalanceIsZero;
|
2022-09-20 20:20:18 -05:00
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
{
|
|
|
|
if (AppState?.SelectedProvider?.IsConfigured ?? false)
|
|
|
|
{
|
2022-09-20 22:24:05 -05:00
|
|
|
SourceAddress = await ResultWrapper.Wrap(() => AppState.SelectedProvider.GetAddress()).Match(x => x, _ => null);
|
2022-09-28 20:49:55 -05:00
|
|
|
AppState.UserStorage.DestinationAddress = SourceAddress;
|
2022-09-24 21:36:36 -05:00
|
|
|
if (string.IsNullOrEmpty(SourceAddress) || AppState.SelectedNetwork == null)
|
2022-09-20 22:24:05 -05:00
|
|
|
{
|
|
|
|
BalanceIsZero = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-24 21:36:36 -05:00
|
|
|
var balance = await ResultWrapper.Wrap(() => AppState.SelectedProvider.GetBalance(AppState.SelectedNetwork)).Match(x => x, _ => 0);
|
2022-09-20 22:24:05 -05:00
|
|
|
BalanceIsZero = balance == 0;
|
|
|
|
}
|
|
|
|
if (AppState.SelectedNetwork != null)
|
|
|
|
{
|
|
|
|
NetworkMatches = await ResultWrapper.Wrap(() => AppState.SelectedProvider.EnsureNetworkMatches(AppState.SelectedNetwork)).Match(x => x, _ => false);
|
|
|
|
}
|
2022-09-20 20:20:18 -05:00
|
|
|
}
|
|
|
|
}
|
2022-09-20 21:05:08 -05:00
|
|
|
|
|
|
|
private async Task Mint()
|
|
|
|
{
|
|
|
|
var mintRequest = new MintRequest(AppState.SelectedNetwork, AppState.SelectedProvider,
|
|
|
|
AppState.SelectedContract, AppState.SelectedToken, AppState.SelectedUploadLocation,
|
2022-09-28 20:49:55 -05:00
|
|
|
AppState.UserStorage.DestinationAddress, AppState.UserStorage.TokenAmount);
|
2022-09-20 21:13:34 -05:00
|
|
|
var result = await AppState.SelectedProvider.Mint(mintRequest);
|
|
|
|
if (result.IsSuccess)
|
|
|
|
{
|
|
|
|
NotificationService.Notify(NotificationSeverity.Success, "Minting finished", result.Value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NotificationService.Notify(NotificationSeverity.Error, "Failed to mint", result.Error);
|
|
|
|
}
|
2022-09-20 21:05:08 -05:00
|
|
|
}
|
2022-09-18 22:15:59 -05:00
|
|
|
}
|