-
Notifications
You must be signed in to change notification settings - Fork 100
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
Benji/ext issue 29 calculate subtotal in SessionApprove TableInvoice #2787
Merged
jbibla
merged 16 commits into
develop
from
Benji/Ext-issue-29-Calculate-Subtotal-in-Approve-TableInvoice
Jul 4, 2019
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bcada60
Adds TableInvoice to SessionApprove with Amount and estimateFee
thebkr7 5351b24
Merge branch 'chrome-extension' into Benji/Ext-issue-29-Calculate-Sub…
thebkr7 1dda831
Moves logic to computed property
thebkr7 1e6fd8e
changelog
thebkr7 7226500
Updates fees and amount in SessionApprove
thebkr7 9d1a96d
Update to wrong work committed
thebkr7 a854bc9
Updates data structure parsing
thebkr7 a01314d
Adds scripts/parsers.js as a helper to SessionApprove
thebkr7 ca7cdb0
Bringing branch up to date with develop
thebkr7 48dc12b
Updates parser to handle different data structures
thebkr7 5c7473c
fixed signMessage being undefined
faboweb c85ac23
fixed sign message issue in tests
faboweb bdd084e
reduce JSON.parse
faboweb 92309f6
reduced parsing
faboweb 0754d8d
Creates tests for Parsers
thebkr7 a715d43
Adds a test for the conditional in parsers
thebkr7 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
1 change: 1 addition & 0 deletions
1
changes/Benji_Ext-issue-29-Calculate-Subtotal-in-Approve-TableInvoice
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 @@ | ||
[Code Improvements] [#2785](https://github.com/cosmos/lunie/pull/2785) Refactors SessionApprove to pass TableInvoice the subtotal fee and amount of the transaction. TableInvoice was refactored in PR #2785 @thebkr7 |
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,34 @@ | ||
"use strict" | ||
|
||
export const parseTx = signMessage => { | ||
const { msgs, fee, memo } = JSON.parse(signMessage) | ||
thebkr7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return { | ||
tx: { | ||
type: "auth/StdTx", | ||
value: { | ||
msg: msgs, | ||
fee, | ||
memo | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const parseFee = stdTx => { | ||
const { | ||
value: { fee } | ||
} = stdTx | ||
return Number(fee.amount[0].amount) | ||
} | ||
|
||
export const parseValueObj = stdTx => { | ||
const { | ||
value: { msg } | ||
} = stdTx | ||
if (msg[0].type === "cosmos-sdk/MsgSend") { | ||
return msg[0].value.amount[0] | ||
} else { | ||
return msg[0].value.amount | ||
} | ||
} |
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,103 @@ | ||
import { parseTx, parseFee, parseValueObj } from "scripts/parsers" | ||
|
||
const signedMessage = { | ||
type: "auth/StdTx", | ||
value: { | ||
msg: [ | ||
{ | ||
type: "cosmos-sdk/MsgSend", | ||
value: { | ||
amount: [ | ||
{ | ||
amount: "10000000", | ||
denom: "stake" | ||
} | ||
], | ||
from_address: "cosmos1ek9cd8ewgxg9w5xllq9um0uf4aaxaruvcw4v9e", | ||
to_address: "cosmos1324vt5j3wzx0xsc32mjhkrvy5gn5ef2hrwcg29" | ||
} | ||
} | ||
], | ||
fee: { | ||
amount: [ | ||
{ | ||
amount: "40", | ||
denom: "stake" | ||
} | ||
], | ||
gas: "39953" | ||
}, | ||
memo: "(Sent via Lunie)" | ||
} | ||
} | ||
|
||
const signedActionMessage = { | ||
type: "auth/StdTx", | ||
value: { | ||
msg: [ | ||
{ | ||
type: "cosmos-sdk/MsgDelegate", | ||
value: { | ||
amount: [ | ||
{ | ||
amount: "10000000", | ||
denom: "stake" | ||
} | ||
], | ||
from_address: "cosmos1ek9cd8ewgxg9w5xllq9um0uf4aaxaruvcw4v9e", | ||
to_address: "cosmos1324vt5j3wzx0xsc32mjhkrvy5gn5ef2hrwcg29" | ||
} | ||
} | ||
], | ||
fee: { | ||
amount: [ | ||
{ | ||
amount: "40", | ||
denom: "stake" | ||
} | ||
], | ||
gas: "39953" | ||
}, | ||
memo: "(Sent via Lunie)" | ||
} | ||
} | ||
|
||
describe(`parsers helper`, () => { | ||
it(`should parse a signedmessaged ParseTx`, () => { | ||
const shortMessage = { | ||
tx: { | ||
type: "auth/StdTx", | ||
value: { | ||
msg: "some message", | ||
fee: 0.01, | ||
memo: "Sent from Lunie" | ||
} | ||
} | ||
} | ||
expect( | ||
parseTx(`{"msgs":"some message","fee":0.01,"memo":"Sent from Lunie"}`) | ||
).toMatchObject(shortMessage) | ||
}) | ||
|
||
it(`should parse a signedmessaged parseFee`, () => { | ||
expect(parseFee(signedMessage)).toBe(40) | ||
}) | ||
|
||
it(`should parse a signedmessaged parseValueObj`, () => { | ||
const parsedValueObj = { | ||
amount: "10000000", | ||
denom: "stake" | ||
} | ||
expect(parseValueObj(signedMessage)).toMatchObject(parsedValueObj) | ||
}) | ||
|
||
it(`should parse a signedActionMessage parseValueObj`, () => { | ||
const parsedValueObj = [ | ||
{ | ||
amount: "10000000", | ||
denom: "stake" | ||
} | ||
] | ||
expect(parseValueObj(signedActionMessage)).toMatchObject(parsedValueObj) | ||
}) | ||
}) |
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.
This won't (yet) pass the tests since the
TableInvoice
code is in the other PR #2802