✨ Wallet funds
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Globalization;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NodaTime;
|
||||
using NodaTime.Serialization.Protobuf;
|
||||
@@ -128,7 +129,8 @@ public class SnWalletGift : ModelBase
|
||||
/// <summary>
|
||||
/// The subscription created when the gift is redeemed.
|
||||
/// </summary>
|
||||
public SnWalletSubscription? Subscription { get; set; }
|
||||
[JsonIgnore] public SnWalletSubscription? Subscription { get; set; }
|
||||
public Guid? SubscriptionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When the gift expires and can no longer be redeemed.
|
||||
@@ -337,7 +339,6 @@ public class SnWalletSubscription : ModelBase
|
||||
/// <summary>
|
||||
/// If this subscription was redeemed from a gift, this references the gift record.
|
||||
/// </summary>
|
||||
public Guid? GiftId { get; set; }
|
||||
public SnWalletGift? Gift { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
|
@@ -1,15 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Globalization;
|
||||
using System.Text.Json.Serialization;
|
||||
using NodaTime;
|
||||
using NodaTime.Serialization.Protobuf;
|
||||
|
||||
namespace DysonNetwork.Shared.Models;
|
||||
|
||||
public class SnWallet : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
|
||||
public ICollection<SnWalletPocket> Pockets { get; set; } = new List<SnWalletPocket>();
|
||||
|
||||
|
||||
public Guid AccountId { get; set; }
|
||||
public SnAccount Account { get; set; } = null!;
|
||||
|
||||
@@ -42,7 +44,7 @@ public class SnWalletPocket : ModelBase
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
[MaxLength(128)] public string Currency { get; set; } = null!;
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
|
||||
public Guid WalletId { get; set; }
|
||||
[JsonIgnore] public SnWallet Wallet { get; set; } = null!;
|
||||
|
||||
@@ -61,4 +63,97 @@ public class SnWalletPocket : ModelBase
|
||||
Amount = decimal.Parse(proto.Amount),
|
||||
WalletId = Guid.Parse(proto.WalletId),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public enum FundSplitType
|
||||
{
|
||||
Even,
|
||||
Random
|
||||
}
|
||||
|
||||
public enum FundStatus
|
||||
{
|
||||
Created,
|
||||
PartiallyReceived,
|
||||
FullyReceived,
|
||||
Expired,
|
||||
Refunded
|
||||
}
|
||||
|
||||
public class SnWalletFund : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
[MaxLength(128)] public string Currency { get; set; } = null!;
|
||||
public decimal TotalAmount { get; set; }
|
||||
public FundSplitType SplitType { get; set; }
|
||||
public FundStatus Status { get; set; } = FundStatus.Created;
|
||||
[MaxLength(4096)] public string? Message { get; set; }
|
||||
|
||||
// Creator
|
||||
public Guid CreatorAccountId { get; set; }
|
||||
public SnAccount CreatorAccount { get; set; } = null!;
|
||||
|
||||
// Recipients
|
||||
public ICollection<SnWalletFundRecipient> Recipients { get; set; } = new List<SnWalletFundRecipient>();
|
||||
|
||||
// Expiration
|
||||
public Instant ExpiredAt { get; set; }
|
||||
|
||||
public Proto.WalletFund ToProtoValue() => new()
|
||||
{
|
||||
Id = Id.ToString(),
|
||||
Currency = Currency,
|
||||
TotalAmount = TotalAmount.ToString(CultureInfo.InvariantCulture),
|
||||
SplitType = (Proto.FundSplitType)SplitType,
|
||||
Status = (Proto.FundStatus)Status,
|
||||
Message = Message,
|
||||
CreatorAccountId = CreatorAccountId.ToString(),
|
||||
ExpiredAt = ExpiredAt.ToTimestamp(),
|
||||
};
|
||||
|
||||
public static SnWalletFund FromProtoValue(Proto.WalletFund proto) => new()
|
||||
{
|
||||
Id = Guid.Parse(proto.Id),
|
||||
Currency = proto.Currency,
|
||||
TotalAmount = decimal.Parse(proto.TotalAmount),
|
||||
SplitType = (FundSplitType)proto.SplitType,
|
||||
Status = (FundStatus)proto.Status,
|
||||
Message = proto.Message,
|
||||
CreatorAccountId = Guid.Parse(proto.CreatorAccountId),
|
||||
ExpiredAt = proto.ExpiredAt.ToInstant(),
|
||||
};
|
||||
}
|
||||
|
||||
public class SnWalletFundRecipient : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid FundId { get; set; }
|
||||
[JsonIgnore] public SnWalletFund Fund { get; set; } = null!;
|
||||
|
||||
public Guid RecipientAccountId { get; set; }
|
||||
public SnAccount RecipientAccount { get; set; } = null!;
|
||||
|
||||
public decimal Amount { get; set; }
|
||||
public bool IsReceived { get; set; } = false;
|
||||
public Instant? ReceivedAt { get; set; }
|
||||
|
||||
public Proto.WalletFundRecipient ToProtoValue() => new()
|
||||
{
|
||||
Id = Id.ToString(),
|
||||
FundId = FundId.ToString(),
|
||||
RecipientAccountId = RecipientAccountId.ToString(),
|
||||
Amount = Amount.ToString(CultureInfo.InvariantCulture),
|
||||
IsReceived = IsReceived,
|
||||
ReceivedAt = ReceivedAt?.ToTimestamp(),
|
||||
};
|
||||
|
||||
public static SnWalletFundRecipient FromProtoValue(Proto.WalletFundRecipient proto) => new()
|
||||
{
|
||||
Id = Guid.Parse(proto.Id),
|
||||
FundId = Guid.Parse(proto.FundId),
|
||||
RecipientAccountId = Guid.Parse(proto.RecipientAccountId),
|
||||
Amount = decimal.Parse(proto.Amount),
|
||||
IsReceived = proto.IsReceived,
|
||||
ReceivedAt = proto.ReceivedAt?.ToInstant(),
|
||||
};
|
||||
}
|
||||
|
@@ -22,6 +22,42 @@ message WalletPocket {
|
||||
string wallet_id = 4;
|
||||
}
|
||||
|
||||
enum FundSplitType {
|
||||
FUND_SPLIT_TYPE_UNSPECIFIED = 0;
|
||||
FUND_SPLIT_TYPE_EVEN = 1;
|
||||
FUND_SPLIT_TYPE_RANDOM = 2;
|
||||
}
|
||||
|
||||
enum FundStatus {
|
||||
FUND_STATUS_UNSPECIFIED = 0;
|
||||
FUND_STATUS_CREATED = 1;
|
||||
FUND_STATUS_PARTIALLY_RECEIVED = 2;
|
||||
FUND_STATUS_FULLY_RECEIVED = 3;
|
||||
FUND_STATUS_EXPIRED = 4;
|
||||
FUND_STATUS_REFUNDED = 5;
|
||||
}
|
||||
|
||||
message WalletFund {
|
||||
string id = 1;
|
||||
string currency = 2;
|
||||
string total_amount = 3;
|
||||
FundSplitType split_type = 4;
|
||||
FundStatus status = 5;
|
||||
optional string message = 6;
|
||||
string creator_account_id = 7;
|
||||
google.protobuf.Timestamp expired_at = 8;
|
||||
repeated WalletFundRecipient recipients = 9;
|
||||
}
|
||||
|
||||
message WalletFundRecipient {
|
||||
string id = 1;
|
||||
string fund_id = 2;
|
||||
string recipient_account_id = 3;
|
||||
string amount = 4;
|
||||
bool is_received = 5;
|
||||
optional google.protobuf.Timestamp received_at = 6;
|
||||
}
|
||||
|
||||
enum SubscriptionStatus {
|
||||
// Using proto3 enum naming convention
|
||||
SUBSCRIPTION_STATUS_UNSPECIFIED = 0;
|
||||
|
Reference in New Issue
Block a user