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

@@ -10,12 +10,14 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="DateTimeConverterCL" Version="1.0.0" /> <PackageReference Include="DateTimeConverterCL" Version="1.0.0" />
<PackageReference Include="Foursat.FrontOffice.BFF.Package.Protobuf" Version="0.0.112" /> <PackageReference Include="Foursat.FrontOffice.BFF.Package.Protobuf" Version="0.0.112" />
<PackageReference Include="Foursat.FrontOffice.BFF.Products.Protobuf" Version="0.0.15" />
<PackageReference Include="Foursat.FrontOffice.BFF.Transaction.Protobuf" Version="0.0.111" /> <PackageReference Include="Foursat.FrontOffice.BFF.Transaction.Protobuf" Version="0.0.111" />
<PackageReference Include="Foursat.FrontOffice.BFF.Category.Protobuf" Version="0.0.12" />
<PackageReference Include="Foursat.FrontOffice.BFF.User.Protobuf" Version="0.0.116" /> <PackageReference Include="Foursat.FrontOffice.BFF.User.Protobuf" Version="0.0.116" />
<PackageReference Include="Foursat.FrontOffice.BFF.UserAddress.Protobuf" Version="0.0.114" /> <PackageReference Include="Foursat.FrontOffice.BFF.UserAddress.Protobuf" Version="0.0.114" />
<PackageReference Include="Foursat.FrontOffice.BFF.UserOrder.Protobuf" Version="0.0.114" /> <PackageReference Include="Foursat.FrontOffice.BFF.UserOrder.Protobuf" Version="0.0.114" />
<PackageReference Include="Foursat.FrontOffice.BFF.ShopingCart.Protobuf" Version="0.0.15" /> <PackageReference Include="Foursat.FrontOffice.BFF.ShopingCart.Protobuf" Version="0.0.15" />
<PackageReference Include="Foursat.FrontOffice.BFF.UserWallet.Protobuf" Version="0.0.12" /> <PackageReference Include="Foursat.FrontOffice.BFF.UserWallet.Protobuf" Version="0.0.14" />
<PackageReference Include="MudBlazor" Version="8.14.0" /> <PackageReference Include="MudBlazor" Version="8.14.0" />
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" /> <PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="Mapster" Version="7.4.0" /> <PackageReference Include="Mapster" Version="7.4.0" />
@@ -26,10 +28,6 @@
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="../../../FrontOffice.BFF/src/Protobufs/FrontOffice.BFF.Products.Protobuf/FrontOffice.BFF.Products.Protobuf.csproj" />
<ProjectReference Include="../../../FrontOffice.BFF/src/Protobufs/FrontOffice.BFF.Category.Protobuf/FrontOffice.BFF.Category.Protobuf.csproj" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Components" /> <Folder Include="Components" />

View File

@@ -36,7 +36,7 @@
<MudTh>توضیحات</MudTh> <MudTh>توضیحات</MudTh>
</HeaderContent> </HeaderContent>
<RowTemplate> <RowTemplate>
<MudTd>@context.Date.ToString("yyyy/MM/dd HH:mm")</MudTd> <MudTd>@context.Date</MudTd>
<MudTd Color="@(context.Amount > 0 ? Color.Success : Color.Error)">@FormatPrice(context.Amount)</MudTd> <MudTd Color="@(context.Amount > 0 ? Color.Success : Color.Error)">@FormatPrice(context.Amount)</MudTd>
<MudTd>@context.Channel</MudTd> <MudTd>@context.Channel</MudTd>
<MudTd>@context.Description</MudTd> <MudTd>@context.Description</MudTd>
@@ -51,7 +51,7 @@
<MudPaper Class="pa-3 rounded-lg" Outlined="true"> <MudPaper Class="pa-3 rounded-lg" Outlined="true">
<MudStack Spacing="1"> <MudStack Spacing="1">
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center"> <MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudText>@tx.Date.ToString("yy/MM/dd HH:mm")</MudText> <MudText>@tx.Date</MudText>
<MudText Color="@(tx.Amount > 0 ? Color.Success : Color.Error)">@FormatPrice(tx.Amount)</MudText> <MudText Color="@(tx.Amount > 0 ? Color.Success : Color.Error)">@FormatPrice(tx.Amount)</MudText>
</MudStack> </MudStack>
<MudText Typo="Typo.caption" Class="mud-text-secondary">@tx.Channel</MudText> <MudText Typo="Typo.caption" Class="mud-text-secondary">@tx.Channel</MudText>

View File

@@ -41,7 +41,7 @@ else
<MudTd> <MudTd>
<MudStack Row="true" Spacing="2" AlignItems="AlignItems.Center"> <MudStack Row="true" Spacing="2" AlignItems="AlignItems.Center">
<MudImage Src="@GetProductImageUrl(context.ProductThumbnailPath)" Alt="@context.ProductTitle" <MudImage Src="@GetProductImageUrl(context.ProductThumbnailPath)" Alt="@context.ProductTitle"
Width="64" Height="64" Class="product-thumb" /> Width="60" Height="60" Class="rounded-circle" />
<MudText>@context.ProductThumbnailPath</MudText> <MudText>@context.ProductThumbnailPath</MudText>
</MudStack> </MudStack>
</MudTd> </MudTd>
@@ -60,7 +60,7 @@ else
<MudStack Spacing="1"> <MudStack Spacing="1">
<MudStack Row="true" Spacing="2" AlignItems="AlignItems.Center"> <MudStack Row="true" Spacing="2" AlignItems="AlignItems.Center">
<MudImage Src="@GetProductImageUrl(it.ProductThumbnailPath)" Alt="@it.ProductTitle" <MudImage Src="@GetProductImageUrl(it.ProductThumbnailPath)" Alt="@it.ProductTitle"
Width="64" Height="64" Class="product-thumb" /> Width="60" Height="60" Class="rounded-circle" />
<MudText>@it.ProductTitle</MudText> <MudText>@it.ProductTitle</MudText>
</MudStack> </MudStack>
<MudStack Row="true" Justify="Justify.SpaceBetween"> <MudStack Row="true" Justify="Justify.SpaceBetween">

View File

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