-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2342 from get10101/feat/web-open-channel-dialog
feat(webapp): Create DLC Channel Dialog
- Loading branch information
Showing
50 changed files
with
915 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
webapp/frontend/lib/change_notifier/trade_constraint_change_notifier.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_10101/logger/logger.dart'; | ||
import 'package:get_10101/services/trade_constraints_service.dart'; | ||
|
||
class TradeConstraintsChangeNotifier extends ChangeNotifier { | ||
final TradeConstraintsService service; | ||
|
||
TradeConstraints? _tradeConstraints; | ||
|
||
TradeConstraintsChangeNotifier(this.service) { | ||
_refresh(); | ||
} | ||
|
||
void _refresh() async { | ||
try { | ||
final tradeConstraints = await service.getTradeConstraints(); | ||
_tradeConstraints = tradeConstraints; | ||
super.notifyListeners(); | ||
} catch (error) { | ||
logger.e(error); | ||
} | ||
} | ||
|
||
TradeConstraints? get tradeConstraints => _tradeConstraints; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_10101/common/color.dart'; | ||
import 'package:get_10101/common/model.dart'; | ||
|
||
class AmountTextField extends StatefulWidget { | ||
const AmountTextField( | ||
{super.key, required this.label, required this.value, this.suffixIcon, this.error}); | ||
|
||
final Amount value; | ||
final String label; | ||
final Widget? suffixIcon; | ||
final String? error; | ||
|
||
@override | ||
State<AmountTextField> createState() => _AmountTextState(); | ||
} | ||
|
||
class _AmountTextState extends State<AmountTextField> { | ||
@override | ||
Widget build(BuildContext context) { | ||
String value = widget.value.formatted(); | ||
|
||
return InputDecorator( | ||
decoration: InputDecoration( | ||
contentPadding: const EdgeInsets.fromLTRB(12, 24, 12, 17), | ||
border: const OutlineInputBorder(), | ||
labelText: widget.label, | ||
labelStyle: const TextStyle(color: Colors.black87), | ||
errorStyle: TextStyle( | ||
color: Colors.red[900], | ||
), | ||
errorText: widget.error, | ||
filled: true, | ||
suffixIcon: widget.suffixIcon, | ||
fillColor: tenTenOnePurple.shade50.withOpacity(0.3)), | ||
child: Text(value, style: const TextStyle(fontSize: 16)), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:get_10101/common/model.dart'; | ||
import 'package:get_10101/services/quote_service.dart'; | ||
|
||
Amount calculateFee(Usd? quantity, BestQuote? quote, bool isLong) { | ||
if (quote?.fee == null || quote?.fee == 0 || quantity == null) { | ||
return Amount.zero(); | ||
} | ||
|
||
return Amount( | ||
(calculateMargin(quantity, quote!, Leverage.one(), isLong).sats * quote.fee!).toInt()); | ||
} | ||
|
||
Amount calculateMargin(Usd quantity, BestQuote quote, Leverage leverage, bool isLong) { | ||
if (isLong && quote.ask != null) { | ||
if (quote.ask!.asDouble == 0) { | ||
return Amount.zero(); | ||
} | ||
return Amount.fromBtc(quantity.asDouble / (quote.ask!.asDouble * leverage.asDouble)); | ||
} else if (!isLong && quote.bid != null) { | ||
if (quote.bid!.asDouble == 0) { | ||
return Amount.zero(); | ||
} | ||
return Amount.fromBtc(quantity.asDouble / (quote.bid!.asDouble * leverage.asDouble)); | ||
} else { | ||
return Amount.zero(); | ||
} | ||
} | ||
|
||
Amount calculateLiquidationPrice( | ||
Usd quantity, BestQuote quote, Leverage leverage, double maintenanceMargin, bool isLong) { | ||
if (isLong && quote.ask != null) { | ||
return Amount((quote.bid!.asDouble * leverage.asDouble) ~/ | ||
(leverage.asDouble + 1.0 + (maintenanceMargin * leverage.asDouble))); | ||
} else if (!isLong && quote.bid != null) { | ||
return Amount((quote.ask!.asDouble * leverage.asDouble) ~/ | ||
(leverage.asDouble - 1.0 + (maintenanceMargin * leverage.asDouble))); | ||
} else { | ||
return Amount.zero(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.