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
efc37fa9
Commit
efc37fa9
authored
Dec 20, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
cced383d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
19 additions
and
19 deletions
+19
-19
resources.ts
lib/api/resources.ts
+0
-9
useApiFetch.tsx
lib/api/useApiFetch.tsx
+2
-2
useApiQuery.tsx
lib/api/useApiQuery.tsx
+11
-2
_app.tsx
pages/_app.tsx
+2
-2
BlockDetails.tsx
ui/block/BlockDetails.tsx
+2
-2
CustomAbiForm.tsx
ui/customAbi/CustomAbiModal/CustomAbiForm.tsx
+2
-2
No files found.
lib/api/resources.ts
View file @
efc37fa9
import
type
{
UserInfo
,
CustomAbis
}
from
'
types/api/account
'
;
import
type
{
CsrfData
}
from
'
types/client/account
'
;
export
const
RESOURCES
=
{
export
const
RESOURCES
=
{
// account
// account
user_info
:
{
user_info
:
{
...
@@ -24,12 +21,6 @@ export const RESOURCES = {
...
@@ -24,12 +21,6 @@ export const RESOURCES = {
export
const
resourceKey
=
(
x
:
keyof
typeof
RESOURCES
)
=>
x
;
export
const
resourceKey
=
(
x
:
keyof
typeof
RESOURCES
)
=>
x
;
export
type
ResourcePayload
<
Q
extends
keyof
typeof
RESOURCES
>
=
Q
extends
'
user_info
'
?
UserInfo
:
Q
extends
'
csrf
'
?
CsrfData
:
Q
extends
'
custom_abi
'
?
CustomAbis
:
never
;
export
interface
ResourceError
<
T
=
unknown
>
{
export
interface
ResourceError
<
T
=
unknown
>
{
error
?:
T
;
error
?:
T
;
payload
?:
T
;
payload
?:
T
;
...
...
lib/api/useApiFetch.tsx
View file @
efc37fa9
...
@@ -4,7 +4,7 @@ import type { Params as FetchParams } from 'lib/hooks/useFetch';
...
@@ -4,7 +4,7 @@ import type { Params as FetchParams } from 'lib/hooks/useFetch';
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
buildUrl
from
'
./buildUrl
'
;
import
buildUrl
from
'
./buildUrl
'
;
import
type
{
RESOURCES
,
Resource
Payload
,
Resource
Error
}
from
'
./resources
'
;
import
type
{
RESOURCES
,
ResourceError
}
from
'
./resources
'
;
export
interface
Params
{
export
interface
Params
{
pathParams
?:
Record
<
string
,
string
>
;
pathParams
?:
Record
<
string
,
string
>
;
...
@@ -15,7 +15,7 @@ export interface Params {
...
@@ -15,7 +15,7 @@ export interface Params {
export
default
function
useApiFetch
()
{
export
default
function
useApiFetch
()
{
const
fetch
=
useFetch
();
const
fetch
=
useFetch
();
return
React
.
useCallback
(<
R
extends
keyof
typeof
RESOURCES
,
SuccessType
=
ResourcePayload
<
R
>
, ErrorType = ResourceError
>
(
return
React
.
useCallback
(<
R
extends
keyof
typeof
RESOURCES
,
SuccessType
=
unknown
,
ErrorType
=
ResourceError
>
(
resource: R,
resource: R,
{
pathParams
,
queryParams
,
fetchParams
}
: Params =
{}
,
{
pathParams
,
queryParams
,
fetchParams
}
: Params =
{}
,
) =
>
{
) =
>
{
...
...
lib/api/useApiQuery.tsx
View file @
efc37fa9
import
type
{
UseQueryOptions
}
from
'
@tanstack/react-query
'
;
import
type
{
UseQueryOptions
}
from
'
@tanstack/react-query
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
type
{
RESOURCES
,
ResourcePayload
,
ResourceError
}
from
'
./resources
'
;
import
type
{
UserInfo
,
CustomAbis
}
from
'
types/api/account
'
;
import
type
{
CsrfData
}
from
'
types/client/account
'
;
import
type
{
RESOURCES
,
ResourceError
}
from
'
./resources
'
;
import
type
{
Params
as
ApiFetchParams
}
from
'
./useApiFetch
'
;
import
type
{
Params
as
ApiFetchParams
}
from
'
./useApiFetch
'
;
import
useApiFetch
from
'
./useApiFetch
'
;
import
useApiFetch
from
'
./useApiFetch
'
;
...
@@ -16,6 +19,12 @@ export default function useApiQuery<R extends keyof typeof RESOURCES>(
...
@@ -16,6 +19,12 @@ export default function useApiQuery<R extends keyof typeof RESOURCES>(
const
apiFetch
=
useApiFetch
();
const
apiFetch
=
useApiFetch
();
return
useQuery
<
unknown
,
ResourceError
,
ResourcePayload
<
R
>>
([
resource
],
async
()
=>
{
return
useQuery
<
unknown
,
ResourceError
,
ResourcePayload
<
R
>>
([
resource
],
async
()
=>
{
return
apiFetch
(
resource
,
{
pathParams
,
queryParams
,
fetchParams
});
return
apiFetch
<
R
,
ResourcePayload
<
R
>
,
ResourceError
>
(
resource
,
{
pathParams
,
queryParams
,
fetchParams
});
},
queryOptions
);
},
queryOptions
);
}
}
export
type
ResourcePayload
<
Q
extends
keyof
typeof
RESOURCES
>
=
Q
extends
'
user_info
'
?
UserInfo
:
Q
extends
'
csrf
'
?
CsrfData
:
Q
extends
'
custom_abi
'
?
CustomAbis
:
never
;
pages/_app.tsx
View file @
efc37fa9
...
@@ -5,11 +5,11 @@ import type { AppProps } from 'next/app';
...
@@ -5,11 +5,11 @@ import type { AppProps } from 'next/app';
import
React
,
{
useState
}
from
'
react
'
;
import
React
,
{
useState
}
from
'
react
'
;
import
appConfig
from
'
configs/app/config
'
;
import
appConfig
from
'
configs/app/config
'
;
import
type
{
ResourceError
}
from
'
lib/api/resources
'
;
import
{
AppContextProvider
}
from
'
lib/appContext
'
;
import
{
AppContextProvider
}
from
'
lib/appContext
'
;
import
{
Chakra
}
from
'
lib/Chakra
'
;
import
{
Chakra
}
from
'
lib/Chakra
'
;
import
{
ScrollDirectionProvider
}
from
'
lib/contexts/scrollDirection
'
;
import
{
ScrollDirectionProvider
}
from
'
lib/contexts/scrollDirection
'
;
import
useConfigSentry
from
'
lib/hooks/useConfigSentry
'
;
import
useConfigSentry
from
'
lib/hooks/useConfigSentry
'
;
import
type
{
ErrorType
}
from
'
lib/hooks/useFetch
'
;
import
{
SocketProvider
}
from
'
lib/socket/context
'
;
import
{
SocketProvider
}
from
'
lib/socket/context
'
;
import
theme
from
'
theme
'
;
import
theme
from
'
theme
'
;
import
AppError
from
'
ui/shared/AppError/AppError
'
;
import
AppError
from
'
ui/shared/AppError/AppError
'
;
...
@@ -22,7 +22,7 @@ function MyApp({ Component, pageProps }: AppProps) {
...
@@ -22,7 +22,7 @@ function MyApp({ Component, pageProps }: AppProps) {
queries
:
{
queries
:
{
refetchOnWindowFocus
:
false
,
refetchOnWindowFocus
:
false
,
retry
:
(
failureCount
,
_error
)
=>
{
retry
:
(
failureCount
,
_error
)
=>
{
const
error
=
_error
as
ErrorType
<
{
status
:
number
}
>
;
const
error
=
_error
as
ResourceError
<
{
status
:
number
}
>
;
const
status
=
error
?.
status
||
error
?.
error
?.
status
;
const
status
=
error
?.
status
||
error
?.
error
?.
status
;
if
(
status
&&
status
>=
400
&&
status
<
500
)
{
if
(
status
&&
status
>=
400
&&
status
<
500
)
{
// don't do retry for client error responses
// don't do retry for client error responses
...
...
ui/block/BlockDetails.tsx
View file @
efc37fa9
...
@@ -13,10 +13,10 @@ import { QueryKeys } from 'types/client/queries';
...
@@ -13,10 +13,10 @@ import { QueryKeys } from 'types/client/queries';
import
appConfig
from
'
configs/app/config
'
;
import
appConfig
from
'
configs/app/config
'
;
import
clockIcon
from
'
icons/clock.svg
'
;
import
clockIcon
from
'
icons/clock.svg
'
;
import
flameIcon
from
'
icons/flame.svg
'
;
import
flameIcon
from
'
icons/flame.svg
'
;
import
type
{
ResourceError
}
from
'
lib/api/resources
'
;
import
getBlockReward
from
'
lib/block/getBlockReward
'
;
import
getBlockReward
from
'
lib/block/getBlockReward
'
;
import
{
WEI
,
WEI_IN_GWEI
,
ZERO
}
from
'
lib/consts
'
;
import
{
WEI
,
WEI_IN_GWEI
,
ZERO
}
from
'
lib/consts
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
type
{
ErrorType
}
from
'
lib/hooks/useFetch
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
{
space
}
from
'
lib/html-entities
'
;
import
{
space
}
from
'
lib/html-entities
'
;
import
link
from
'
lib/link/link
'
;
import
link
from
'
lib/link/link
'
;
...
@@ -37,7 +37,7 @@ const BlockDetails = () => {
...
@@ -37,7 +37,7 @@ const BlockDetails = () => {
const
router
=
useRouter
();
const
router
=
useRouter
();
const
fetch
=
useFetch
();
const
fetch
=
useFetch
();
const
{
data
,
isLoading
,
isError
,
error
}
=
useQuery
<
unknown
,
ErrorType
<
{
status
:
number
}
>
,
Block
>
(
const
{
data
,
isLoading
,
isError
,
error
}
=
useQuery
<
unknown
,
ResourceError
<
{
status
:
number
}
>
,
Block
>
(
[
QueryKeys
.
block
,
router
.
query
.
id
],
[
QueryKeys
.
block
,
router
.
query
.
id
],
async
()
=>
await
fetch
(
`/node-api/blocks/
${
router
.
query
.
id
}
`
),
async
()
=>
await
fetch
(
`/node-api/blocks/
${
router
.
query
.
id
}
`
),
{
{
...
...
ui/customAbi/CustomAbiModal/CustomAbiForm.tsx
View file @
efc37fa9
...
@@ -52,10 +52,10 @@ const CustomAbiForm: React.FC<Props> = ({ data, onClose, setAlertVisible }) => {
...
@@ -52,10 +52,10 @@ const CustomAbiForm: React.FC<Props> = ({ data, onClose, setAlertVisible }) => {
const
body
=
{
name
:
data
.
name
,
contract_address_hash
:
data
.
contract_address_hash
,
abi
:
data
.
abi
};
const
body
=
{
name
:
data
.
name
,
contract_address_hash
:
data
.
contract_address_hash
,
abi
:
data
.
abi
};
if
(
!
data
.
id
)
{
if
(
!
data
.
id
)
{
return
apiFetch
<
'
custom_abi
'
,
CustomAbi
,
CustomAbiErrors
>
(
'
custom_abi
'
,
{
fetchParams
:
{
method
:
'
POST
'
,
body
}
});
return
apiFetch
(
'
custom_abi
'
,
{
fetchParams
:
{
method
:
'
POST
'
,
body
}
});
}
}
return
apiFetch
<
'
custom_abi
'
,
CustomAbi
,
CustomAbiErrors
>
(
'
custom_abi
'
,
{
return
apiFetch
(
'
custom_abi
'
,
{
pathParams
:
{
id
:
String
(
data
.
id
)
},
pathParams
:
{
id
:
String
(
data
.
id
)
},
fetchParams
:
{
method
:
'
PUT
'
,
body
},
fetchParams
:
{
method
:
'
PUT
'
,
body
},
});
});
...
...
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