Skip to content

Transaction flow#394

Open
jbrauck-unchained wants to merge 21 commits intocaravan-bitcoin:mainfrom
jbrauck-unchained:transaction-flow
Open

Transaction flow#394
jbrauck-unchained wants to merge 21 commits intocaravan-bitcoin:mainfrom
jbrauck-unchained:transaction-flow

Conversation

@jbrauck-unchained
Copy link
Contributor

What kind of change does this PR introduce?

This introduces a new tranasction flow diagram feature

Issue Number:

Fixes #393 #393

Snapshots/Videos:

Screenshot 2025-10-05 at 10 54 04 PM

If relevant, did you update the documentation?

Summary

I like what sparrow does to try and give a user a sense of understanding their own transaction. I think this is a small lift to gain feature parity in a place that makes caravan more educational.

Does this PR introduce a breaking change?

Checklist

  • I have tested my changes thoroughly.
  • I have added or updated tests to cover my changes (if applicable).
  • I have verified that test coverage meets or exceeds 95% (if applicable).
  • I have run the test suite locally, and all tests pass.
  • I have written tests for all new changes/features
  • I have followed the project's coding style and conventions.
  • I have created a changeset to document my changes (npm run changeset)

Other information

Have you read the contributing guide?

For information on creating and using changesets, please refer to our documentation on changesets.

@changeset-bot
Copy link

changeset-bot bot commented Oct 8, 2025

⚠️ No Changeset found

Latest commit: 1f76f55

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 8, 2025

@jbrauck-unchained is attempting to deploy a commit to the Unchained Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Oct 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
caravan-coordinator Ready Ready Preview, Comment Jan 22, 2026 2:33am

Request Review

@Legend101Zz
Copy link
Contributor

Screenshot 2025-10-23 at 19 43 39 @jbrauck-unchained maybe you'll have do the formatting ( run the linter ) and get the unsed imports out for the ci to pass :)

@Legend101Zz
Copy link
Contributor

One small nit: maybe we can add ~ 0.00% total so we can tell the user we are rounding up here and they don't think of this as a bug
Screenshot 2025-10-23 at 19 46 56

@Legend101Zz
Copy link
Contributor

Legend101Zz commented Oct 23, 2025

Screenshot 2025-10-23 at 19 50 13

maybe we can remove one of the Edit Transaction Button

@github-actions
Copy link
Contributor

This pull request has been inactive for 30 days and has been marked as stale. It will be closed in 7 days if no further activity occurs. To keep this PR open, add the "long-lived" label or comment on it.

@github-actions github-actions bot added the stale label Dec 17, 2025
Copy link
Contributor

@Legend101Zz Legend101Zz left a comment

Choose a reason for hiding this comment

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

@jbrauck-unchained thanks for the awesome work , I tested it and it looks super good to me , now I guess we can move towards the code changes , the main concern I have is over modularity and an IIFE used in rendering of the flow status

Screenshot 2026-01-06 at 07 22 52

return `${address.slice(0, 10)}...${address.slice(-8)}`;
};

const getStatusDisplay = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

this can go in the utils file then

};

// Format script type for display
const formatScriptType = (scriptType?: string) => {
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 add this and formatAddress in the general utils file as they can be used by other components too :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a different general utils file you are talking about? For now I added to the TransactionFlowUtils.ts file

Copy link
Contributor

Choose a reason for hiding this comment

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

that works perfectly for me :)

- Create TransactionFlowDiagram directory structure with separate files:
  - index.tsx: Main component file (cleaner, more focused)
  - hooks.ts: Custom useFlowPaths hook for SVG path calculations
  - utils.ts: Utility functions (buildCurvePath, formatAddress, formatScriptType, getScriptTypeColor, getStatusDisplay)
  - FlowDrawers.tsx: Input and output drawer components
  - FlowSummary.tsx: Summary section with legend and transaction totals
- Move formatSats and formatAddress to transactionFlowUtils.ts for reuse
- Remove old 1704-line monolithic TransactionFlowDiagram.tsx file

This addresses code review feedback to improve maintainability and readability.
- Remove unused variables in TransactionPreview.jsx render method
- Fix prettier formatting in TransactionsTable.tsx
- Fix prettier formatting in useTransactionDetails.ts
- Remove unused blockHeight variable in transactionFlowUtils.ts
Copy link
Contributor

@Legend101Zz Legend101Zz left a comment

Choose a reason for hiding this comment

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

Thanks alot for the changes , it's looking really good now , nothing from my end now :)

@bucko13 can you please review it when you get the chance ...

Copy link
Contributor

@bucko13 bucko13 left a comment

Choose a reason for hiding this comment

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

I don't love all of the inline stylings that we have throughout this. it will make the aesthetics come out inconsistent with the rest of the app and also harder to maintain. we should be able to use existing theming or components and/or update to the theme.

few other opportunities for code consolidation/cleanup. Also would like to add type safety where possible.

}}
>
{inputs.map((input, idx) => {
const inputAmount = BigNumber(
Copy link
Contributor

Choose a reason for hiding this comment

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

We should pull this out to be its own component and then just pass in the props.

label="Economical"
color="success"
size="small"
sx={{ height: 20, fontSize: "0.7rem" }}
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like there's some room for code consolidation here. this styling is repeated on every box as far as I can tell and it should be generalized. If we change the look somehow you'll have to change every single line. do we want this to be a specialized kind of component?

}}
>
{inputs.slice(0, 4).map((input, idx) => {
const inputAmount = BigNumber(
Copy link
Contributor

Choose a reason for hiding this comment

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

another one that should be its own component to simplify this file a bit. and what can we do to clean up the inline styles?


{/* Change Outputs */}
{flowData.changeOutputs.map((output, idx) => {
const amount = BigNumber(output.amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

modular component opportunity here.

Copy link
Contributor

Choose a reason for hiding this comment

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

lots of simplification we can get here.

const blockchainClient = useGetClient();

return useQuery(
[TRANSACTION_DETAILS_KEY, txid],
Copy link
Contributor

Choose a reason for hiding this comment

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

see some of the other hooks for how we setup the query cache keys.

return updateState(state);
case SET_TXID:
return updateState(state, { txid: action.value });
case SET_BROADCASTING:
Copy link
Contributor

Choose a reason for hiding this comment

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

now i'm curious what this is actually indicating. also wonder if there's a way we can avoid adding to the redux store. It's hard in caravan since we have a lot of tightly coupled legacy code, but if we can avoid adding to the redux store that would definitely be the preference.

changeAddress?: string;
inputsTotalSats: BigNumber;
status:
| "draft"
Copy link
Contributor

Choose a reason for hiding this comment

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

see we're using these values in other places. what if we made this a shareable type and then could make all uses of it type safe.

/**
* Detect script type from address prefix (heuristic)
*/
const detectScriptTypeFromAddress = (address?: string): string | undefined => {
Copy link
Contributor

Choose a reason for hiding this comment

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

we have address type detection tools in caravan-bitcoin

* @returns FlowDiagramProps ready for the component
*/
export const transformTransactionToFlowDiagram = (
tx: any,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we have some types for this don't we @Legend101Zz ?

@jevidon
Copy link
Contributor

jevidon commented Mar 6, 2026

Overall really solid. Just a couple nits I noticed, but not blocking.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transaction flow diagram

4 participants