feat(wallet): enhance ChargeCreditWallet and Wallet components with magic ceiling consent logic
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:
masoodafar-web
2026-08-08 23:59:36 +03:30
parent 6123e47968
commit 8e98c50bdf
7 changed files with 194 additions and 28 deletions
@@ -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,25 +138,47 @@ 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;
}
var multiplier = status.MagicMultiplier > 0 ? status.MagicMultiplier : 2.5;
var multiplierText = multiplier.ToString("0.#");
if (status.MagicRemainingDeposit > 0)
{
var multiplier = status.MagicMultiplier > 0 ? status.MagicMultiplier : 2.5;
var multiplierText = multiplier.ToString("0.#");
_redirectingToMagic = true;
Snackbar.Add(
$"کیف پول شما در حالت جادویی است. شارژ از این صفحه موجودی را چندبرابر نمی‌کند. برای دریافت ضریب جادویی (×{multiplierText}) به صفحه شارژ کیف پول جادویی هدایت می‌شوید.",
Severity.Info);
_redirectingToMagic = true;
_needsMagicCeilingConsent = false;
Snackbar.Add(
$"کیف پول شما در حالت جادویی است. شارژ از این صفحه موجودی را چندبرابر نمی‌کند. برای دریافت ضریب جادویی (×{multiplierText}) به صفحه شارژ کیف پول جادویی هدایت می‌شوید.",
Severity.Info);
Navigation.NavigateTo(RouteConstants.Profile.MagicWallet);
return true;
}
_needsMagicCeilingConsent = true;
if (promptConsent)
{
await PromptMagicCeilingConsentAsync();
return !_allowNormalDespiteMagic;
}
Navigation.NavigateTo(RouteConstants.Profile.MagicWallet);
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);