Skip to content

Commit

Permalink
feat: Show fee rebate on order matching fee
Browse files Browse the repository at this point in the history
  • Loading branch information
holzeis committed Apr 11, 2024
1 parent 158cc5b commit 6605dbb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
23 changes: 22 additions & 1 deletion mobile/lib/features/trade/trade_bottom_sheet_confirmation.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:get_10101/common/application/tentenone_config_change_notifier.dart';
import 'package:get_10101/common/dlc_channel_change_notifier.dart';
import 'package:get_10101/common/dlc_channel_service.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -149,6 +150,8 @@ class TradeBottomSheetConfirmation extends StatelessWidget {
TradeValues tradeValues =
Provider.of<TradeValuesChangeNotifier>(context).fromDirection(direction);

final referralStatus = context.read<TenTenOneConfigChangeNotifier>().referalStatus;

bool isClose = tradeAction == TradeAction.closePosition;
bool isChannelOpen = tradeAction == TradeAction.openChannel;

Expand All @@ -173,6 +176,12 @@ class TradeBottomSheetConfirmation extends StatelessWidget {

TextStyle dataRowStyle = const TextStyle(fontSize: 14);

final orderMatchingFee = tradeValues.fee ?? Amount.zero();
final feeRebate = referralStatus != null
? Amount((referralStatus.referralFeeBonus * orderMatchingFee.sats).ceil())
: Amount.zero();
final feeBeforeRebate = orderMatchingFee + feeRebate;

return Container(
padding: EdgeInsets.only(left: 20, right: 20, top: (isClose ? 20 : 10), bottom: 10),
child: Column(
Expand Down Expand Up @@ -215,9 +224,21 @@ class TradeBottomSheetConfirmation extends StatelessWidget {
),
ValueDataRow(
type: ValueType.amount,
value: tradeValues.fee ?? Amount.zero(),
value: feeBeforeRebate,
label: "Order-matching fee",
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Fee rebate (${(referralStatus!.referralFeeBonus * 100.0).toStringAsFixed(0)}%)",
style: const TextStyle(color: Colors.green)),
Text(
"-$feeRebate",
style: const TextStyle(color: Colors.green),
)
]),
isChannelOpen
? ValueDataRow(
type: ValueType.amount,
Expand Down
60 changes: 45 additions & 15 deletions mobile/lib/features/trade/trade_bottom_sheet_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
Wrap buildChildren(Direction direction, rust.TradeConstraints channelTradeConstraints,
BuildContext context, ChannelInfoService channelInfoService, GlobalKey<FormState> formKey) {
final tradeValues = context.watch<TradeValuesChangeNotifier>().fromDirection(direction);
final referralStatus = context.read<TenTenOneConfigChangeNotifier>().referalStatus;

bool hasPosition = positionChangeNotifier.positions.containsKey(contractSymbol);

Expand Down Expand Up @@ -304,23 +305,52 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
context.read<TradeValuesChangeNotifier>().updateLeverage(direction, Leverage(value));
formKey.currentState?.validate();
}),
Row(
Column(
children: [
Selector<TradeValuesChangeNotifier, double>(
selector: (_, provider) =>
provider.fromDirection(direction).liquidationPrice ?? 0.0,
builder: (context, liquidationPrice, child) {
return ValueDataRow(
type: ValueType.fiat, value: liquidationPrice, label: "Liquidation:");
}),
const SizedBox(width: 55),
Selector<TradeValuesChangeNotifier, Amount>(
selector: (_, provider) => provider.orderMatchingFee(direction) ?? Amount.zero(),
builder: (context, fee, child) {
return ValueDataRow(type: ValueType.amount, value: fee, label: "Fee:");
}),
Row(
children: [
Selector<TradeValuesChangeNotifier, double>(
selector: (_, provider) =>
provider.fromDirection(direction).liquidationPrice ?? 0.0,
builder: (context, liquidationPrice, child) {
return ValueDataRow(
type: ValueType.fiat, value: liquidationPrice, label: "Liquidation:");
}),
const SizedBox(width: 55),
Selector<TradeValuesChangeNotifier, Amount>(
selector: (_, provider) =>
provider.orderMatchingFee(direction) ?? Amount.zero(),
builder: (context, fee, child) {
final feeRebate = referralStatus != null
? Amount((referralStatus.referralFeeBonus * fee.sats).ceil())
: Amount.zero();
final feeBeforeRebate = fee + feeRebate;
return Flexible(
child: ValueDataRow(
type: ValueType.amount, value: feeBeforeRebate, label: "Fee:"));
}),
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Fee rebate (${(referralStatus!.referralFeeBonus * 100.0).toStringAsFixed(0)}%):",
style: const TextStyle(color: Colors.green)),
Selector<TradeValuesChangeNotifier, Amount>(
selector: (_, provider) =>
provider.orderMatchingFee(direction) ?? Amount.zero(),
builder: (context, fee, child) {
return Text(
"-${Amount((referralStatus.referralFeeBonus * fee.sats).ceil())}",
style: const TextStyle(color: Colors.green),
);
}),
],
),
],
)
),
],
);
}
Expand Down

0 comments on commit 6605dbb

Please sign in to comment.