Skip to content

Commit

Permalink
refactor(app): Use direction variable
Browse files Browse the repository at this point in the history
  • Loading branch information
luckysori committed Jul 5, 2023
1 parent 74a0acf commit 1e25231
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions mobile/lib/features/trade/trade_bottom_sheet_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
Amount maxChannelCapacity = channelInfoService.getMaxCapacity();
Amount initialReserve = channelInfoService.getInitialReserve();

String label = widget.direction == Direction.long ? "Buy" : "Sell";
Color color = widget.direction == Direction.long ? tradeTheme.buy : tradeTheme.sell;
Direction direction = widget.direction;

String label = direction == Direction.long ? "Buy" : "Sell";
Color color = direction == Direction.long ? tradeTheme.buy : tradeTheme.sell;

Amount channelReserve = channelInfo?.reserve ?? initialReserve;
int totalReserve = channelReserve.sats + tradeFeeReserve.sats;
Expand Down Expand Up @@ -131,7 +133,7 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
),
),
Selector<TradeValuesChangeNotifier, double>(
selector: (_, provider) => provider.fromDirection(widget.direction).price ?? 0,
selector: (_, provider) => provider.fromDirection(direction).price ?? 0,
builder: (context, price, child) {
return DoubleTextInputFormField(
value: price,
Expand All @@ -145,8 +147,7 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
children: [
Flexible(
child: Selector<TradeValuesChangeNotifier, double>(
selector: (_, provider) =>
provider.fromDirection(widget.direction).quantity ?? 0.0,
selector: (_, provider) => provider.fromDirection(direction).quantity ?? 0.0,
builder: (context, quantity, child) {
return DoubleTextInputFormField(
value: quantity,
Expand All @@ -162,11 +163,11 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
double quantity = double.parse(value);
context
.read<TradeValuesChangeNotifier>()
.updateQuantity(widget.direction, quantity);
.updateQuantity(direction, quantity);
} on Exception {
context
.read<TradeValuesChangeNotifier>()
.updateQuantity(widget.direction, 0);
.updateQuantity(direction, 0);
}
},
);
Expand All @@ -179,7 +180,7 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
Flexible(
child: Selector<TradeValuesChangeNotifier, Amount>(
selector: (_, provider) =>
provider.fromDirection(widget.direction).margin ?? Amount(0),
provider.fromDirection(direction).margin ?? Amount(0),
builder: (context, margin, child) {
return AmountInputField(
value: margin,
Expand All @@ -195,11 +196,11 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
Amount margin = Amount.parse(value);
context
.read<TradeValuesChangeNotifier>()
.updateMargin(widget.direction, margin);
.updateMargin(direction, margin);
} on Exception {
context
.read<TradeValuesChangeNotifier>()
.updateMargin(widget.direction, Amount.zero());
.updateMargin(direction, Amount.zero());
}
},
validator: (value) {
Expand All @@ -210,8 +211,7 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
try {
int margin = int.parse(value);

int? optCounterPartyMargin =
provider.counterpartyMargin(widget.direction);
int? optCounterPartyMargin = provider.counterpartyMargin(direction);
if (optCounterPartyMargin == null) {
return "Counterparty margin not available";
}
Expand Down Expand Up @@ -264,21 +264,21 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
LeverageSlider(
initialValue: context
.read<TradeValuesChangeNotifier>()
.fromDirection(widget.direction)
.fromDirection(direction)
.leverage
.leverage,
onLeverageChanged: (value) {
context
.read<TradeValuesChangeNotifier>()
.updateLeverage(widget.direction, Leverage(value));
.updateLeverage(direction, Leverage(value));
}),
Row(
children: [
const Flexible(child: Text("Liquidation Price:")),
const SizedBox(width: 5),
Selector<TradeValuesChangeNotifier, double>(
selector: (_, provider) =>
provider.fromDirection(widget.direction).liquidationPrice ?? 0.0,
provider.fromDirection(direction).liquidationPrice ?? 0.0,
builder: (context, liquidationPrice, child) {
return Flexible(child: FiatText(amount: liquidationPrice));
}),
Expand All @@ -294,11 +294,11 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
onPressed: () {
if (_formKey.currentState!.validate()) {
TradeValues tradeValues =
context.read<TradeValuesChangeNotifier>().fromDirection(widget.direction);
context.read<TradeValuesChangeNotifier>().fromDirection(direction);
final submitOrderChangeNotifier = context.read<SubmitOrderChangeNotifier>();
tradeBottomSheetConfirmation(
context: context,
direction: widget.direction,
direction: direction,
onConfirmation: () {
submitOrderChangeNotifier.submitPendingOrder(
tradeValues, PositionAction.open);
Expand Down

0 comments on commit 1e25231

Please sign in to comment.