-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bnjs devtools utils + remove logs
- Loading branch information
1 parent
8c466f7
commit 25444dc
Showing
4 changed files
with
56 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import BN from 'bignumber.js'; | ||
|
||
interface WindowExtended extends Window { | ||
devtoolsFormatters?: Array<{ | ||
header: (obj: any) => (string | null) | (Node[] | null); | ||
hasBody: (obj: any) => boolean; | ||
}>; | ||
} | ||
|
||
export const runOnDev = () => { | ||
if (!import.meta.env.VITE_SHOW_DEV_CHAINS) return; | ||
|
||
// useful in logging BigNumberJS objects in the console. | ||
if (typeof window !== 'undefined') { | ||
if (!(window as WindowExtended)?.devtoolsFormatters) { | ||
(window as WindowExtended).devtoolsFormatters = []; | ||
} | ||
(window as WindowExtended).devtoolsFormatters?.push({ | ||
header: (obj: any) => { | ||
if (BN.isBigNumber(obj)) { | ||
return ['div', {}, obj.toString()] as Node[]; | ||
} | ||
return null; | ||
}, | ||
hasBody: () => false, | ||
}); | ||
} | ||
}; |