-
Notifications
You must be signed in to change notification settings - Fork 2
feat(web): get last max fee from batcher #337
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9b4f376
Add initial version of useBatcherMaxFee hook
maximopalopoli df1d86a
Use hook in submit step to cap the max fee value
maximopalopoli 4d2988d
Use hook when setting the values on bump fee modal
maximopalopoli 2398b5a
Fix the chriteria to choose between estimated and latest
maximopalopoli a6337af
Update the useBatcherMaxFee component
maximopalopoli 5880088
Revert "Use hook when setting the values on bump fee modal"
maximopalopoli 733c02f
Remove console logs and unused property param
maximopalopoli f1cdc7c
Merge branch 'main' into feat/get-last-max-fee-from-batcher
maximopalopoli 9c45678
Merge branch 'main' into feat/get-last-max-fee-from-batcher
maximopalopoli aa1782b
Add latestMaxFee and maxFee vars to the callbacks
maximopalopoli 8e79834
Cap the estimated max fee with the latest one in the cost shown in modal
maximopalopoli f2e1e19
Merge branch 'main' into feat/get-last-max-fee-from-batcher
maximopalopoli 3b044cb
Merge branch 'main' into feat/get-last-max-fee-from-batcher
maximopalopoli 2d8759f
Merge branch 'main' into feat/get-last-max-fee-from-batcher
MarcosNicolau 8f2d780
Merge branch 'main' into feat/get-last-max-fee-from-batcher
maximopalopoli 8d5db8c
Merge branch 'main' into feat/get-last-max-fee-from-batcher
maximopalopoli 9907047
Merge branch 'main' into feat/get-last-max-fee-from-batcher
maximopalopoli 5713102
Merge branch 'main' into feat/get-last-max-fee-from-batcher
MarcosNicolau 468a9ad
Merge branch 'main' into feat/get-last-max-fee-from-batcher
JuArce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { encode as cborEncode, decode as cborDecode } from 'cbor2'; | ||
| import { hexToBigInt } from "viem"; | ||
|
|
||
| type GetLastMaxFeeFromBatcherResponse = { | ||
| ProtocolVersion: string, | ||
| LastMaxFee: `0x${string}`; | ||
| EthRpcError: string; | ||
| InvalidRequest: string; | ||
| } | ||
|
|
||
| export function useBatcherMaxFee(batcher_url: string, address?: string) { | ||
| const [maxFee, setMaxFee] = useState<bigint | null>(null); | ||
| const [error, setError] = useState<Error | null>(null); | ||
| const [isLoading, setIsLoading] = useState(true); | ||
|
|
||
| useEffect(() => { | ||
| let ws: WebSocket | null = null; | ||
|
|
||
| const fetchMaxFee = () => { | ||
| if (!address) { | ||
| return | ||
| } | ||
|
|
||
| ws = new WebSocket(`${batcher_url}`); | ||
| ws.binaryType = 'arraybuffer'; | ||
|
|
||
| ws.onopen = () => { | ||
| console.log("WebSocket connection established"); | ||
| }; | ||
|
|
||
| ws.onmessage = (event) => { | ||
| try { | ||
| const cbor_data = event.data; | ||
| const data = cborDecode<GetLastMaxFeeFromBatcherResponse>(new Uint8Array(cbor_data)); | ||
|
|
||
| if (data?.ProtocolVersion) { | ||
| const message = { GetLastMaxFee: address }; | ||
| const encoded = cborEncode(message).buffer; | ||
| ws?.send(encoded); | ||
| } else if (data?.LastMaxFee) { | ||
| ws?.close(); | ||
| setMaxFee(hexToBigInt(data.LastMaxFee)); | ||
| setIsLoading(false); | ||
| } else if (data?.EthRpcError || data?.InvalidRequest) { | ||
| ws?.close(); | ||
| setError(new Error(JSON.stringify(data))); | ||
| setIsLoading(false); | ||
| } | ||
| } catch (e) { | ||
| ws?.close(); | ||
| setError(e as Error); | ||
| setIsLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| ws.onerror = () => { | ||
| ws?.close(); | ||
| setError(new Error("WebSocket connection error")); | ||
| setIsLoading(false); | ||
| }; | ||
| }; | ||
|
|
||
| fetchMaxFee(); | ||
|
|
||
| return () => { | ||
| ws?.close(); | ||
| }; | ||
| }, [batcher_url, address]); | ||
|
|
||
| return { maxFee, isLoading, error }; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.