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
16185d52
Commit
16185d52
authored
Mar 13, 2025
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement async select
parent
0d73ad81
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
179 additions
and
61 deletions
+179
-61
select.tsx
toolkit/chakra/select.tsx
+61
-1
ContractDetailsVerificationButton.tsx
ui/address/contract/ContractDetailsVerificationButton.tsx
+3
-3
ContractVerificationFieldCompiler.tsx
...Verification/fields/ContractVerificationFieldCompiler.tsx
+43
-45
ContractVerificationFieldZkCompiler.tsx
...rification/fields/ContractVerificationFieldZkCompiler.tsx
+20
-12
FormFieldSelectAsync.tsx
ui/shared/forms/fields/FormFieldSelectAsync.tsx
+52
-0
No files found.
toolkit/chakra/select.tsx
View file @
16185d52
'
use client
'
;
'
use client
'
;
import
type
{
CollectionItem
,
ListCollection
}
from
'
@chakra-ui/react
'
;
import
type
{
CollectionItem
,
ListCollection
}
from
'
@chakra-ui/react
'
;
import
{
Select
as
ChakraSelect
,
Portal
,
useSelectContext
}
from
'
@chakra-ui/react
'
;
import
{
Select
as
ChakraSelect
,
createListCollection
,
Portal
,
useSelectContext
}
from
'
@chakra-ui/react
'
;
import
{
useDebounce
}
from
'
@uidotdev/usehooks
'
;
import
*
as
React
from
'
react
'
;
import
*
as
React
from
'
react
'
;
import
FilterInput
from
'
ui/shared/filters/FilterInput
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
{
CloseButton
}
from
'
./close-button
'
;
import
{
CloseButton
}
from
'
./close-button
'
;
...
@@ -203,3 +205,61 @@ export const Select = React.forwardRef<HTMLDivElement, SelectProps>((props, ref)
...
@@ -203,3 +205,61 @@ export const Select = React.forwardRef<HTMLDivElement, SelectProps>((props, ref)
</
SelectRoot
>
</
SelectRoot
>
);
);
});
});
export
interface
SelectAsyncProps
extends
Omit
<
SelectRootProps
,
'
collection
'
>
{
placeholder
:
string
;
portalled
?:
boolean
;
loading
?:
boolean
;
loadOptions
:
(
input
:
string
,
currentValue
:
Array
<
string
>
)
=>
Promise
<
ListCollection
<
CollectionItem
>>
;
extraControls
?:
React
.
ReactNode
;
}
export
const
SelectAsync
=
React
.
forwardRef
<
HTMLDivElement
,
SelectAsyncProps
>
((
props
,
ref
)
=>
{
const
{
placeholder
,
portalled
=
true
,
loading
,
loadOptions
,
extraControls
,
onValueChange
,
...
rest
}
=
props
;
const
[
collection
,
setCollection
]
=
React
.
useState
<
ListCollection
<
CollectionItem
>>
(
createListCollection
({
items
:
[]
}));
const
[
inputValue
,
setInputValue
]
=
React
.
useState
(
''
);
const
[
value
,
setValue
]
=
React
.
useState
<
Array
<
string
>>
([]);
const
debouncedInputValue
=
useDebounce
(
inputValue
,
300
);
React
.
useEffect
(()
=>
{
loadOptions
(
debouncedInputValue
,
value
).
then
(
setCollection
);
},
[
debouncedInputValue
,
loadOptions
,
value
]);
const
handleFilterChange
=
React
.
useCallback
((
value
:
string
)
=>
{
setInputValue
(
value
);
},
[
]);
const
handleValueChange
=
React
.
useCallback
(({
value
,
items
}:
{
value
:
Array
<
string
>
;
items
:
Array
<
CollectionItem
>
})
=>
{
setValue
(
value
);
onValueChange
?.({
value
,
items
});
},
[
onValueChange
]);
return
(
<
SelectRoot
ref=
{
ref
}
collection=
{
collection
}
variant=
"outline"
onValueChange=
{
handleValueChange
}
{
...
rest
}
>
<
SelectControl
loading=
{
loading
}
>
<
SelectValueText
placeholder=
{
placeholder
}
/>
</
SelectControl
>
<
SelectContent
portalled=
{
portalled
}
>
<
FilterInput
placeholder=
"Search"
initialValue=
{
inputValue
}
onChange=
{
handleFilterChange
}
/>
{
extraControls
}
{
collection
.
items
.
map
((
item
)
=>
(
<
SelectItem
item=
{
item
}
key=
{
item
.
value
}
>
{
item
.
label
}
</
SelectItem
>
))
}
</
SelectContent
>
</
SelectRoot
>
);
});
ui/address/contract/ContractDetailsVerificationButton.tsx
View file @
16185d52
...
@@ -15,13 +15,13 @@ const ContractDetailsVerificationButton = ({ isLoading, addressHash, isPartially
...
@@ -15,13 +15,13 @@ const ContractDetailsVerificationButton = ({ isLoading, addressHash, isPartially
return
(
return
(
<
Link
<
Link
href=
{
route
({
pathname
:
'
/address/[hash]/contract-verification
'
,
query
:
{
hash
:
addressHash
}
})
}
href=
{
route
({
pathname
:
'
/address/[hash]/contract-verification
'
,
query
:
{
hash
:
addressHash
}
})
}
mr=
{
isPartiallyVerified
?
0
:
3
}
ml=
{
isPartiallyVerified
?
0
:
'
auto
'
}
flexShrink=
{
0
}
asChild
asChild
>
>
<
Button
<
Button
size=
"sm"
size=
"sm"
mr=
{
isPartiallyVerified
?
0
:
3
}
ml=
{
isPartiallyVerified
?
0
:
'
auto
'
}
flexShrink=
{
0
}
loadingSkeleton=
{
isLoading
}
loadingSkeleton=
{
isLoading
}
>
>
Verify
&
publish
Verify
&
publish
...
...
ui/contractVerification/fields/ContractVerificationFieldCompiler.tsx
View file @
16185d52
...
@@ -8,7 +8,7 @@ import type { SmartContractVerificationConfig } from 'types/client/contract';
...
@@ -8,7 +8,7 @@ import type { SmartContractVerificationConfig } from 'types/client/contract';
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
{
Checkbox
}
from
'
toolkit/chakra/checkbox
'
;
import
{
Checkbox
}
from
'
toolkit/chakra/checkbox
'
;
import
FormFieldSelect
from
'
ui/shared/forms/fields/FormFieldSelect
'
;
import
FormFieldSelect
Async
from
'
ui/shared/forms/fields/FormFieldSelectAsync
'
;
import
ContractVerificationFormRow
from
'
../ContractVerificationFormRow
'
;
import
ContractVerificationFormRow
from
'
../ContractVerificationFormRow
'
;
...
@@ -36,8 +36,7 @@ const ContractVerificationFieldCompiler = ({ isVyper, isStylus }: Props) => {
...
@@ -36,8 +36,7 @@ const ContractVerificationFieldCompiler = ({ isVyper, isStylus }: Props) => {
});
});
},
[
getValues
,
resetField
]);
},
[
getValues
,
resetField
]);
const
options
=
React
.
useMemo
(()
=>
{
const
versions
=
React
.
useMemo
(()
=>
{
const
versions
=
(()
=>
{
if
(
isStylus
)
{
if
(
isStylus
)
{
return
config
?.
stylus_compiler_versions
;
return
config
?.
stylus_compiler_versions
;
}
}
...
@@ -45,32 +44,28 @@ const ContractVerificationFieldCompiler = ({ isVyper, isStylus }: Props) => {
...
@@ -45,32 +44,28 @@ const ContractVerificationFieldCompiler = ({ isVyper, isStylus }: Props) => {
return
config
?.
vyper_compiler_versions
;
return
config
?.
vyper_compiler_versions
;
}
}
return
config
?.
solidity_compiler_versions
;
return
config
?.
solidity_compiler_versions
;
})();
return
versions
?.
map
((
option
)
=>
({
label
:
option
,
value
:
option
}))
||
[];
},
[
isStylus
,
isVyper
,
config
?.
solidity_compiler_versions
,
config
?.
stylus_compiler_versions
,
config
?.
vyper_compiler_versions
]);
},
[
isStylus
,
isVyper
,
config
?.
solidity_compiler_versions
,
config
?.
stylus_compiler_versions
,
config
?.
vyper_compiler_versions
]);
// const loadOptions = React.useCallback(async(inputValue: string) => {
const
loadOptions
=
React
.
useCallback
(
async
(
inputValue
:
string
,
currentValue
:
Array
<
string
>
)
=>
{
// return options
const
items
=
versions
// .filter(({ label }) => !inputValue || label.toLowerCase().includes(inputValue.toLowerCase()))
?.
filter
((
value
)
=>
!
inputValue
||
currentValue
.
includes
(
value
)
||
value
.
toLowerCase
().
includes
(
inputValue
.
toLowerCase
()))
// .filter(({ label }) => isNightly ? true : !label.includes('nightly'))
.
filter
((
value
)
=>
isNightly
?
true
:
!
value
.
includes
(
'
nightly
'
))
// .slice(0, OPTIONS_LIMIT);
.
sort
((
a
,
b
)
=>
{
// }, [ isNightly, options ]);
if
(
currentValue
.
includes
(
a
))
{
return
-
1
;
// TODO @tom2drum implement filtering the options
}
const
collection
=
React
.
useMemo
(()
=>
{
if
(
currentValue
.
includes
(
b
))
{
const
items
=
options
return
1
;
// .filter(({ label }) => !inputValue || label.toLowerCase().includes(inputValue.toLowerCase()))
}
.
filter
(({
label
})
=>
isNightly
?
true
:
!
label
.
includes
(
'
nightly
'
))
return
0
;
.
slice
(
0
,
OPTIONS_LIMIT
);
})
.
slice
(
0
,
OPTIONS_LIMIT
)
.
map
((
value
)
=>
({
label
:
value
,
value
}))
??
[];
return
createListCollection
({
items
});
return
createListCollection
({
items
});
},
[
isNightly
,
opt
ions
]);
},
[
isNightly
,
vers
ions
]);
return
(
const
extraControls
=
!
isVyper
&&
!
isStylus
?
(
<
ContractVerificationFormRow
>
<>
{
!
isVyper
&&
!
isStylus
&&
(
<
Checkbox
<
Checkbox
mb=
{
2
}
mb=
{
2
}
checked=
{
isNightly
}
checked=
{
isNightly
}
...
@@ -79,14 +74,17 @@ const ContractVerificationFieldCompiler = ({ isVyper, isStylus }: Props) => {
...
@@ -79,14 +74,17 @@ const ContractVerificationFieldCompiler = ({ isVyper, isStylus }: Props) => {
>
>
Include nightly builds
Include nightly builds
</
Checkbox
>
</
Checkbox
>
)
}
)
:
null
;
<
FormFieldSelect
<
FormFields
,
'
compiler
'
>
return
(
<
ContractVerificationFormRow
>
<
FormFieldSelectAsync
<
FormFields
,
'
compiler
'
>
name="compiler"
name="compiler"
placeholder="Compiler (enter version or use the dropdown)"
placeholder="Compiler (enter version or use the dropdown)"
collection=
{
collection
}
loadOptions=
{
loadOptions
}
extraControls=
{
extraControls
}
required
required
/
>
/
>
</>
{
isVyper
||
isStylus
?
null
:
(
{
isVyper
||
isStylus
?
null
:
(
<
chakra
.
div
mt=
{
{
base
:
0
,
lg
:
8
}
}
>
<
chakra
.
div
mt=
{
{
base
:
0
,
lg
:
8
}
}
>
<
span
>
The compiler version is specified in
</
span
>
<
span
>
The compiler version is specified in
</
span
>
...
...
ui/contractVerification/fields/ContractVerificationFieldZkCompiler.tsx
View file @
16185d52
...
@@ -7,7 +7,7 @@ import type { SmartContractVerificationConfig } from 'types/client/contract';
...
@@ -7,7 +7,7 @@ import type { SmartContractVerificationConfig } from 'types/client/contract';
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
{
Link
}
from
'
toolkit/chakra/link
'
;
import
{
Link
}
from
'
toolkit/chakra/link
'
;
import
FormFieldSelect
from
'
ui/shared/forms/fields/FormFieldSelect
'
;
import
FormFieldSelect
Async
from
'
ui/shared/forms/fields/FormFieldSelectAsync
'
;
import
ContractVerificationFormRow
from
'
../ContractVerificationFormRow
'
;
import
ContractVerificationFormRow
from
'
../ContractVerificationFormRow
'
;
...
@@ -17,26 +17,34 @@ const ContractVerificationFieldZkCompiler = () => {
...
@@ -17,26 +17,34 @@ const ContractVerificationFieldZkCompiler = () => {
const
queryClient
=
useQueryClient
();
const
queryClient
=
useQueryClient
();
const
config
=
queryClient
.
getQueryData
<
SmartContractVerificationConfig
>
(
getResourceKey
(
'
contract_verification_config
'
));
const
config
=
queryClient
.
getQueryData
<
SmartContractVerificationConfig
>
(
getResourceKey
(
'
contract_verification_config
'
));
const
opt
ions
=
React
.
useMemo
(()
=>
(
const
vers
ions
=
React
.
useMemo
(()
=>
(
config
?.
zk_compiler_versions
?.
map
((
option
)
=>
({
label
:
option
,
value
:
option
}))
||
[]
config
?.
zk_compiler_versions
||
[]
),
[
config
?.
zk_compiler_versions
]);
),
[
config
?.
zk_compiler_versions
]);
// TODO @tom2drum implement filtering the options
const
loadOptions
=
React
.
useCallback
(
async
(
inputValue
:
string
,
currentValue
:
Array
<
string
>
)
=>
{
const
items
=
versions
const
collection
=
React
.
useMemo
(()
=>
{
?.
filter
((
value
)
=>
!
inputValue
||
currentValue
.
includes
(
value
)
||
value
.
toLowerCase
().
includes
(
inputValue
.
toLowerCase
()))
const
items
=
options
.
sort
((
a
,
b
)
=>
{
// .filter(({ label }) => !inputValue || label.toLowerCase().includes(inputValue.toLowerCase()))
if
(
currentValue
.
includes
(
a
))
{
.
slice
(
0
,
OPTIONS_LIMIT
);
return
-
1
;
}
if
(
currentValue
.
includes
(
b
))
{
return
1
;
}
return
0
;
})
.
slice
(
0
,
OPTIONS_LIMIT
)
.
map
((
value
)
=>
({
label
:
value
,
value
}))
??
[];
return
createListCollection
({
items
});
return
createListCollection
({
items
});
},
[
opt
ions
]);
},
[
vers
ions
]);
return
(
return
(
<
ContractVerificationFormRow
>
<
ContractVerificationFormRow
>
<
FormFieldSelect
<
FormFields
,
'
zk_compiler
'
>
<
FormFieldSelect
Async
<
FormFields
,
'
zk_compiler
'
>
name="zk_compiler"
name="zk_compiler"
placeholder="ZK compiler (enter version or use the dropdown)"
placeholder="ZK compiler (enter version or use the dropdown)"
collection=
{
collection
}
loadOptions=
{
loadOptions
}
required
required
/
>
/
>
<
Box
>
<
Box
>
...
...
ui/shared/forms/fields/FormFieldSelectAsync.tsx
0 → 100644
View file @
16185d52
import
React
from
'
react
'
;
import
type
{
Path
,
FieldValues
}
from
'
react-hook-form
'
;
import
{
useController
,
useFormContext
}
from
'
react-hook-form
'
;
import
type
{
FormFieldPropsBase
}
from
'
./types
'
;
import
type
{
SelectAsyncProps
}
from
'
toolkit/chakra/select
'
;
import
{
SelectAsync
}
from
'
toolkit/chakra/select
'
;
type
Props
<
FormFields
extends
FieldValues
,
Name
extends
Path
<
FormFields
>
,
>
=
FormFieldPropsBase
<
FormFields
,
Name
>
&
SelectAsyncProps
;
const
FormFieldSelectAsync
=
<
FormFields
extends
FieldValues
,
Name
extends
Path
<
FormFields
>
,
>
(props: Props
<
FormFields
,
Name
>
) =
>
{
const
{
name
,
rules
,
...
rest
}
=
props
;
const
{
control
}
=
useFormContext
<
FormFields
>
();
const
{
field
,
fieldState
,
formState
}
=
useController
<
FormFields
,
typeof
name
>
({
control
,
name
,
rules
,
});
const
isDisabled
=
formState
.
isSubmitting
;
const
handleChange
=
React
.
useCallback
(({
value
}:
{
value
:
Array
<
string
>
})
=>
{
field
.
onChange
(
value
);
},
[
field
]);
const
handleBlur
=
React
.
useCallback
(()
=>
{
field
.
onBlur
();
},
[
field
]);
return
(
<
SelectAsync
ref=
{
field
.
ref
}
name=
{
field
.
name
}
value=
{
field
.
value
}
onValueChange=
{
handleChange
}
onInteractOutside=
{
handleBlur
}
disabled=
{
isDisabled
}
invalid=
{
Boolean
(
fieldState
.
error
)
}
{
...
rest
}
/>
);
}
;
export default React.memo(FormFieldSelectAsync) as typeof FormFieldSelectAsync;
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