-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathgetGasPrice.tsx
More file actions
90 lines (77 loc) · 1.98 KB
/
Copy pathgetGasPrice.tsx
File metadata and controls
90 lines (77 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { option } from 'pastel'
import { z } from 'zod'
import CliAction from '../components/CliAction.js'
import { useAction } from '../hooks/useAction.js'
// Add command description for help output
export const description =
'Get the current gas price\nExample: tevm get-gas-price --rpc https://mainnet.optimism.io --run --json'
// Options definitions and descriptions
const optionDescriptions = {
rpc: 'RPC endpoint (env: TEVM_RPC)',
}
// Empty args tuple
export const args = z.tuple([])
export const options = z.object({
// Interactive mode flag
run: z
.boolean()
.default(false)
.describe(
option({
description: 'Run directly without interactive parameter editing (env: TEVM_RUN)',
alias: 'r',
}),
),
// Transport options
rpc: z
.string()
.optional()
.describe(
option({
description: optionDescriptions.rpc,
defaultValueDescription: 'http://localhost:8545',
}),
),
// Output formatting
json: z
.boolean()
.optional()
.describe(
option({
description: 'Emit the stable machine-readable JSON envelope (env: TEVM_JSON)',
defaultValueDescription: 'false',
}),
),
})
type Props = {
args: z.infer<typeof args>
options: z.infer<typeof options>
}
// COMPREHENSIVE DEFAULTS
const defaultValues: Record<string, any> = {
rpc: 'http://localhost:8545',
}
export default function GetGasPrice({ options }: Props) {
// Use the action hook
const actionResult = useAction({
actionName: 'getGasPrice',
options,
defaultValues,
optionDescriptions,
// Create params - getGasPrice takes no parameters
createParams: (_enhancedOptions: Record<string, any>) => {
return {}
},
// Execute the action
executeAction: async (client: any, _params: any): Promise<any> => {
return await client.getGasPrice()
},
})
// If editor is active, render nothing
if (actionResult.editorActive) {
return null
}
return (
<CliAction {...actionResult} targetName="current gas price" successMessage="Gas price retrieved successfully!" />
)
}