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

chore: add defensive code and better analytics for broadcast errors, … #5375

Merged
merged 1 commit into from
May 20, 2024

Conversation

pete-watters
Copy link
Contributor

@pete-watters pete-watters commented May 15, 2024

Try out Leather build bf36652Extension build, Test report, Storybook, Chromatic

This PR adds some extra analytics and defensive code to try and gather more insight into and prevent #5118

The analytics added are:

  • track fail of stacks tx publish on ledger via ledger_transaction_publish_error
  • track failure to broadcast of:
    • Ordinal via broadcast_ordinal_error
    • BRC20 via broadcast_brc20_error
    • BTC via broadcast_btc_error

Summary by CodeRabbit

  • New Features

    • Enhanced error tracking and analytics for transaction errors across various components.
  • Bug Fixes

    • Improved conditional rendering for address display to handle cases where the address is undefined.
  • Chores

    • Updated @leather-wallet/models dependency version from 0.4.4 to 0.4.5 for better compatibility and performance.
  • Documentation

    • Added a comment in the useNativeSegwitAccountIndexAddressIndexZero function for clarity on potential scenarios.

Copy link

coderabbitai bot commented May 15, 2024

Walkthrough

The recent updates focus on enhancing error tracking and refining prop handling across various components. Key changes include the removal of unnecessary prop spreading, conditional rendering of components, and the addition of analytics tracking for error events. The version of @leather-wallet/models has also been incremented in the package.json file.

Changes

Files Change Summary
src/app/components/address-displayer/form-address-displayer.tsx Removed prop spreading, added conditional rendering for address prop, updated FormAddressDisplayerProps interface.
src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx Added analytics tracking for transaction publish errors.
src/app/pages/send/ordinal-inscription/send-inscription-review.tsx Added analytics tracking for ordinal broadcast errors.
src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx Added analytics tracking for BRC20 broadcast errors.
src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx Added analytics tracking for BTC broadcast errors.
src/app/query/stacks/bns/bns.utils.ts Added a conditional check for res.address in fetchNameOwner function.
src/app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks.ts Added a comment regarding a potential scenario in useNativeSegwitAccountIndexAddressIndexZero function.
src/app/ui/components/address-displayer/address-displayer.tsx Removed dependency on HTMLStyledProps and the spread of props in AddressDisplayerLayout component.
package.json Updated @leather-wallet/models version from "0.4.4" to "0.4.5".

In the world of code, so bright and grand,
Changes come with a guiding hand.
Errors tracked, props refined,
A smoother path, with bugs confined.
Version bumped, the models grow,
In this garden, watch it glow! 🌸🐇


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -122,6 +122,7 @@ export function useCurrentAccountNativeSegwitAddressIndexZero() {
*/
export function useNativeSegwitAccountIndexAddressIndexZero(accountIndex: number) {
const signer = useNativeSegwitSigner(accountIndex)?.(0);
// could it be this?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding this note as the error thrown was Cannot read property of undefined reading .address" .

I see the deprecation warning above this function but I don't understand what it means.


/**
 * @deprecated Use signer.address instead
 */

Does that mean I can refactor this to use signer?.address instead of signer?.payment.address?

@@ -129,7 +130,15 @@ function LedgerSignStacksTxContainer() {
signedTx,
});
} catch (e) {
ledgerNavigate.toBroadcastErrorStep(isError(e) ? e.message : 'Unknown error');
const error = isError(e) ? e.message : 'Unknown error';
void analytics.track('ledger_transaction_publish_error', {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added analytics to errors that bring us to the broadcast error screen. I am unsure what we should use analytics for though.

  • should only use them for events and leave errors to sentry?
  • should I have access to segment?

address: string;
}
export function FormAddressDisplayer({ address, ...rest }: FormAddressDisplayerProps) {
export function FormAddressDisplayer({ address }: FormAddressDisplayerProps) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored this on my travels as we don't need the ...rest and in case address here is undefined and the cause of the runtime error

@pete-watters
Copy link
Contributor Author

@kyranjamie : I was still unable to reproduce this issue, see comment here

Opening this as a draft as I have some Q's and in case adding this tracking and defensive code helps either identify / prevent this issue.

>
<AddressDisplayer address={address} />
{address && <AddressDisplayer address={address} />}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why would address be undefined if it isn't an optional prop?

If it is undefined sometimes, then our types are wrong, and this treats a symptom rather than the root cause of the problem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's more guesswork/ clutching at straws so I can roll it back?

I added this as sometimes we map and pass recipient.address.

I was searching for the cause of a possible "Cannot read property of undefined reading .address" error. It should throw a type error but I'm not sure if that will help if we are mapping through recipients with an undefined address.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would prefer to revert this change. This would really confuse me reading this code.

If investigating, suggesting put a analytics event here if undefined? Or, to do a runtime check on this, do it where the component is used vs inside it.

@pete-watters pete-watters marked this pull request as ready for review May 16, 2024 13:43
Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 9f73b24 and 1fab7d8.
Files selected for processing (8)
  • src/app/components/address-displayer/form-address-displayer.tsx (2 hunks)
  • src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx (2 hunks)
  • src/app/pages/send/ordinal-inscription/send-inscription-review.tsx (1 hunks)
  • src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx (1 hunks)
  • src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx (1 hunks)
  • src/app/query/stacks/bns/bns.utils.ts (1 hunks)
  • src/app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks.ts (1 hunks)
  • src/app/ui/components/address-displayer/address-displayer.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks.ts
Additional comments not posted (9)
src/app/ui/components/address-displayer/address-displayer.tsx (2)

6-7: Simplified the AddressDisplayerProps interface by removing unnecessary dependencies.


9-13: Refactored the AddressDisplayer function to directly use the address property without spreading other props.

src/app/components/address-displayer/form-address-displayer.tsx (2)

6-7: Simplified the FormAddressDisplayerProps interface by removing unnecessary dependencies.


Line range hint 9-19: Refactored the FormAddressDisplayer function to directly use the address property without spreading other props and added a conditional rendering check for the address prop.

src/app/pages/send/ordinal-inscription/send-inscription-review.tsx (1)

67-67: Added error tracking for broadcast_ordinal_transaction_error in the onError callback.

src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx (1)

101-103: Added error tracking for broadcast_brc20_transaction_error in the onError callback.

src/app/query/stacks/bns/bns.utils.ts (1)

143-143: Good defensive coding practice by checking if res.address is undefined before proceeding.

src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx (1)

134-139: Adding analytics tracking for ledger_transaction_publish_error is a good practice for monitoring and diagnosing issues.

src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx (1)

141-143: Adding analytics tracking for btc_transaction_broadcast_error is a good practice for monitoring and diagnosing issues.

@markmhendrickson
Copy link
Collaborator

@pete-watters mind adding details about the new analytics (e.g. new events?) to the description? 🙏

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 1fab7d8 and 82ce4a1.
Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !pnpm-lock.yaml
Files selected for processing (4)
  • package.json (1 hunks)
  • src/app/pages/send/ordinal-inscription/send-inscription-review.tsx (1 hunks)
  • src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx (1 hunks)
  • src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • package.json
Files skipped from review as they are similar to previous changes (3)
  • src/app/pages/send/ordinal-inscription/send-inscription-review.tsx
  • src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx
  • src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 82ce4a1 and 5446e92.
Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !pnpm-lock.yaml
Files selected for processing (9)
  • package.json (1 hunks)
  • src/app/components/address-displayer/form-address-displayer.tsx (2 hunks)
  • src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx (2 hunks)
  • src/app/pages/send/ordinal-inscription/send-inscription-review.tsx (1 hunks)
  • src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx (1 hunks)
  • src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx (1 hunks)
  • src/app/query/stacks/bns/bns.utils.ts (1 hunks)
  • src/app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks.ts (1 hunks)
  • src/app/ui/components/address-displayer/address-displayer.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx
Files skipped from review as they are similar to previous changes (8)
  • package.json
  • src/app/components/address-displayer/form-address-displayer.tsx
  • src/app/pages/send/ordinal-inscription/send-inscription-review.tsx
  • src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx
  • src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx
  • src/app/query/stacks/bns/bns.utils.ts
  • src/app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks.ts
  • src/app/ui/components/address-displayer/address-displayer.tsx

>
<AddressDisplayer address={address} />
{address && <AddressDisplayer address={address} />}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would prefer to revert this change. This would really confuse me reading this code.

If investigating, suggesting put a analytics event here if undefined? Or, to do a runtime check on this, do it where the component is used vs inside it.

@pete-watters pete-watters added this pull request to the merge queue May 20, 2024
Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 5446e92 and bf36652.
Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !pnpm-lock.yaml
Files selected for processing (7)
  • package.json (1 hunks)
  • src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx (2 hunks)
  • src/app/pages/send/ordinal-inscription/send-inscription-review.tsx (1 hunks)
  • src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx (1 hunks)
  • src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx (1 hunks)
  • src/app/query/stacks/bns/bns.utils.ts (1 hunks)
  • src/app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks.ts (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • package.json
  • src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx
  • src/app/pages/send/ordinal-inscription/send-inscription-review.tsx
  • src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx
  • src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx
  • src/app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks.ts
Additional comments not posted (1)
src/app/query/stacks/bns/bns.utils.ts (1)

143-143: Added null checks for res.address enhance robustness by preventing potential runtime errors when the address is undefined or an empty string.

Merged via the queue into dev with commit a36dae4 May 20, 2024
27 checks passed
@pete-watters pete-watters deleted the fix/5118/broadcast-error branch May 20, 2024 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ledger bug: Erroneous Unable to broadcast transaction error
3 participants