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
5f5e99cc
Commit
5f5e99cc
authored
Jul 28, 2022
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common handler
parent
85a02bf2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
123 additions
and
104 deletions
+123
-104
[id].ts
pages/api/account/private-tags/address/[id].ts
+5
-22
index.ts
pages/api/account/private-tags/address/index.ts
+4
-30
[id].ts
pages/api/account/private-tags/transaction/[id].ts
+5
-22
index.ts
pages/api/account/private-tags/transaction/index.ts
+4
-30
account.ts
pages/api/types/account.ts
+70
-0
handler.ts
pages/api/utils/handler.ts
+35
-0
No files found.
pages/api/account/private-tags/address/[id].ts
View file @
5f5e99cc
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
import
type
{
NextApiRequest
}
from
'
next
'
import
fetch
from
'
pages/api/utils/fetch
'
;
import
handler
from
'
pages/api/utils/handler
'
;
export
default
async
function
handler
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
const
{
id
}
=
_req
.
query
;
const
url
=
`/account/v1/user/tags/address/
${
id
}
`
;
const
getUrl
=
(
req
:
NextApiRequest
)
=>
`/account/v1/user/tags/address/
${
req
.
query
.
id
}
`
switch
(
_req
.
method
)
{
case
'
DELETE
'
:
{
const
response
=
await
fetch
(
url
,
{
method
:
'
DELETE
'
});
// FIXME: add error handlers
if
(
response
.
status
!==
200
)
{
// eslint-disable-next-line no-console
console
.
log
(
response
.
statusText
);
}
res
.
status
(
200
).
end
();
break
;
}
const
addressDeleteHandler
=
handler
(
getUrl
,
[
'
DELETE
'
]);
default
:
{
res
.
setHeader
(
'
Allow
'
,
[
'
DELETE
'
])
res
.
status
(
405
).
end
(
`Method
${
_req
.
method
}
Not Allowed`
)
}
}
}
export
default
addressDeleteHandler
;
pages/api/account/private-tags/address/index.ts
View file @
5f5e99cc
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
import
handler
from
'
pages/api/utils/handler
'
;
import
fetch
from
'
pages/api/utils/fetch
'
;
import
type
{
AddressTags
}
from
'
pages/api/types/account
'
;
export
default
async
function
handler
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
const
url
=
'
/account/v1/user/tags/address
'
;
const
addressHandler
=
handler
<
AddressTags
>
(()
=>
'
/account/v1/user/tags/address
'
,
[
'
GET
'
,
'
POST
'
]);
switch
(
_req
.
method
)
{
case
'
GET
'
:
{
const
response
=
await
fetch
(
url
)
const
data
=
await
response
.
json
();
res
.
status
(
200
).
json
(
data
)
break
;
}
case
'
POST
'
:
{
const
response
=
await
fetch
(
url
,
{
method
:
'
POST
'
,
body
:
_req
.
body
,
})
const
data
=
await
response
.
json
();
res
.
status
(
200
).
json
(
data
)
break
;
}
default
:
{
res
.
setHeader
(
'
Allow
'
,
[
'
GET
'
,
'
POST
'
])
res
.
status
(
405
).
end
(
`Method
${
_req
.
method
}
Not Allowed`
)
}
}
}
export
default
addressHandler
;
pages/api/account/private-tags/transaction/[id].ts
View file @
5f5e99cc
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
import
type
{
NextApiRequest
}
from
'
next
'
import
fetch
from
'
pages/api/utils/fetch
'
;
import
handler
from
'
pages/api/utils/handler
'
;
export
default
async
function
handler
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
const
{
id
}
=
_req
.
query
;
const
url
=
`/account/v1/user/tags/transaction/
${
id
}
`
;
const
getUrl
=
(
req
:
NextApiRequest
)
=>
`/account/v1/user/tags/transaction/
${
req
.
query
.
id
}
`
switch
(
_req
.
method
)
{
case
'
DELETE
'
:
{
const
response
=
await
fetch
(
url
,
{
method
:
'
DELETE
'
});
// FIXME: add error handlers
if
(
response
.
status
!==
200
)
{
// eslint-disable-next-line no-console
console
.
log
(
response
.
statusText
);
}
res
.
status
(
200
).
end
();
break
;
}
const
transactionDeleteHandler
=
handler
(
getUrl
,
[
'
DELETE
'
]);
default
:
{
res
.
setHeader
(
'
Allow
'
,
[
'
DELETE
'
])
res
.
status
(
405
).
end
(
`Method
${
_req
.
method
}
Not Allowed`
)
}
}
}
export
default
transactionDeleteHandler
;
pages/api/account/private-tags/transaction/index.ts
View file @
5f5e99cc
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
import
handler
from
'
pages/api/utils/handler
'
;
import
fetch
from
'
pages/api/utils/fetch
'
;
import
type
{
TransactionTags
}
from
'
pages/api/types/account
'
;
export
default
async
function
handler
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
const
url
=
'
/account/v1/user/tags/transaction
'
;
const
transactionHandler
=
handler
<
TransactionTags
>
(()
=>
'
/account/v1/user/tags/transaction
'
,
[
'
GET
'
,
'
POST
'
]);
switch
(
_req
.
method
)
{
case
'
GET
'
:
{
const
response
=
await
fetch
(
url
)
const
data
=
await
response
.
json
();
res
.
status
(
200
).
json
(
data
)
break
;
}
case
'
POST
'
:
{
const
response
=
await
fetch
(
url
,
{
method
:
'
POST
'
,
body
:
_req
.
body
,
})
const
data
=
await
response
.
json
();
res
.
status
(
200
).
json
(
data
)
break
;
}
default
:
{
res
.
setHeader
(
'
Allow
'
,
[
'
GET
'
,
'
POST
'
])
res
.
status
(
405
).
end
(
`Method
${
_req
.
method
}
Not Allowed`
)
}
}
}
export
default
transactionHandler
;
pages/api/types/account.ts
0 → 100644
View file @
5f5e99cc
// FIXME: here are types of the elixir api's responses
// and in types/api/ folder we have types of the node api's responses
// maybe they are always the same and there is no need to keep two separate files with types
export
interface
AddressTag
{
address_hash
:
string
;
name
:
string
;
id
:
string
;
}
export
type
AddressTags
=
Array
<
AddressTag
>
export
interface
ApiKey
{
apiKey
:
string
;
apiKeyName
:
string
;
}
export
type
ApiKeys
=
Array
<
ApiKey
>
export
interface
ModelError
{
message
:
string
;
}
export
interface
NotificationDirection
{
incoming
:
boolean
;
outcoming
:
boolean
;
}
export
interface
NotificationSettings
{
_native
?:
NotificationDirection
;
erc20
?:
NotificationDirection
;
erc7211155
?:
NotificationDirection
;
}
export
interface
Transaction
{
fromAddressHash
?:
string
;
toAddressHash
?:
string
;
createdContractAddressHash
?:
string
;
}
export
interface
TransactionTag
{
transaction_hash
:
string
;
name
:
string
;
id
:
string
;
}
export
type
TransactionTags
=
Array
<
TransactionTag
>
export
type
Transactions
=
Array
<
Transaction
>
export
interface
UserInfo
{
name
?:
string
;
nickname
?:
string
;
email
?:
string
;
}
export
interface
WatchlistAddress
{
addressHash
:
string
;
addressName
:
string
;
addressBalance
:
number
;
coinName
:
string
;
exchangeRate
?:
number
;
notificationSettings
:
NotificationSettings
;
}
export
interface
WatchlistAddressNew
{
addressName
:
string
;
notificationSettings
:
NotificationSettings
;
}
export
type
WatchlistAddresses
=
Array
<
WatchlistAddress
>
pages/api/utils/handler.ts
0 → 100644
View file @
5f5e99cc
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
import
fetch
from
'
./fetch
'
;
type
Methods
=
'
GET
'
|
'
POST
'
|
'
DELETE
'
;
export
default
function
handler
<
TRes
>
(
getUrl
:
(
_req
:
NextApiRequest
)
=>
string
,
allowedMethods
:
Array
<
Methods
>
)
{
return
async
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
<
TRes
>
)
=>
{
if
(
_req
.
method
===
'
GET
'
&&
allowedMethods
.
includes
(
'
GET
'
))
{
const
response
=
await
fetch
(
getUrl
(
_req
))
const
data
=
await
response
.
json
()
as
TRes
;
res
.
status
(
200
).
json
(
data
);
}
else
if
(
allowedMethods
.
includes
(
'
POST
'
)
&&
_req
.
method
===
'
POST
'
)
{
const
response
=
await
fetch
(
getUrl
(
_req
),
{
method
:
'
POST
'
,
body
:
_req
.
body
,
})
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
'
});
// FIXME: add error handlers
if
(
response
.
status
!==
200
)
{
// eslint-disable-next-line no-console
console
.
log
(
response
.
statusText
);
}
res
.
status
(
200
).
end
();
}
else
{
res
.
setHeader
(
'
Allow
'
,
allowedMethods
)
res
.
status
(
405
).
end
(
`Method
${
_req
.
method
}
Not Allowed`
)
}
}
}
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