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
75836a7e
Commit
75836a7e
authored
Oct 30, 2023
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
radio group button
parent
de9afb2b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
12 deletions
+84
-12
cookies.ts
lib/cookies.ts
+1
-0
address.ts
types/api/address.ts
+1
-4
AddressTokens.tsx
ui/address/AddressTokens.tsx
+16
-8
RadioButtonGroup.tsx
ui/shared/RadioButtonGroup.tsx
+66
-0
No files found.
lib/cookies.ts
View file @
75836a7e
...
@@ -12,6 +12,7 @@ export enum NAMES {
...
@@ -12,6 +12,7 @@ export enum NAMES {
INDEXING_ALERT
=
'
indexing_alert
'
,
INDEXING_ALERT
=
'
indexing_alert
'
,
ADBLOCK_DETECTED
=
'
adblock_detected
'
,
ADBLOCK_DETECTED
=
'
adblock_detected
'
,
MIXPANEL_DEBUG
=
'
_mixpanel_debug
'
,
MIXPANEL_DEBUG
=
'
_mixpanel_debug
'
,
ADDRESS_NFT_DISPLAY_TYPE
=
'
address_nft_display_type
'
}
}
export
function
get
(
name
?:
NAMES
|
undefined
|
null
,
serverCookie
?:
string
)
{
export
function
get
(
name
?:
NAMES
|
undefined
|
null
,
serverCookie
?:
string
)
{
...
...
types/api/address.ts
View file @
75836a7e
...
@@ -84,11 +84,8 @@ export interface AddressNFTsResponse {
...
@@ -84,11 +84,8 @@ export interface AddressNFTsResponse {
export
interface
AddressCollectionsResponse
{
export
interface
AddressCollectionsResponse
{
items
:
Array
<
AddressCollection
>
;
items
:
Array
<
AddressCollection
>
;
next_page_params
:
{
next_page_params
:
{
items_count
:
number
;
token_contract_address_hash
:
string
;
token_name
:
string
|
null
;
token_type
:
TokenType
;
token_type
:
TokenType
;
value
:
number
;
fiat_value
:
string
|
null
;
}
|
null
;
}
|
null
;
}
}
...
...
ui/address/AddressTokens.tsx
View file @
75836a7e
import
{
Box
,
Radio
,
RadioGroup
}
from
'
@chakra-ui/react
'
;
import
{
Box
}
from
'
@chakra-ui/react
'
;
import
{
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
{
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
...
@@ -9,6 +9,8 @@ import type { TokenType } from 'types/api/token';
...
@@ -9,6 +9,8 @@ import type { TokenType } from 'types/api/token';
import
type
{
PaginationParams
}
from
'
ui/shared/pagination/types
'
;
import
type
{
PaginationParams
}
from
'
ui/shared/pagination/types
'
;
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
{
useAppContext
}
from
'
lib/contexts/app
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
useSocketChannel
from
'
lib/socket/useSocketChannel
'
;
import
useSocketChannel
from
'
lib/socket/useSocketChannel
'
;
...
@@ -17,6 +19,7 @@ import { ADDRESS_TOKEN_BALANCE_ERC_20, ADDRESS_NFT_1155, ADDRESS_COLLECTION } fr
...
@@ -17,6 +19,7 @@ import { ADDRESS_TOKEN_BALANCE_ERC_20, ADDRESS_NFT_1155, ADDRESS_COLLECTION } fr
import
{
generateListStub
}
from
'
stubs/utils
'
;
import
{
generateListStub
}
from
'
stubs/utils
'
;
import
Pagination
from
'
ui/shared/pagination/Pagination
'
;
import
Pagination
from
'
ui/shared/pagination/Pagination
'
;
import
useQueryWithPages
from
'
ui/shared/pagination/useQueryWithPages
'
;
import
useQueryWithPages
from
'
ui/shared/pagination/useQueryWithPages
'
;
import
RadioButtonGroup
from
'
ui/shared/RadioButtonGroup
'
;
import
RoutedTabs
from
'
ui/shared/Tabs/RoutedTabs
'
;
import
RoutedTabs
from
'
ui/shared/Tabs/RoutedTabs
'
;
import
AddressCollections
from
'
./tokens/AddressCollections
'
;
import
AddressCollections
from
'
./tokens/AddressCollections
'
;
...
@@ -24,7 +27,7 @@ import AddressNFTs from './tokens/AddressNFTs';
...
@@ -24,7 +27,7 @@ import AddressNFTs from './tokens/AddressNFTs';
import
ERC20Tokens
from
'
./tokens/ERC20Tokens
'
;
import
ERC20Tokens
from
'
./tokens/ERC20Tokens
'
;
import
TokenBalances
from
'
./tokens/TokenBalances
'
;
import
TokenBalances
from
'
./tokens/TokenBalances
'
;
type
TNftDisplayType
=
'
collection
'
|
'
list
'
;
type
TNftDisplayType
=
'
collection
s
'
|
'
list
'
;
const
TAB_LIST_PROPS
=
{
const
TAB_LIST_PROPS
=
{
marginBottom
:
0
,
marginBottom
:
0
,
...
@@ -50,7 +53,8 @@ const AddressTokens = () => {
...
@@ -50,7 +53,8 @@ const AddressTokens = () => {
const
scrollRef
=
React
.
useRef
<
HTMLDivElement
>
(
null
);
const
scrollRef
=
React
.
useRef
<
HTMLDivElement
>
(
null
);
const
[
nftDisplayType
,
setNftDisplayType
]
=
React
.
useState
<
TNftDisplayType
>
(
'
collection
'
);
const
displayTypeCookie
=
cookies
.
get
(
cookies
.
NAMES
.
ADDRESS_NFT_DISPLAY_TYPE
,
useAppContext
().
cookies
);
const
[
nftDisplayType
,
setNftDisplayType
]
=
React
.
useState
<
TNftDisplayType
>
(
displayTypeCookie
===
'
list
'
?
'
list
'
:
'
collections
'
);
const
tab
=
getQueryParamString
(
router
.
query
.
tab
);
const
tab
=
getQueryParamString
(
router
.
query
.
tab
);
const
hash
=
getQueryParamString
(
router
.
query
.
hash
);
const
hash
=
getQueryParamString
(
router
.
query
.
hash
);
...
@@ -72,7 +76,7 @@ const AddressTokens = () => {
...
@@ -72,7 +76,7 @@ const AddressTokens = () => {
pathParams
:
{
hash
},
pathParams
:
{
hash
},
scrollRef
,
scrollRef
,
options
:
{
options
:
{
enabled
:
tab
===
'
tokens_nfts
'
&&
nftDisplayType
===
'
collection
'
,
enabled
:
tab
===
'
tokens_nfts
'
&&
nftDisplayType
===
'
collection
s
'
,
refetchOnMount
:
false
,
refetchOnMount
:
false
,
placeholderData
:
generateListStub
<
'
address_collections
'
>
(
ADDRESS_COLLECTION
,
10
,
{
next_page_params
:
null
}),
placeholderData
:
generateListStub
<
'
address_collections
'
>
(
ADDRESS_COLLECTION
,
10
,
{
next_page_params
:
null
}),
},
},
...
@@ -153,6 +157,7 @@ const AddressTokens = () => {
...
@@ -153,6 +157,7 @@ const AddressTokens = () => {
});
});
const
handleNFTsDisplayTypeChange
=
React
.
useCallback
((
val
:
TNftDisplayType
)
=>
{
const
handleNFTsDisplayTypeChange
=
React
.
useCallback
((
val
:
TNftDisplayType
)
=>
{
cookies
.
set
(
cookies
.
NAMES
.
ADDRESS_NFT_DISPLAY_TYPE
,
val
);
setNftDisplayType
(
val
);
setNftDisplayType
(
val
);
},
[]);
},
[]);
...
@@ -168,10 +173,12 @@ const AddressTokens = () => {
...
@@ -168,10 +173,12 @@ const AddressTokens = () => {
];
];
const
nftDisplayTypeRadio
=
(
const
nftDisplayTypeRadio
=
(
<
RadioGroup
onChange=
{
handleNFTsDisplayTypeChange
}
value=
{
nftDisplayType
}
>
<
RadioButtonGroup
<
TNftDisplayType
>
<
Radio
value=
"collection"
>
Collection
</
Radio
>
onChange=
{
handleNFTsDisplayTypeChange
}
<
Radio
value=
"list"
>
List
</
Radio
>
defaultValue=
{
nftDisplayType
}
</
RadioGroup
>
name="type"
options=
{
[
{
title
:
'
By collections
'
,
value
:
'
collections
'
},
{
title
:
'
List
'
,
value
:
'
list
'
}
]
}
/
>
);
);
let pagination: PaginationParams | undefined;
let pagination: PaginationParams | undefined;
...
@@ -201,6 +208,7 @@ const AddressTokens = () => {
...
@@ -201,6 +208,7 @@ const AddressTokens = () => {
size=
"sm"
size=
"sm"
tabListProps=
{
isMobile
?
TAB_LIST_PROPS_MOBILE
:
TAB_LIST_PROPS
}
tabListProps=
{
isMobile
?
TAB_LIST_PROPS_MOBILE
:
TAB_LIST_PROPS
}
rightSlot=
{
rightSlot
}
rightSlot=
{
rightSlot
}
rightSlotProps=
{
tab
!==
'
tokens_erc20
'
&&
!
isMobile
?
{
flexGrow
:
1
,
display
:
'
flex
'
,
justifyContent
:
'
space-between
'
,
ml
:
8
}
:
{}
}
stickyEnabled=
{
!
isMobile
}
stickyEnabled=
{
!
isMobile
}
/>
/>
</>
</>
...
...
ui/shared/RadioButtonGroup.tsx
0 → 100644
View file @
75836a7e
import
{
ButtonGroup
,
Button
,
Box
,
useRadio
,
useRadioGroup
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
type
{
UseRadioProps
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
type
RadioButtonProps
=
UseRadioProps
&
{
children
:
React
.
ReactNode
;
}
const
RadioButton
=
(
props
:
RadioButtonProps
)
=>
{
const
{
getInputProps
,
getRadioProps
}
=
useRadio
(
props
);
const
buttonColor
=
useColorModeValue
(
'
blue.50
'
,
'
gray.800
'
);
const
input
=
getInputProps
();
const
checkbox
=
getRadioProps
();
return
(
<
Button
as=
"label"
variant=
"outline"
fontWeight=
{
500
}
cursor=
{
props
.
isChecked
?
'
initial
'
:
'
pointer
'
}
borderColor=
{
buttonColor
}
_hover=
{
{
borderColor
:
buttonColor
,
...(
props
.
isChecked
?
{}
:
{
color
:
'
link_hovered
'
}),
}
}
_active=
{
{
backgroundColor
:
'
none
'
,
}
}
backgroundColor=
{
props
.
isChecked
?
buttonColor
:
'
none
'
}
{
...
(
props
.
isChecked
?
{
color
:
'
text
'
}
:
{})
}
>
<
input
{
...
input
}
/>
<
Box
{
...
checkbox
}
>
{
props
.
children
}
</
Box
>
</
Button
>
);
};
type
RadioButtonGroupProps
<
T
extends
string
>
=
{
onChange
:
(
value
:
T
)
=>
void
;
name
:
string
;
defaultValue
:
string
;
options
:
Array
<
{
title
:
string
;
value
:
T
}
>
;
}
const
RadioButtonGroup
=
<
T
extends
string
>
(
{
onChange
,
name
,
defaultValue
,
options
}
: RadioButtonGroupProps
<
T
>
) =
>
{
const
{
getRootProps
,
getRadioProps
}
=
useRadioGroup
({
name
,
defaultValue
,
onChange
});
const
group
=
getRootProps
();
return
(
<
ButtonGroup
{
...
group
}
isAttached
size=
"sm"
>
{
options
.
map
((
option
)
=>
{
const
props
=
getRadioProps
({
value
:
option
.
value
});
return
<
RadioButton
{
...
props
}
key=
{
option
.
value
}
>
{
option
.
title
}
</
RadioButton
>;
})
}
</
ButtonGroup
>
);
}
;
export default RadioButtonGroup;
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