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
e6cd85d8
Commit
e6cd85d8
authored
Aug 09, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change types according new model
parent
0064819c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
61 deletions
+53
-61
apiKey.ts
data/apiKey.ts
+0
-21
account.ts
pages/api/types/account.ts
+2
-2
ApiKeyForm.tsx
ui/apiKey/ApiKeyModal/ApiKeyForm.tsx
+3
-3
ApiKeyModal.tsx
ui/apiKey/ApiKeyModal/ApiKeyModal.tsx
+4
-3
ApiKeyTable.tsx
ui/apiKey/ApiKeyTable/ApiKeyTable.tsx
+5
-5
ApiKeyTableItem.tsx
ui/apiKey/ApiKeyTable/ApiKeyTableItem.tsx
+8
-7
ApiKeys.tsx
ui/pages/ApiKeys.tsx
+31
-20
No files found.
data/apiKey.ts
deleted
100644 → 0
View file @
0064819c
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/api/types/account.ts
View file @
e6cd85d8
...
...
@@ -10,8 +10,8 @@ export interface AddressTag {
export
type
AddressTags
=
Array
<
AddressTag
>
export
interface
ApiKey
{
api
K
ey
:
string
;
apiKeyN
ame
:
string
;
api
_k
ey
:
string
;
n
ame
:
string
;
}
export
type
ApiKeys
=
Array
<
ApiKey
>
...
...
ui/apiKey/ApiKeyModal/ApiKeyForm.tsx
View file @
e6cd85d8
...
...
@@ -9,10 +9,10 @@ import React, { useCallback, useEffect } from 'react';
import
type
{
SubmitHandler
,
ControllerRenderProps
}
from
'
react-hook-form
'
;
import
{
useForm
,
Controller
}
from
'
react-hook-form
'
;
import
type
{
TApiKeyItem
}
from
'
data/apiKey
'
;
import
type
{
ApiKey
}
from
'
pages/api/types/account
'
;
type
Props
=
{
data
?:
TApiKeyItem
;
data
?:
ApiKey
;
}
type
Inputs
=
{
...
...
@@ -27,7 +27,7 @@ const ApiKeyForm: React.FC<Props> = ({ data }) => {
const
{
control
,
handleSubmit
,
formState
:
{
errors
},
setValue
}
=
useForm
<
Inputs
>
();
useEffect
(()
=>
{
setValue
(
'
token
'
,
data
?.
token
||
''
);
setValue
(
'
token
'
,
data
?.
api_key
||
''
);
setValue
(
'
name
'
,
data
?.
name
||
''
);
},
[
setValue
,
data
]);
...
...
ui/apiKey/ApiKeyModal/ApiKeyModal.tsx
View file @
e6cd85d8
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
ApiKeyForm
from
'
./ApiKeyForm
'
;
...
...
@@ -8,7 +9,7 @@ import ApiKeyForm from './ApiKeyForm';
type
Props
=
{
isOpen
:
boolean
;
onClose
:
()
=>
void
;
data
?:
TApiKeyItem
;
data
?:
ApiKey
;
}
const
AddressModal
:
React
.
FC
<
Props
>
=
({
isOpen
,
onClose
,
data
})
=>
{
...
...
@@ -19,7 +20,7 @@ const AddressModal: React.FC<Props> = ({ isOpen, onClose, data }) => {
return
<
ApiKeyForm
data=
{
data
}
/>;
},
[
data
]);
return
(
<
FormModal
<
TApiKeyItem
>
<
FormModal
<
ApiKey
>
isOpen=
{
isOpen
}
onClose=
{
onClose
}
title=
{
title
}
...
...
ui/apiKey/ApiKeyTable/ApiKeyTable.tsx
View file @
e6cd85d8
...
...
@@ -8,14 +8,14 @@ import {
}
from
'
@chakra-ui/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
'
;
interface
Props
{
data
:
TApiKey
;
onEditClick
:
(
data
:
TApiKeyItem
)
=>
void
;
onDeleteClick
:
(
data
:
TApiKeyItem
)
=>
void
;
data
:
ApiKeys
;
onEditClick
:
(
item
:
ApiKey
)
=>
void
;
onDeleteClick
:
(
item
:
ApiKey
)
=>
void
;
limit
:
number
;
}
...
...
@@ -33,7 +33,7 @@ const ApiKeyTable = ({ data, onDeleteClick, onEditClick, limit }: Props) => {
{
data
.
map
((
item
)
=>
(
<
ApiKeyTableItem
item=
{
item
}
key=
{
item
.
token
}
key=
{
item
.
api_key
}
onDeleteClick=
{
onDeleteClick
}
onEditClick=
{
onEditClick
}
/>
...
...
ui/apiKey/ApiKeyTable/ApiKeyTableItem.tsx
View file @
e6cd85d8
...
...
@@ -6,15 +6,16 @@ import {
}
from
'
@chakra-ui/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
DeleteButton
from
'
ui/shared/DeleteButton
'
;
import
EditButton
from
'
ui/shared/EditButton
'
;
interface
Props
{
item
:
TApiKeyItem
;
onEditClick
:
(
data
:
TApiKeyItem
)
=>
void
;
onDeleteClick
:
(
data
:
TApiKeyItem
)
=>
void
;
item
:
ApiKey
;
onEditClick
:
(
item
:
ApiKey
)
=>
void
;
onDeleteClick
:
(
item
:
ApiKey
)
=>
void
;
}
const
WatchlistTableItem
=
({
item
,
onEditClick
,
onDeleteClick
}:
Props
)
=>
{
...
...
@@ -28,11 +29,11 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
},
[
item
,
onDeleteClick
]);
return
(
<
Tr
alignItems=
"top"
key=
{
item
.
token
}
>
<
Tr
alignItems=
"top"
key=
{
item
.
api_key
}
>
<
Td
>
<
HStack
>
<
Text
fontSize=
"md"
fontWeight=
{
600
}
>
{
item
.
token
}
</
Text
>
<
CopyToClipboard
text=
{
item
.
token
}
/>
<
Text
fontSize=
"md"
fontWeight=
{
600
}
>
{
item
.
api_key
}
</
Text
>
<
CopyToClipboard
text=
{
item
.
api_key
}
/>
</
HStack
>
<
Text
fontSize=
"sm"
marginTop=
{
0.5
}
variant=
"secondary"
>
{
item
.
name
}
</
Text
>
</
Td
>
...
...
ui/pages/ApiKeys.tsx
View file @
e6cd85d8
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
type
{
TApiKeyItem
}
from
'
data/apiKey
'
;
import
{
apiKey
}
from
'
data/apiKey
'
;
import
type
{
ApiKey
,
ApiKeys
}
from
'
pages/api/types/account
'
;
import
{
space
}
from
'
lib/html-entities
'
;
import
ApiKeyModal
from
'
ui/apiKey/ApiKeyModal/ApiKeyModal
'
;
import
ApiKeyTable
from
'
ui/apiKey/ApiKeyTable/ApiKeyTable
'
;
...
...
@@ -13,14 +13,14 @@ import Page from 'ui/shared/Page/Page';
const
DATA_LIMIT
=
3
;
const
ApiKeys
:
React
.
FC
=
()
=>
{
const
ApiKeys
Page
:
React
.
FC
=
()
=>
{
const
apiKeyModalProps
=
useDisclosure
();
const
deleteModalProps
=
useDisclosure
();
const
[
apiKeyModalData
,
setApiKeyModalData
]
=
useState
<
TApiKeyItem
>
();
const
[
apiKeyModalData
,
setApiKeyModalData
]
=
useState
<
ApiKey
>
();
const
[
deleteModalData
,
setDeleteModalData
]
=
useState
<
string
>
();
useQuery
([
'
api-keys
'
],
async
()
=>
{
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
'
);
...
...
@@ -28,7 +28,7 @@ const ApiKeys: React.FC = () => {
return
response
.
json
();
});
const
onEditClick
=
useCallback
((
data
:
TApiKeyItem
)
=>
{
const
onEditClick
=
useCallback
((
data
:
ApiKey
)
=>
{
setApiKeyModalData
(
data
);
apiKeyModalProps
.
onOpen
();
},
[
apiKeyModalProps
]);
...
...
@@ -38,7 +38,7 @@ const ApiKeys: React.FC = () => {
apiKeyModalProps
.
onClose
();
},
[
apiKeyModalProps
]);
const
onDeleteClick
=
useCallback
((
data
:
TApiKeyItem
)
=>
{
const
onDeleteClick
=
useCallback
((
data
:
ApiKey
)
=>
{
setDeleteModalData
(
data
.
name
);
deleteModalProps
.
onOpen
();
},
[
deleteModalProps
]);
...
...
@@ -48,19 +48,17 @@ const ApiKeys: React.FC = () => {
deleteModalProps
.
onClose
();
},
[
deleteModalProps
]);
const
canAdd
=
apiKey
.
length
<
DATA_LIMIT
;
const
content
=
(()
=>
{
if
(
isLoading
||
isError
)
{
return
<
Spinner
/>;
}
const
canAdd
=
data
.
length
<
DATA_LIMIT
;
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
>
{
Boolean
(
apiKey
.
length
)
&&
(
<>
{
data
.
length
>
0
&&
(
<
ApiKeyTable
data=
{
apiKey
}
data=
{
data
}
onDeleteClick=
{
onDeleteClick
}
onEditClick=
{
onEditClick
}
limit=
{
DATA_LIMIT
}
...
...
@@ -81,6 +79,19 @@ const ApiKeys: React.FC = () => {
</
Text
>
)
}
</
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
>
<
ApiKeyModal
{
...
apiKeyModalProps
}
onClose=
{
onApiKeyModalClose
}
data=
{
apiKeyModalData
}
/>
<
DeleteApiKeyModal
{
...
deleteModalProps
}
onClose=
{
onDeleteModalClose
}
name=
{
deleteModalData
}
/>
...
...
@@ -88,4 +99,4 @@ const ApiKeys: React.FC = () => {
);
};
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