Update wallet service with Jalali date conversion and UI improvements

This commit is contained in:
masoodafar-web
2025-11-28 14:43:58 +03:30
parent 48dadf007a
commit 771c740c62
4 changed files with 39 additions and 18 deletions

View File

@@ -1,10 +1,11 @@
using DateTimeConverterCL;
using FrontOffice.BFF.UserWallet.Protobuf.Protos.UserWallet;
using Google.Protobuf.WellKnownTypes;
namespace FrontOffice.Main.Utilities;
public record WalletBalances(long CreditBalance, long NetworkBalance);
public record WalletTransaction(DateTime Date, long Amount, string Channel, string Description);
public record WalletTransaction(string Date, long Amount, string Channel, string Description);
public class WalletService
{
@@ -34,22 +35,44 @@ public class WalletService
try
{
var response = await _client.GetAllUserWalletChangeLogAsync(new Empty());
return response.Models.Select(t => new WalletTransaction(DateTime.Now, t.CurrentBalance,t.RefrenceId.Value.ToString(),t.IsIncrease?"شارژ کیف پول":"برداشت از کیف پول")
).ToList();
return response.Models
.Select(t => new WalletTransaction(
ResolveTransactionDate(t),
t.CurrentBalance,
t.RefrenceId?.ToString() ?? "-",
t.IsIncrease ? "شارژ کیف پول" : "برداشت از کیف پول"))
.OrderByDescending(t => t.Date)
.ToList();
}
catch
{
// Fallback to mock data if backend is unavailable
var _transactions = new List<WalletTransaction>
{
new(DateTime.Now.AddDays(-1), 500_000, "درگاه بانکی", "شارژ کیف پول"),
new(DateTime.Now.AddDays(-2), 200_000, "شبکه/معرف", "پاداش شبکه"),
new(DateTime.Now.AddDays(-4), -120_000, "خرید", "برداشت بابت سفارش #1452"),
new(DateTime.Now.AddDays(-9), 900_000, "کیف پول شرکای تجاری", "اعتبار خرید"),
new(DateTime.Now.AddDays(-1).ToString(), 500_000, "درگاه بانکی", "شارژ کیف پول"),
new(DateTime.Now.AddDays(-2).ToString(), 200_000, "شبکه/معرف", "پاداش شبکه"),
new(DateTime.Now.AddDays(-4).ToString(), -120_000, "خرید", "برداشت بابت سفارش #1452"),
new(DateTime.Now.AddDays(-9).ToString(), 900_000, "کیف پول شرکای تجاری", "اعتبار خرید"),
};
return _transactions.OrderByDescending(t => t.Date).ToList();
}
}
private static string ResolveTransactionDate(GetAllUserWalletChangeLogResponseModel model)
{
if (model.CreatedAt is not null)
{
try
{
return model.CreatedAt.ToDateTime().MiladiToJalaliWithTime();
}
catch
{
// ignore conversion issues and fall through to default
}
}
return DateTime.Now.MiladiToJalaliWithTime();
}
}