Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lum-network/sdk-javascript",
"version": "0.4.4",
"version": "0.4.5",
"license": "Apache-2.0",
"description": "Javascript SDK library for NodeJS and Web browsers to interact with the Lum Network.",
"homepage": "https://github.com/lum-network/sdk-javascript#readme",
Expand Down
4 changes: 3 additions & 1 deletion src/utils/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const convertUnit = (coin: LumTypes.Coin, toDenom: string): string => {
throw new Error('More than one separator found');
}

if (coin.denom.startsWith('u') && coin.denom.endsWith(toDenom)) {
if (coin.denom === toDenom) {
return coin.amount;
} else if (coin.denom.startsWith('u') && coin.denom.endsWith(toDenom)) {
// from micro to base
if (parts.length !== 1) {
throw new Error('Micro units cannot have floating precision');
Expand Down
1 change: 1 addition & 0 deletions tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LumConstants, LumUtils } from '../src';

describe('Utils', () => {
it('Unit conversion should output consistent results', () => {
expect(LumUtils.convertUnit({ denom: LumConstants.MicroLumDenom, amount: '23456789' }, LumConstants.MicroLumDenom)).toEqual('23456789');
expect(LumUtils.convertUnit({ denom: LumConstants.LumDenom, amount: '23.456789' }, LumConstants.LumDenom)).toEqual('23.456789');
expect(LumUtils.convertUnit({ denom: LumConstants.LumDenom, amount: '23.456789' }, LumConstants.MicroLumDenom)).toEqual('23456789');
expect(LumUtils.convertUnit({ denom: LumConstants.LumDenom, amount: '23456789' }, LumConstants.MicroLumDenom)).toEqual('23456789000000');
Expand Down