From 771c740c62c5d797f59ea3300128304fce9a5bfa Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Fri, 28 Nov 2025 14:43:58 +0330 Subject: [PATCH] Update wallet service with Jalali date conversion and UI improvements --- src/FrontOffice.Main/FrontOffice.Main.csproj | 10 ++--- .../Pages/Profile/Wallet.razor | 4 +- .../Pages/Store/OrderDetail.razor | 4 +- .../Utilities/WalletService.cs | 39 +++++++++++++++---- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/FrontOffice.Main/FrontOffice.Main.csproj b/src/FrontOffice.Main/FrontOffice.Main.csproj index e89524f..82abddc 100644 --- a/src/FrontOffice.Main/FrontOffice.Main.csproj +++ b/src/FrontOffice.Main/FrontOffice.Main.csproj @@ -10,12 +10,14 @@ + + - + @@ -25,11 +27,7 @@ - - - - - + diff --git a/src/FrontOffice.Main/Pages/Profile/Wallet.razor b/src/FrontOffice.Main/Pages/Profile/Wallet.razor index d672792..dfc22e5 100644 --- a/src/FrontOffice.Main/Pages/Profile/Wallet.razor +++ b/src/FrontOffice.Main/Pages/Profile/Wallet.razor @@ -36,7 +36,7 @@ توضیحات - @context.Date.ToString("yyyy/MM/dd HH:mm") + @context.Date @FormatPrice(context.Amount) @context.Channel @context.Description @@ -51,7 +51,7 @@ - @tx.Date.ToString("yy/MM/dd HH:mm") + @tx.Date @FormatPrice(tx.Amount) @tx.Channel diff --git a/src/FrontOffice.Main/Pages/Store/OrderDetail.razor b/src/FrontOffice.Main/Pages/Store/OrderDetail.razor index d473c56..337ee94 100644 --- a/src/FrontOffice.Main/Pages/Store/OrderDetail.razor +++ b/src/FrontOffice.Main/Pages/Store/OrderDetail.razor @@ -41,7 +41,7 @@ else + Width="60" Height="60" Class="rounded-circle" /> @context.ProductThumbnailPath @@ -60,7 +60,7 @@ else + Width="60" Height="60" Class="rounded-circle" /> @it.ProductTitle diff --git a/src/FrontOffice.Main/Utilities/WalletService.cs b/src/FrontOffice.Main/Utilities/WalletService.cs index 0b9439f..19c4ee6 100644 --- a/src/FrontOffice.Main/Utilities/WalletService.cs +++ b/src/FrontOffice.Main/Utilities/WalletService.cs @@ -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 { - 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(); + } }