Skip to content

Instantly share code, notes, and snippets.

@mqklin
Created January 2, 2022 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mqklin/17b90cd513149c0ad6b2ac673aacbec1 to your computer and use it in GitHub Desktop.
Save mqklin/17b90cd513149c0ad6b2ac673aacbec1 to your computer and use it in GitHub Desktop.
import {ethers} from 'ethers';
import {cloneDeepWith} from 'lodash';
export default function logBNs(arg) {
function customizer(value) {
if (Array.isArray(value)) {
const arr = [];
Object.keys(value).forEach(key => {
arr[key] = cloneDeepWith(value[key], customizer);
});
return arr;
}
}
arg = cloneDeepWith(arg, customizer);
function convert(value) {
if (Array.isArray(value)) {
for (const key in value) {
if (ethers.BigNumber.isBigNumber(value[key])) {
value[key] = String(value[key]);
}
else {
convert(value[key]);
}
}
}
else if (value instanceof Object) {
for (const key in value) {
if (ethers.BigNumber.isBigNumber(value[key])) {
value[key] = String(value[key]);
}
else {
const value1 = value[key];
if (Array.isArray(value1)) {
convert(value1);
}
else if (value1 instanceof Object) {
convert(value1);
}
}
}
}
}
convert(arg);
console.log(arg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment