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

feat: bitcoin regtest network option #4270

Merged
merged 3 commits into from
Nov 21, 2023

Conversation

Polybius93
Copy link
Collaborator

@Polybius93 Polybius93 commented Sep 26, 2023

Try out this version of Leather — download extension builds.

We have added a Bitcoin regtest option to the 'Add Network' function. This new feature allows you to add Bitcoin network alongside the Stacks networks.

This feature allows the user to add and use Bitcoin regtest networks, which can be much faster Testnet.

Currently when you add a Bitcoin network, the associated Stacks network will be Stacks Testnet.

@markmhendrickson markmhendrickson added Enhancement 💡 enhancement-p2 Critical functionality needed by few users, with no clear alternatives area:networks area:dlcs labels Sep 26, 2023
@Polybius93 Polybius93 force-pushed the feat/bitcoin-regtest-network-option branch 2 times, most recently from 500282b to 842f90d Compare September 26, 2023 13:54
<Stack justifyContent={'center'}>
<LeatherButton
onClick={() => setBlockchain('stacks')}
backgroundColor={
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you post a screenshot of these UI changes? There are variants of the LeatherButton to use here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, here you go:
Screenshot 2023-09-26 at 16 59 03

Copy link
Collaborator

Choose a reason for hiding this comment

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

These would better be tabs than buttons. You can reuse the tabs from the homepage

Copy link
Collaborator

Choose a reason for hiding this comment

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

Although, wouldn't it be better to have this all on the same page, seeing as you need them all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So these buttons won't take you to another page, it just changes the blockchain variable. So if you click Bitcoin, you'll add a Bitcoin network with this form.

@@ -165,6 +233,7 @@ export function AddNetwork() {
placeholder="Key"
value={values.key}
width="100%"
isDisabled={blockchain === 'bitcoin' ? true : false}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need the ternary here? The boolean itself will be true/false?

@kyranjamie
Copy link
Collaborator

@fabric-8 @mica000 are you able to provide to general design guidance for this feature we'd like to get into production?

The gist here is that @Polybius93, and many other developers, need to be able to target different network types, such as regtest. Our current UI doesn't support this, and a solution would valuable for many devs. As this is a developer-only feature, we don't need to finesse this particular part of the app, but think some feedback would still go a long way.

@Polybius93 for the designer to best help, can you please describe the problem this solves, and what the minimum requirements to fix the problem. I find the buttons added here a little confusing, plus I also don't understand why you don't need to fill in all the fields. Wouldn't a network type select here work too?

@fabric-8
Copy link
Contributor

A segmented control would be pretty good here! (figma mockup)

While doing a quick mockup I also noticed that we aren't "containerizing" the contents in fullpage view. Do I remember correctly that this is something @pete-watters is looking into as part of the broader brand refinement work? 😅

image

@Polybius93
Copy link
Collaborator Author

@kyranjamie @fabric-8 @mica000

Hello!

In the current dev branch, the "add network" feature only allows users to add a new Stacks network. Afterwards, it associates a Bitcoin network constant with it (either Mainnet or Testnet). However, the network slice and its PersistedNetworkConfiguration are not prepared to handle a custom Bitcoin network.

This PR addresses the issue by enabling users to choose whether they want to add a new Stacks or Bitcoin network. If the user selects a Bitcoin network, the key field is disabled and automatically set to "bitcoin-regtest" for differentiation in the network converting logic.

The logic for adding Stacks networks remains unchanged, as it will still select a corresponding Bitcoin network. Additionally, when adding a Bitcoin network, the Stacks Testnet network is automatically made available alongside it.

Ideally, users should be able to set both Stacks and Bitcoin networks at the same time. However, I have not yet found an easy solution for this. There may be possible ways to modify the objects and functions involved to handle both scenarios effectively.

@markmhendrickson markmhendrickson assigned mica000 and unassigned mica000 Oct 2, 2023
@fabric-8
Copy link
Contributor

fabric-8 commented Oct 9, 2023

CleanShot 2023-10-09 at 11 54 01

Thanks for the summary @Polybius93! Here's a design proposal (Figma), WDYT?

@Polybius93
Copy link
Collaborator Author

CleanShot 2023-10-09 at 11 54 01 CleanShot 2023-10-09 at 11 54 01

Thanks for the summary @Polybius93! Here's a design proposal (Figma), WDYT?

Hello! It looks really great, but before I proceed with making the changes to align with your design, I would prefer to wait for input from other developers, as the UI might undergo changes afterward (if any changes to the logic are required).
What do you think @kyranjamie ?

Thank you!

@fabric-8
Copy link
Contributor

@Polybius93 Discussed this with @kyranjamie yesterday based upon which the design proposal has been updated.

Link to Design on Figma

We simplified things as much as possible, effectively merging both "tabs" into one unified view as that represents things more accurately.

Add BTC Network

At it's core, we porpose a dropdown ("Bitcoin API") where any selection will populate the text inputs below with defaults we assume would be useful.

But since those are just text inputs, the end user can obv. change this to whatever they need.

Add BTC Network

Propose selection / applied defaults:

Add BTC Network

Happy to hear any thoughts or questions you might have on this and thanks for your support!

Comment on lines 50 to 53
type NetworkMap<T> = Record<BitcoinNetworkModes, T>;
export function whenNetwork(mode: BitcoinNetworkModes) {
return <T extends NetworkMap<unknown>>(networkMap: T) =>
networkMap[mode] as T[BitcoinNetworkModes];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you revert this change, sometimes we need the 2 network map. The function you're looking for exists https://github.com/leather-wallet/extension/blob/b926b27c50269d9f678e82a3aea0e1cdcc695375/src/app/common/utils.ts#L267-L269

Comment on lines 96 to 97
stacksChainId: ChainID.Mainnet,
stacksUrl: HIRO_API_BASE_URL_MAINNET,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it necessary to change these names?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was cleaner for me to distinguish it from the bitcoin properties, but I can revert this if you think it is unnecessary.

@@ -105,6 +105,7 @@ interface CreateSignersForAllNetworkTypesArgs {
paymentFn: (keychain: HDKey, network: BitcoinNetworkModes) => unknown;
mainnetKeychainFn: (accountIndex: number) => BitcoinAccount | undefined;
testnetKeychainFn: (accountIndex: number) => BitcoinAccount | undefined;
regtestKeychainFn: (accountIndex: number) => BitcoinAccount | undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't understand these changes and don't think they're needed? Afaik, regtest uses the same derivation path, and thus keychain as testnet?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, tried without this, it works just fine, so I'll revert this. At first, even though I used regtest, testnet addresses were shown, thought maybe this is one of the reasons, but turns out, it's not. Thank you!

@fabric-8
Copy link
Contributor

👋 Feel free to ping me once you feel the implementation is ready for a design review — or if there are any design-questions.

@Polybius93 Polybius93 force-pushed the feat/bitcoin-regtest-network-option branch from dedeb5e to cc27cba Compare October 16, 2023 13:36
@Polybius93
Copy link
Collaborator Author

👋 Feel free to ping me once you feel the implementation is ready for a design review — or if there are any design-questions.

👋 Feel free to ping me once you feel the implementation is ready for a design review — or if there are any design-questions.

👋 Feel free to ping me once you feel the implementation is ready for a design review — or if there are any design-questions.

@fabric-8 Hey! Finished the code and all the checks are passing now, so the PR is ready to be reviewed! Thank you!

@fabric-8
Copy link
Contributor

All good from my side for now, we'll probably do some design updates here in the aftermath as part of a broader design/brand-alignment initiative, but that shouldn't block the merge here!

Maybe just one minor thing: In fullscreen/tab view, the form contents are very narrow - any chance we can fix this? I think usually the max-width here should sit at around 400px, not quite sure why that doesn't work here. The width worked correctly in the previous add network view

CleanShot 2023-10-17 at 09 15 12@2x

@Polybius93 Polybius93 force-pushed the feat/bitcoin-regtest-network-option branch from cc27cba to 86f6c54 Compare October 17, 2023 08:17
@Polybius93
Copy link
Collaborator Author

All good from my side for now, we'll probably do some design updates here in the aftermath as part of a broader design/brand-alignment initiative, but that shouldn't block the merge here!

Maybe just one minor thing: In fullscreen/tab view, the form contents are very narrow - any chance we can fix this? I think usually the max-width here should sit at around 400px, not quite sure why that doesn't work here. The width worked correctly in the previous add network view

CleanShot 2023-10-17 at 09 15 12@2x

Thank you @fabric-8 ! Yeah, now that you have wrote this, I noticed that there is an extra container in the layout, that's why it was narrow, I've fixed and pushed it up.

@Polybius93 Polybius93 requested a review from kyranjamie October 17, 2023 14:03
Copy link
Contributor

@fabric-8 fabric-8 left a comment

Choose a reason for hiding this comment

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

👍

@markmhendrickson
Copy link
Collaborator

@kyranjamie to do final code review

@kyranjamie kyranjamie force-pushed the feat/bitcoin-regtest-network-option branch from 86f6c54 to 9c67d10 Compare October 31, 2023 09:35
Copy link
Collaborator

@kyranjamie kyranjamie left a comment

Choose a reason for hiding this comment

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

Sorry @Polybius93, reviewing this I discovered that there's a breaking change for users with existing networks saved.

Because we changed the name of the networks from stacks.url --> stacks.stacksUrl and bitcoin.url to bitcoin.bitcoinUrl, users with existing networks persisted will try and read bitcoinUrl which will be undefined.

Is it possible to leave the network schema as it was before?

@Polybius93
Copy link
Collaborator Author

Sorry @Polybius93, reviewing this I discovered that there's a breaking change for users with existing networks saved.

Because we changed the name of the networks from stacks.url --> stacks.stacksUrl and bitcoin.url to bitcoin.bitcoinUrl, users with existing networks persisted will try and read bitcoinUrl which will be undefined.

Is it possible to leave the network schema as it was before?

Sure, I'll make it work in the afternoon! Thank you!

@markmhendrickson
Copy link
Collaborator

@Polybius93 any updates here? It'd be great to get this merged in soon

@Polybius93
Copy link
Collaborator Author

@Polybius93 any updates here? It'd be great to get this merged in soon

We were having some issues migrating the existing networks into this new structure, @kyranjamie is helping me out in in this issue currently.

@Polybius93 Polybius93 force-pushed the feat/bitcoin-regtest-network-option branch from 704584c to a81dace Compare November 21, 2023 11:25
@Polybius93 Polybius93 added this pull request to the merge queue Nov 21, 2023
Merged via the queue into dev with commit c8724b4 Nov 21, 2023
26 checks passed
@Polybius93 Polybius93 deleted the feat/bitcoin-regtest-network-option branch November 21, 2023 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:dlcs area:networks enhancement-p2 Critical functionality needed by few users, with no clear alternatives
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants