1
+ import { Box , Text , Button , TextInput , Spinner } from '@0xsequence/design-system'
2
+ import { SetStateAction , useEffect , useState } from 'react'
3
+ import { sequence } from '../../main'
4
+ import { delayedEncode , FeeOption , isSentTransactionResponse , Network } from '@0xsequence/waas'
5
+ import { checkTransactionFeeOptions , TransactionFeeOptions } from './TransactionFeeOptions.tsx'
6
+ import { findSupportedNetwork } from '@0xsequence/network'
1
7
2
- import { Box , Text , Button , TextInput , Spinner } from "@0xsequence/design-system"
3
- import { SetStateAction , useState } from "react"
4
- import { sequence } from "../../main"
5
- import {
6
- delayedEncode ,
7
- FeeOption ,
8
- isSentTransactionResponse ,
9
- Network ,
10
- } from "@0xsequence/waas"
11
- import { checkTransactionFeeOptions , TransactionFeeOptions } from "./TransactionFeeOptions.tsx" ;
12
-
13
- export function CallContractsView ( props : { network ?: Network } ) {
8
+ export function CallContractsView ( props : { network ?: Network } ) {
14
9
const [ contractAddress , setContractAddress ] = useState < string > ( '' )
15
10
const [ contractAbi , setContractAbi ] = useState < string > ( '' )
16
11
const [ contractMethod , setContractMethod ] = useState < string > ( '' )
@@ -24,15 +19,28 @@ export function CallContractsView(props: {network?: Network}) {
24
19
const [ feeQuote , setFeeQuote ] = useState < string > ( )
25
20
const [ feeSponsored , setFeeSponsored ] = useState < boolean > ( false )
26
21
22
+ const [ blockExplorerURL , setBlockExplorerURL ] = useState < string > ( '' )
23
+
24
+ useEffect ( ( ) => {
25
+ if ( props . network ) {
26
+ const networkConfig = findSupportedNetwork ( props . network . name )
27
+ if ( networkConfig ?. blockExplorer ?. rootUrl ) {
28
+ setBlockExplorerURL ( networkConfig . blockExplorer ?. rootUrl )
29
+ }
30
+ }
31
+ } , [ props . network ] )
32
+
27
33
const checkFeeOptions = async ( ) => {
28
34
const resp = await checkTransactionFeeOptions ( {
29
- transactions : [ delayedEncode ( {
30
- to : contractAddress ,
31
- abi : contractAbi ,
32
- func : contractMethod ,
33
- args : JSON . parse ( contractMethodArgs ) ,
34
- value : "0"
35
- } ) ] ,
35
+ transactions : [
36
+ delayedEncode ( {
37
+ to : contractAddress ,
38
+ abi : contractAbi ,
39
+ func : contractMethod ,
40
+ args : JSON . parse ( contractMethodArgs ) ,
41
+ value : '0'
42
+ } )
43
+ ] ,
36
44
network : props . network
37
45
} )
38
46
@@ -132,44 +140,30 @@ export function CallContractsView(props: {network?: Network}) {
132
140
/>
133
141
</ Box >
134
142
135
- < TransactionFeeOptions feeOptions = { feeOptions } onSelected = { setFeeOption } />
136
- { feeSponsored && (
143
+ < TransactionFeeOptions feeOptions = { feeOptions } onSelected = { setFeeOption } />
144
+ { feeSponsored && (
137
145
< Box marginTop = "5" >
138
146
< Text variant = "normal" fontWeight = "bold" >
139
147
Fee options: Tx Sponsored!
140
148
</ Text >
141
149
</ Box >
142
150
) }
143
151
144
- { sendTransactionError && (
145
- < Box marginTop = "3" >
146
- Transaction failed: { sendTransactionError }
147
- </ Box >
148
- ) }
152
+ { sendTransactionError && < Box marginTop = "3" > Transaction failed: { sendTransactionError } </ Box > }
149
153
{ ! inProgress ? (
150
154
< Box >
151
155
< Button
152
156
marginTop = "5"
153
157
marginRight = "2"
154
158
label = "Check fee options"
155
- disabled = {
156
- contractAddress === '' &&
157
- contractAbi === '' &&
158
- contractMethod === '' &&
159
- contractMethodArgs === ''
160
- }
159
+ disabled = { contractAddress === '' && contractAbi === '' && contractMethod === '' && contractMethodArgs === '' }
161
160
onClick = { ( ) => checkFeeOptions ( ) }
162
161
/>
163
162
< Button
164
163
marginTop = "5"
165
164
label = "Call contract"
166
- disabled = {
167
- contractAddress === '' &&
168
- contractAbi === '' &&
169
- contractMethod === '' &&
170
- contractMethodArgs === ''
171
- }
172
- onClick = { ( ) => callContract ( ) }
165
+ disabled = { contractAddress === '' && contractAbi === '' && contractMethod === '' && contractMethodArgs === '' }
166
+ onClick = { ( ) => callContract ( ) }
173
167
/>
174
168
</ Box >
175
169
) : (
@@ -183,7 +177,7 @@ export function CallContractsView(props: {network?: Network}) {
183
177
Send native token transaction hash:
184
178
</ Text >
185
179
< br />
186
- < a href = { `https://polygonscan.com/ tx/${ transactionHash } ` } target = "_blank" rel = "noopener noreferrer" >
180
+ < a href = { `${ blockExplorerURL } tx/${ transactionHash } ` } target = "_blank" rel = "noopener noreferrer" >
187
181
{ transactionHash }
188
182
</ a >
189
183
</ Box >
0 commit comments