Skip to content

Commit a5c14b3

Browse files
author
Fabrice Bascoulergue
committed
Fix ulum to ulum unit conversion
1 parent 9d28b92 commit a5c14b3

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/utils/units.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export const convertUnit = (coin: LumTypes.Coin, toDenom: string): string => {
1616
throw new Error('More than one separator found');
1717
}
1818

19-
if (coin.denom.startsWith('u') && coin.denom.endsWith(toDenom)) {
19+
if (coin.denom === toDenom) {
20+
return coin.amount;
21+
} else if (coin.denom.startsWith('u') && coin.denom.endsWith(toDenom)) {
2022
// from micro to base
2123
if (parts.length !== 1) {
2224
throw new Error('Micro units cannot have floating precision');

tests/utils.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { LumConstants, LumUtils } from '../src';
22

33
describe('Utils', () => {
44
it('Unit conversion should output consistent results', () => {
5+
expect(LumUtils.convertUnit({ denom: LumConstants.MicroLumDenom, amount: '23456789' }, LumConstants.MicroLumDenom)).toEqual('23456789');
56
expect(LumUtils.convertUnit({ denom: LumConstants.LumDenom, amount: '23.456789' }, LumConstants.LumDenom)).toEqual('23.456789');
67
expect(LumUtils.convertUnit({ denom: LumConstants.LumDenom, amount: '23.456789' }, LumConstants.MicroLumDenom)).toEqual('23456789');
78
expect(LumUtils.convertUnit({ denom: LumConstants.LumDenom, amount: '23456789' }, LumConstants.MicroLumDenom)).toEqual('23456789000000');

0 commit comments

Comments
 (0)