diff --git a/src/lib/components/abi/args-form/field/utils.ts b/src/lib/components/abi/args-form/field/utils.ts index 75866515f..bf8708fcb 100644 --- a/src/lib/components/abi/args-form/field/utils.ts +++ b/src/lib/components/abi/args-form/field/utils.ts @@ -17,7 +17,9 @@ const validateUint = (uintType: string) => (v: string) => { : `Input must be ‘${uintType}’`; }; const validateBool = (v: string) => - v === "true" || v === "false" ? undefined : "Input must be ‘boolean’"; + v.toLowerCase() === "true" || v.toLowerCase() === "false" + ? undefined + : "Input must be ‘boolean’"; const validateAddress = (isValidArgAddress: (input: string) => boolean) => (v: string) => @@ -29,6 +31,9 @@ const validateVector = ( isValidArgAddress: (input: string) => boolean ) => { const value = v.trim(); + if (!value.startsWith("[") || !value.endsWith("]")) + return "Input must be ‘vector’"; + const [, elementType] = vectorType.split(/<(.*)>/); // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -41,10 +46,13 @@ const validateVector = ( // TODO: handle Vector? let error: Option; - value.split(",").forEach((elementValue) => { - const res = validateElement(elementValue.trim()); - if (res !== undefined) error = `Invalid element: ${res}`; - }); + value + .slice(1, -1) + .split(",") + .forEach((elementValue) => { + const res = validateElement(elementValue.trim()); + if (res !== undefined) error = `Invalid element: ${res}`; + }); return error; }; diff --git a/src/lib/pages/pools/data.ts b/src/lib/pages/pools/data.ts index a79789e04..70316292f 100644 --- a/src/lib/pages/pools/data.ts +++ b/src/lib/pages/pools/data.ts @@ -1,6 +1,7 @@ import type { Big } from "big.js"; import big from "big.js"; +import { UPPERBOUND_COUNT } from "lib/data"; import type { Order_By } from "lib/gql/graphql"; import { useAssetInfos } from "lib/services/assetService"; import { usePoolByPoolId, usePoolListQuery } from "lib/services/poolService"; @@ -134,11 +135,10 @@ export const usePoolTxsCount = ( const loading = isLoading || txsIsLoading; if (error && txs?.length === 0) return { count: 0, countDisplay: "0", isLoading: loading }; - const upperboundCount = 10000; - const showActualCount = data !== undefined && data <= upperboundCount; + const showActualCount = data !== undefined && data <= UPPERBOUND_COUNT; return { - count: showActualCount ? data : upperboundCount, - countDisplay: showActualCount ? data.toString() : `${upperboundCount}+`, + count: showActualCount ? data : UPPERBOUND_COUNT, + countDisplay: showActualCount ? data.toString() : `${UPPERBOUND_COUNT}+`, isLoading: loading, }; }; diff --git a/src/lib/utils/abi.ts b/src/lib/utils/abi.ts index 3d957e124..02af6729b 100644 --- a/src/lib/utils/abi.ts +++ b/src/lib/utils/abi.ts @@ -66,38 +66,47 @@ const getArgType = (argType: string) => .replaceAll("0x1::option::Option", "option"); const getArgValue = ({ - // type, + type, value, }: { - // type: string; + type: string; value: Nullable; }) => { try { if (value === null) return null; - // if (type.startsWith("vector")) return JSON.parse(value) as string[]; + if (type.startsWith("vector")) { + const [, elementType] = type.split(/<(.*)>/); + const values = value + .split(/\[(.*)\]/)[1] + .split(",") + .map((element) => element.trim()); + return elementType === "bool" + ? values.map((element) => element.toLowerCase() === "true") + : values; + } + if (type === "bool") return value === "true"; return value.trim(); } catch (e) { return ""; } }; -const serializeArg = ( - arg: { type: string; value: Nullable }, - bcs: BCS -) => { +const BUFFER_SIZE = 1024 * 1024; +const bcs = BCS.getInstance(); + +const serializeArg = (arg: { type: string; value: Nullable }) => { try { const argType = getArgType(arg.type); const argValue = getArgValue(arg); - return bcs.serialize(argType, argValue, 1024 * 1024); + return bcs.serialize(argType, argValue, BUFFER_SIZE); } catch (e) { return ""; } }; export const serializeAbiData = (fn: ExposedFunction, abiData: AbiFormData) => { - const bcs = BCS.getInstance(); const serializedArgs = fn.params.map((type, index) => - serializeArg({ type, value: abiData.args[index] }, bcs) + serializeArg({ type, value: abiData.args[index] }) ); return { typeArgs: fn.generic_type_params.map((_, index) => abiData.typeArgs[index]),