-
Notifications
You must be signed in to change notification settings - Fork 98
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
Peng/123 vuex tests #333
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8f6e8b0
remove blockchainSelect
nylira b55a924
remove unused code
nylira 23a6c85
tests for validators.js
nylira 49d79af
Merge branch 'develop' into peng/123-vuex-tests
nylira fa9edc9
fix lint errors
nylira 6b833e2
more wallet tests
nylira d16a3ae
Merge branch 'develop' into peng/123-vuex-tests
nylira 05e66d8
fixed wallet tests
faboweb b2b7673
Merge remote-tracking branch 'origin/develop' into peng/123-vuex-tests
faboweb 0a31a82
added wallet tests and fixed and refactored other stuff
faboweb ad826b9
linted
faboweb 35aaaf8
Merge branch 'develop' into peng/123-vuex-tests
nylira d993b82
Merge branch 'develop' into peng/123-vuex-tests
jbibla 7ed1de1
Merge branch 'develop' into peng/123-vuex-tests
nylira 7cbd185
Merge branch 'develop' into peng/123-vuex-tests
mappum 753d769
Moved send logic into new 'send' module
mappum e169eb6
Created send tests, updated tests for send changes
mappum 3ccb91c
Lint
mappum e9265d8
Improve nonce incrementing
mappum 6fce13a
Merge remote-tracking branch 'origin/develop' into peng/123-vuex-tests
faboweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
57 changes: 0 additions & 57 deletions
57
app/src/renderer/components/monitor/BlockchainSelectModal.vue
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
export default ({ commit, node }) => { | ||
let state = { | ||
// account nonce number, used to prevent replay attacks | ||
nonce: 0, | ||
// queue of transactions to be sent | ||
queue: [], | ||
sending: false | ||
} | ||
|
||
const mutations = { | ||
queueSend (state, sendReq) { | ||
state.queue.push(sendReq) | ||
}, | ||
shiftSendQueue (state) { | ||
state.queue = state.queue.slice(1) | ||
}, | ||
setSending (state, sending) { | ||
state.sending = sending | ||
}, | ||
setNonce (state, nonce) { | ||
state.nonce = nonce | ||
} | ||
} | ||
|
||
let actions = { | ||
// queries for our account's nonce | ||
async queryNonce ({ commit }, address) { | ||
let res = await node.queryNonce(address) | ||
if (!res) return | ||
commit('setNonce', res.data) | ||
}, | ||
|
||
// builds, signs, and broadcasts a tx of any type | ||
sendTx ({ state, dispatch, commit, rootState }, args) { | ||
// wait until the current send operation is done | ||
if (state.sending) { | ||
args.done = new Promise((resolve, reject) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thx for picking up my promise over callback solution |
||
args.resolve = resolve | ||
args.reject = reject | ||
}) | ||
commit('queueSend', args) | ||
return args.done | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
commit('setSending', true) | ||
|
||
// once done, do next send in queue | ||
function done (err, res) { | ||
commit('setSending', false) | ||
|
||
if (state.queue.length > 0) { | ||
// do next send | ||
let send = state.queue[0] | ||
commit('shiftSendQueue') | ||
dispatch('sendTx', send) | ||
} | ||
|
||
if (err) { | ||
reject(err) | ||
if (args.reject) args.reject(err) | ||
} else { | ||
resolve(res) | ||
if (args.resolve) args.resolve(res) | ||
} | ||
} | ||
|
||
args.sequence = state.nonce + 1 | ||
args.from = { | ||
chain: '', | ||
app: 'sigs', | ||
addr: rootState.wallet.key.address | ||
}; | ||
|
||
(async function () { | ||
// build tx | ||
let tx = await node[args.type](args) | ||
|
||
// sign tx | ||
let signedTx = await node.sign({ | ||
name: rootState.user.account, | ||
password: rootState.user.password, | ||
tx | ||
}) | ||
|
||
// broadcast tx | ||
let res = await node.postTx(signedTx) | ||
|
||
// 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) | ||
} | ||
})().then(() => { | ||
commit('setNonce', state.nonce + 1) | ||
done(null, args) | ||
dispatch('queryWalletBalances') | ||
}, (err) => { | ||
done(err || Error('Error sending transaction')) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
return { state, mutations, actions } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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()
?There was a problem hiding this comment.
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.catch
if available. See: https://codepen.io/faboweb/pen/WdmRoOThere was a problem hiding this comment.
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...?