feat(wallet): enhance ChargeCreditWallet and Wallet components with magic ceiling consent logic
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 5m29s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 5m29s
- Added new logic to handle user consent for charging without a magic multiplier when the magic wallet ceiling is full. - Updated the ChargeCreditWallet component to display alerts and prompts based on the user's magic wallet status and consent. - Enhanced the Wallet component to conditionally render buttons and alerts related to the magic wallet ceiling status. - Improved user feedback in the InsufficientCreditDialog to guide users on charging options based on their wallet status. These changes enhance the user experience by providing clear instructions and options for charging wallets under specific conditions.
This commit is contained in:
@@ -83,7 +83,18 @@
|
||||
</MudStack>
|
||||
</MudAlert>
|
||||
}
|
||||
else if (_authLoaded)
|
||||
else if (_authLoaded && _needsMagicCeilingConsent && !_allowNormalDespiteMagic && !_redirectingToMagic)
|
||||
{
|
||||
<MudAlert Severity="MudBlazor.Severity.Warning" Class="rounded-lg" Variant="Variant.Outlined">
|
||||
<MudStack Spacing="2" AlignItems="AlignItems.Center">
|
||||
<MudProgressCircular Size="Size.Small" Indeterminate="true" Color="Color.Warning" />
|
||||
<MudText>
|
||||
سقف شارژ جادویی پر است. برای شارژ بدون ضریب باید تأیید کنید...
|
||||
</MudText>
|
||||
</MudStack>
|
||||
</MudAlert>
|
||||
}
|
||||
else if (ShowChargeForm)
|
||||
{
|
||||
<MudPaper Elevation="2" Class="pa-5 rounded-lg">
|
||||
<MudText Typo="Typo.h6" Class="mb-3">
|
||||
@@ -91,6 +102,13 @@
|
||||
شارژ موجودی اصلی
|
||||
</MudText>
|
||||
|
||||
@if (_allowNormalDespiteMagic)
|
||||
{
|
||||
<MudAlert Severity="MudBlazor.Severity.Warning" Dense="true" Class="mb-3" Icon="@Icons.Material.Filled.Warning">
|
||||
این شارژ بدون ضریب جادویی است (۱:۱). سقف واریز جادویی شما در این دور پر شده است.
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
<MudAlert Severity="MudBlazor.Severity.Info" Dense="true" Class="mb-3" Icon="@Icons.Material.Filled.Info">
|
||||
مبلغ وارد شده (به تومان) از طریق درگاه پرداخت به موجودی اصلی شما اضافه میشود.
|
||||
از موجودی اصلی برای خرید از فروشگاه عادی و پرداخت سفارش استفاده میشود.
|
||||
|
||||
@@ -17,6 +17,9 @@ public partial class ChargeCreditWallet : ComponentBase
|
||||
private bool _hasPurchasedPackage;
|
||||
private bool _authLoaded;
|
||||
private bool _redirectingToMagic;
|
||||
private bool _allowNormalDespiteMagic;
|
||||
private bool _needsMagicCeilingConsent;
|
||||
private bool _magicConsentPrompted;
|
||||
|
||||
private readonly long[] _presetAmounts = { 500_000, 1_000_000, 5_000_000, 10_000_000, 20_000_000, 50_000_000 };
|
||||
|
||||
@@ -29,6 +32,12 @@ public partial class ChargeCreditWallet : ComponentBase
|
||||
[SupplyParameterFromQuery(Name = "returnUrl")]
|
||||
public string? ReturnUrlQueryParam { get; set; }
|
||||
|
||||
private bool ShowChargeForm =>
|
||||
_authLoaded
|
||||
&& _isClubMemberActive
|
||||
&& !_redirectingToMagic
|
||||
&& (!_needsMagicCeilingConsent || _allowNormalDespiteMagic);
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_paymentResult = PaymentQueryParam;
|
||||
@@ -55,16 +64,20 @@ public partial class ChargeCreditWallet : ComponentBase
|
||||
_authLoaded = true;
|
||||
}
|
||||
|
||||
// اگر کیف پول جادویی فعال است، فرم شارژ ۱:۱ نشان داده نشود
|
||||
if (_isClubMemberActive && await TryRedirectIfMagicWalletAsync())
|
||||
return;
|
||||
if (_isClubMemberActive)
|
||||
await EvaluateMagicWalletGateAsync(promptConsent: false);
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender && !string.IsNullOrEmpty(_pendingReturnUrl) && _isClubMemberActive && !_redirectingToMagic)
|
||||
{
|
||||
await CreditChargeNavigation.SaveReturnUrlAsync(JSRuntime, _pendingReturnUrl);
|
||||
|
||||
if (firstRender && _needsMagicCeilingConsent && !_allowNormalDespiteMagic && !_magicConsentPrompted)
|
||||
{
|
||||
_magicConsentPrompted = true;
|
||||
await PromptMagicCeilingConsentAsync();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
@@ -80,7 +93,10 @@ public partial class ChargeCreditWallet : ComponentBase
|
||||
return;
|
||||
}
|
||||
|
||||
if (await TryRedirectIfMagicWalletAsync())
|
||||
if (await EvaluateMagicWalletGateAsync(promptConsent: true))
|
||||
return;
|
||||
|
||||
if (!_allowNormalDespiteMagic && _needsMagicCeilingConsent)
|
||||
return;
|
||||
|
||||
if (_chargeAmount <= 0 || _isProcessing) return;
|
||||
@@ -122,20 +138,31 @@ public partial class ChargeCreditWallet : ComponentBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// اگر WalletMode جادویی باشد، پیام میدهد و به صفحه شارژ کیف جادویی هدایت میکند.
|
||||
/// Magic با ظرفیت باقیمانده → ریدایرکت به MagicWallet.
|
||||
/// Magic با سقف پر → نیاز به رضایت برای شارژ ۱:۱.
|
||||
/// true یعنی مسیر شارژ فعلی باید متوقف شود.
|
||||
/// </summary>
|
||||
private async Task<bool> TryRedirectIfMagicWalletAsync()
|
||||
private async Task<bool> EvaluateMagicWalletGateAsync(bool promptConsent)
|
||||
{
|
||||
if (_allowNormalDespiteMagic)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var status = await WalletService.GetMagicWalletStatusAsync();
|
||||
if (status.WalletMode != 1)
|
||||
{
|
||||
_needsMagicCeilingConsent = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (status.MagicRemainingDeposit > 0)
|
||||
{
|
||||
var multiplier = status.MagicMultiplier > 0 ? status.MagicMultiplier : 2.5;
|
||||
var multiplierText = multiplier.ToString("0.#");
|
||||
|
||||
_redirectingToMagic = true;
|
||||
_needsMagicCeilingConsent = false;
|
||||
Snackbar.Add(
|
||||
$"کیف پول شما در حالت جادویی است. شارژ از این صفحه موجودی را چندبرابر نمیکند. برای دریافت ضریب جادویی (×{multiplierText}) به صفحه شارژ کیف پول جادویی هدایت میشوید.",
|
||||
Severity.Info);
|
||||
@@ -143,6 +170,17 @@ public partial class ChargeCreditWallet : ComponentBase
|
||||
Navigation.NavigateTo(RouteConstants.Profile.MagicWallet);
|
||||
return true;
|
||||
}
|
||||
|
||||
_needsMagicCeilingConsent = true;
|
||||
|
||||
if (promptConsent)
|
||||
{
|
||||
await PromptMagicCeilingConsentAsync();
|
||||
return !_allowNormalDespiteMagic;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// در صورت خطا در خواندن وضعیت، مانع شارژ عادی نشو
|
||||
@@ -150,6 +188,25 @@ public partial class ChargeCreditWallet : ComponentBase
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PromptMagicCeilingConsentAsync()
|
||||
{
|
||||
var confirmed = await DialogService.ShowMessageBox(
|
||||
"شارژ بدون ضریب جادویی",
|
||||
"سقف شارژ کیف پول جادویی شما در این دور پر شده است. شارژ از این صفحه بدون ضریب (۱:۱) به موجودی اضافه میشود و ضریب جادویی اعمال نمیشود. آیا مایلید ادامه دهید؟",
|
||||
yesText: "ادامه شارژ بدون ضریب",
|
||||
cancelText: "انصراف");
|
||||
|
||||
if (confirmed == true)
|
||||
{
|
||||
_allowNormalDespiteMagic = true;
|
||||
_redirectingToMagic = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_redirectingToMagic = true;
|
||||
Navigation.NavigateTo(RouteConstants.Profile.MagicWallet);
|
||||
}
|
||||
|
||||
private async Task ContinueShoppingAsync()
|
||||
{
|
||||
var returnUrl = await CreditChargeNavigation.GetReturnUrlAsync(JSRuntime);
|
||||
|
||||
@@ -166,8 +166,23 @@
|
||||
else
|
||||
{
|
||||
<MudAlert Severity="MudBlazor.Severity.Warning" Class="rounded-lg">
|
||||
<MudStack Spacing="2">
|
||||
<MudText>
|
||||
سقف شارژ جادویی در این دور پر شده است.
|
||||
با خرج کردن موجودی و خرید مجدد پکیج، سقف ریست میشود.
|
||||
</MudText>
|
||||
<MudText Typo="Typo.body2">
|
||||
اگر برای تکمیل خرید به موجودی بیشتری نیاز دارید، میتوانید بهصورت استثنایی کیف اصلی را بدون ضریب (۱:۱) شارژ کنید.
|
||||
</MudText>
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.AccountBalanceWallet"
|
||||
Href="@RouteConstants.Profile.ChargeCreditWallet"
|
||||
Class="rounded-lg align-self-start">
|
||||
شارژ عادی بدون ضریب
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
|
||||
@@ -52,10 +52,28 @@
|
||||
Class="rounded-lg">
|
||||
شارژ کیفپول جادویی
|
||||
</MudButton>
|
||||
@if (_magicCeilingFull)
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning" Dense="true" Variant="Variant.Outlined">
|
||||
سقف شارژ جادویی این دور پر است. در صورت نیاز میتوانید بهصورت استثنایی بدون ضریب شارژ کنید.
|
||||
</MudAlert>
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
Color="Color.Primary"
|
||||
Size="Size.Large"
|
||||
FullWidth="true"
|
||||
StartIcon="@Icons.Material.Filled.AccountBalanceWallet"
|
||||
Href="@RouteConstants.Profile.ChargeCreditWallet"
|
||||
Class="rounded-lg">
|
||||
شارژ عادی بدون ضریب
|
||||
</MudButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Dense="true" Variant="Variant.Outlined">
|
||||
کیف پول شما در حالت جادویی است؛ شارژ از مسیر جادویی با ضریب چندبرابر اعمال میشود.
|
||||
</MudAlert>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Filled"
|
||||
|
||||
@@ -15,6 +15,7 @@ public partial class Wallet : ComponentBase
|
||||
private bool _isClubMemberActive;
|
||||
private bool _hasPurchasedPackage;
|
||||
private bool _isMagicWallet;
|
||||
private bool _magicCeilingFull;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
@@ -34,10 +35,12 @@ public partial class Wallet : ComponentBase
|
||||
{
|
||||
var magicStatus = await WalletService.GetMagicWalletStatusAsync();
|
||||
_isMagicWallet = magicStatus.WalletMode == 1;
|
||||
_magicCeilingFull = _isMagicWallet && magicStatus.MagicRemainingDeposit <= 0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_isMagicWallet = false;
|
||||
_magicCeilingFull = false;
|
||||
}
|
||||
|
||||
var b = await WalletService.GetBalancesAsync();
|
||||
|
||||
@@ -127,6 +127,8 @@ public partial class CheckoutSummary : ComponentBase
|
||||
var shortfall = totalRequired - walletBalance;
|
||||
var allowCharge = false;
|
||||
var hasPurchasedPackage = false;
|
||||
var isMagicWallet = false;
|
||||
var magicCeilingFull = false;
|
||||
try
|
||||
{
|
||||
var userInfo = await AuthService.GetUserAuthInfo();
|
||||
@@ -138,13 +140,27 @@ public partial class CheckoutSummary : ComponentBase
|
||||
allowCharge = false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var magicStatus = await WalletService.GetMagicWalletStatusAsync();
|
||||
isMagicWallet = magicStatus.WalletMode == 1;
|
||||
magicCeilingFull = isMagicWallet && magicStatus.MagicRemainingDeposit <= 0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
isMagicWallet = false;
|
||||
magicCeilingFull = false;
|
||||
}
|
||||
|
||||
var parameters = new DialogParameters<InsufficientCreditDialog>
|
||||
{
|
||||
{ x => x.CurrentBalance, walletBalance },
|
||||
{ x => x.RequiredAmount, totalRequired },
|
||||
{ x => x.ShortfallAmount, shortfall },
|
||||
{ x => x.AllowChargeCredit, allowCharge },
|
||||
{ x => x.HasPurchasedPackage, hasPurchasedPackage }
|
||||
{ x => x.HasPurchasedPackage, hasPurchasedPackage },
|
||||
{ x => x.IsMagicWallet, isMagicWallet },
|
||||
{ x => x.MagicCeilingFull, magicCeilingFull }
|
||||
};
|
||||
|
||||
var dialog = await DialogService.ShowAsync<InsufficientCreditDialog>(
|
||||
|
||||
@@ -10,11 +10,26 @@
|
||||
<DialogContent>
|
||||
<MudStack Spacing="2">
|
||||
@if (AllowChargeCredit)
|
||||
{
|
||||
@if (IsMagicWallet && !MagicCeilingFull)
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="mud-text-secondary">
|
||||
برای تکمیل این سفارش موجودی شما کافی نیست. کیف پول شما در حالت جادویی است؛ برای دریافت ضریب، از مسیر شارژ جادویی اقدام کنید.
|
||||
</MudText>
|
||||
}
|
||||
else if (IsMagicWallet && MagicCeilingFull)
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning" Dense="true" Variant="Variant.Outlined">
|
||||
سقف شارژ جادویی شما در این دور پر است. میتوانید بهصورت استثنایی کیف اصلی را بدون ضریب (۱:۱) شارژ کنید.
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="mud-text-secondary">
|
||||
برای تکمیل این سفارش، موجودی اصلی شما کافی نیست. میتوانید کیف پول را شارژ کنید و سپس سفارش را ثبت کنید.
|
||||
</MudText>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning" Dense="true" Variant="Variant.Outlined">
|
||||
@@ -46,10 +61,10 @@
|
||||
@if (AllowChargeCredit)
|
||||
{
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Payment"
|
||||
Color="@(IsMagicWallet && !MagicCeilingFull ? Color.Secondary : Color.Primary)"
|
||||
StartIcon="@(IsMagicWallet && !MagicCeilingFull ? Icons.Material.Filled.AutoAwesome : Icons.Material.Filled.Payment)"
|
||||
OnClick="GoToCharge">
|
||||
شارژ حساب اصلی
|
||||
@ChargeButtonLabel
|
||||
</MudButton>
|
||||
}
|
||||
else if (!HasPurchasedPackage)
|
||||
@@ -93,9 +108,33 @@
|
||||
[Parameter]
|
||||
public bool HasPurchasedPackage { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsMagicWallet { get; set; }
|
||||
|
||||
/// <summary>سقف واریز جادویی این دور پر شده است.</summary>
|
||||
[Parameter]
|
||||
public bool MagicCeilingFull { get; set; }
|
||||
|
||||
private string ChargeButtonLabel =>
|
||||
IsMagicWallet && !MagicCeilingFull
|
||||
? "شارژ کیف جادویی"
|
||||
: IsMagicWallet && MagicCeilingFull
|
||||
? "شارژ عادی بدون ضریب (سقف جادویی پر است)"
|
||||
: "شارژ حساب اصلی";
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
|
||||
private void GoToCharge() => MudDialog.Close(DialogResult.Ok(ShortfallAmount));
|
||||
private void GoToCharge()
|
||||
{
|
||||
if (IsMagicWallet && !MagicCeilingFull)
|
||||
{
|
||||
MudDialog.Cancel();
|
||||
Navigation.NavigateTo(RouteConstants.Profile.MagicWallet);
|
||||
return;
|
||||
}
|
||||
|
||||
MudDialog.Close(DialogResult.Ok(ShortfallAmount));
|
||||
}
|
||||
|
||||
private void GoToPackages()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user