pieces-app / example-typescript

A React example project showing how to get started with Pieces TS SDK.
MIT License
31 stars 39 forks source link

feat: Refactor Promises to Use Async/Await in assets.tsx #127

Open Arindam200 opened 3 weeks ago

Arindam200 commented 3 weeks ago

Description

The current implementation in assets.tsx uses the .then() method to handle promises. While this approach works, it can lead to nested callbacks and less readable code. To improve code clarity and maintainability, we should refactor the code to use async/await.

Proposed Solution

Refactor the promise handling in assets.tsx to use async/await syntax. This will make the asynchronous code more readable and easier to follow.

Detailed Steps

  1. Identify Promise Chains:

    • Locate all instances in assets.tsx where .then() is used to handle promises.
  2. Refactor to Async/Await:

    • Convert the functions containing .then() chains to async functions.
    • Replace .then() with await to handle the resolved values of the promises.
    • Use try/catch blocks to handle errors instead of .catch().
  3. Testing:

    • Ensure that the refactored code is thoroughly tested.
    • Write unit tests to verify that the asynchronous operations work as expected.
    • Test error handling to ensure that errors are caught and handled properly.

Benefits

Additional Notes

By refactoring the promise handling in assets.tsx to use async/await, we can enhance the readability and maintainability of the codebase. This approach also aligns with modern JavaScript best practices for handling asynchronous operations.

Babuprasanth27 commented 3 weeks ago

@Arindam200 Hey Greetings, I am interested in fixing this issue. Please assign it to me.

Arindam200 commented 3 weeks ago

Go Ahead!