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

Fund channel flow #2544

Merged
merged 5 commits into from
May 22, 2024
Merged

Fund channel flow #2544

merged 5 commits into from
May 22, 2024

Conversation

bonomat
Copy link
Contributor

@bonomat bonomat commented May 16, 2024

Ready for review :)

@bonomat bonomat force-pushed the feat/on-boarding-dialog branch 2 times, most recently from 92ccceb to 33202e7 Compare May 16, 2024 06:01
@bonomat

This comment was marked as outdated.

bonomat added 3 commits May 20, 2024 11:43
We know if finished syncing because `syncing` is `false` and the screen will finish reloading.
@bonomat bonomat force-pushed the feat/on-boarding-dialog branch from c2c1b98 to 4868b9d Compare May 20, 2024 06:22
@bonomat
Copy link
Contributor Author

bonomat commented May 20, 2024

Final version before review :)

Simulator.Screen.Recording.-.iPhone.15.Plus.-.2024-05-20.at.16.25.03.mp4

@bonomat bonomat marked this pull request as ready for review May 20, 2024 06:25
@bonomat bonomat requested review from holzeis and luckysori May 20, 2024 06:25
mobile/native/src/api.rs Outdated Show resolved Hide resolved
mobile/native/src/api.rs Outdated Show resolved Hide resolved
mobile/native/src/event/api.rs Show resolved Hide resolved
mobile/native/src/event/api.rs Show resolved Hide resolved
Column buildInfoBox(FundingChannelTaskStatus? value, FundinType selectedBox) {
String transactionStatusText = "Waiting for payment...";
String transactionStatusInformationText =
"Please wait. If you leave now, your position won’t be opened when the funds arrive.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 if the user would want to switch to another app to send the onchain funds this message might be misleading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be. Do you have a proposal to change this?

@holzeis
Copy link
Contributor

holzeis commented May 20, 2024

❓ It's a bit weird to me that one jumps from the modal to a screen. What do you think about showing the new screens also as modals?

@holzeis
Copy link
Contributor

holzeis commented May 20, 2024

❓ Did you test this with smaller devices?

@holzeis
Copy link
Contributor

holzeis commented May 20, 2024

❓ Do we still need to show the QR code when the trade is executing? I think I would prefer if the user sees directly the position tab.

children: [
TextSpan(
text:
"🔔 This is your first trade and you do not have a channel yet. "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the video this is very hard to read. I also think its too much text, maybe the title is enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to propose something else :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the title is enough?

😅

value: ownTotalCollateral,
label: 'Channel size'),
FeeExpansionTile(
label: "Fee*",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 The asterix isn't pointing to anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, I wanted to indicate that one can click on it.

@bonomat
Copy link
Contributor Author

bonomat commented May 21, 2024

❓ It's a bit weird to me that one jumps from the modal to a screen. What do you think about showing the new screens also as modals?

I agree, I switched to an extra screen because the modals were a pita to design.

@bonomat
Copy link
Contributor Author

bonomat commented May 21, 2024

❓ Did you test this with smaller devices?

Yes, tested iPhone SE and looks ok.

@bonomat
Copy link
Contributor Author

bonomat commented May 21, 2024

❓ Do we still need to show the QR code when the trade is executing? I think I would prefer if the user sees directly the position tab.

Probably not. I think there is lots we could improve. For example, I wouldn't show the popup dialog here at all but it's kinda impossible to control 😬

@bonomat bonomat force-pushed the feat/on-boarding-dialog branch 3 times, most recently from 6bbb5c0 to 5143cd9 Compare May 21, 2024 10:48
Copy link
Contributor

@luckysori luckysori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I did not delve into the Flutter code, but the screens look like a good starting point!

tracing::error!(
txid = tx.txid.to_string(),
address = address.to_string(),
"Output not found. This should not happen, but if, it indicates something is wrong.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Output not found. This should not happen, but if, it indicates something is wrong.");
"Output not found. This should not happen, but if it does, it indicates something is wrong.");

@@ -125,6 +129,7 @@ impl Subscriber for FlutterSubscriber {
EventType::ServiceHealthUpdate,
EventType::ChannelStatusUpdate,
EventType::BackgroundNotification,
EventType::FundingChannelNotification,
Copy link
Contributor

@luckysori luckysori May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only spent 1 hour yesterday debugging because I forgot to add my new EventType ❤️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to hear ... this literally happened to me as well :/

@@ -36,3 +36,4 @@ pub use report_error::report_error_to_coordinator;
)]
mod bridge_generated;
mod position;
pub mod unfunded_orders;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃 Should go with the other pub mods in this file.

@@ -126,7 +139,7 @@ pub fn max_quantity(
Ok(max_quantity)
}

/// Calculates the max quantity for the given input parameters. If an on-chai fee estimate is
/// Calculates the max quantity. If an on-chai fee estimate is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Calculates the max quantity. If an on-chai fee estimate is
/// Calculates the max quantity. If an on-chain fee estimate is

use std::time::Duration;
use xxi_node::commons::ChannelOpeningParams;

pub(crate) async fn submit_unfunded_channel_opening_order(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃 Every channel that is not yet open is unfunded. We could go for submit_unfunded_wallet_channel_opening_order or submit_channel_opening_order_without_utxos.

Comment on lines 28 to 30
event::publish(&EventInternal::FundingChannelNotification(
FundingChannelTask::Pending,
));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Why do you need to send Pending so many times?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question 🙈

if let Err(error) = bdk_node.sync_on_chain_wallet().await {
tracing::error!("Failed at syncing wallet {error:?}")
}

let balance = bdk_node.get_on_chain_balance();
tracing::debug!(balance = balance.to_string(), "Wallet synced");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 The second log message can contradict the first one.

Should we just loop until the on-chain balance is enough? We confirmed that the UTXOs are there, but we can also confirm that the balance is up to date.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could try to do it without the manual sync. It might not be necessary if we have broken out of the loop above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured syncing the wallet is more expensive than looking up just a single address. But you are right, this would be an alternative.

Alternatively, we could try to do it without the manual sync. It might not be necessary if we have broken out of the loop above.

Unfortunately we need to sync the wallet once we found the address holds enough funds as otherwise we might fail later on because the wallet thinks it doesn't have enough funds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured syncing the wallet is more expensive than looking up just a single address. But you are right, this would be an alternative.

Right. My first suggestion was to sync in a loop after the first loop has exited successfully. In theory, you only need to sync once, but there is an error path that we are currently just logging. I think if we fail to sync we want to keep trying until the UTXOs that we think should be there appear in the wallet.

Unfortunately we need to sync the wallet once we found the address holds enough funds as otherwise we might fail later on because the wallet thinks it doesn't have enough funds.

Okay, so one successful sync is necessary.

}
.remote_handle();

// We need to store the handler which will drop any old handler if present.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// We need to store the handler which will drop any old handler if present.
// We need to store the handle which will drop any old handle if present.

We introduce a new flow to fund the first position and with it the first channel. The idea is that the user does not have to have any on-chain funds before opening the first position.
The flow is divided into two parts:
1) open a position using on-chain funds:
if the user has already on-chain funds, then he can opt to use said funds and open the channel immediately
2) open a position using external funds:
the user has the option to fund the wallet using an external wallet such as a lightning wallet, another on-chain wallet, or maybe even using a hardware wallet in the future.
In this patch, we only introduce funding using an on-chain transaction. The app waits until it sees the funds incoming and then proceeds with the channel creation.
We can't navigate using the mocked router (I don't understand why). Which means, we can't navigate to the new channel configuration flow.
Because of this, I've split up the tests into more fine granular tests. We test now each widget separately.
This has the advantage that our tests are smaller and easier to understand.
It seems like that if we want to test navigation, we should write integration tests instead.
@bonomat bonomat force-pushed the feat/on-boarding-dialog branch from 5143cd9 to ef42084 Compare May 22, 2024 05:51
@bonomat bonomat enabled auto-merge May 22, 2024 05:51
@bonomat bonomat added this pull request to the merge queue May 22, 2024
Merged via the queue into main with commit 10aff81 May 22, 2024
22 checks passed
@bonomat bonomat deleted the feat/on-boarding-dialog branch May 22, 2024 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants