Skip to content

Commit

Permalink
Workaround to fix COSMOS REST api bug (#3239)
Browse files Browse the repository at this point in the history
* Workaround to fix COSMOS REST api bug

* changelog

* Improve testing

* Comment
  • Loading branch information
mariopino authored and faboweb committed Dec 3, 2019
1 parent 439b7b2 commit 532c6ca
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions changes/mario_3237-wrong-denom-unstake-workaround
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Fixed] [#3237](https://github.com/cosmos/lunie/issues/3237) Workaround to fix wrong denom NDEFINED showed in Staking and Restaking transactions @mariopino
11 changes: 9 additions & 2 deletions src/scripts/transaction-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,18 @@ export const isPendingUndelegation = tx =>
!isNaN(tx.liquidDate) && tx.type === messageType.UNDELEGATE

export const getCoin = transaction => {
let coin
if (Array.isArray(transaction.value.amount)) {
return transaction.value.amount[0]
coin = transaction.value.amount[0]
} else {
return transaction.value.amount
coin = transaction.value.amount
}
// Workaround to fix COSMOS REST api bug, see https://github.com/luniehq/lunie/issues/3237
// and https://github.com/cosmos/cosmos-sdk/issues/5353
if (coin.denom === `undefined`) {
coin.denom = `uatom`
}
return coin
}

// We currently don't support MultiCoin transactions in the design. For simplicity we display only the first outgoing or incomming denomination.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ describe(`BeginRedelegateMessageDetails`, () => {
type: `cosmos-sdk/MsgBeginRedelegate`
}

let buggyTx = tx;
buggyTx.value.amount[0].denom = "undefined"

it(`renders a redelegate transaction message`, () => {
wrapper = shallowMount(BeginRedelegateMessageDetails, {
propsData: {
Expand All @@ -39,4 +42,15 @@ describe(`BeginRedelegateMessageDetails`, () => {
})
expect(wrapper.element).toMatchSnapshot()
})

it(`renders a transaction message with undefined denom`, () => {
wrapper = shallowMount(BeginRedelegateMessageDetails, {
propsData: {
transaction: buggyTx,
validators: {}
},
stubs: [`router-link`]
})
expect(wrapper.html()).toContain("ATOM")
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ describe(`DelegateMessageDetails`, () => {
height: 2000000,
value: {
validator_address: `cosmos1`,
amount: [
{
amount: "10000000000",
denom: "uatom"
}
]
amount: {
amount: "10000000000",
denom: "uatom"
}
},
fee: {
amount: "37",
Expand Down

0 comments on commit 532c6ca

Please sign in to comment.