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
758f8465
Commit
758f8465
authored
Jan 12, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
form submit state
parent
ff2ffc33
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
10 deletions
+30
-10
ContractMethodCallable.tsx
ui/address/contract/ContractMethodCallable.tsx
+12
-3
ContractMethodField.tsx
ui/address/contract/ContractMethodField.tsx
+5
-3
ContractRead.tsx
ui/address/contract/ContractRead.tsx
+3
-1
ContractWrite.tsx
ui/address/contract/ContractWrite.tsx
+2
-2
ContractWriteResult.tsx
ui/address/contract/ContractWriteResult.tsx
+8
-1
No files found.
ui/address/contract/ContractMethodCallable.tsx
View file @
758f8465
...
@@ -15,7 +15,7 @@ import ContractMethodField from './ContractMethodField';
...
@@ -15,7 +15,7 @@ import ContractMethodField from './ContractMethodField';
interface
Props
<
T
extends
SmartContractMethod
>
{
interface
Props
<
T
extends
SmartContractMethod
>
{
data
:
T
;
data
:
T
;
onSubmit
:
(
data
:
T
,
args
:
Array
<
string
|
Array
<
string
>>
)
=>
Promise
<
ContractMethodCallResult
<
T
>>
;
onSubmit
:
(
data
:
T
,
args
:
Array
<
string
|
Array
<
string
>>
)
=>
Promise
<
ContractMethodCallResult
<
T
>>
;
renderResult
:
(
data
:
T
,
result
:
ContractMethodCallResult
<
T
>
)
=>
React
.
ReactNode
;
renderResult
:
(
data
:
T
,
result
:
ContractMethodCallResult
<
T
>
,
onSettle
:
()
=>
void
)
=>
React
.
ReactNode
;
isWrite
?:
boolean
;
isWrite
?:
boolean
;
}
}
...
@@ -66,6 +66,14 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
...
@@ -66,6 +66,14 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
defaultValues
:
_fromPairs
(
inputs
.
map
(({
name
},
index
)
=>
[
getFieldName
(
name
,
index
),
''
])),
defaultValues
:
_fromPairs
(
inputs
.
map
(({
name
},
index
)
=>
[
getFieldName
(
name
,
index
),
''
])),
});
});
const
handleTxSettle
=
React
.
useCallback
(()
=>
{
setLoading
(
false
);
},
[]);
const
handleFormChange
=
React
.
useCallback
(()
=>
{
result
&&
setResult
(
undefined
);
},
[
result
]);
const
onFormSubmit
:
SubmitHandler
<
MethodFormFields
>
=
React
.
useCallback
(
async
(
formData
)
=>
{
const
onFormSubmit
:
SubmitHandler
<
MethodFormFields
>
=
React
.
useCallback
(
async
(
formData
)
=>
{
const
args
=
Object
.
entries
(
formData
)
const
args
=
Object
.
entries
(
formData
)
.
sort
(
sortFields
(
inputs
))
.
sort
(
sortFields
(
inputs
))
...
@@ -78,7 +86,6 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
...
@@ -78,7 +86,6 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
onSubmit
(
data
,
args
)
onSubmit
(
data
,
args
)
.
then
((
result
)
=>
{
.
then
((
result
)
=>
{
setResult
(
result
);
setResult
(
result
);
setLoading
(
false
);
})
})
.
catch
((
error
)
=>
{
.
catch
((
error
)
=>
{
setResult
(
error
?.
error
||
error
?.
data
||
(
error
?.
reason
&&
{
message
:
error
.
reason
})
||
error
);
setResult
(
error
?.
error
||
error
?.
data
||
(
error
?.
reason
&&
{
message
:
error
.
reason
})
||
error
);
...
@@ -97,6 +104,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
...
@@ -97,6 +104,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
alignItems=
{
{
base
:
'
flex-start
'
,
lg
:
'
center
'
}
}
alignItems=
{
{
base
:
'
flex-start
'
,
lg
:
'
center
'
}
}
onSubmit=
{
handleSubmit
(
onFormSubmit
)
}
onSubmit=
{
handleSubmit
(
onFormSubmit
)
}
flexWrap=
"wrap"
flexWrap=
"wrap"
onChange=
{
handleFormChange
}
>
>
{
inputs
.
map
(({
type
,
name
},
index
)
=>
{
{
inputs
.
map
(({
type
,
name
},
index
)
=>
{
const
fieldName
=
getFieldName
(
name
,
index
);
const
fieldName
=
getFieldName
(
name
,
index
);
...
@@ -108,6 +116,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
...
@@ -108,6 +116,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
control=
{
control
}
control=
{
control
}
setValue=
{
setValue
}
setValue=
{
setValue
}
isDisabled=
{
isLoading
}
isDisabled=
{
isLoading
}
onClear=
{
handleFormChange
}
/>
/>
);
);
})
}
})
}
...
@@ -128,7 +137,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
...
@@ -128,7 +137,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
<
Text
>
{
data
.
outputs
.
map
(({
type
})
=>
type
).
join
(
'
,
'
)
}
</
Text
>
<
Text
>
{
data
.
outputs
.
map
(({
type
})
=>
type
).
join
(
'
,
'
)
}
</
Text
>
</
Flex
>
</
Flex
>
)
}
)
}
{
result
&&
renderResult
(
data
,
result
)
}
{
result
&&
renderResult
(
data
,
result
,
handleTxSettle
)
}
</
Box
>
</
Box
>
);
);
}
;
}
;
...
...
ui/address/contract/ContractMethodField.tsx
View file @
758f8465
...
@@ -13,19 +13,21 @@ interface Props {
...
@@ -13,19 +13,21 @@ interface Props {
placeholder
:
string
;
placeholder
:
string
;
name
:
string
;
name
:
string
;
isDisabled
:
boolean
;
isDisabled
:
boolean
;
onClear
:
()
=>
void
;
}
}
const
ContractMethodField
=
({
control
,
name
,
placeholder
,
setValue
,
isDisabled
}:
Props
)
=>
{
const
ContractMethodField
=
({
control
,
name
,
placeholder
,
setValue
,
isDisabled
,
onClear
}:
Props
)
=>
{
const
ref
=
React
.
useRef
<
HTMLInputElement
>
(
null
);
const
ref
=
React
.
useRef
<
HTMLInputElement
>
(
null
);
const
handleClear
=
React
.
useCallback
(()
=>
{
const
handleClear
=
React
.
useCallback
(()
=>
{
setValue
(
name
,
''
);
setValue
(
name
,
''
);
onClear
();
ref
.
current
?.
focus
();
ref
.
current
?.
focus
();
},
[
name
,
setValue
]);
},
[
name
,
onClear
,
setValue
]);
const
renderInput
=
React
.
useCallback
(({
field
}:
{
field
:
ControllerRenderProps
<
MethodFormFields
>
})
=>
{
const
renderInput
=
React
.
useCallback
(({
field
}:
{
field
:
ControllerRenderProps
<
MethodFormFields
>
})
=>
{
return
(
return
(
<
FormControl
id=
{
name
}
m
axW=
{
{
base
:
'
100%
'
,
lg
:
'
calc((100% - 24px) / 3)
'
}
}
isDisabled=
{
isDisabled
}
>
<
FormControl
id=
{
name
}
m
inW=
{
{
base
:
'
100%
'
,
lg
:
'
calc((100% - 24px) / 3 - 65px)
'
}
}
w=
"auto"
flexGrow=
{
1
}
isDisabled=
{
isDisabled
}
>
<
InputGroup
size=
"xs"
>
<
InputGroup
size=
"xs"
>
<
Input
<
Input
{
...
field
}
{
...
field
}
...
...
ui/address/contract/ContractRead.tsx
View file @
758f8465
...
@@ -51,7 +51,9 @@ const ContractRead = ({ isProxy }: Props) => {
...
@@ -51,7 +51,9 @@ const ContractRead = ({ isProxy }: Props) => {
const
resultBgColor
=
useColorModeValue
(
'
blackAlpha.50
'
,
'
whiteAlpha.50
'
);
const
resultBgColor
=
useColorModeValue
(
'
blackAlpha.50
'
,
'
whiteAlpha.50
'
);
const
renderResult
=
React
.
useCallback
((
item
:
SmartContractReadMethod
,
result
:
ContractMethodReadResult
)
=>
{
const
renderResult
=
React
.
useCallback
((
item
:
SmartContractReadMethod
,
result
:
ContractMethodReadResult
,
onSettle
:
()
=>
void
)
=>
{
onSettle
();
if
(
'
status
'
in
result
)
{
if
(
'
status
'
in
result
)
{
return
<
Alert
status=
"error"
mt=
{
3
}
p=
{
4
}
borderRadius=
"md"
fontSize=
"sm"
>
{
result
.
statusText
}
</
Alert
>;
return
<
Alert
status=
"error"
mt=
{
3
}
p=
{
4
}
borderRadius=
"md"
fontSize=
"sm"
>
{
result
.
statusText
}
</
Alert
>;
}
}
...
...
ui/address/contract/ContractWrite.tsx
View file @
758f8465
...
@@ -89,8 +89,8 @@ const ContractWrite = ({ isProxy }: Props) => {
...
@@ -89,8 +89,8 @@ const ContractWrite = ({ isProxy }: Props) => {
}
}
},
[
_contract
,
addressHash
,
isConnected
,
signer
]);
},
[
_contract
,
addressHash
,
isConnected
,
signer
]);
const
renderResult
=
React
.
useCallback
((
item
:
SmartContractWriteMethod
,
result
:
ContractMethodWriteResult
)
=>
{
const
renderResult
=
React
.
useCallback
((
item
:
SmartContractWriteMethod
,
result
:
ContractMethodWriteResult
,
onSettle
:
()
=>
void
)
=>
{
return
<
ContractWriteResult
result=
{
result
}
/>;
return
<
ContractWriteResult
result=
{
result
}
onSettle=
{
onSettle
}
/>;
},
[]);
},
[]);
const
renderContent
=
React
.
useCallback
((
item
:
SmartContractWriteMethod
,
index
:
number
,
id
:
number
)
=>
{
const
renderContent
=
React
.
useCallback
((
item
:
SmartContractWriteMethod
,
index
:
number
,
id
:
number
)
=>
{
...
...
ui/address/contract/ContractWriteResult.tsx
View file @
758f8465
...
@@ -8,14 +8,21 @@ import link from 'lib/link/link';
...
@@ -8,14 +8,21 @@ import link from 'lib/link/link';
interface
Props
{
interface
Props
{
result
:
ContractMethodWriteResult
;
result
:
ContractMethodWriteResult
;
onSettle
:
()
=>
void
;
}
}
const
ContractWriteResult
=
({
result
}:
Props
)
=>
{
const
ContractWriteResult
=
({
result
,
onSettle
}:
Props
)
=>
{
const
txHash
=
result
&&
'
hash
'
in
result
?
result
.
hash
as
`0x
${
string
}
`
:
undefined
;
const
txHash
=
result
&&
'
hash
'
in
result
?
result
.
hash
as
`0x
${
string
}
`
:
undefined
;
const
txInfo
=
useWaitForTransaction
({
const
txInfo
=
useWaitForTransaction
({
hash
:
txHash
,
hash
:
txHash
,
});
});
React
.
useEffect
(()
=>
{
if
(
txInfo
.
status
!==
'
loading
'
)
{
onSettle
();
}
},
[
onSettle
,
txInfo
.
status
]);
// eslint-disable-next-line no-console
// eslint-disable-next-line no-console
console
.
log
(
'
__>__ txInfo
'
,
txInfo
);
console
.
log
(
'
__>__ txInfo
'
,
txInfo
);
...
...
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