Skip to content

Commit

Permalink
feat: Implement the calculation of tokens amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
nbetsaif committed Sep 26, 2024
1 parent 095ac10 commit dd3f621
Show file tree
Hide file tree
Showing 2 changed files with 361 additions and 290 deletions.
45 changes: 32 additions & 13 deletions lib/core/extension/proposal_details_model_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import 'package:hypha_wallet/core/network/models/proposal_details_model.dart';
import 'package:intl/intl.dart';

extension ProposalDetailsModelExtension on ProposalDetailsModel {
double tokenMixToPercent() => tokenMixPercentage == null ? 0 : tokenMixPercentage! * .01;
double tokenMixToPercent() =>
tokenMixPercentage == null ? 0 : tokenMixPercentage! * .01;

String formatCycleStartDate() => cycleStartDate != null ? DateFormat('EEEE, MMMM yyyy').format(cycleStartDate!) : '';
String formatCycleStartDate() => cycleStartDate != null
? DateFormat('EEEE, MMMM yyyy').format(cycleStartDate!)
: '';

String cycleEndDate() => DateFormat('EEEE, MMMM yyyy').format(cycleStartDate!.add(Duration(days: cycleCount! * 7)));
String cycleEndDate() => DateFormat('EEEE, MMMM yyyy')
.format(cycleStartDate!.add(Duration(days: cycleCount! * 7)));

String? tokenTitle(int index) {
String input;
Expand Down Expand Up @@ -39,27 +43,42 @@ extension ProposalDetailsModelExtension on ProposalDetailsModel {
return null;
}

// TODO(Saif): adjust this function
String? tokenValue(int index, bool isOneCycleRewardsShown) {
String input;
String? input;
String? perPeriodInput;

switch (index) {
case 0:
input = utilityAmount ?? utilityAmountPerPeriod!;
input = utilityAmount;
perPeriodInput = utilityAmountPerPeriod;
break;
case 1:
input = voiceAmount ?? voiceAmountPerPeriod!;
input = voiceAmount;
perPeriodInput = voiceAmountPerPeriod;
break;
case 2:
input = cashAmount ?? cashAmountPerPeriod!;
input = cashAmount;
perPeriodInput = cashAmountPerPeriod;

break;
default:
return null;
}

final RegExp regExp = RegExp(r'(\S+)\s');
final match = regExp.firstMatch(input);

return match?.group(1);
final RegExp regExp = RegExp(r'(\d+(\.\d+)?)');
if (input != null) {
final match = regExp.firstMatch(input);
if (isOneCycleRewardsShown || cycleCount == 1) return match?.group(1);
return (double.parse((match?.group(1))!) * cycleCount!)
.toStringAsFixed(3);
}
if (perPeriodInput != null) {
final match = regExp.firstMatch(perPeriodInput);
if (isOneCycleRewardsShown && cycleCount != 1) {
return (double.parse((match?.group(1))!) / cycleCount!)
.toStringAsFixed(3);
}
return match?.group(1);
}
return input;
}
}
Loading

0 comments on commit dd3f621

Please sign in to comment.