-
Notifications
You must be signed in to change notification settings - Fork 20
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(frontend): New derived store currentBtcAddress
#2537
Conversation
@peterpeterparker @AntonioVentilii-DFINITY please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, we decided to start creating tests for derived stores. Can you please provide one if possible?
export const currentBtcAddress: Readable<OptionBtcAddress | undefined> = derived( | ||
[networkId, btcAddressMainnet, btcAddressTestnet, btcAddressRegtest], | ||
([$networkId, $btcAddressMainnet, $btcAddressTestnet, $btcAddressRegtest]) => { | ||
const mapper: Record<symbol, OptionBtcAddress> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance-wise, is it more efficient if
conditions or a mapper? Honest question
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, but I don't think it matters much the performance difference if any in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For which feature exactly do we need this derived store?
Context: I think we have too many derived stores. Generally speaking, our goal is also to use more contextual stores and replace some global stores. That's why, for example, the token is deprecated. I'm just asking to ensure there is a use case that absolutely requires another derived global store.
6ea4508
to
d88a9a1
Compare
It's for the bitcoin integration. To use in the send modal for btc and probably in the receive modal or wherever we use it. @AntonioVentilii-DFINITY I also added tests. But since we are on a tight deadline, could I ask to avoid changing patterns now and stick to simple ways? I'm all-in to add tests in general, but I'm not sure the moment to start doing it is when we have a deadline. |
d88a9a1
to
0aaf30c
Compare
If I'm not wrong, in the "Receive" modal we don't display just one address but all Regtest, testnet and prod Bitcoin address separatly. In the send modal we use a context and avoid the usage of global store. Are you sure we need this global derived store? |
I meant the Receive modal in the transactions page. Isn't there one? I used a different send modal. My idea is to create a new BtcSendTokenWizard. And inside there I reuse some components. I use this derived store to pass the source to Is there another way to align the code than doing it and then reviewing in a PR? I feel I lose quite some time back and forth with multiple small PRs. |
I mean the Receive modal on Chain Fusion on the main page
We should probably avoid using a global store in this particular "Send" modal, assuming that, similar to ETH/ERC20, we might reuse it for both Bitcoin and IC. For instance, when the user converts BTC to ckBTC and ckBTC back to BTC. This may be far off, but we faced difficulties refactoring ETH when we needed to, so I think it's worth anticipating any potential challenges. Furthermore, our existing IC and ETH modals use a That being said, if there are indeed two or more uses of the same store, I agree it makes sense to add a derived store. Once again, my original point is that we should be cautious with these kinds of stores. If you are sure it's the case, then so be it.
I'm definitely not going to rush PR reviews when it comes to core features. |
We can accomplish the same functionality without a global store. Therefore, closing this PR. |
Motivation
The address within ETH or IC doesn't change, but in BTC, there is a different address per network. However, I still want to reuse the components across those three networks.
In this PR, I introduce
currentBtcAddress
which returns a btc address (or not) depending on the current selected network which comes fromnetworkId
derived store.Changes
currentBtcAddress
.Tests
Used and tested in #2528