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
a775d015
Unverified
Commit
a775d015
authored
Jul 28, 2022
by
Igor Stuev
Committed by
GitHub
Jul 28, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #67 from blockscout/private-tag-edit
add edit private tag method
parents
faf75c79
1e667edf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
10 deletions
+52
-10
[id].ts
pages/api/account/private-tags/address/[id].ts
+10
-2
[id].ts
pages/api/account/private-tags/transaction/[id].ts
+10
-2
handler.ts
pages/api/utils/handler.ts
+8
-1
AddressForm.tsx
ui/privateTags/AddressModal/AddressForm.tsx
+12
-3
TransactionForm.tsx
ui/privateTags/TransactionModal/TransactionForm.tsx
+12
-2
No files found.
pages/api/account/private-tags/address/[id].ts
View file @
a775d015
...
...
@@ -2,8 +2,16 @@ import type { NextApiRequest } from 'next'
import
handler
from
'
pages/api/utils/handler
'
;
const
getUrl
=
(
req
:
NextApiRequest
)
=>
`/account/v1/user/tags/address/
${
req
.
query
.
id
}
`
const
getUrl
=
(
req
:
NextApiRequest
)
=>
{
let
url
=
`/account/v1/user/tags/address/
${
req
.
query
.
id
}
`
;
if
(
req
.
method
===
'
PUT
'
)
{
const
params
=
{
address_hash
:
req
.
query
.
address_hash
as
string
,
name
:
req
.
query
.
name
as
string
};
const
searchParams
=
new
URLSearchParams
(
params
);
url
+=
`?
${
searchParams
.
toString
()
}
`
}
return
url
;
}
const
addressDeleteHandler
=
handler
(
getUrl
,
[
'
DELETE
'
]);
const
addressDeleteHandler
=
handler
(
getUrl
,
[
'
DELETE
'
,
'
PUT
'
]);
export
default
addressDeleteHandler
;
pages/api/account/private-tags/transaction/[id].ts
View file @
a775d015
...
...
@@ -2,8 +2,16 @@ import type { NextApiRequest } from 'next'
import
handler
from
'
pages/api/utils/handler
'
;
const
getUrl
=
(
req
:
NextApiRequest
)
=>
`/account/v1/user/tags/transaction/
${
req
.
query
.
id
}
`
const
getUrl
=
(
req
:
NextApiRequest
)
=>
{
let
url
=
`/account/v1/user/tags/transaction/
${
req
.
query
.
id
}
`
;
if
(
req
.
method
===
'
PUT
'
)
{
const
params
=
{
transaction_hash
:
req
.
query
.
transaction_hash
as
string
,
name
:
req
.
query
.
name
as
string
};
const
searchParams
=
new
URLSearchParams
(
params
);
url
+=
`?
${
searchParams
.
toString
()
}
`
}
return
url
;
}
const
transactionDeleteHandler
=
handler
(
getUrl
,
[
'
DELETE
'
]);
const
transactionDeleteHandler
=
handler
(
getUrl
,
[
'
DELETE
'
,
'
PUT
'
]);
export
default
transactionDeleteHandler
;
pages/api/utils/handler.ts
View file @
a775d015
...
...
@@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'
import
fetch
from
'
./fetch
'
;
type
Methods
=
'
GET
'
|
'
POST
'
|
'
DELETE
'
;
type
Methods
=
'
GET
'
|
'
POST
'
|
'
PUT
'
|
'
DELETE
'
;
export
default
function
handler
<
TRes
>
(
getUrl
:
(
_req
:
NextApiRequest
)
=>
string
,
allowedMethods
:
Array
<
Methods
>
)
{
return
async
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
<
TRes
>
)
=>
{
...
...
@@ -18,6 +18,13 @@ export default function handler<TRes>(getUrl: (_req: NextApiRequest) => string,
})
const
data
=
await
response
.
json
()
as
TRes
;
res
.
status
(
200
).
json
(
data
)
}
else
if
(
allowedMethods
.
includes
(
'
PUT
'
)
&&
_req
.
method
===
'
PUT
'
)
{
const
response
=
await
fetch
(
getUrl
(
_req
),
{
method
:
'
PUT
'
,
})
const
data
=
await
response
.
json
()
as
TRes
;
res
.
status
(
200
).
json
(
data
)
}
else
if
(
allowedMethods
.
includes
(
'
DELETE
'
)
&&
_req
.
method
===
'
DELETE
'
)
{
const
response
=
await
fetch
(
getUrl
(
_req
),
{
method
:
'
DELETE
'
});
...
...
ui/privateTags/AddressModal/AddressForm.tsx
View file @
a775d015
...
...
@@ -38,10 +38,20 @@ const AddressForm: React.FC<Props> = ({ data, onClose }) => {
const
queryClient
=
useQueryClient
();
const
{
mutate
}
=
useMutation
((
formData
:
Inputs
)
=>
{
return
fetch
(
'
/api/account/private-tags/address
'
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
({
let
mutationFunction
;
const
requestParams
=
{
name
:
formData
?.
tag
,
address_hash
:
formData
?.
address
,
})
})
}
if
(
data
)
{
// edit tag
const
params
=
new
URLSearchParams
(
requestParams
);
mutationFunction
=
()
=>
fetch
(
`/api/account/private-tags/address/
${
data
.
id
}
?
${
params
.
toString
()
}
`
,
{
method
:
'
PUT
'
})
}
else
{
// add tag
mutationFunction
=
()
=>
fetch
(
'
/api/account/private-tags/address
'
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
(
requestParams
)
})
}
return
mutationFunction
();
},
{
onError
:
()
=>
{
// eslint-disable-next-line no-console
...
...
@@ -57,7 +67,6 @@ const AddressForm: React.FC<Props> = ({ data, onClose }) => {
const
onSubmit
:
SubmitHandler
<
Inputs
>
=
(
formData
)
=>
{
setPending
(
true
);
// api method for editing is not implemented now!!!
mutate
(
formData
);
};
...
...
ui/privateTags/TransactionModal/TransactionForm.tsx
View file @
a775d015
...
...
@@ -39,10 +39,20 @@ const TransactionForm: React.FC<Props> = ({ data, onClose }) => {
const
queryClient
=
useQueryClient
();
const
{
mutate
}
=
useMutation
((
formData
:
Inputs
)
=>
{
return
fetch
(
'
/api/account/private-tags/transaction
'
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
({
let
mutationFunction
;
const
requestParams
=
{
name
:
formData
?.
tag
,
transaction_hash
:
formData
?.
transaction
,
})
})
}
if
(
data
)
{
// edit tag
const
params
=
new
URLSearchParams
(
requestParams
);
mutationFunction
=
()
=>
fetch
(
`/api/account/private-tags/transaction/
${
data
.
id
}
?
${
params
.
toString
()
}
`
,
{
method
:
'
PUT
'
})
}
else
{
// add tag
mutationFunction
=
()
=>
fetch
(
'
/api/account/private-tags/transaction
'
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
(
requestParams
)
})
}
return
mutationFunction
();
},
{
onError
:
()
=>
{
// eslint-disable-next-line no-console
...
...
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