Update order system with new gRPC services and wallet integration
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
using FrontOffice.BFF.UserWallet.Protobuf.Protos.UserWallet;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace FrontOffice.Main.Utilities;
|
||||
|
||||
public record WalletBalances(long CreditBalance, long NetworkBalance);
|
||||
@@ -5,16 +8,48 @@ public record WalletTransaction(DateTime Date, long Amount, string Channel, stri
|
||||
|
||||
public class WalletService
|
||||
{
|
||||
private WalletBalances _balances = new(350_000, 1_250_000);
|
||||
private readonly List<WalletTransaction> _transactions = new()
|
||||
{
|
||||
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, "کیف پول شرکای تجاری", "اعتبار خرید"),
|
||||
};
|
||||
private readonly UserWalletContract.UserWalletContractClient _client;
|
||||
|
||||
public Task<WalletBalances> GetBalancesAsync() => Task.FromResult(_balances);
|
||||
public Task<List<WalletTransaction>> GetTransactionsAsync() => Task.FromResult(_transactions.OrderByDescending(t => t.Date).ToList());
|
||||
public WalletService(UserWalletContract.UserWalletContractClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public async Task<WalletBalances> GetBalancesAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _client.GetUserWalletAsync(new Empty());
|
||||
return new WalletBalances(response.Balance, response.NetworkBalance);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback to mock data if backend is unavailable
|
||||
return new WalletBalances(350_000, 1_250_000);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<WalletTransaction>> GetTransactionsAsync()
|
||||
{
|
||||
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();
|
||||
}
|
||||
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, "کیف پول شرکای تجاری", "اعتبار خرید"),
|
||||
};
|
||||
return _transactions.OrderByDescending(t => t.Date).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user