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

POC: Add examples to stackblitz #574

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

roninjin10
Copy link

This pr is a proof of concept and guide to how to integrate stack blitz examples into docs

See stackblitz

OP Stack viem example

An example of getting a withdrawal status with viem that runs in a stack blitz

Open in StackBlitz

Note: this can be also embedded into a docs site via an iframe

<iframe src="https://stackblitz.com/github/ethereum-optimism/docs/tree/01-03-feat_Add_404_page/examples?file=viem%2Fwithdrawal-status.mjs"></iframe>

.stackblitzrc

This is how you configure stackblitz https://developer.stackblitz.com/platform/webcontainers/project-config#frontmatter-title

index.html and main.mjs

I made a really simple basic html site that runs via vitest. The html file imports the main.mjs file. It's not using a framework it's just basic html and javascript for simplicity.

All the site does is run the example code and output the result. This is useful within stackblitz because it gives you something to look at in the browser.

viem/withdrawal-status.mjs

Simple example of getting withdrawal status with viem. For simplicity it just uses javascript which means you can run it with node without needing to build or use ts-node etc.

viem/withdrawal-status.spec.mjs

Might be worth adding checks that make sure the example is working as expected

@roninjin10 roninjin10 requested a review from a team as a code owner March 15, 2024 18:34
Copy link
Contributor

coderabbitai bot commented Mar 15, 2024

Walkthrough

The changes encompass the creation of a StackBlitz project showcasing withdrawal status retrieval with Viem in the context of the Optimism protocol. This project includes essential setup files, a detailed guide, web interface components like HTML and JavaScript files, as well as a package setup for managing dependencies. Furthermore, a specific example focusing on withdrawal status retrieval is provided, complemented by a test suite to validate its functionality.

Changes

File(s) Summary
examples/.stackblitzrc Specifies project metadata for the StackBlitz project.
examples/README.md Introduces an example for withdrawal status retrieval using Viem in StackBlitz.
examples/index.html Provides a basic HTML structure for the Optimism examples page.
examples/main.mjs Implements JavaScript for displaying withdrawal status data.
examples/package.json Configures "@eth-optimism/examples" package with dependencies and scripts.
examples/viem/README.md Offers an example related to deposit functionality for the OP Stack system.
examples/viem/withdrawal-status.mjs Implements withdrawal status retrieval using Viem's clients.
examples/viem/withdrawal-status.spec.js Includes a test suite to verify withdrawal status retrieval functionality.

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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

netlify bot commented Mar 15, 2024

Deploy Preview for docs-optimism ready!

Name Link
🔨 Latest commit c8d7d58
🔍 Latest deploy log https://app.netlify.com/sites/docs-optimism/deploys/65f49833845248000854425f
😎 Deploy Preview https://deploy-preview-574--docs-optimism.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -0,0 +1,2 @@
OP Stack – Deposit Example
Copy link
Contributor

Choose a reason for hiding this comment

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

The title "OP Stack – Deposit Example" seems to be a placeholder or incorrect. Given the PR's focus on withdrawal status, consider updating the title to accurately reflect the content, such as "OP Stack – Withdrawal Status Example".

Comment on lines +1 to +40
// Source: https://github.com/wevm/viem/blob/main/src/chains/opStack/actions/getWithdrawalStatus.ts
// Docs: https://viem.sh/op-stack/actions/getWithdrawalStatus
import { createPublicClient, http } from 'viem'
import { mainnet, optimism } from 'viem/chains'
import { publicActionsL1, publicActionsL2 } from 'viem/op-stack'
// https://optimistic.etherscan.io/tx/0x7b5cedccfaf9abe6ce3d07982f57bcb9176313b019ff0fc602a0b70342fe3147
const DEFAULT_TX_HASH = '0x7b5cedccfaf9abe6ce3d07982f57bcb9176313b019ff0fc602a0b70342fe3147'

const l1Client = createPublicClient({
name: "Ethereum L1 Client",
// Note: you should consider using an authenticated endpoint to prevent throttling
transport: http(mainnet.rpcUrls.default.http[0]),
chain: mainnet,
}).extend(publicActionsL1())

const l2Client = createPublicClient({
name: "Optimism L2 Client",
// Note: you should consider using an authenticated endpoint to prevent throttling
transport: http(optimism.rpcUrls.default.http[0]),
// TODO this type needing to be cast is an actual bug in viem
chain: /** import('viem').Chain*/(optimism),
}).extend(publicActionsL2())

/**
* @param {import('viem').Hex} txHash
*/
export const getWithdrawalStatusExample = async (txHash = DEFAULT_TX_HASH) => {
const receipt = await l2Client.getTransactionReceipt({
hash: txHash,
})
const status = await l1Client.getWithdrawalStatus({
receipt,
chain: l1Client.chain,
targetChain: l2Client.chain,
})

console.log(status) // ready-to-prove

return status
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation for fetching withdrawal status using Viem's public clients is well-done and serves as a clear example. The comments are helpful and improve the understandability of the code. Consider creating an issue or a task to address the known bug mentioned in the TODO comment on line 20 to ensure it doesn't get overlooked.

Would you like me to open a GitHub issue to track the resolution of the type casting bug mentioned in the TODO comment?

@roninjin10 roninjin10 changed the title feat: Add examples to stackblitz POC: Add examples to stackblitz Mar 15, 2024
@roninjin10 roninjin10 requested a review from sbvegan March 15, 2024 18:46
@@ -0,0 +1,31 @@
See stackblitz
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible spelling mistake found in "See stackblitz". The correct spelling should be "StackBlitz" as it is a proper noun.

- See stackblitz
+ See StackBlitz

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
See stackblitz
See StackBlitz


# OP Stack viem example

An example of getting a withdrawal status with viem that runs in a stack blitz
Copy link
Contributor

Choose a reason for hiding this comment

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

The phrase "that runs in a stack blitz" should be corrected to "that runs in StackBlitz" for consistency and proper noun usage.

- An example of getting a withdrawal status with viem that runs in a stack blitz
+ An example of getting a withdrawal status with viem that runs in StackBlitz

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
An example of getting a withdrawal status with viem that runs in a stack blitz
An example of getting a withdrawal status with viem that runs in StackBlitz


[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/ethereum-optimism/docs/tree/01-03-feat_Add_404_page/examples?file=viem%2Fwithdrawal-status.mjs)

Note: this can be also embedded into a docs site via an iframe
Copy link
Contributor

Choose a reason for hiding this comment

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

The word order in "this can be also embedded" might sound more natural as "this can also be embedded".

- Note: this can be also embedded into a docs site via an iframe
+ Note: this can also be embedded into a docs site via an iframe

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Note: this can be also embedded into a docs site via an iframe
Note: this can also be embedded into a docs site via an iframe


## index.html and main.mjs

I made a really simple basic html site that runs via [vitest](https://vitest.dev/). The html file imports the main.mjs file. It's not using a framework it's just basic html and javascript for simplicity.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider simplifying "I made a really simple basic html site" to "I made a simple basic HTML site" for clarity and to avoid redundancy. Also, capitalize "html" to "HTML".

- I made a really simple basic html site that runs via [vitest](https://vitest.dev/).
+ I made a simple basic HTML site that runs via [vitest](https://vitest.dev/).

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
I made a really simple basic html site that runs via [vitest](https://vitest.dev/). The html file imports the main.mjs file. It's not using a framework it's just basic html and javascript for simplicity.
I made a simple basic HTML site that runs via [vitest](https://vitest.dev/). The html file imports the main.mjs file. It's not using a framework it's just basic html and javascript for simplicity.

The phrase "It's not using a framework it's just basic html and javascript" could be improved by adding a comma for clarity and capitalizing "html" and "javascript".

- It's not using a framework it's just basic html and javascript for simplicity.
+ It's not using a framework, it's just basic HTML and JavaScript for simplicity.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
I made a really simple basic html site that runs via [vitest](https://vitest.dev/). The html file imports the main.mjs file. It's not using a framework it's just basic html and javascript for simplicity.
I made a really simple basic html site that runs via [vitest](https://vitest.dev/). The html file imports the main.mjs file. It's not using a framework, it's just basic HTML and JavaScript for simplicity.


## viem/withdrawal-status.mjs

Simple example of getting withdrawal status with viem. For simplicity it just uses javascript which means you can run it with node without needing to build or use ts-node etc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a comma after "For simplicity" for better readability.

- Simple example of getting withdrawal status with viem. For simplicity it just uses javascript
+ Simple example of getting withdrawal status with viem. For simplicity, it just uses JavaScript

Also, capitalize "javascript" to "JavaScript".


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Simple example of getting withdrawal status with viem. For simplicity it just uses javascript which means you can run it with node without needing to build or use ts-node etc.
Simple example of getting withdrawal status with viem. For simplicity, it just uses JavaScript


## viem/withdrawal-status.spec.mjs

Might be worth adding checks that make sure the example is working as expected
Copy link
Contributor

Choose a reason for hiding this comment

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

The sentence "Might be worth adding checks that make sure the example is working as expected" could be improved for clarity and completeness.

- Might be worth adding checks that make sure the example is working as expected
+ It might be worth adding checks to ensure the example is working as expected.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Might be worth adding checks that make sure the example is working as expected
It might be worth adding checks to ensure the example is working as expected.

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.

None yet

1 participant