Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent multiple next button clicks #2572

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class _ChannelConfiguration extends State<ChannelConfiguration> {
/// funded positions.
final minTraderReserveSats = 15000;

bool externalFundingChannelButtonPressed = false;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -426,52 +428,67 @@ class _ChannelConfiguration extends State<ChannelConfiguration> {
child: Visibility(
visible: useInnerWallet,
replacement: Padding(
padding: const EdgeInsets.only(top: 1, left: 8, right: 8, bottom: 8),
child: ElevatedButton(
key: tradeScreenBottomSheetChannelConfigurationConfirmButton,
onPressed: _formKey.currentState != null &&
_formKey.currentState!.validate()
? () async {
logger.d(
"Submitting an order with ownTotalCollateral: $ownTotalCollateral orderMatchingFee: $orderMatchingFee, fundingTxFee: $fundingTxFee, channelFeeReserve: $channelFeeReserve, counterpartyCollateral: $counterpartyCollateral, ownMargin: ${widget.tradeValues.margin}");

// TODO(holzeis): The coordinator leverage should not be hard coded here.
final coordinatorCollateral =
widget.tradeValues.calculateMargin(Leverage(2.0));

final coordinatorReserve = max(
0, counterpartyCollateral.sub(coordinatorCollateral).sats);
final traderReserve = max(minTraderReserveSats,
ownTotalCollateral.sub(widget.tradeValues.margin!).sats);

await submitOrderChangeNotifier
.submitUnfundedOrder(
widget.tradeValues,
ChannelOpeningParams(
coordinatorReserve: Amount(coordinatorReserve),
traderReserve: Amount(traderReserve)))
.then((ExternalFunding funding) {
GoRouter.of(context).push(ChannelFundingScreen.route, extra: {
"funding": funding,
"amount": totalAmountToBeFunded
});
}).onError((error, stackTrace) {
logger.e("Failed at submitting unfunded order $error");
final messenger = ScaffoldMessenger.of(context);
showSnackBar(
messenger, "Failed creating order ${error.toString()}");
});
}
: null,
style: ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(50),
backgroundColor: tenTenOnePurple),
child: const Text(
"Next",
style: TextStyle(color: Colors.white),
),
),
),
padding: const EdgeInsets.only(top: 1, left: 8, right: 8, bottom: 8),
child: ElevatedButton.icon(
key: tradeScreenBottomSheetChannelConfigurationConfirmButton,
onPressed: _formKey.currentState != null &&
_formKey.currentState!.validate() &&
!externalFundingChannelButtonPressed
? () async {
logger.d(
"Submitting an order with ownTotalCollateral: $ownTotalCollateral orderMatchingFee: $orderMatchingFee, fundingTxFee: $fundingTxFee, channelFeeReserve: $channelFeeReserve, counterpartyCollateral: $counterpartyCollateral, ownMargin: ${widget.tradeValues.margin}");

setState(() => externalFundingChannelButtonPressed = true);

// TODO(holzeis): The coordinator leverage should not be hard coded here.
final coordinatorCollateral =
widget.tradeValues.calculateMargin(Leverage(2.0));

final coordinatorReserve = max(0,
counterpartyCollateral.sub(coordinatorCollateral).sats);
final traderReserve = max(
minTraderReserveSats,
ownTotalCollateral
.sub(widget.tradeValues.margin!)
.sats);

await submitOrderChangeNotifier
.submitUnfundedOrder(
widget.tradeValues,
ChannelOpeningParams(
coordinatorReserve: Amount(coordinatorReserve),
traderReserve: Amount(traderReserve)))
.then((ExternalFunding funding) {
externalFundingChannelButtonPressed = false;
GoRouter.of(context).push(ChannelFundingScreen.route,
extra: {
"funding": funding,
"amount": totalAmountToBeFunded
});
}).onError((error, stackTrace) {
setState(
() => externalFundingChannelButtonPressed = false);
logger.e("Failed at submitting unfunded order $error");
final messenger = ScaffoldMessenger.of(context);
showSnackBar(messenger,
"Failed creating order ${error.toString()}");
});
}
: null,
icon: externalFundingChannelButtonPressed
? const SizedBox(
width: 15,
height: 15,
child: CircularProgressIndicator(
color: Colors.white, strokeWidth: 2))
: Container(),
label: const Text(
"Next",
style: TextStyle(color: Colors.white),
),
style: ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(50),
disabledBackgroundColor: tenTenOnePurple.shade200))),
child: Padding(
padding: const EdgeInsets.only(top: 1, left: 8, right: 8, bottom: 8),
child: ConfirmationSlider(
Expand Down
Loading