-
Notifications
You must be signed in to change notification settings - Fork 5
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: migrate stacks generate txs, closes LEA-1732 #627
base: dev
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #627 +/- ##
==========================================
+ Coverage 23.76% 24.75% +0.99%
==========================================
Files 165 169 +4
Lines 6194 6317 +123
Branches 337 361 +24
==========================================
+ Hits 1472 1564 +92
- Misses 4722 4753 +31
|
apps/mobile/src/features/send/send-form/hooks/use-send-form-stx.tsx
Outdated
Show resolved
Hide resolved
apps/mobile/src/features/send/send-sheets/send-form-stx-sheet.tsx
Outdated
Show resolved
Hide resolved
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.
Nice work @fbwoolf 👍
There's some console logs + commented code to remove.
For the stacks
package work, maybe we could add some of the functions into smaller independent files and generate some unit tests for them also?
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.
Great work!🚀
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.
Great work @fbwoolf
Lots to discuss here though. I think there's some code, and general patterns here, we might want to reconsider bringing over if possible
apps/mobile/src/features/send/send-form/components/send-form-stacks-setter.tsx
Outdated
Show resolved
Hide resolved
apps/mobile/src/common/transactions/stacks-transactions.hooks.ts
Outdated
Show resolved
Hide resolved
apps/mobile/src/common/transactions/stacks-transactions.hooks.ts
Outdated
Show resolved
Hide resolved
I would investigate options where we do not even render the form components until we have this data loaded from the external source. Either the loader pattern, or some kind of route loader if Expo has those. |
Yep, agree, I was debating abt just doing a draft PR but wasn't sure how quickly we wanted to push the send form forward. I'll change this to draft and tackle some of the refactoring you pointed out. I mostly wanted to make sure I got feedback on effort here so far. 👍 |
f99a878
to
1f9ea83
Compare
apps/mobile/src/features/send/send-form/hooks/use-send-form-stx.tsx
Outdated
Show resolved
Hide resolved
81d205b
to
d869a60
Compare
apps/mobile/src/features/send/send-form/hooks/use-send-form-btc.tsx
Outdated
Show resolved
Hide resolved
db07cf2
to
93a6ffc
Compare
I am going to open this for review again. Open to feedback on using the separate providers here vs our loader pattern. I'm happy to switch if people prefer the loader pattern. Expo router doesn't offer loaders. |
Working a bit more here to split up the providers bc currently they are named incorrectly. They need to be protocol specific. |
93a6ffc
to
3b5e1fb
Compare
3b5e1fb
to
da70099
Compare
Looking at this closer, it might be that we want separate providers per protocol for flexibility, but use the loader pattern per chain so we don't duplicate efforts with loading chain data like fees and nonces. Might try adding that as a next step. |
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.
Curious to hear your thoughts on feedback I've left, but very impressed with this solution. Think you've struck a great balance between reusability of the form, and compatibility of all the elements with the context.
apps/mobile/src/features/send/send-form/hooks/use-send-form-stx.tsx
Outdated
Show resolved
Hide resolved
export type ReplaceTypes<T, Replacements extends { [K in keyof T]?: any }> = Omit< | ||
T, | ||
keyof Replacements | ||
> & { | ||
[K in keyof Replacements]: Replacements[K]; | ||
}; |
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.
What does this do?
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 wanted to reuse part of the @stacks/transactions types but replace their use of IntegerType
from @stacks/common with our Money
type and narrow the other types rather than installing another lib to handle their IntegerType
. I could completely create our own types copied from @stacks/transactions, but I looked up this utility to replace types. Now, we can pass our Money type all the way to the stacks pkg and then just convert it to a string there before using their typed function. Look at use in transaction.types.ts
.
packages/stacks/src/transactions/generate-unsigned-transaction.ts
Outdated
Show resolved
Hide resolved
const stxAddress = stxSigner?.address ?? ''; | ||
const { data: nextNonce } = useNextNonce(stxAddress); | ||
|
||
if (!account || !stxSigner) return; |
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.
Any way to handle these missing values differently, such that by the time we get to this hook, we're sure they're defined?
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 ended up creating a loader for the StacksSigner and passing the signer address and publicKey hex thru the route params. Hoping this is a good solution here?
defaultStacksFees.estimates[0]?.fee ?? defaultFeeFallbackAsMoney | ||
); | ||
|
||
if (!nextNonce) return null; |
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.
Should we have a nonce
loader component, or even a loader component specific to this send form?
I could see the Loader pattern living side by side use of context here.
<StxSendFormLoader fallback={<LoadingScreen />}>
{nonceEtc => <SendFormProvider {...nonceEtc} />}
</StxSendFormLoader/>
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.
Yep, agree, was refactoring to this when you were reviewing. I was thinking maybe we only need loaders per chain, but maybe we do need per protocol. 🤔 Stacks would load the same fees and nonce for stx and sip10, so there would be some duplication there if do separately.
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.
Thinking should be separate, so separating. I think the loader pattern makes more sense to me rather than using the hook for loading, but open if others feel strongly either way.
a31a7cf
to
1b127cd
Compare
@kyranjamie hoping to get your feedback on how I've addressed your questions. I am now handling all undefined values thru a form loader component, which I think is working well. |
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.
Looks great, thanks Fara
1b127cd
to
741dba7
Compare
This PR migrates code from the extension to generate the unsigned stacks tx for the STX send flow.
Approach here now uses a separate Provider for each chain/protocol form so that we can handle loading data in the provider. I also did a version using our loader pattern, which seemed ok too, but felt using this approach might be more straightforward with using React context for the forms. We can add a loading state later, etc.
I also removed any helper functions I wasn't directly using with generating the unsigned tx. I realized I had ported over some unnec functions for this work. I got rid of all the stacks connect types.
I did add two new money formatters that can eventually help to replace
stacksValue
, thought I didn't end up needing them anywhere for now.