Skip to content

Commit

Permalink
[BX-1342] Add Trim Hex To Utils (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
derHowie authored Mar 20, 2024
1 parent e00264c commit e7745ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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());
};

0 comments on commit e7745ec

Please sign in to comment.