Skip to content

Commit

Permalink
fix: stringifyBigNumProps
Browse files Browse the repository at this point in the history
  • Loading branch information
dohaki committed Jan 3, 2025
1 parent 05d05f8 commit 1d1399c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion api/relay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const BaseRelayRequestBodySchema = object({

const strategies = {
default: strategiesByName.gelato,
[CHAIN_IDs.ARBITRUM]: strategiesByName["local-signers"],
[CHAIN_IDs.WORLD_CHAIN]: strategiesByName["local-signers"],
};

export default async function handler(
Expand Down
28 changes: 20 additions & 8 deletions api/swap/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,28 @@ export async function calculateCrossSwapFees(
};
}

export function stringifyBigNumProps(value: object): object {
export function stringifyBigNumProps<T extends object | any[]>(value: T): T {
if (Array.isArray(value)) {
return value.map((element) => {
if (element instanceof BigNumber) {
return element.toString();
}
if (typeof element === "object" && element !== null) {
return stringifyBigNumProps(element);
}
return element;
}) as T;
}

return Object.fromEntries(
Object.entries(value).map(([key, value]) => {
if (value instanceof BigNumber) {
return [key, value.toString()];
Object.entries(value).map(([key, val]) => {
if (val instanceof BigNumber) {
return [key, val.toString()];
}
if (typeof value === "object" && value !== null) {
return [key, stringifyBigNumProps(value)];
if (typeof val === "object" && val !== null) {
return [key, stringifyBigNumProps(val)];
}
return [key, value];
return [key, val];
})
);
) as T;
}
2 changes: 1 addition & 1 deletion scripts/tests/_swap-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export async function fetchSwapQuote(slug: "approval" | "permit") {
const response = await axios.get(`${SWAP_API_BASE_URL}/api/swap/${slug}`, {
params: testCase.params,
});
console.log(response.data);
console.log(JSON.stringify(response.data, null, 2));
return response.data;
}
}

0 comments on commit 1d1399c

Please sign in to comment.