Skip to content

Commit

Permalink
Merge pull request #241 from cosmos/fabo/22-hook-history-up
Browse files Browse the repository at this point in the history
Fabo/22 hook history up
  • Loading branch information
jbibla authored Dec 14, 2017
2 parents 23d91c4 + adef7e9 commit 1cefea7
Show file tree
Hide file tree
Showing 7 changed files with 526 additions and 59 deletions.
46 changes: 0 additions & 46 deletions app/src/main/mockServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,6 @@ let randomAddress = () => randomBytes(20).toString('hex')

let randomTime = () => Date.now() - casual.integer(0, 32e7)

let randomTx = ({ from, to }) => {
let amountOne = casual.double(1, 1e6)
let amountTwo = casual.double(1, 1e4)
let amountThree = casual.double(1, 1e2)
let threeCoins = [
{ amount: amountOne, denom: 'fermion' },
{ amount: amountThree, denom: 'lepton' },
{ amount: amountTwo, denom: 'quark' }
]
let twoCoins = [
{ amount: amountThree, denom: 'lepton' },
{ amount: amountTwo, denom: 'quark' }
]
let oneCoin = [
{ amount: amountOne, denom: 'fermion' }
]
let coins = [oneCoin, twoCoins, threeCoins]
let randomCoins = coins[Math.floor(Math.random() * coins.length)]
return {
tx: {
inputs: [{
sender: from || randomAddress(),
coins: randomCoins
}],
outputs: [{
receiver: to || randomAddress(),
coins: randomCoins
}]
},
time: randomTime(),
height: 1000
}
}

let randomBondTx = (address, delegator) => ({
tx: {
type: Math.random() > 0.5 ? 'bond' : 'unbond',
Expand Down Expand Up @@ -187,18 +153,6 @@ module.exports = function (port = 8999) {
app.get('/candidates', (req, res) => {
res.json(new Array(200).fill(0).map(randomCandidate))
})

// tx history
app.get('/tx/coins/:address', (req, res) => {
let { address } = req.params
let txs = []
for (let i = 0; i < 100; i++) {
let toMe = Math.random() > 0.5
txs.push(randomTx(toMe ? { to: address } : { from: address }))
}
txs.sort((a, b) => b.time - a.time)
res.json(txs)
})
app.get('/tx/bondings/delegator/:address', (req, res) => {
let { address } = req.params
let txs = new Array(100).fill(0)
Expand Down
2 changes: 1 addition & 1 deletion app/src/renderer/components/common/AppMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ menu.app-menu
part(title='Wallet')
list-item(to="/" exact @click.native="close" title="Balance")
list-item(to="/wallet/send" exact @click.native="close" title="Send")
list-item(to="/wallet/transactions" exact @click.native="close" title="Transactions" v-if="config.devMode")
list-item(to="/wallet/transactions" exact @click.native="close" title="Transactions")
part(title='Governance' v-if="config.devMode")
list-item(to="/proposals" exact @click.native="close" title="Proposals")
part(title='Stake' v-if="config.devMode")
Expand Down
10 changes: 5 additions & 5 deletions app/src/renderer/components/wallet/LiTransaction.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<template lang='pug'>
.ni-li-tx.ni-li-tx-sent(v-if="sent" @click="viewTransaction")
.ni-li-tx.ni-li-tx-sent(v-if="sent" @click="() => devMode && viewTransaction()")
.tx-icon: i.material-icons remove_circle
.tx-container
.tx-element.tx-coins
.tx-coin(v-for='coin in coinsSent')
.value {{ num.pretty(coin.amount) }}
.key {{ coin.denom }}
.tx-element.tx-date {{ date }}
.tx-element.tx-date(v-if="devMode") {{ date }}
.tx-element.tx-address {{ receiver }}

.ni-li-tx.ni-li-tx-received(v-else @click="viewTransaction")
.ni-li-tx.ni-li-tx-received(v-else @click="() => devMode && viewTransaction()")
.tx-icon: i.material-icons add_circle
.tx-container
.tx-element.tx-coins
.tx-coin(v-for='coin in coinsReceived')
.value {{ num.pretty(coin.amount) }}
.key {{ coin.denom }}
.tx-element.tx-date {{ date }}
.tx-element.tx-date(v-if="devMode") {{ date }}
.tx-element.tx-address {{ sender }}
</template>

Expand Down Expand Up @@ -57,7 +57,7 @@ export default {
})
}
},
props: ['transaction-value', 'address']
props: ['transaction-value', 'address', 'devMode']
}
</script>

Expand Down
25 changes: 20 additions & 5 deletions app/src/renderer/components/wallet/PageTransactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ page(title='Transactions')
li-transaction(
v-for="i in filteredTransactions"
:transaction-value="i"
:address="wallet.key.address")
:address="wallet.key.address"
:devMode="config.devMode")
data-empty-tx(v-if='filteredTransactions.length === 0')
</template>

<script>
import { mapGetters } from 'vuex'
// import { includes, orderBy } from 'lodash'
import { includes, orderBy } from 'lodash'
import Mousetrap from 'mousetrap'
import DataEmptyTx from 'common/NiDataEmptyTx'
import LiTransaction from 'wallet/LiTransaction'
Expand All @@ -35,12 +36,26 @@ export default {
ToolBar
},
computed: {
...mapGetters(['filters', 'transactions', 'wallet']),
...mapGetters(['filters', 'transactions', 'wallet', 'config']),
orderedTransactions () {
return orderBy(this.transactions, [this.sort.property], [this.sort.order])
},
filteredTransactions () {
return this.transactions
// TODO: restore searchability? (what part of the tx are we searching?)
let query = this.filters.transactions.search.query
if (this.filters.transactions.search.visible) {
// doing a full text comparison on the transaction data
return this.orderedTransactions.filter(t => includes(JSON.stringify(t).toLowerCase(), query))
} else {
return this.orderedTransactions
}
}
},
data: () => ({
sort: {
property: 'time',
order: 'desc'
}
}),
methods: {
setSearch (bool) {
this.$store.commit('setSearchVisible', ['transactions', bool])
Expand Down
5 changes: 3 additions & 2 deletions test/unit/specs/LiTransaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import LiTransaction from 'renderer/components/wallet/LiTransaction'
describe('LiTransaction', () => {
let wrapper
let propsData = {
devMode: true,
transactionValue: {
tx: {
inputs: [
Expand Down Expand Up @@ -40,11 +41,11 @@ describe('LiTransaction', () => {
expect(wrapper.vm.$el).toMatchSnapshot()
})

it('should show incoming transcations', () => {
it('should show incoming transactions', () => {
expect(wrapper.find('.ni-li-tx').hasClass('ni-li-tx-received')).toBe(true)
})

it('should show outgoing transcations', () => {
it('should show outgoing transactions', () => {
wrapper.setProps({
transactionValue: {
tx: {
Expand Down
115 changes: 115 additions & 0 deletions test/unit/specs/PageTransactions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import Vuex from 'vuex'
import { mount, createLocalVue } from 'vue-test-utils'
import PageTransactions from 'renderer/components/wallet/PageTransactions'

const wallet = require('renderer/vuex/modules/wallet').default({})
const filters = require('renderer/vuex/modules/filters').default({})

const localVue = createLocalVue()
localVue.use(Vuex)

describe('PageTransactions', () => {
let wrapper, store

beforeEach(() => {
store = new Vuex.Store({
getters: {
wallet: () => wallet.state,
transactions: () => wallet.state.history,
filters: () => filters.state,
config: () => ({devMode: true})
},
modules: {
wallet,
filters
}
})

store.commit('setWalletHistory', [{
tx: {
hash: 'x',
inputs: [
{
coins: [{
denom: 'jbcoins',
amount: 1234
}],
sender: 'myAddress'
}
],
outputs: [
{
coins: [{
denom: 'jbcoins',
amount: 1234
}],
recipient: 'otherAddress'
}
]
},
time: Date.now()
}, {
tx: {
hash: 'y',
inputs: [
{
coins: [{
denom: 'fabocoins',
amount: 1234
}],
sender: 'otherAddress'
}
],
outputs: [
{
coins: [{
denom: 'fabocoins',
amount: 1234
}],
recipient: 'myAddress'
}
]
},
time: Date.now() + 10
}])

wrapper = mount(PageTransactions, {
localVue,
store,
stubs: {
'data-empty-tx': '<data-empty-tx />'
}
})

jest.spyOn(store, 'commit')
})

it('has the expected html structure', () => {
expect(wrapper.vm.$el).toMatchSnapshot()
})

it('should show the search on click', () => {
wrapper.find('.ni-tool-bar i').trigger('click')
expect(wrapper.contains('.ni-modal-search')).toBe(true)
})

it('should sort the transaction by time', () => {
expect(wrapper.vm.filteredTransactions.map(x => x.tx.hash)).toEqual(['y', 'x'])
})

it('should filter the transactions', () => {
store.commit('setSearchVisible', ['transactions', true])
store.commit('setSearchQuery', ['transactions', 'fabo'])
expect(wrapper.vm.filteredTransactions.map(x => x.tx.hash)).toEqual(['y'])
// reflects the filter in the view
expect(wrapper.vm.$el).toMatchSnapshot()
store.commit('setSearchQuery', ['transactions', 'jb'])
expect(wrapper.vm.filteredTransactions.map(x => x.tx.hash)).toEqual(['x'])
})

it('should show an error if there are no transactions', () => {
store.commit('setWalletHistory', [])
wrapper.update()
expect(wrapper.contains('data-empty-tx')).toBe(true)
})
})
Loading

0 comments on commit 1cefea7

Please sign in to comment.