-
Notifications
You must be signed in to change notification settings - Fork 146
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: cancel stacks pending transaction #5501
feat: cancel stacks pending transaction #5501
Conversation
WalkthroughThe recent changes introduce a new feature for canceling Stacks transactions, including UI components, hooks, and routes. Enhancements include a new Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 1
Outside diff range and nitpick comments (4)
src/app/components/stacks-transaction-item/cancel-transaction-button.tsx (1)
19-21
: Consider adding a comment explaining whye.stopPropagation()
is used here, to help future maintainers understand its purpose.src/app/components/transaction-item/transaction-item.layout.tsx (1)
Line range hint
22-50
: Consider using destructuring forprops
in the function signature to improve readability.- export function TransactionItemLayout({ + export function TransactionItemLayout({ actionButtonGroupElement, txCaption, txIcon, txStatus, txTitle, txValue, ...props }: TransactionItemLayoutProps) {src/app/features/dialogs/cancel-transaction-dialog/hooks/use-stx-cancel-transaction.ts (1)
25-89
: Consider adding detailed comments explaining the transaction crafting and broadcasting process within theuseStxCancelTransaction
hook to aid future maintainers.src/app/features/dialogs/cancel-transaction-dialog/cancel-stx-transaction-dialog.tsx (1)
63-63
: Add a user-friendly message or UI element when waiting for transaction details.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (14)
- src/app/common/hooks/use-loading.ts (1 hunks)
- src/app/common/utils/get-burn-address.ts (1 hunks)
- src/app/components/bitcoin-transaction-item/bitcoin-transaction-item.tsx (1 hunks)
- src/app/components/stacks-transaction-item/cancel-transaction-button.tsx (1 hunks)
- src/app/components/stacks-transaction-item/increase-fee-button.tsx (1 hunks)
- src/app/components/stacks-transaction-item/stacks-transaction-item.tsx (4 hunks)
- src/app/components/transaction-item/transaction-item.layout.tsx (3 hunks)
- src/app/features/dialogs/cancel-transaction-dialog/cancel-stx-transaction-dialog.tsx (1 hunks)
- src/app/features/dialogs/cancel-transaction-dialog/components/cancel-transaction-actions.tsx (1 hunks)
- src/app/features/dialogs/cancel-transaction-dialog/hooks/use-selected-tx.ts (1 hunks)
- src/app/features/dialogs/cancel-transaction-dialog/hooks/use-stx-cancel-transaction.ts (1 hunks)
- src/app/features/stacks-transaction-request/hooks/use-stacks-broadcast-transaction.tsx (4 hunks)
- src/app/routes/app-routes.tsx (2 hunks)
- src/shared/route-urls.ts (1 hunks)
Additional comments not posted (16)
src/app/features/dialogs/cancel-transaction-dialog/hooks/use-selected-tx.ts (1)
4-7
: LGTM! The hookuseSelectedTx
is well-implemented and correctly utilizes existing hooks to fetch transaction data.src/app/common/utils/get-burn-address.ts (1)
4-12
: LGTM! The functiongetBurnAddress
is well-implemented. Consider adding a comment for the default case to clarify that it returns the testnet address as a fallback.src/app/common/hooks/use-loading.ts (1)
5-5
: LGTM! The addition ofCANCEL_TRANSACTION_DRAWER
to theLoadingKeys
enum is correctly implemented.src/app/components/stacks-transaction-item/increase-fee-button.tsx (1)
15-37
: LGTM! The update to conditionally render theIncreaseFeeButton
based on theisActive
state is well-implemented. Ensure that the use ofe.stopPropagation()
in the onClick handler is intentional and necessary to prevent event bubbling.src/app/components/stacks-transaction-item/cancel-transaction-button.tsx (1)
8-37
: The implementation ofCancelTransactionButton
looks solid and follows best practices for conditional rendering and event handling.src/app/features/dialogs/cancel-transaction-dialog/components/cancel-transaction-actions.tsx (1)
12-39
: TheCancelTransactionActions
component is well-implemented with proper use of hooks and accessibility attributes.src/app/components/transaction-item/transaction-item.layout.tsx (1)
Line range hint
22-50
: The updates toTransactionItemLayout
are well-executed, enhancing the component's flexibility and maintainability.src/app/features/dialogs/cancel-transaction-dialog/hooks/use-stx-cancel-transaction.ts (1)
25-89
: TheuseStxCancelTransaction
hook is robust, correctly managing dependencies and state with comprehensive error handling and validation.src/app/components/bitcoin-transaction-item/bitcoin-transaction-item.tsx (1)
89-89
: RenamingrightElement
toactionButtonGroupElement
improves clarity. Ensure all references to the old prop name are updated across the project.Verification successful
Renaming
rightElement
toactionButtonGroupElement
improves clarity. Ensure all references to the old prop name are updated across the project.The search for
rightElement
in.tsx
and.ts
files returned no results, indicating that all instances have been updated.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that all instances of `rightElement` have been updated to `actionButtonGroupElement`. # Test: Search for the old prop name. Expect: No occurrences. rg --type typescript $'rightElement'Length of output: 70
Script:
#!/bin/bash # Description: Verify that all instances of `rightElement` have been updated to `actionButtonGroupElement`. # Test: Search for the old prop name in .tsx and .ts files. Expect: No occurrences. rg 'rightElement' --glob '**/*.tsx' --glob '**/*.ts'Length of output: 52
src/shared/route-urls.ts (1)
30-30
: Addition ofCancelStxTransaction
route aligns with the new feature. Verify that this route is correctly handled in the routing logic.Verification successful
The new route
CancelStxTransaction
is correctly handled in the routing logic and other relevant parts of the codebase.
src/app/routes/app-routes.tsx
: The route is imported and used in the routing logic.src/app/features/dialogs/cancel-transaction-dialog/cancel-stx-transaction-dialog.tsx
: The route is used in the dialog component.src/app/components/stacks-transaction-item/stacks-transaction-item.tsx
: The route is used in multiple places within this component.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the new route is correctly handled in the routing logic. # Test: Search for the new route in the routing logic. Expect: At least one occurrence. rg --type typescript $'CancelStxTransaction'Length of output: 78
Script:
#!/bin/bash # Description: Verify that the new route is correctly handled in the routing logic. # Test: Search for the new route in the routing logic. Expect: At least one occurrence. rg --type ts 'CancelStxTransaction'Length of output: 1457
src/app/components/stacks-transaction-item/stacks-transaction-item.tsx (1)
24-24
: Introduction ofCancelTransactionButton
and related logic for handling transaction cancellation. Ensure that the new components and methods are correctly implemented and tested.Also applies to: 70-84, 97-120
Verification successful
The verification confirms that the
CancelTransactionButton
component and theonCancelTransaction
method are correctly implemented and referenced in the codebase.
CancelTransactionButton
is imported and used insrc/app/components/stacks-transaction-item/stacks-transaction-item.tsx
and defined insrc/app/components/stacks-transaction-item/cancel-transaction-button.tsx
.onCancelTransaction
is defined and used insrc/app/components/stacks-transaction-item/stacks-transaction-item.tsx
and referenced insrc/app/components/stacks-transaction-item/cancel-transaction-button.tsx
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the new components and methods for handling transaction cancellation are correctly implemented and tested. # Test: Search for the new components and methods in the codebase. Expect: At least one occurrence of each. rg --type typescript $'CancelTransactionButton' rg --type typescript $'onCancelTransaction'Length of output: 159
Script:
#!/bin/bash # Description: Verify that the new components and methods for handling transaction cancellation are correctly implemented and tested. # Test: Search for the new components and methods in the codebase. Expect: At least one occurrence of each. rg --glob '*.ts' --glob '*.tsx' 'CancelTransactionButton' rg --glob '*.ts' --glob '*.tsx' 'onCancelTransaction'Length of output: 1198
src/app/features/stacks-transaction-request/hooks/use-stacks-broadcast-transaction.tsx (1)
30-30
: Update touseStacksBroadcastTransaction
hook to handle transaction cancellation. Ensure that the updated hook is correctly implemented and tested.Also applies to: 37-37, 64-104, 144-144
Verification successful
The
useStacksBroadcastTransaction
hook is correctly implemented and used in multiple files across the codebase. Here are the locations where it is imported and utilized:
src/app/pages/transaction-request/transaction-request.tsx
src/app/pages/send/send-crypto-asset-form/form/stacks/stacks-send-form-confirmation.tsx
src/app/features/dialogs/cancel-transaction-dialog/hooks/use-stx-cancel-transaction.ts
src/app/features/dialogs/increase-fee-dialog/increase-stx-fee-dialog.tsx
This confirms that the hook is integrated and used in various parts of the application.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the updated hook for handling transaction cancellation is correctly implemented and tested. # Test: Search for the updated hook in the codebase. Expect: At least one occurrence. rg --type typescript $'useStacksBroadcastTransaction'Length of output: 87
Script:
#!/bin/bash # Description: Verify that the updated hook for handling transaction cancellation is correctly implemented and tested. # Test: Search for the updated hook in the codebase. Expect: At least one occurrence. rg 'useStacksBroadcastTransaction' --glob '*.ts' --glob '*.tsx'Length of output: 1651
src/app/features/dialogs/cancel-transaction-dialog/cancel-stx-transaction-dialog.tsx (3)
26-134
: The implementation ofCancelStxTransactionDialog
appears robust and well-structured.
47-52
: Ensure proper handling of transaction statuses other than 'pending'.
70-133
: Review the form validation logic to ensure it aligns with the expected transaction cancellation requirements.Verification successful
The search results indicate that the
validationSchema
for theCancelStxTransactionDialog
component is defined in theuseStxCancelTransaction
hook. The relevant snippet is:src/app/features/dialogs/cancel-transaction-dialog/hooks/use-stx-cancel-transaction.ts: validationSchema: yup.object({ fee: stxFeeValidator(availableUnlockedBalance) }),This schema validates the
fee
field using thestxFeeValidator
function, which likely ensures that the fee is appropriate based on the available unlocked balance.Locations in the codebase:
src/app/features/dialogs/cancel-transaction-dialog/hooks/use-stx-cancel-transaction.ts
Conclusion:
The form validation logic for transaction cancellation appears to be in place and aligns with the expected requirements by validating the fee against the available unlocked balance.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the form validation logic for transaction cancellation. # Test: Search for form validation related to transaction cancellation. Expect: Comprehensive validation rules. rg --type typescript $'validationSchema' --context 10Length of output: 87
Script:
#!/bin/bash # Description: Verify the form validation logic for transaction cancellation. # Test: Search for form validation related to transaction cancellation. Expect: Comprehensive validation rules. rg --type ts,tsx 'validationSchema' --context 10Length of output: 79
Script:
#!/bin/bash # Description: Verify the form validation logic for transaction cancellation. # Test: Search for form validation related to transaction cancellation. Expect: Comprehensive validation rules. rg --type ts 'validationSchema' --context 10 rg --type tsx 'validationSchema' --context 10Length of output: 77600
src/app/routes/app-routes.tsx (1)
104-106
: The new route forCancelStxTransactionDialog
is correctly set up.
useEffect(() => { | ||
if (!rawTxId && txIdFromParams) { | ||
setRawTxId(txIdFromParams); | ||
} | ||
if (isLoading && !rawTxId) { | ||
setIsIdle(); | ||
} | ||
}, [isLoading, rawTxId, setIsIdle, setRawTxId, txIdFromParams]); |
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.
Tip
Codebase Verification
The search results indicate that txIdFromParams
is being retrieved from the URL search parameters using searchParams.get('txId')
, but there is no evidence of validation logic for txIdFromParams
in the provided context.
- File:
src/app/features/dialogs/cancel-transaction-dialog/cancel-stx-transaction-dialog.tsx
- Lines:
const txIdFromParams = searchParams.get('txId');
if (!rawTxId && txIdFromParams) { setRawTxId(txIdFromParams); }
There is no validation to check if txIdFromParams
is valid before it is used.
Analysis chain
Consider adding error handling for cases where txIdFromParams
is invalid.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the validation of `txIdFromParams`.
# Test: Search for validation logic for `txIdFromParams`. Expect: Proper validation checks.
rg --type typescript $'txIdFromParams' --context 5
Length of output: 84
Script:
#!/bin/bash
# Description: Verify the validation of `txIdFromParams`.
# Test: Search for validation logic for `txIdFromParams`. Expect: Proper validation checks.
rg --type ts 'txIdFromParams' --context 5
Length of output: 6346
e44e80c
to
7f46856
Compare
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (14)
- src/app/common/hooks/use-loading.ts (1 hunks)
- src/app/common/utils/get-burn-address.ts (1 hunks)
- src/app/components/bitcoin-transaction-item/bitcoin-transaction-item.tsx (1 hunks)
- src/app/components/stacks-transaction-item/cancel-transaction-button.tsx (1 hunks)
- src/app/components/stacks-transaction-item/increase-fee-button.tsx (1 hunks)
- src/app/components/stacks-transaction-item/stacks-transaction-item.tsx (4 hunks)
- src/app/components/transaction-item/transaction-item.layout.tsx (3 hunks)
- src/app/features/dialogs/cancel-transaction-dialog/cancel-stx-transaction-dialog.tsx (1 hunks)
- src/app/features/dialogs/cancel-transaction-dialog/components/cancel-transaction-actions.tsx (1 hunks)
- src/app/features/dialogs/cancel-transaction-dialog/hooks/use-selected-tx.ts (1 hunks)
- src/app/features/dialogs/cancel-transaction-dialog/hooks/use-stx-cancel-transaction.ts (1 hunks)
- src/app/features/stacks-transaction-request/hooks/use-stacks-broadcast-transaction.tsx (4 hunks)
- src/app/routes/app-routes.tsx (2 hunks)
- src/shared/route-urls.ts (1 hunks)
Files skipped from review as they are similar to previous changes (14)
- src/app/common/hooks/use-loading.ts
- src/app/common/utils/get-burn-address.ts
- src/app/components/bitcoin-transaction-item/bitcoin-transaction-item.tsx
- src/app/components/stacks-transaction-item/cancel-transaction-button.tsx
- src/app/components/stacks-transaction-item/increase-fee-button.tsx
- src/app/components/stacks-transaction-item/stacks-transaction-item.tsx
- src/app/components/transaction-item/transaction-item.layout.tsx
- src/app/features/dialogs/cancel-transaction-dialog/cancel-stx-transaction-dialog.tsx
- src/app/features/dialogs/cancel-transaction-dialog/components/cancel-transaction-actions.tsx
- src/app/features/dialogs/cancel-transaction-dialog/hooks/use-selected-tx.ts
- src/app/features/dialogs/cancel-transaction-dialog/hooks/use-stx-cancel-transaction.ts
- src/app/features/stacks-transaction-request/hooks/use-stacks-broadcast-transaction.tsx
- src/app/routes/app-routes.tsx
- src/shared/route-urls.ts
Without a dev build, it is hard for me to test this. I assume it didn't build due to the failing tests. I think the "cancel transaction" text on the button could be shorter. Just "Cancel" is enough. That may leave enough room for a small symbol infront of it 🚫, 🛑 ? or simply an "x" in the same color as the >> in front of "increase fee" to match? |
Yeah the workflows are pending and i think approval is required for build process. Is there any way i can help? i can upload the build and share a link
I tried adding an icon but reverted it cause the longer text was resizing the icon, but making it "cancel" with an icon makes sense. I can try that and post a image here later and if it looks good i will commit the changes. |
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.
Thanks for the contribution @Aman-zishan—we'll try and review & QA this as soon as possible
whenWallet({ | ||
ledger: () => | ||
whenPageMode({ | ||
full: () => navigate(RouteUrls.CancelStxTransaction), | ||
popup: () => openIndexPageInNewTab(RouteUrls.CancelStxTransaction, urlSearchParams), | ||
})(), | ||
software: () => navigate(RouteUrls.CancelStxTransaction), | ||
})(); |
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 think we can always just navigate? Not sure we need to handle ledger/software differently here.
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 think we can always just navigate? Not sure we need to handle ledger/software differently here.
I coped this from increase fee logic not sure why it was in that way since increase fee was working fine i thought it's better to rely on already established code
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.
thanks for the contribution @Aman-zishan!
will test it a little bit later
amount: 1, | ||
memo: '_cancel transaction', | ||
network: network, | ||
} as any, |
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.
is it possible to avoid any
here and above?
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.
isActive && ( | ||
<styled.button | ||
_hover={{ color: 'ink.text-subdued' }} | ||
bg="ink.background-primary" | ||
maxWidth="125px" | ||
ml="auto" | ||
onClick={e => { | ||
onCancelTransaction(); | ||
e.stopPropagation(); | ||
}} | ||
pointerEvents={!isActive ? 'none' : 'all'} | ||
position="relative" | ||
px="space.02" | ||
py="space.01" | ||
rounded="xs" | ||
zIndex={999} | ||
> | ||
<HStack gap="space.01"> | ||
<styled.span textStyle="label.03" color="yellow.action-primary-default"> | ||
Cancel transaction | ||
</styled.span> | ||
</HStack> | ||
</styled.button> |
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.
code here is pretty much similar to increase fee btn, can we create component to avoid code duplication?
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.
code here is pretty much similar to increase fee btn, can we create component to avoid code duplication?
Yes that makes sense, i can work on it
@kyranjamie Thanks for the review comments. I'm starting to address them. Is QA still pending? If so, I can continue working on the feedback alongside QA to streamline the process. Let me know if that works or if you'd prefer I wait until QA is complete. |
export function useStxCancelTransaction() { | ||
const [rawTxId, setRawTxId] = useRawTxIdState(); | ||
const tx = useSelectedTx(); | ||
const [, setTxId] = useRawTxIdState(); |
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.
Made a comment on the duplicated PR, but this code can't just be copied from the increase fee dialog. I have refactored it here bc there is code duplication causing bugs. See changes here: #5500
useRawTxIdState
is an old atom being deprecated.
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.
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.
This will need to get rebased after #5500 is merged.
closing in favour of #5533 |
feature for stacks transactions Add option to cancel pending transaction #3406
New layout to have cancel transaction & increase fee without affecting tx caption
Attempts to cancel a transaction by crafting a new Tx that sends 1µSTX to burn address with a increase of 1µSTX to the previous fee.
Notifies the user once the transaction is fired
test case video (sending max to an address and trying to cancel that trasaction)
Screen.Recording.2024-06-07.at.11.02.00.AM.mov
https://explorer.hiro.so/txid/0x454c0b34dcaefd619766472652309dce44b95ad1b7795f3b9763d7403c28c2f1?chain=testnet
Summary by CodeRabbit
New Features
CancelTransactionButton
component for canceling transactions.CancelStxTransactionDialog
for managing Stacks transaction cancellations.CancelTransactionActions
component with cancel and submit buttons.Enhancements
IncreaseFeeButton
to conditionally render based on theisActive
state.CancelStxTransaction
.Refactor
rightElement
prop toactionButtonGroupElement
in various components for better clarity.Bug Fixes