mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Merge pull request #1336 from cosmos/fix-protoDecimalToJson-simon
Fix protoDecimalToJson for 0 fractional parts
This commit is contained in:
commit
2ded20c73b
@ -6,6 +6,14 @@ and this project adheres to
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- @cosmjs/stargate: Fix `protoDecimalToJson` for values with a 0 fractional
|
||||||
|
part, such as `0.000000000000000000`, `1.000000000000000000` or
|
||||||
|
`42.000000000000000000` ([#1326]).
|
||||||
|
|
||||||
|
[#1326] : https://github.com/cosmos/cosmjs/pull/1326
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
- @cosmjs/stargate: Deprecate `QueryClient.queryUnverified` in favour of newly
|
- @cosmjs/stargate: Deprecate `QueryClient.queryUnverified` in favour of newly
|
||||||
|
@ -18,9 +18,21 @@ import {
|
|||||||
AminoMsgEditValidator,
|
AminoMsgEditValidator,
|
||||||
AminoMsgUndelegate,
|
AminoMsgUndelegate,
|
||||||
createStakingAminoConverters,
|
createStakingAminoConverters,
|
||||||
|
protoDecimalToJson,
|
||||||
} from "./aminomessages";
|
} from "./aminomessages";
|
||||||
|
|
||||||
describe("AminoTypes", () => {
|
describe("AminoTypes", () => {
|
||||||
|
describe("protoDecimalToJson", () => {
|
||||||
|
it("works", () => {
|
||||||
|
expect(protoDecimalToJson("0")).toEqual("0.000000000000000000");
|
||||||
|
expect(protoDecimalToJson("1")).toEqual("0.000000000000000001");
|
||||||
|
expect(protoDecimalToJson("2497")).toEqual("0.000000000000002497");
|
||||||
|
expect(protoDecimalToJson("987000000000000000")).toEqual("0.987000000000000000");
|
||||||
|
expect(protoDecimalToJson("123987000000000000000")).toEqual("123.987000000000000000");
|
||||||
|
expect(protoDecimalToJson("4872000000000000000000")).toEqual("4872.000000000000000000");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("toAmino", () => {
|
describe("toAmino", () => {
|
||||||
it("works for MsgBeginRedelegate", () => {
|
it("works for MsgBeginRedelegate", () => {
|
||||||
const msg: MsgBeginRedelegate = {
|
const msg: MsgBeginRedelegate = {
|
||||||
|
@ -29,10 +29,10 @@ interface Description {
|
|||||||
readonly details: string;
|
readonly details: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function protoDecimalToJson(decimal: string): string {
|
export function protoDecimalToJson(decimal: string): string {
|
||||||
const parsed = Decimal.fromAtomics(decimal, 18);
|
const parsed = Decimal.fromAtomics(decimal, 18);
|
||||||
const [whole, fractional] = parsed.toString().split(".");
|
const [whole, fractional] = parsed.toString().split(".");
|
||||||
return `${whole}.${fractional.padEnd(18, "0")}`;
|
return `${whole}.${(fractional ?? "").padEnd(18, "0")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function jsonDecimalToProto(decimal: string): string {
|
function jsonDecimalToProto(decimal: string): string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user