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
a21554b1
Unverified
Commit
a21554b1
authored
Aug 10, 2022
by
tom goriunov
Committed by
GitHub
Aug 10, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #73 from blockscout/api-keys-backend
api keys: backend integration
parents
e4dd9486
cb9ff16a
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
161 additions
and
75 deletions
+161
-75
apiKey.ts
data/apiKey.ts
+0
-21
_app.tsx
pages/_app.tsx
+2
-0
[id].ts
pages/api/account/api-keys/[id].ts
+11
-0
index.ts
pages/api/account/api-keys/index.ts
+7
-0
account.ts
pages/api/types/account.ts
+2
-2
handler.ts
pages/api/utils/handler.ts
+1
-0
ApiKeyForm.tsx
ui/apiKey/ApiKeyModal/ApiKeyForm.tsx
+47
-6
ApiKeyModal.tsx
ui/apiKey/ApiKeyModal/ApiKeyModal.tsx
+6
-5
ApiKeyTable.tsx
ui/apiKey/ApiKeyTable/ApiKeyTable.tsx
+5
-5
ApiKeyTableItem.tsx
ui/apiKey/ApiKeyTable/ApiKeyTableItem.tsx
+8
-7
DeleteApiKeyModal.tsx
ui/apiKey/DeleteApiKeyModal.tsx
+30
-7
ApiKeys.tsx
ui/pages/ApiKeys.tsx
+42
-22
No files found.
data/apiKey.ts
deleted
100644 → 0
View file @
e4dd9486
export
const
apiKey
=
[
{
token
:
'
6fd12fe0-841c-4abf-ac2a-8c1b08dadf8e
'
,
name
:
'
zapper.fi
'
,
},
{
token
:
'
057085a1-d2eb-4d8d-8b89-1dd9fba32071
'
,
name
:
'
TenderlyBlaBlaName
'
,
},
{
token
:
'
057085a1-d2eb-4d8d-8b89-1dd9fba32071
'
,
name
:
'
Application name
'
,
},
];
export
type
TApiKey
=
Array
<
TApiKeyItem
>
export
type
TApiKeyItem
=
{
token
:
string
;
name
:
string
;
}
pages/_app.tsx
View file @
a21554b1
import
{
ChakraProvider
}
from
'
@chakra-ui/react
'
;
import
{
ChakraProvider
}
from
'
@chakra-ui/react
'
;
import
{
QueryClient
,
QueryClientProvider
}
from
'
@tanstack/react-query
'
;
import
{
QueryClient
,
QueryClientProvider
}
from
'
@tanstack/react-query
'
;
import
{
ReactQueryDevtools
}
from
'
@tanstack/react-query-devtools
'
;
import
type
{
AppProps
}
from
'
next/app
'
;
import
type
{
AppProps
}
from
'
next/app
'
;
import
React
,
{
useState
}
from
'
react
'
;
import
React
,
{
useState
}
from
'
react
'
;
...
@@ -19,6 +20,7 @@ function MyApp({ Component, pageProps }: AppProps) {
...
@@ -19,6 +20,7 @@ function MyApp({ Component, pageProps }: AppProps) {
<
ChakraProvider
theme=
{
theme
}
>
<
ChakraProvider
theme=
{
theme
}
>
<
Component
{
...
pageProps
}
/>
<
Component
{
...
pageProps
}
/>
</
ChakraProvider
>
</
ChakraProvider
>
<
ReactQueryDevtools
/>
</
QueryClientProvider
>
</
QueryClientProvider
>
);
);
}
}
...
...
pages/api/account/api-keys/[id].ts
0 → 100644
View file @
a21554b1
import
type
{
NextApiRequest
}
from
'
next
'
;
import
handler
from
'
pages/api/utils/handler
'
;
const
getUrl
=
(
req
:
NextApiRequest
)
=>
{
return
`/account/v1/user/api_keys/
${
req
.
query
.
id
}
`
;
};
const
apiKeysHandler
=
handler
(
getUrl
,
[
'
DELETE
'
,
'
PUT
'
]);
export
default
apiKeysHandler
;
pages/api/account/api-keys/index.ts
0 → 100644
View file @
a21554b1
import
type
{
ApiKeys
}
from
'
pages/api/types/account
'
;
import
handler
from
'
pages/api/utils/handler
'
;
const
apiKeysHandler
=
handler
<
ApiKeys
>
(()
=>
'
/account/v1/user/api_keys
'
,
[
'
GET
'
,
'
POST
'
]);
export
default
apiKeysHandler
;
pages/api/types/account.ts
View file @
a21554b1
...
@@ -10,8 +10,8 @@ export interface AddressTag {
...
@@ -10,8 +10,8 @@ export interface AddressTag {
export
type
AddressTags
=
Array
<
AddressTag
>
export
type
AddressTags
=
Array
<
AddressTag
>
export
interface
ApiKey
{
export
interface
ApiKey
{
api
K
ey
:
string
;
api
_k
ey
:
string
;
apiKeyN
ame
:
string
;
n
ame
:
string
;
}
}
export
type
ApiKeys
=
Array
<
ApiKey
>
export
type
ApiKeys
=
Array
<
ApiKey
>
...
...
pages/api/utils/handler.ts
View file @
a21554b1
...
@@ -22,6 +22,7 @@ export default function handler<TRes>(getUrl: (_req: NextApiRequest) => string,
...
@@ -22,6 +22,7 @@ export default function handler<TRes>(getUrl: (_req: NextApiRequest) => string,
}
else
if
(
allowedMethods
.
includes
(
'
PUT
'
)
&&
_req
.
method
===
'
PUT
'
)
{
}
else
if
(
allowedMethods
.
includes
(
'
PUT
'
)
&&
_req
.
method
===
'
PUT
'
)
{
const
response
=
await
fetch
(
getUrl
(
_req
),
{
const
response
=
await
fetch
(
getUrl
(
_req
),
{
method
:
'
PUT
'
,
method
:
'
PUT
'
,
body
:
_req
.
body
,
});
});
const
data
=
await
response
.
json
()
as
TRes
;
const
data
=
await
response
.
json
()
as
TRes
;
...
...
ui/apiKey/ApiKeyModal/ApiKeyForm.tsx
View file @
a21554b1
...
@@ -5,14 +5,16 @@ import {
...
@@ -5,14 +5,16 @@ import {
FormLabel
,
FormLabel
,
Input
,
Input
,
}
from
'
@chakra-ui/react
'
;
}
from
'
@chakra-ui/react
'
;
import
{
useMutation
,
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
React
,
{
useCallback
,
useEffect
}
from
'
react
'
;
import
React
,
{
useCallback
,
useEffect
}
from
'
react
'
;
import
type
{
SubmitHandler
,
ControllerRenderProps
}
from
'
react-hook-form
'
;
import
type
{
SubmitHandler
,
ControllerRenderProps
}
from
'
react-hook-form
'
;
import
{
useForm
,
Controller
}
from
'
react-hook-form
'
;
import
{
useForm
,
Controller
}
from
'
react-hook-form
'
;
import
type
{
TApiKeyItem
}
from
'
data/apiKey
'
;
import
type
{
ApiKey
,
ApiKeys
}
from
'
pages/api/types/account
'
;
type
Props
=
{
type
Props
=
{
data
?:
TApiKeyItem
;
data
?:
ApiKey
;
onClose
:
()
=>
void
;
}
}
type
Inputs
=
{
type
Inputs
=
{
...
@@ -23,16 +25,54 @@ type Inputs = {
...
@@ -23,16 +25,54 @@ type Inputs = {
// idk, maybe there is no limit
// idk, maybe there is no limit
const
NAME_MAX_LENGTH
=
100
;
const
NAME_MAX_LENGTH
=
100
;
const
ApiKeyForm
:
React
.
FC
<
Props
>
=
({
data
})
=>
{
const
ApiKeyForm
:
React
.
FC
<
Props
>
=
({
data
,
onClose
})
=>
{
const
{
control
,
handleSubmit
,
formState
:
{
errors
},
setValue
}
=
useForm
<
Inputs
>
();
const
{
control
,
handleSubmit
,
formState
:
{
errors
},
setValue
}
=
useForm
<
Inputs
>
();
const
queryClient
=
useQueryClient
();
useEffect
(()
=>
{
useEffect
(()
=>
{
setValue
(
'
token
'
,
data
?.
token
||
''
);
setValue
(
'
token
'
,
data
?.
api_key
||
''
);
setValue
(
'
name
'
,
data
?.
name
||
''
);
setValue
(
'
name
'
,
data
?.
name
||
''
);
},
[
setValue
,
data
]);
},
[
setValue
,
data
]);
// eslint-disable-next-line no-console
const
updateApiKey
=
(
data
:
Inputs
)
=>
{
const
onSubmit
:
SubmitHandler
<
Inputs
>
=
data
=>
console
.
log
(
data
);
const
body
=
JSON
.
stringify
({
name
:
data
.
name
});
if
(
!
data
.
token
)
{
return
fetch
(
'
/api/account/api-keys
'
,
{
method
:
'
POST
'
,
body
});
}
return
fetch
(
`/api/account/api-keys/
${
data
.
token
}
`
,
{
method
:
'
PUT
'
,
body
});
};
const
mutation
=
useMutation
(
updateApiKey
,
{
onSuccess
:
async
(
data
)
=>
{
const
response
:
ApiKey
=
await
data
.
json
();
queryClient
.
setQueryData
([
'
api-keys
'
],
(
prevData
:
ApiKeys
|
undefined
)
=>
{
const
isExisting
=
prevData
&&
prevData
.
some
((
item
)
=>
item
.
api_key
===
response
.
api_key
);
if
(
isExisting
)
{
return
prevData
.
map
((
item
)
=>
{
if
(
item
.
api_key
===
response
.
api_key
)
{
return
response
;
}
return
item
;
});
}
return
[
...(
prevData
||
[]),
response
];
});
onClose
();
},
// eslint-disable-next-line no-console
onError
:
console
.
error
,
});
const
onSubmit
:
SubmitHandler
<
Inputs
>
=
useCallback
((
data
)
=>
{
mutation
.
mutate
(
data
);
},
[
mutation
]);
const
renderTokenInput
=
useCallback
(({
field
}:
{
field
:
ControllerRenderProps
<
Inputs
,
'
token
'
>
})
=>
{
const
renderTokenInput
=
useCallback
(({
field
}:
{
field
:
ControllerRenderProps
<
Inputs
,
'
token
'
>
})
=>
{
return
(
return
(
...
@@ -86,6 +126,7 @@ const ApiKeyForm: React.FC<Props> = ({ data }) => {
...
@@ -86,6 +126,7 @@ const ApiKeyForm: React.FC<Props> = ({ data }) => {
variant=
"primary"
variant=
"primary"
onClick=
{
handleSubmit
(
onSubmit
)
}
onClick=
{
handleSubmit
(
onSubmit
)
}
disabled=
{
Object
.
keys
(
errors
).
length
>
0
}
disabled=
{
Object
.
keys
(
errors
).
length
>
0
}
isLoading=
{
mutation
.
isLoading
}
>
>
{
data
?
'
Save
'
:
'
Generate API key
'
}
{
data
?
'
Save
'
:
'
Generate API key
'
}
</
Button
>
</
Button
>
...
...
ui/apiKey/ApiKeyModal/ApiKeyModal.tsx
View file @
a21554b1
import
React
,
{
useCallback
}
from
'
react
'
;
import
React
,
{
useCallback
}
from
'
react
'
;
import
type
{
TApiKeyItem
}
from
'
data/apiKey
'
;
import
type
{
ApiKey
}
from
'
pages/api/types/account
'
;
import
FormModal
from
'
ui/shared/FormModal
'
;
import
FormModal
from
'
ui/shared/FormModal
'
;
import
ApiKeyForm
from
'
./ApiKeyForm
'
;
import
ApiKeyForm
from
'
./ApiKeyForm
'
;
...
@@ -8,7 +9,7 @@ import ApiKeyForm from './ApiKeyForm';
...
@@ -8,7 +9,7 @@ import ApiKeyForm from './ApiKeyForm';
type
Props
=
{
type
Props
=
{
isOpen
:
boolean
;
isOpen
:
boolean
;
onClose
:
()
=>
void
;
onClose
:
()
=>
void
;
data
?:
TApiKeyItem
;
data
?:
ApiKey
;
}
}
const
AddressModal
:
React
.
FC
<
Props
>
=
({
isOpen
,
onClose
,
data
})
=>
{
const
AddressModal
:
React
.
FC
<
Props
>
=
({
isOpen
,
onClose
,
data
})
=>
{
...
@@ -16,10 +17,10 @@ const AddressModal: React.FC<Props> = ({ isOpen, onClose, data }) => {
...
@@ -16,10 +17,10 @@ const AddressModal: React.FC<Props> = ({ isOpen, onClose, data }) => {
const
text
=
'
Add an application name to identify your API key. Click the button below to auto-generate the associated key.
'
;
const
text
=
'
Add an application name to identify your API key. Click the button below to auto-generate the associated key.
'
;
const
renderForm
=
useCallback
(()
=>
{
const
renderForm
=
useCallback
(()
=>
{
return
<
ApiKeyForm
data=
{
data
}
/>;
return
<
ApiKeyForm
data=
{
data
}
onClose=
{
onClose
}
/>;
},
[
data
]);
},
[
data
,
onClose
]);
return
(
return
(
<
FormModal
<
TApiKeyItem
>
<
FormModal
<
ApiKey
>
isOpen=
{
isOpen
}
isOpen=
{
isOpen
}
onClose=
{
onClose
}
onClose=
{
onClose
}
title=
{
title
}
title=
{
title
}
...
...
ui/apiKey/ApiKeyTable/ApiKeyTable.tsx
View file @
a21554b1
...
@@ -8,14 +8,14 @@ import {
...
@@ -8,14 +8,14 @@ import {
}
from
'
@chakra-ui/react
'
;
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
TApiKey
,
TApiKeyItem
}
from
'
data/apiKey
'
;
import
type
{
ApiKeys
,
ApiKey
}
from
'
pages/api/types/account
'
;
import
ApiKeyTableItem
from
'
./ApiKeyTableItem
'
;
import
ApiKeyTableItem
from
'
./ApiKeyTableItem
'
;
interface
Props
{
interface
Props
{
data
:
TApiKey
;
data
:
ApiKeys
;
onEditClick
:
(
data
:
TApiKeyItem
)
=>
void
;
onEditClick
:
(
item
:
ApiKey
)
=>
void
;
onDeleteClick
:
(
data
:
TApiKeyItem
)
=>
void
;
onDeleteClick
:
(
item
:
ApiKey
)
=>
void
;
limit
:
number
;
limit
:
number
;
}
}
...
@@ -33,7 +33,7 @@ const ApiKeyTable = ({ data, onDeleteClick, onEditClick, limit }: Props) => {
...
@@ -33,7 +33,7 @@ const ApiKeyTable = ({ data, onDeleteClick, onEditClick, limit }: Props) => {
{
data
.
map
((
item
)
=>
(
{
data
.
map
((
item
)
=>
(
<
ApiKeyTableItem
<
ApiKeyTableItem
item=
{
item
}
item=
{
item
}
key=
{
item
.
token
}
key=
{
item
.
api_key
}
onDeleteClick=
{
onDeleteClick
}
onDeleteClick=
{
onDeleteClick
}
onEditClick=
{
onEditClick
}
onEditClick=
{
onEditClick
}
/>
/>
...
...
ui/apiKey/ApiKeyTable/ApiKeyTableItem.tsx
View file @
a21554b1
...
@@ -6,15 +6,16 @@ import {
...
@@ -6,15 +6,16 @@ import {
}
from
'
@chakra-ui/react
'
;
}
from
'
@chakra-ui/react
'
;
import
React
,
{
useCallback
}
from
'
react
'
;
import
React
,
{
useCallback
}
from
'
react
'
;
import
type
{
TApiKeyItem
}
from
'
data/apiKey
'
;
import
type
{
ApiKey
}
from
'
pages/api/types/account
'
;
import
CopyToClipboard
from
'
ui/shared/CopyToClipboard
'
;
import
CopyToClipboard
from
'
ui/shared/CopyToClipboard
'
;
import
DeleteButton
from
'
ui/shared/DeleteButton
'
;
import
DeleteButton
from
'
ui/shared/DeleteButton
'
;
import
EditButton
from
'
ui/shared/EditButton
'
;
import
EditButton
from
'
ui/shared/EditButton
'
;
interface
Props
{
interface
Props
{
item
:
TApiKeyItem
;
item
:
ApiKey
;
onEditClick
:
(
data
:
TApiKeyItem
)
=>
void
;
onEditClick
:
(
item
:
ApiKey
)
=>
void
;
onDeleteClick
:
(
data
:
TApiKeyItem
)
=>
void
;
onDeleteClick
:
(
item
:
ApiKey
)
=>
void
;
}
}
const
WatchlistTableItem
=
({
item
,
onEditClick
,
onDeleteClick
}:
Props
)
=>
{
const
WatchlistTableItem
=
({
item
,
onEditClick
,
onDeleteClick
}:
Props
)
=>
{
...
@@ -28,11 +29,11 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
...
@@ -28,11 +29,11 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
},
[
item
,
onDeleteClick
]);
},
[
item
,
onDeleteClick
]);
return
(
return
(
<
Tr
alignItems=
"top"
key=
{
item
.
token
}
>
<
Tr
alignItems=
"top"
key=
{
item
.
api_key
}
>
<
Td
>
<
Td
>
<
HStack
>
<
HStack
>
<
Text
fontSize=
"md"
fontWeight=
{
600
}
>
{
item
.
token
}
</
Text
>
<
Text
fontSize=
"md"
fontWeight=
{
600
}
>
{
item
.
api_key
}
</
Text
>
<
CopyToClipboard
text=
{
item
.
token
}
/>
<
CopyToClipboard
text=
{
item
.
api_key
}
/>
</
HStack
>
</
HStack
>
<
Text
fontSize=
"sm"
marginTop=
{
0.5
}
variant=
"secondary"
>
{
item
.
name
}
</
Text
>
<
Text
fontSize=
"sm"
marginTop=
{
0.5
}
variant=
"secondary"
>
{
item
.
name
}
</
Text
>
</
Td
>
</
Td
>
...
...
ui/apiKey/DeleteApiKeyModal.tsx
View file @
a21554b1
import
{
Text
}
from
'
@chakra-ui/react
'
;
import
{
Text
}
from
'
@chakra-ui/react
'
;
import
{
useMutation
,
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
React
,
{
useCallback
}
from
'
react
'
;
import
React
,
{
useCallback
}
from
'
react
'
;
import
type
{
ApiKey
,
ApiKeys
}
from
'
pages/api/types/account
'
;
import
DeleteModal
from
'
ui/shared/DeleteModal
'
;
import
DeleteModal
from
'
ui/shared/DeleteModal
'
;
type
Props
=
{
type
Props
=
{
isOpen
:
boolean
;
isOpen
:
boolean
;
onClose
:
()
=>
void
;
onClose
:
()
=>
void
;
name
?:
string
;
data
:
ApiKey
;
}
}
const
DeleteAddressModal
:
React
.
FC
<
Props
>
=
({
isOpen
,
onClose
,
name
})
=>
{
const
DeleteAddressModal
:
React
.
FC
<
Props
>
=
({
isOpen
,
onClose
,
data
})
=>
{
const
onDelete
=
useCallback
(()
=>
{
const
queryClient
=
useQueryClient
();
const
deleteApiKey
=
()
=>
{
return
fetch
(
`/api/account/api-keys/
${
data
.
api_key
}
`
,
{
method
:
'
DELETE
'
});
};
const
mutation
=
useMutation
(
deleteApiKey
,
{
onSuccess
:
async
()
=>
{
queryClient
.
setQueryData
([
'
api-keys
'
],
(
prevData
:
ApiKeys
|
undefined
)
=>
{
return
prevData
?.
filter
((
item
)
=>
item
.
api_key
!==
data
.
api_key
);
});
onClose
();
},
// eslint-disable-next-line no-console
// eslint-disable-next-line no-console
console
.
log
(
'
delete
'
,
name
);
onError
:
console
.
error
,
},
[
name
]);
});
const
onDelete
=
useCallback
(()
=>
{
mutation
.
mutate
(
data
);
},
[
data
,
mutation
]);
const
renderText
=
useCallback
(()
=>
{
const
renderText
=
useCallback
(()
=>
{
return
(
return
(
<
Text
display=
"flex"
>
API key for
<
Text
fontWeight=
"600"
whiteSpace=
"pre"
>
{
` "${ name || 'name' }" `
}
</
Text
>
will be deleted
</
Text
>
<
Text
display=
"flex"
>
API key for
<
Text
fontWeight=
"600"
whiteSpace=
"pre"
>
{
` "${
data.
name || 'name' }" `
}
</
Text
>
will be deleted
</
Text
>
);
);
},
[
name
]);
},
[
data
.
name
]);
return
(
return
(
<
DeleteModal
<
DeleteModal
isOpen=
{
isOpen
}
isOpen=
{
isOpen
}
...
@@ -27,6 +49,7 @@ const DeleteAddressModal: React.FC<Props> = ({ isOpen, onClose, name }) => {
...
@@ -27,6 +49,7 @@ const DeleteAddressModal: React.FC<Props> = ({ isOpen, onClose, name }) => {
onDelete=
{
onDelete
}
onDelete=
{
onDelete
}
title=
"Remove API key"
title=
"Remove API key"
renderContent=
{
renderText
}
renderContent=
{
renderText
}
pending=
{
mutation
.
isLoading
}
/>
/>
);
);
};
};
...
...
ui/pages/ApiKeys.tsx
View file @
a21554b1
import
{
Box
,
Button
,
HStack
,
Link
,
Text
,
useDisclosure
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Button
,
HStack
,
Link
,
Text
,
Spinner
,
useDisclosure
}
from
'
@chakra-ui/react
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
React
,
{
useCallback
,
useState
}
from
'
react
'
;
import
React
,
{
useCallback
,
useState
}
from
'
react
'
;
import
type
{
TApiKeyItem
}
from
'
data/apiKey
'
;
import
type
{
ApiKey
,
ApiKeys
}
from
'
pages/api/types/account
'
;
import
{
apiKey
}
from
'
data/apiKey
'
;
import
{
space
}
from
'
lib/html-entities
'
;
import
{
space
}
from
'
lib/html-entities
'
;
import
ApiKeyModal
from
'
ui/apiKey/ApiKeyModal/ApiKeyModal
'
;
import
ApiKeyModal
from
'
ui/apiKey/ApiKeyModal/ApiKeyModal
'
;
import
ApiKeyTable
from
'
ui/apiKey/ApiKeyTable/ApiKeyTable
'
;
import
ApiKeyTable
from
'
ui/apiKey/ApiKeyTable/ApiKeyTable
'
;
...
@@ -12,14 +13,22 @@ import Page from 'ui/shared/Page/Page';
...
@@ -12,14 +13,22 @@ import Page from 'ui/shared/Page/Page';
const
DATA_LIMIT
=
3
;
const
DATA_LIMIT
=
3
;
const
ApiKeys
:
React
.
FC
=
()
=>
{
const
ApiKeys
Page
:
React
.
FC
=
()
=>
{
const
apiKeyModalProps
=
useDisclosure
();
const
apiKeyModalProps
=
useDisclosure
();
const
deleteModalProps
=
useDisclosure
();
const
deleteModalProps
=
useDisclosure
();
const
[
apiKeyModalData
,
setApiKeyModalData
]
=
useState
<
TApiKeyItem
>
();
const
[
apiKeyModalData
,
setApiKeyModalData
]
=
useState
<
ApiKey
>
();
const
[
deleteModalData
,
setDeleteModalData
]
=
useState
<
string
>
();
const
[
deleteModalData
,
setDeleteModalData
]
=
useState
<
ApiKey
>
();
const
{
data
,
isLoading
,
isError
}
=
useQuery
<
unknown
,
unknown
,
ApiKeys
>
([
'
api-keys
'
],
async
()
=>
{
const
response
=
await
fetch
(
'
/api/account/api-keys
'
);
if
(
!
response
.
ok
)
{
throw
new
Error
(
'
Network response was not ok
'
);
}
return
response
.
json
();
});
const
onEditClick
=
useCallback
((
data
:
TApiKeyItem
)
=>
{
const
onEditClick
=
useCallback
((
data
:
ApiKey
)
=>
{
setApiKeyModalData
(
data
);
setApiKeyModalData
(
data
);
apiKeyModalProps
.
onOpen
();
apiKeyModalProps
.
onOpen
();
},
[
apiKeyModalProps
]);
},
[
apiKeyModalProps
]);
...
@@ -29,8 +38,8 @@ const ApiKeys: React.FC = () => {
...
@@ -29,8 +38,8 @@ const ApiKeys: React.FC = () => {
apiKeyModalProps
.
onClose
();
apiKeyModalProps
.
onClose
();
},
[
apiKeyModalProps
]);
},
[
apiKeyModalProps
]);
const
onDeleteClick
=
useCallback
((
data
:
TApiKeyItem
)
=>
{
const
onDeleteClick
=
useCallback
((
data
:
ApiKey
)
=>
{
setDeleteModalData
(
data
.
name
);
setDeleteModalData
(
data
);
deleteModalProps
.
onOpen
();
deleteModalProps
.
onOpen
();
},
[
deleteModalProps
]);
},
[
deleteModalProps
]);
...
@@ -39,19 +48,17 @@ const ApiKeys: React.FC = () => {
...
@@ -39,19 +48,17 @@ const ApiKeys: React.FC = () => {
deleteModalProps
.
onClose
();
deleteModalProps
.
onClose
();
},
[
deleteModalProps
]);
},
[
deleteModalProps
]);
const
canAdd
=
apiKey
.
length
<
DATA_LIMIT
;
const
content
=
(()
=>
{
if
(
isLoading
||
isError
)
{
return
<
Spinner
/>;
}
return
(
const
canAdd
=
data
.
length
<
DATA_LIMIT
;
<
Page
>
return
(
<
Box
h=
"100%"
>
<>
<
AccountPageHeader
text=
"API keys"
/>
{
data
.
length
>
0
&&
(
<
Text
marginBottom=
{
12
}
>
Create API keys to use for your RPC and EthRPC API requests. For more information, see
{
space
}
<
Link
href=
"#"
>
“How to use a Blockscout API key”
</
Link
>
.
</
Text
>
{
Boolean
(
apiKey
.
length
)
&&
(
<
ApiKeyTable
<
ApiKeyTable
data=
{
apiKey
}
data=
{
data
}
onDeleteClick=
{
onDeleteClick
}
onDeleteClick=
{
onDeleteClick
}
onEditClick=
{
onEditClick
}
onEditClick=
{
onEditClick
}
limit=
{
DATA_LIMIT
}
limit=
{
DATA_LIMIT
}
...
@@ -72,11 +79,24 @@ const ApiKeys: React.FC = () => {
...
@@ -72,11 +79,24 @@ const ApiKeys: React.FC = () => {
</
Text
>
</
Text
>
)
}
)
}
</
HStack
>
</
HStack
>
</>
);
})();
return
(
<
Page
>
<
Box
h=
"100%"
>
<
AccountPageHeader
text=
"API keys"
/>
<
Text
marginBottom=
{
12
}
>
Create API keys to use for your RPC and EthRPC API requests. For more information, see
{
space
}
<
Link
href=
"#"
>
“How to use a Blockscout API key”
</
Link
>
.
</
Text
>
{
content
}
</
Box
>
</
Box
>
<
ApiKeyModal
{
...
apiKeyModalProps
}
onClose=
{
onApiKeyModalClose
}
data=
{
apiKeyModalData
}
/>
<
ApiKeyModal
{
...
apiKeyModalProps
}
onClose=
{
onApiKeyModalClose
}
data=
{
apiKeyModalData
}
/>
<
DeleteApiKeyModal
{
...
deleteModalProps
}
onClose=
{
onDeleteModalClose
}
name=
{
deleteModalData
}
/>
{
deleteModalData
&&
<
DeleteApiKeyModal
{
...
deleteModalProps
}
onClose=
{
onDeleteModalClose
}
data=
{
deleteModalData
}
/>
}
</
Page
>
</
Page
>
);
);
};
};
export
default
ApiKeys
;
export
default
ApiKeys
Page
;
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