✨ Open fund total amount of splits
This commit is contained in:
2726
DysonNetwork.Pass/Migrations/20251116163407_OpenFundsTotalSplits.Designer.cs
generated
Normal file
2726
DysonNetwork.Pass/Migrations/20251116163407_OpenFundsTotalSplits.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DysonNetwork.Pass.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class OpenFundsTotalSplits : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "amount_of_splits",
|
||||
table: "wallet_funds",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "amount_of_splits",
|
||||
table: "wallet_funds");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1712,6 +1712,10 @@ namespace DysonNetwork.Pass.Migrations
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<int>("AmountOfSplits")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("amount_of_splits");
|
||||
|
||||
b.Property<Instant>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
@@ -475,6 +475,7 @@ public class PaymentService(
|
||||
List<Guid> recipientAccountIds,
|
||||
string currency,
|
||||
decimal totalAmount,
|
||||
int amountOfSplits,
|
||||
Shared.Models.FundSplitType splitType,
|
||||
string? message = null,
|
||||
Duration? expiration = null)
|
||||
@@ -506,6 +507,7 @@ public class PaymentService(
|
||||
Currency = currency,
|
||||
TotalAmount = totalAmount,
|
||||
RemainingAmount = totalAmount,
|
||||
AmountOfSplits = amountOfSplits,
|
||||
SplitType = splitType,
|
||||
Message = message,
|
||||
ExpiredAt = now.Plus(expiration ?? Duration.FromHours(24)),
|
||||
@@ -582,14 +584,12 @@ public class PaymentService(
|
||||
if (fund.RemainingAmount <= 0)
|
||||
return 0;
|
||||
|
||||
// For open mode funds: use percentage-based calculation
|
||||
// For open mode funds: calculate amount per split
|
||||
if (fund.IsOpen)
|
||||
{
|
||||
const decimal percentagePerClaim = 0.1m; // 10% of remaining amount per claim
|
||||
const decimal minimumAmount = 0.01m; // Minimum 0.01 per claim
|
||||
|
||||
var calculatedAmount = Math.Max(fund.RemainingAmount * percentagePerClaim, minimumAmount);
|
||||
return Math.Min(calculatedAmount, fund.RemainingAmount);
|
||||
// Calculate amount per split: TotalAmount / AmountOfSplits
|
||||
var amountPerSplit = fund.TotalAmount / fund.AmountOfSplits;
|
||||
return Math.Max(amountPerSplit, 0.01m); // Minimum 0.01 per claim
|
||||
}
|
||||
// For closed mode funds: use split type calculation
|
||||
else
|
||||
|
||||
@@ -254,6 +254,7 @@ public class WalletController(
|
||||
[Required] public List<Guid> RecipientAccountIds { get; set; } = new();
|
||||
[Required] public string Currency { get; set; } = null!;
|
||||
[Required] public decimal TotalAmount { get; set; }
|
||||
[Required] public int AmountOfSplits { get; set; }
|
||||
[Required] public FundSplitType SplitType { get; set; }
|
||||
public string? Message { get; set; }
|
||||
public int? ExpirationHours { get; set; } // Optional: hours until expiration
|
||||
@@ -283,6 +284,7 @@ public class WalletController(
|
||||
recipientAccountIds: request.RecipientAccountIds,
|
||||
currency: request.Currency,
|
||||
totalAmount: request.TotalAmount,
|
||||
amountOfSplits: request.AmountOfSplits,
|
||||
splitType: request.SplitType,
|
||||
message: request.Message,
|
||||
expiration: expiration
|
||||
@@ -395,4 +397,4 @@ public class WalletController(
|
||||
return BadRequest(err.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,10 +86,11 @@ public class SnWalletFund : ModelBase
|
||||
[MaxLength(128)] public string Currency { get; set; } = null!;
|
||||
public decimal TotalAmount { get; set; }
|
||||
public decimal RemainingAmount { get; set; }
|
||||
public int AmountOfSplits { get; set; }
|
||||
public FundSplitType SplitType { get; set; }
|
||||
public FundStatus Status { get; set; } = FundStatus.Created;
|
||||
[MaxLength(4096)] public string? Message { get; set; }
|
||||
public bool IsOpen { get; set; } = false;
|
||||
public bool IsOpen { get; set; }
|
||||
|
||||
// Creator
|
||||
public Guid CreatorAccountId { get; set; }
|
||||
@@ -119,7 +120,9 @@ public class SnWalletFund : ModelBase
|
||||
Id = Guid.Parse(proto.Id),
|
||||
Currency = proto.Currency,
|
||||
TotalAmount = decimal.Parse(proto.TotalAmount),
|
||||
RemainingAmount = proto.RemainingAmount is not null ? decimal.Parse(proto.RemainingAmount) : decimal.Parse(proto.TotalAmount),
|
||||
RemainingAmount = proto.RemainingAmount is not null
|
||||
? decimal.Parse(proto.RemainingAmount)
|
||||
: decimal.Parse(proto.TotalAmount),
|
||||
SplitType = (FundSplitType)proto.SplitType,
|
||||
Status = (FundStatus)proto.Status,
|
||||
Message = proto.Message,
|
||||
|
||||
Reference in New Issue
Block a user