From db288b475c46aca3f03a06176655fb6be1b915a0 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Mon, 16 Oct 2023 16:52:16 -0700 Subject: [PATCH] Add API error --- pages/api/fund.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pages/api/fund.ts b/pages/api/fund.ts index a0b9853..8e3492f 100644 --- a/pages/api/fund.ts +++ b/pages/api/fund.ts @@ -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" @@ -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} @@ -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