Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
43370774
Commit
43370774
authored
Jan 11, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
custom error message
parent
f0302aed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
21 deletions
+43
-21
ContractMethodCallable.tsx
ui/address/contract/ContractMethodCallable.tsx
+1
-1
ContractWrite.tsx
ui/address/contract/ContractWrite.tsx
+42
-20
No files found.
ui/address/contract/ContractMethodCallable.tsx
View file @
43370774
...
...
@@ -81,7 +81,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
setLoading
(
false
);
})
.
catch
((
error
)
=>
{
setResult
(
error
?.
error
||
error
?.
data
||
error
);
setResult
(
error
?.
error
||
error
?.
data
||
(
error
?.
reason
&&
{
message
:
error
.
reason
})
||
error
);
setLoading
(
false
);
});
},
[
onSubmit
,
data
,
inputs
]);
...
...
ui/address/contract/ContractWrite.tsx
View file @
43370774
import
{
Alert
}
from
'
@chakra-ui/react
'
;
import
_capitalize
from
'
lodash/capitalize
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
{
useSigner
}
from
'
wagmi
'
;
...
...
@@ -6,6 +7,7 @@ import { useSigner } from 'wagmi';
import
type
{
ContractMethodWriteResult
}
from
'
./types
'
;
import
type
{
SmartContractWriteMethod
}
from
'
types/api/contract
'
;
import
config
from
'
configs/app/config
'
;
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
ContractMethodsAccordion
from
'
ui/address/contract/ContractMethodsAccordion
'
;
import
ContentLoader
from
'
ui/shared/ContentLoader
'
;
...
...
@@ -37,29 +39,49 @@ const ContractWrite = ({ isProxy }: Props) => {
const
contract
=
useContractContext
();
const
handleMethodFormSubmit
=
React
.
useCallback
(
async
(
item
:
SmartContractWriteMethod
,
args
:
Array
<
string
|
Array
<
string
>>
)
=>
{
if
(
!
contract
)
{
return
;
}
if
(
item
.
type
===
'
fallback
'
||
item
.
type
===
'
receive
'
)
{
const
value
=
args
[
0
]
?
getNativeCoinValue
(
args
[
0
])
:
'
0
'
;
const
result
=
await
signer
?.
sendTransaction
({
to
:
addressHash
,
try
{
if
(
!
contract
)
{
return
;
}
if
(
item
.
type
===
'
fallback
'
||
item
.
type
===
'
receive
'
)
{
const
value
=
args
[
0
]
?
getNativeCoinValue
(
args
[
0
])
:
'
0
'
;
const
result
=
await
signer
?.
sendTransaction
({
to
:
addressHash
,
value
,
});
return
{
hash
:
result
?.
hash
as
string
};
}
const
_args
=
item
.
stateMutability
===
'
payable
'
?
args
.
slice
(
0
,
-
1
)
:
args
;
const
value
=
item
.
stateMutability
===
'
payable
'
?
getNativeCoinValue
(
args
[
args
.
length
-
1
])
:
undefined
;
const
methodName
=
item
.
name
;
const
result
=
await
contract
[
methodName
](...
_args
,
{
gasLimit
:
100
_000
,
value
,
});
return
{
hash
:
result
?.
hash
as
string
};
}
const
_args
=
item
.
stateMutability
===
'
payable
'
?
args
.
slice
(
0
,
-
1
)
:
args
;
const
value
=
item
.
stateMutability
===
'
payable
'
?
getNativeCoinValue
(
args
[
args
.
length
-
1
])
:
undefined
;
const
methodName
=
item
.
name
;
const
result
=
await
contract
[
methodName
](...
_args
,
{
gasLimit
:
100
_000
,
value
,
});
return
{
hash
:
result
.
hash
as
string
};
return
{
hash
:
result
.
hash
as
string
};
}
catch
(
error
)
{
if
(
error
instanceof
Error
)
{
if
(
'
reason
'
in
error
&&
error
.
reason
===
'
underlying network changed
'
)
{
if
(
'
detectedNetwork
'
in
error
)
{
const
networkName
=
(
error
.
detectedNetwork
as
{
name
:
string
}).
name
;
if
(
networkName
)
{
throw
new
Error
(
`You connected to
${
_capitalize
(
networkName
)
}
chain in the wallet,
but the current instance of Blockscout is for
${
config
.
network
.
name
}
chain`
,
);
}
}
throw
new
Error
(
'
Wrong network detected, please make sure you are switched to the correct network, and try again
'
);
}
}
throw
error
;
}
},
[
addressHash
,
contract
,
signer
]);
const
renderResult
=
React
.
useCallback
((
item
:
SmartContractWriteMethod
,
result
:
ContractMethodWriteResult
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment