Skip to content

Commit b588d0f

Browse files
author
James0126
authored
Show message without coin format (stationmoney#1)
* 1.0.2 * Show message without coin format * fix typo
1 parent 986c072 commit b588d0f

File tree

5 files changed

+17
-53
lines changed

5 files changed

+17
-53
lines changed

package-lock.json

+3-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@terra-money/msg-reader",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Convert common terra.js msg to a sentence",
55
"main": "dist/index.js",
66
"author": "Terra <[email protected]>",
@@ -16,8 +16,7 @@
1616
"test": "jest"
1717
},
1818
"dependencies": {
19-
"@terra-money/terra.js": "^2.0.14",
20-
"bignumber.js": "^9.0.1"
19+
"@terra-money/terra.js": "^2.0.14"
2120
},
2221
"devDependencies": {
2322
"@types/jest": "^27.0.2",

src/index.test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ describe("Bank", () => {
2323
test("Send", () => {
2424
const msg = new MsgSend(address, recipient, [coin])
2525
expect(readMsg(msg)).toBe(
26-
"Send 1 Luna to terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp"
26+
"Send 1000000uluna to terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp"
2727
)
2828
})
2929

3030
test("Send multiple coins", () => {
3131
const msg = new MsgSend(address, recipient, coins)
3232
expect(readMsg(msg)).toBe(
33-
"Send 1 KRT, 1 Luna to terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp"
33+
"Send 1000000ukrw, 1000000uluna to terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp"
3434
)
3535
})
3636
})
3737

3838
describe("Market", () => {
3939
test("Swap", () => {
4040
const msg = new MsgSwap(address, coin, "uusd")
41-
expect(readMsg(msg)).toBe("Swap 1 Luna to UST")
41+
expect(readMsg(msg)).toBe("Swap 1000000uluna to uusd")
4242
})
4343
})
4444

@@ -49,21 +49,21 @@ describe("Staking", () => {
4949
test("Delegate", () => {
5050
const msg = new MsgDelegate(address, validator, coin)
5151
expect(readMsg(msg)).toBe(
52-
"Delegate 1 Luna to terravaloper1dcegyrekltswvyy0xy69ydgxn9x8x32zdy3ua5"
52+
"Delegate 1000000uluna to terravaloper1dcegyrekltswvyy0xy69ydgxn9x8x32zdy3ua5"
5353
)
5454
})
5555

5656
test("Undelegate", () => {
5757
const msg = new MsgUndelegate(address, validator, coin)
5858
expect(readMsg(msg)).toBe(
59-
"Undelegate 1 Luna to terravaloper1dcegyrekltswvyy0xy69ydgxn9x8x32zdy3ua5"
59+
"Undelegate 1000000uluna to terravaloper1dcegyrekltswvyy0xy69ydgxn9x8x32zdy3ua5"
6060
)
6161
})
6262

6363
test("Redelegate", () => {
6464
const msg = new MsgBeginRedelegate(address, source, validator, coin)
6565
expect(readMsg(msg)).toBe(
66-
"Redelegate 1 Luna from terravaloper1krj7amhhagjnyg2tkkuh6l0550y733jnjnnlzy to terravaloper1dcegyrekltswvyy0xy69ydgxn9x8x32zdy3ua5"
66+
"Redelegate 1000000uluna from terravaloper1krj7amhhagjnyg2tkkuh6l0550y733jnjnnlzy to terravaloper1dcegyrekltswvyy0xy69ydgxn9x8x32zdy3ua5"
6767
)
6868
})
6969

@@ -78,7 +78,7 @@ describe("Staking", () => {
7878
describe("Gov", () => {
7979
test("Deposit", () => {
8080
const msg = new MsgDeposit(123, address, [coin])
81-
expect(readMsg(msg)).toBe("Deposit 1 Luna to proposal 123")
81+
expect(readMsg(msg)).toBe("Deposit 1000000uluna to proposal 123")
8282
})
8383

8484
test("Vote", () => {
@@ -95,6 +95,6 @@ test("Default", () => {
9595
test("Decimal", () => {
9696
const msg = new MsgSend(address, recipient, new Coins({ uluna: 1234560 }))
9797
expect(readMsg(msg)).toBe(
98-
"Send 1.23456 Luna to terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp"
98+
"Send 1234560uluna to terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp"
9999
)
100100
})

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Msg, Vote } from "@terra-money/terra.js"
2-
import { formatCoin, formatDenom, formatCoins } from "./utility"
2+
import { formatCoin, formatCoins } from "./utility"
33

44
export const readMsg = (msg: Msg) => {
55
try {
@@ -13,7 +13,7 @@ export const readMsg = (msg: Msg) => {
1313

1414
case "market/MsgSwap": {
1515
const { ask_denom, offer_coin } = data.value
16-
return `Swap ${formatCoin(offer_coin)} to ${formatDenom(ask_denom)}`
16+
return `Swap ${formatCoin(offer_coin)} to ${ask_denom}`
1717
}
1818

1919
case "staking/MsgDelegate": {

src/utility.ts

+2-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,4 @@
11
import { Coin, Coins } from "@terra-money/terra.js"
2-
import { BigNumber } from "bignumber.js"
32

4-
export const formatCoins = (data: Coins.Data) => {
5-
return data.map(formatCoin).join(", ")
6-
}
7-
8-
export const formatCoin = ({ amount, denom }: Coin.Data) => {
9-
return `${formatAmount(amount)} ${formatDenom(denom)}`
10-
}
11-
12-
export const formatAmount = (amount: BigNumber.Value): string =>
13-
new BigNumber(amount)
14-
.div(1e6)
15-
.decimalPlaces(6, BigNumber.ROUND_DOWN)
16-
.toString()
17-
18-
export const formatDenom = (denom: string): string => {
19-
if (denom[0] === "u") {
20-
const f = denom.slice(1)
21-
return f === "luna" ? "Luna" : f.slice(0, 2).toUpperCase() + "T"
22-
}
23-
24-
return denom
25-
}
3+
export const formatCoins = (data: Coins.Data) => data.map(formatCoin).join(",")
4+
export const formatCoin = ({ amount, denom }: Coin.Data) => `${amount}${denom}`

0 commit comments

Comments
 (0)