Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BX-1342] Add Trim Hex To Utils #10

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/utils/hex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ describe('Utils hex', () => {

it('converts a string to a hex string', () => {
const stringInput = '456';
const expectedHex = '0x01c8';
const expectedHex = '0x1c8';
expect(toHex(stringInput)).toBe(expectedHex);
});

it('converts a BigNumber to a hex string', () => {
const bigNumberInput = BigNumber.from(789);
const expectedHex = '0x0315';
const expectedHex = '0x315';
expect(toHex(bigNumberInput)).toBe(expectedHex);
});
});
6 changes: 4 additions & 2 deletions src/utils/hex.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { BigNumber } from '@ethersproject/bignumber';
import { hexValue } from '@ethersproject/bytes';

export const toHex = (stringToConvert: string | number | BigNumber): string =>
BigNumber.from(stringToConvert).toHexString();
export const toHex = (stringToConvert: string | number | BigNumber): string => {
return hexValue(BigNumber.from(stringToConvert).toHexString());
};
Loading