Skip to content

Commit

Permalink
Fabo/fix single denom send modal (#3436)
Browse files Browse the repository at this point in the history
* set denom for single denom send

* added test

* changelog
  • Loading branch information
faboweb authored Jan 18, 2020
1 parent f3be67f commit b34ddb0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions changes/fabo_fix-single-denom-send-modal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Fixed] Fixed denom not selected if only one balance @faboweb
19 changes: 11 additions & 8 deletions src/ActionModal/components/SendModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,19 @@ export default {
editMemo: false,
isFirstLoad: true,
selectedToken: ``,
balances: [
{
amount: null,
denom: ``
}
]
balances: []
}),
computed: {
...mapGetters([`network`]),
...mapGetters({ userAddress: `address` }),
selectedBalance() {
return this.balances.filter(
const selectedBalance = this.balances.filter(
balance => balance.denom === this.selectedToken || this.denoms[0]
)[0]
)
if (selectedBalance.length > 0) {
return selectedBalance[0]
}
return { amount: 0 }
},
transactionData() {
return {
Expand Down Expand Up @@ -237,6 +236,10 @@ export default {
} else {
this.isFirstLoad = false
}
},
balances: function(balances) {
if (balances.length === 0) return
this.selectedToken = balances[0].denom
}
},
mounted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ describe(`SendModal`, () => {
})
expect(wrapper.vm.selectedBalance.amount).toBe(1)
})

it(`it automatically picks the balance from the balances array when
balances are only one denom`, async () => {
wrapper.setData({
balances: [
{
amount: 1,
denom: "TOKEN1"
}
]
})
expect(wrapper.vm.selectedBalance.amount).toBe(1)
})
// This one creates a lot of ugly errors
// it(`returns empty string if selectedToken hasn't been chosen yet`, () => {
// wrapper.setData({
Expand Down

0 comments on commit b34ddb0

Please sign in to comment.