Skip to content

Commit

Permalink
Add API error
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Oct 16, 2023
1 parent b5e87bf commit db288b4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pages/api/fund.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as fcl from "@onflow/fcl"
import * as t from "@onflow/types"
import {verify} from "hcaptcha"
import {FUSD_TYPE, MISSING_FUSD_VAULT_ERROR} from "lib/constants"
import {
FUSD_TYPE,
INVALID_NETWORK_ADDRESS_ERROR,
MISSING_FUSD_VAULT_ERROR,
} from "lib/constants"
import publicConfig from "lib/publicConfig"
import {NextApiRequest, NextApiResponse} from "next"
import config from "../../lib/config"
Expand All @@ -10,6 +14,7 @@ import {getSignerKeyIndex} from "../../lib/keys"
import {fundAccountSchemaServer} from "../../lib/validate"
import {verifyAPIKey} from "../../lib/common"
import {ValidationError} from "yup"
import {isValidNetworkAddress} from "lib/network"

const scriptCheckFUSDVault = `
import FUSD from ${publicConfig.contractFUSD}
Expand Down Expand Up @@ -44,6 +49,14 @@ export default async function fund(req: NextApiRequest, res: NextApiResponse) {
const address = fcl.withPrefix(req.body.address) || ""
const token = req.body.token

// Validate address
if (!isValidNetworkAddress(address, publicConfig.network)) {
res
.status(400)
.json({errors: [INVALID_NETWORK_ADDRESS_ERROR(publicConfig.network)]})
return
}

if (token === FUSD_TYPE) {
try {
const hasFUSDVault = await fcl
Expand Down

0 comments on commit db288b4

Please sign in to comment.