Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peng/123 vuex tests #333

Merged
merged 20 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions app/src/renderer/components/monitor/BlockchainSelect.vue

This file was deleted.

57 changes: 0 additions & 57 deletions app/src/renderer/components/monitor/BlockchainSelectModal.vue

This file was deleted.

32 changes: 15 additions & 17 deletions app/src/renderer/components/wallet/PageSend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,25 @@ export default {
await this.walletSend({
fees: { denom, amount: 0 },
to: address,
amount: [{ denom, amount }],
cb: (err) => {
this.sending = false
if (err) {
this.$store.commit('notifyError', {
title: 'Error Sending',
body: `An error occurred while trying to send: "${err.message}"`
})
return
}
this.$store.commit('notify', {
title: 'Successfully Sent',
body: `Successfully sent ${amount} ${denom.toUpperCase()} to ${address}`
})
amount: [{ denom, amount }]
}).then(() => {
this.sending = false
this.$store.commit('notify', {
title: 'Successfully Sent',
body: `Successfully sent ${amount} ${denom.toUpperCase()} to ${address}`
})

// resets send transaction form
this.resetForm()
this.resetForm()

// refreshes user transaction history
this.$store.dispatch('queryWalletHistory')
}
this.$store.dispatch('queryWalletHistory')
}, err => {
Copy link
Collaborator

@jbibla jbibla Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is err => { ... } the same as .catch()?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the then(_, onReject) will get called instead of .catchif available. See: https://codepen.io/faboweb/pen/WdmRoO

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool! thanks for the example. still not sure when to use one vs the other...?

this.sending = false
this.$store.commit('notifyError', {
title: 'Error Sending',
body: `An error occurred while trying to send: "${err.message}"`
})
})
},
...mapActions(['walletSend'])
Expand Down
23 changes: 23 additions & 0 deletions app/src/renderer/node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
const RpcClient = require('tendermint')
const RestClient = require('cosmos-sdk')
const axios = require('axios')

const RELAY_SERVER = 'http://localhost:8999'

Expand Down Expand Up @@ -61,6 +62,28 @@ module.exports = function (nodeIP) {

node.rpcConnecting = false
return nodeIP
},
async sendTx (args, account, password) {
Copy link
Collaborator

@jbibla jbibla Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this in node.js now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this might not be the right module, although I understand why wallet might not have felt right either. Maybe this could just be its own tx module, with only this action and the queue of transactions plus the sequence number?

let tx = await (async function () {
switch (args.type) {
case 'buildDelegate': return axios.post('http://localhost:8998/build/stake/delegate', args)
.then(res => res.data)
case 'buildUnbond': return axios.post('http://localhost:8998/build/stake/unbond', args)
.then(res => res.data)
default: return node[args.type](args)
}
})()
let signedTx = await node.sign({
name: account,
password: password,
tx
})
let res = await node.postTx(signedTx)
Copy link
Contributor

@mappum mappum Jan 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important that this goes through the same wallet sending code that it was separated from in this PR, to properly process multiple transactions serially and set the correct account sequence number on each transaction. Otherwise, transactions created here will only succeed if it is an account's first transaction.

// check response code
if (res.check_tx.code || res.deliver_tx.code) {
let message = res.check_tx.log || res.deliver_tx.log
throw new Error('Error sending transaction: ' + message)
}
}
})
// TODO: eventually, get all data from light-client connection instead of RPC
Expand Down
9 changes: 0 additions & 9 deletions app/src/renderer/vuex/actions.js

This file was deleted.

18 changes: 6 additions & 12 deletions app/src/renderer/vuex/modules/delegation.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export default ({ commit }) => {
await dispatch('walletTx', args)
},
async submitDelegation ({ state, dispatch }, delegation) {
for (let delegate of delegation.delegates) {
return Promise.all(delegation.delegates.map(delegate => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running these in parallel does not help since we have to sequentially increment the nonce and check that the tx went through. Really this should all happen in an atomic operation, but the LCD does not support that. Will open a ticket.

let candidateId = delegate.delegate.pub_key.data
let currentlyDelegated = state.committedDelegates[candidateId] || 0
let amountChange = delegate.atoms - currentlyDelegated
let action = amountChange > 0 ? 'walletDelegate' : 'walletUnbond'

// skip if no change
if (amountChange === 0) continue
if (amountChange === 0) return null

// bonding takes a 'coin' object, unbond just takes a number
let amount
Expand All @@ -84,17 +84,11 @@ export default ({ commit }) => {
amount = Math.abs(amountChange)
}

await new Promise((resolve, reject) => {
dispatch(action, {
amount,
pub_key: delegate.delegate.pub_key,
cb: (err, res) => {
if (err) return reject(err)
resolve(res)
}
})
return dispatch(action, {
amount,
pub_key: delegate.delegate.pub_key
})
}
}).filter(x => x !== null))
}
}

Expand Down
8 changes: 8 additions & 0 deletions app/src/renderer/vuex/modules/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function ({ node }) {

const state = {
nodeIP,
stopConnecting: false,
connected: false,
lastHeader: {
height: 0,
Expand All @@ -16,6 +17,9 @@ export default function ({ node }) {
}

const mutations = {
stopConnecting (state, stop) {
state.stopConnecting = stop
},
setConnected (state, connected) {
state.connected = connected
}
Expand All @@ -27,11 +31,15 @@ export default function ({ node }) {
dispatch('maybeUpdateValidators', header)
},
async reconnect ({commit, dispatch}) {
if (state.stopConnecting) return

commit('setConnected', false)
await node.rpcReconnect()
dispatch('nodeSubscribe')
},
nodeSubscribe ({commit, dispatch}) {
if (state.stopConnecting) return

// the rpc socket can be closed before we can even attach a listener
// so we remember if the connection is open
// we handle the reconnection here so we can attach all these listeners on reconnect
Expand Down
4 changes: 0 additions & 4 deletions app/src/renderer/vuex/modules/validators.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
export default ({ commit, node }) => {
const state = {
blockchainName: '',
validators: {},
validatorHash: null
}

const mutations = {
setValidatorBlockchainName (state, name) {
state.blockchainName = name
},
setValidators (state, validators) {
state.validators = validators
},
Expand Down
Loading