@@ -51,10 +51,18 @@ export default function ParserOpenRPC({
51
51
const [ isDrawerContentFixed , setIsDrawerContentFixed ] = useState ( false ) ;
52
52
const [ drawerLabel , setDrawerLabel ] = useState ( null ) ;
53
53
const [ isComplexTypeView , setIsComplexTypeView ] = useState ( false ) ;
54
- const { metaMaskAccount, metaMaskProvider } = useContext (
54
+ const { metaMaskAccount, metaMaskProvider, userAPIKey } = useContext (
55
55
MetamaskProviderContext
56
56
) ;
57
57
const { colorMode } = useColorMode ( ) ;
58
+ const trackAnalyticsForRequest = ( response ) => {
59
+ trackClickForSegment ( {
60
+ eventName : "Request Sent" ,
61
+ clickType : "Request Sent" ,
62
+ userExperience : "B" ,
63
+ ...( response ?. code && { responseStatus : response . code } ) ,
64
+ } ) ;
65
+ }
58
66
const openModal = ( ) => {
59
67
setModalOpen ( true ) ;
60
68
trackClickForSegment ( {
@@ -147,21 +155,39 @@ export default function ParserOpenRPC({
147
155
} ;
148
156
149
157
const onSubmitRequestHandle = async ( ) => {
150
- if ( ! metaMaskProvider ) return ;
151
- try {
152
- const response = await metaMaskProvider ?. request ( {
153
- method : method ,
154
- params : paramsData ,
155
- } ) ;
156
- setReqResult ( response ) ;
157
- trackClickForSegment ( {
158
- eventName : "Request Sent" ,
159
- clickType : "Request Sent" ,
160
- userExperience : "B" ,
161
- ...( response ?. code && { responseStatus : response . code } ) ,
162
- } ) ;
163
- } catch ( e ) {
164
- setReqResult ( e ) ;
158
+ if ( isMetamaskNetwork ) {
159
+ if ( ! metaMaskProvider ) return
160
+ try {
161
+ const response = await metaMaskProvider ?. request ( {
162
+ method : method ,
163
+ params : paramsData
164
+ } )
165
+ setReqResult ( response ) ;
166
+ trackAnalyticsForRequest ( response ) ;
167
+ } catch ( e ) {
168
+ setReqResult ( e ) ;
169
+ }
170
+ } else {
171
+ const NETWORK_URL = "https://linea-mainnet.infura.io" ;
172
+ const URL = `${ NETWORK_URL } /v3/${ userAPIKey } ` ;
173
+ let params = {
174
+ method : "POST" ,
175
+ "Content-Type" : "application/json" ,
176
+ body : JSON . stringify ( {
177
+ jsonrpc : "2.0" ,
178
+ method,
179
+ params : paramsData ,
180
+ id : 1 ,
181
+ } ) ,
182
+ } ;
183
+ const res = await fetch ( URL , params ) ;
184
+ if ( res . ok ) {
185
+ const response = await res . json ( ) ;
186
+ setReqResult ( response . result ) ;
187
+ trackAnalyticsForRequest ( response . result ) ;
188
+ } else {
189
+ console . error ( "error" ) ;
190
+ }
165
191
}
166
192
} ;
167
193
0 commit comments