Skip to content

Commit 74ffe25

Browse files
Copilotdangershony
andauthored
Fix release schedule percentages and miner fee estimate in Avalonia invest view (block-core#681)
* Initial plan * Fix release schedule percentages and miner fee in Avalonia invest view Co-authored-by: dangershony <7487930+dangershony@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dangershony <7487930+dangershony@users.noreply.github.com>
1 parent 8d38bd0 commit 74ffe25

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/Angor/Avalonia/Angor.Sdk/Funding/Services/DocumentProjectService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public async Task<Result<IEnumerable<Project>>> GetAllAsync(params ProjectId[] i
8888
{
8989
Index = i,
9090
ReleaseDate = stage.ReleaseDate,
91-
RatioOfTotal = stage.AmountToRelease
91+
RatioOfTotal = stage.AmountToRelease / 100m
9292
}),
9393
StartingDate = info.StartDate,
9494
EndDate = info.EndDate,

src/Angor/Avalonia/AngorApp/UI/Flows/InvestV2/InvestViewModel.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ IWalletContext walletContext
4848
StageBreakdowns = this.WhenAnyValue(model => model.AmountToInvest)
4949
.CombineLatest(this.WhenAnyValue(model => model.SelectedPattern),
5050
(amount, pattern) => GetStageBreakdowns(fullProject, amount, pattern));
51-
Details = this.WhenAnyValue(model => model.AmountToInvest).Select(GetTransactionDetails);
51+
Details = this.WhenAnyValue(model => model.AmountToInvest)
52+
.CombineLatest(this.WhenAnyValue(model => model.SelectedPattern),
53+
(amount, pattern) => GetTransactionDetails(fullProject, amount, pattern));
5254
IsValid = this.WhenAnyValue(model => model.AmountToInvest).NotNull();
5355
}
5456

@@ -168,15 +170,28 @@ private static DateTimeOffset ComputeSpecificDayOfWeek(DateTimeOffset startDate,
168170
return target.AddDays(diff);
169171
}
170172

171-
private static TransactionDetails GetTransactionDetails(IAmountUI? amount)
173+
private static TransactionDetails GetTransactionDetails(IFullProject fullProject, IAmountUI? amount, DynamicStagePattern? pattern)
172174
{
173175
if (amount == null)
174176
{
175177
return TransactionDetails.Empty();
176178
}
177179

180+
int stageCount = pattern != null && fullProject.ProjectType is ProjectType.Fund or ProjectType.Subscribe
181+
? pattern.StageCount
182+
: fullProject.Stages.Count();
183+
184+
// Estimate transaction virtual size:
185+
// overhead + 1 P2WPKH input + Angor fee output + N stage outputs + change output
186+
const int txOverhead = 10;
187+
const int inputSize = 68; // P2WPKH input
188+
const int outputSize = 31; // P2WPKH output
189+
const int defaultFeeRateSatsPerVByte = 1;
190+
int estimatedVSize = txOverhead + inputSize + (stageCount + 2) * outputSize;
191+
long minerFeeSats = estimatedVSize * defaultFeeRateSatsPerVByte;
192+
178193
AmountUI angorFee = new((long)Math.Ceiling(amount.Sats * 0.01));
179-
return new TransactionDetails(amount, new AmountUI(0), angorFee);
194+
return new TransactionDetails(amount, new AmountUI(minerFeeSats), angorFee);
180195
}
181196
}
182197
}

0 commit comments

Comments
 (0)