diff --git a/app/src/main/mockServer.js b/app/src/main/mockServer.js index 16c878ec8b..1986a1a44b 100644 --- a/app/src/main/mockServer.js +++ b/app/src/main/mockServer.js @@ -10,8 +10,14 @@ let randomPubkey = () => ({ module.exports = function (port = 8999) { let app = express() + // log all requests + app.use((req, res, next) => { + console.log('REST request:', req.method, req.originalUrl, req.body) + next() + }) + // delegation mock API - let candidates = new Array(205).fill(0).map(randomPubkey) + let candidates = new Array(50).fill(0).map(randomPubkey) app.get('/query/stake/candidate', (req, res) => { res.json({ height: 10000, @@ -34,6 +40,72 @@ module.exports = function (port = 8999) { } }) }) + app.post('/tx/stake/delegate/:pubkey/:amount', (req, res) => { + res.json({ + "type": "sigs/one", + "data": { + "tx": { + "type": "chain/tx", + "data": { + "chain_id": "gaia-1", + "expires_at": 0, + "tx": { + "type": "nonce", + "data": { + "sequence": 1, + "signers": [ + { + "chain": "", + "app": "sigs", + "addr": "84A057DCE7E1DB8EBE3903FC6B2D912E63EF9BEA" + } + ], + "tx": { + "type": "coin/send", + "data": { + "inputs": [ + { + "address": { + "chain": "", + "app": "sigs", + "addr": "84A057DCE7E1DB8EBE3903FC6B2D912E63EF9BEA" + }, + "coins": [ + { + "denom": "atom", + "amount": 1 + } + ] + } + ], + "outputs": [ + { + "address": { + "chain": "", + "app": "sigs", + "addr": "84A057DCE7E1DB8EBE3903FC6B2D912E63EF9BEA" + }, + "coins": [ + { + "denom": "atom", + "amount": 1 + } + ] + } + ] + } + } + } + } + } + }, + "signature": { + "Sig": null, + "Pubkey": null + } + } + }) + }) // proxy everything else to light client app.use(proxy('http://localhost:8998')) diff --git a/app/src/renderer/components/staking/CardCandidate.vue b/app/src/renderer/components/staking/CardCandidate.vue index af34327271..1af1939a24 100644 --- a/app/src/renderer/components/staking/CardCandidate.vue +++ b/app/src/renderer/components/staking/CardCandidate.vue @@ -13,7 +13,7 @@ transition(name='ts-card-candidate'): div(:class='cssClass') span {{ num.prettyInt(candidate.voting_power) }} .bar(:style='atomsCss') .value.atoms.num.bar.delegated(v-if='signedIn') - span {{ num.prettyInt(candidate.computed.delegatedCoins) }} + span {{ num.prettyInt(candidate.delegatedCoins) }} .bar(:style='delegatedAtomsCss') .value.shares.num span @@ -66,7 +66,7 @@ export default { return 0 }, delegatedAtomsCss () { - let percentage = Math.round((this.candidate.computed.delegatedAtoms / + let percentage = Math.round((this.candidate.delegatedAtoms / this.maxDelegatedAtoms) * 100) return { width: percentage + '%' } }, diff --git a/app/src/renderer/vuex/modules/user.js b/app/src/renderer/vuex/modules/user.js index 8e6b77290e..8c5baa8ffe 100644 --- a/app/src/renderer/vuex/modules/user.js +++ b/app/src/renderer/vuex/modules/user.js @@ -17,14 +17,14 @@ export default ({ commit, node }) => { } const emptyUser = { - atoms: 0, + atoms: 10000, nominationActive: false, nomination: JSON.parse(JSON.stringify(emptyNomination)), delegationActive: false, delegation: [], pubkey: '', privkey: null, - signedIn: false + signedIn: true } const state = JSON.parse(JSON.stringify(emptyUser)) @@ -50,13 +50,6 @@ export default ({ commit, node }) => { state.ownCoinsBonded = 0 node.wallet = null }, - activateNomination (state) { - state.nominationActive = true - }, - saveNomination (state, value) { - state.nomination = value - console.log('nomination saved: ', JSON.stringify(state.nomination)) - }, activateDelegation (state) { state.delegationActive = true } @@ -93,11 +86,19 @@ export default ({ commit, node }) => { async submitDelegation (state, value) { state.delegation = value console.log('submitting delegation txs: ', JSON.stringify(state.delegation)) + for (let candidate of value.candidates) { - let pubKeyBytes = Buffer.from(candidate.id, 'base64') - let pubKey = PubKey.decode(pubKeyBytes) - await node.delegationGame.delegate(pubKey, node.wallet, candidate.atoms) + let tx = await node.buildDelegate([ candidate.id, candidate.atoms ]) + let signedTx = await node.sign({ + name: 'default', + password: '1234567890', + tx + }) + let res = await node.postTx(signedTx) + console.log(res) } + + commit('activateDelegation', true) } }