|
1 | | -import { Request, Response, Router } from "express"; |
2 | | -import { handlerWrapper } from "../errors/AppError"; |
3 | | -import { convertToHexIfBech32, validateAddress } from "../helpers/validator"; |
4 | | -import { fetchStakeAddressDetails } from "../repository/stakeAddress"; |
| 1 | +import { Request, Response, Router } from 'express' |
| 2 | +import { handlerWrapper } from '../errors/AppError' |
| 3 | +import { convertToHexIfBech32, validateAddress } from '../helpers/validator' |
| 4 | +import { fetchStakeAddressDetails } from '../repository/stakeAddress' |
5 | 5 |
|
6 | | -const router = Router(); |
| 6 | +const router = Router() |
7 | 7 |
|
8 | 8 | const getStakeAddressDetails = async (req: Request, res: Response): Promise<any> => { |
9 | | - let address = convertToHexIfBech32(req.query.address as string) |
10 | | - if (validateAddress(address)){ |
11 | | - address = address.length === 56 ? `e0${address}`:address |
12 | | - }else{ |
13 | | - return res.status(400).json({message:'Provide a valid address'}) |
14 | | - } |
| 9 | + let address = convertToHexIfBech32(req.query.address as string) |
| 10 | + if (validateAddress(address)) { |
| 11 | + if (address.length == 56) { |
| 12 | + return res.status(400).json({ mesage: `Provide a valid address` }) |
| 13 | + } |
| 14 | + } else { |
| 15 | + return res.status(400).json({ message: 'Provide a valid address' }) |
| 16 | + } |
15 | 17 |
|
16 | | -const result = await fetchStakeAddressDetails(address) |
17 | | - return res.status(200).json(result); |
18 | | -}; |
| 18 | + const result = await fetchStakeAddressDetails(address) |
| 19 | + return res.status(200).json(result) |
| 20 | +} |
19 | 21 |
|
20 | | -router.get('/', handlerWrapper(getStakeAddressDetails)); |
| 22 | +router.get('/', handlerWrapper(getStakeAddressDetails)) |
21 | 23 |
|
22 | | -export default router; |
| 24 | +export default router |
0 commit comments