This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(exactly): Serialize definition (#2878)
- Loading branch information
1 parent
f7f873c
commit 9d7a2bd
Showing
7 changed files
with
38 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { isBigNumberish } from '@ethersproject/bignumber/lib/bignumber'; | ||
import _ from 'lodash'; | ||
|
||
const isPureArray = (obj: any): obj is any[] => { | ||
const props = Object.getOwnPropertyNames(obj); | ||
return _.isArray(obj) && props.every(key => key === 'length' || _.isInteger(_.toNumber(key))); | ||
}; | ||
|
||
export const serializeEthersResult = (obj: Record<string, any>) => { | ||
if (isPureArray(obj)) { | ||
return obj.map(innerObj => serializeEthersResult(innerObj)); | ||
} else if (_.isObject(obj) && !isBigNumberish(obj)) { | ||
return _.mapValues(obj, val => serializeEthersResult(val)); | ||
} else if (_.isString(obj) || _.isBoolean(obj) || _.isNumber(obj)) { | ||
return obj; | ||
} else { | ||
return _.toString(obj); | ||
} | ||
}; |