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
53b175ba
Commit
53b175ba
authored
Feb 17, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
contract: custom write methods
parent
428ec75e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
6 deletions
+33
-6
ContractWrite.tsx
ui/address/contract/ContractWrite.tsx
+13
-3
context.tsx
ui/address/contract/context.tsx
+20
-3
No files found.
ui/address/contract/ContractWrite.tsx
View file @
53b175ba
...
@@ -42,8 +42,18 @@ const ContractWrite = ({ isProxy, isCustomAbi }: Props) => {
...
@@ -42,8 +42,18 @@ const ContractWrite = ({ isProxy, isCustomAbi }: Props) => {
},
},
});
});
const
{
contract
,
proxy
}
=
useContractContext
();
const
{
contract
,
proxy
,
custom
}
=
useContractContext
();
const
_contract
=
isProxy
?
proxy
:
contract
;
const
_contract
=
(()
=>
{
if
(
isProxy
)
{
return
proxy
;
}
if
(
isCustomAbi
)
{
return
custom
;
}
return
contract
;
})();
const
handleMethodFormSubmit
=
React
.
useCallback
(
async
(
item
:
SmartContractWriteMethod
,
args
:
Array
<
string
|
Array
<
string
>>
)
=>
{
const
handleMethodFormSubmit
=
React
.
useCallback
(
async
(
item
:
SmartContractWriteMethod
,
args
:
Array
<
string
|
Array
<
string
>>
)
=>
{
if
(
!
isConnected
)
{
if
(
!
isConnected
)
{
...
@@ -52,7 +62,7 @@ const ContractWrite = ({ isProxy, isCustomAbi }: Props) => {
...
@@ -52,7 +62,7 @@ const ContractWrite = ({ isProxy, isCustomAbi }: Props) => {
try
{
try
{
if
(
!
_contract
)
{
if
(
!
_contract
)
{
return
;
throw
new
Error
(
'
Something went wrong. Try again later.
'
)
;
}
}
if
(
item
.
type
===
'
receive
'
)
{
if
(
item
.
type
===
'
receive
'
)
{
...
...
ui/address/contract/context.tsx
View file @
53b175ba
...
@@ -15,11 +15,13 @@ type ProviderProps = {
...
@@ -15,11 +15,13 @@ type ProviderProps = {
type
TContractContext
=
{
type
TContractContext
=
{
contract
:
Contract
|
null
;
contract
:
Contract
|
null
;
proxy
:
Contract
|
null
;
proxy
:
Contract
|
null
;
custom
:
Contract
|
null
;
};
};
const
ContractContext
=
React
.
createContext
<
TContractContext
>
({
const
ContractContext
=
React
.
createContext
<
TContractContext
>
({
contract
:
null
,
contract
:
null
,
proxy
:
null
,
proxy
:
null
,
custom
:
null
,
});
});
export
function
ContractContextProvider
({
children
}:
ProviderProps
)
{
export
function
ContractContextProvider
({
children
}:
ProviderProps
)
{
...
@@ -49,21 +51,36 @@ export function ContractContextProvider({ children }: ProviderProps) {
...
@@ -49,21 +51,36 @@ export function ContractContextProvider({ children }: ProviderProps) {
},
},
});
});
const
{
data
:
customInfo
}
=
useApiQuery
(
'
contract_methods_write
'
,
{
pathParams
:
{
hash
:
addressHash
},
queryParams
:
{
is_custom_abi
:
'
true
'
},
queryOptions
:
{
enabled
:
Boolean
(
addressInfo
?.
has_custom_methods_write
),
refetchOnMount
:
false
,
},
});
const
contract
=
useContract
({
const
contract
=
useContract
({
address
:
addressHash
,
address
:
addressHash
,
abi
:
contractInfo
?.
abi
||
undefined
,
abi
:
contractInfo
?.
abi
??
undefined
,
signerOrProvider
:
signer
||
provider
,
signerOrProvider
:
signer
??
provider
,
});
});
const
proxy
=
useContract
({
const
proxy
=
useContract
({
address
:
addressInfo
?.
implementation_address
??
undefined
,
address
:
addressInfo
?.
implementation_address
??
undefined
,
abi
:
proxyInfo
?.
abi
??
undefined
,
abi
:
proxyInfo
?.
abi
??
undefined
,
signerOrProvider
:
signer
??
provider
,
signerOrProvider
:
signer
??
provider
,
});
});
const
custom
=
useContract
({
address
:
addressHash
,
abi
:
customInfo
??
undefined
,
signerOrProvider
:
signer
??
provider
,
});
const
value
=
React
.
useMemo
(()
=>
({
const
value
=
React
.
useMemo
(()
=>
({
contract
,
contract
,
proxy
,
proxy
,
}),
[
contract
,
proxy
]);
custom
,
}),
[
contract
,
proxy
,
custom
]);
return
(
return
(
<
ContractContext
.
Provider
value=
{
value
}
>
<
ContractContext
.
Provider
value=
{
value
}
>
...
...
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