Created
January 2, 2022 17:29
-
-
Save mqklin/17b90cd513149c0ad6b2ac673aacbec1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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