Skip to content

Commit

Permalink
Fabo/fix tx parsing (#179)
Browse files Browse the repository at this point in the history
* changelog

* preload network capabilities

* tests fixed

* add slug to store and mutations

* lunie version changed

* Aleksei/fixing path on extension (#173)

* changelog

* fixing redirect path after account creation in extension

* refactor isExtension getter using lunie config

Co-authored-by: Bitcoinera <[email protected]>

* correct submodule version

* added missing webpack resolution

* force checkout

* change to working commit

* make updates async

* remove package lock again

* use working commit

* first steps to parsing to v2 txs

* clone parsing from API

* linted

* move parsetx to store

* delete consolelog

* fix tests

* fix actions tests

* lint

* just in case add ledger_app like in fe

* working with #3736 in fe

* stay clean

* fix validators names in claim rewards

* fix tests

* lint

* working with #3736 now for real

* add claimable rewards

* lint. kill now unused functions

* changelog

* refactor property names

* linted

Co-authored-by: Aleksei Rudometov <[email protected]>
Co-authored-by: Bitcoinera <[email protected]>
  • Loading branch information
3 people authored Mar 20, 2020
1 parent 4a61d8e commit bba1eea
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 228 deletions.
1 change: 1 addition & 0 deletions pending/fabo_fix-tx-parsing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Fixed] Parse transactions in new transaction format @faboweb
52 changes: 16 additions & 36 deletions src/components/SessionApprove.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</div>
<TmFormGroup v-if="signRequest">
<TransactionItem
v-if="transaction"
:key="transaction.key"
:transaction="transaction"
v-if="tx"
:key="tx.hash"
:transaction="tx"
:validators="validatorsAddressMap"
:address="senderAddress"
:show-meta-data="false"
Expand Down Expand Up @@ -78,33 +78,10 @@ import TransactionItem from 'transactions/TransactionItem'
import TableInvoice from 'src/ActionModal/components/TableInvoice'
import Address from 'common/Address'
import { required } from 'vuelidate/lib/validators'
import { parseTx, parseFee, parseValueObj } from '../scripts/parsers.js'
import { atoms } from 'scripts/num.js'
import actions from '../store/actions.js'
const getValidatorsData = actions({}).getValidatorsData
import { flattenTransactionMsgs } from '../scripts/transaction-utils'
const getWithdrawValidators = messages => {
const withdrawMessages = messages.filter(({ type }) => {
const messageSuffix = type.split('/')[1]
return messageSuffix === 'MsgWithdrawDelegationReward'
})
// strange syntax where we actually return the whole message instead of just the validator
return withdrawMessages
}
const getLunieTransaction = tx => {
const lunieTransactions = flattenTransactionMsgs([], tx)
const pickFirst = lunieTransactions[0] // obviously error prone as we ignore the rest
pickFirst.withdrawValidators = JSON.stringify(
getWithdrawValidators(lunieTransactions)
)
return pickFirst
}
const parseSignMessageTx = actions({}).parseSignMessageTx
export default {
name: `session-approve`,
Expand All @@ -125,33 +102,36 @@ export default {
computed: {
...mapGetters(['signRequest']),
tx() {
return this.signRequest ? parseTx(this.signRequest.signMessage) : null
return parseSignMessageTx(
this.signRequest.signMessage,
this.displayedProperties
)
},
network() {
return this.signRequest ? this.signRequest.network : null
},
transaction() {
return getLunieTransaction(this.tx)
},
fees() {
return this.tx ? atoms(parseFee(this.tx.tx)) : null
return this.tx ? this.tx.fees[0].amount : null
},
senderAddress() {
return this.signRequest ? this.signRequest.senderAddress : null
},
displayedProperties() {
return this.signRequest ? this.signRequest.displayedProperties : null
},
amountCoin() {
return this.tx ? parseValueObj(this.tx.tx) : null
return this.tx ? this.tx.details.amount : null
},
amount() {
return this.amountCoin ? atoms(Number(this.amountCoin.amount)) : 0
return this.amountCoin ? this.amountCoin.amount : 0
},
bondDenom() {
return this.amountCoin ? this.amountCoin.denom : ''
},
validatorsAddressMap() {
const names = {}
this.validators.forEach(item => {
names[item.operator_address] = item
names[item.operatorAddress] = item
})
return names
}
Expand All @@ -162,7 +142,7 @@ export default {
}
},
async mounted() {
const validatorsObject = await getValidatorsData(this.tx.tx, this.network)
const validatorsObject = await getValidatorsData(this.tx, this.network)
this.validators = validatorsObject
},
methods: {
Expand Down
8 changes: 7 additions & 1 deletion src/messageHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ export function signMessageHandler(
break
}
case 'LUNIE_SIGN_REQUEST': {
const { signMessage, senderAddress, network } = message.payload
const {
signMessage,
senderAddress,
network,
displayedProperties
} = message.payload
const wallet = getWalletFromIndex(getWalletIndex(), senderAddress)
if (!wallet) {
throw new Error('No wallet found matching the sender address.')
Expand All @@ -39,6 +44,7 @@ export function signMessageHandler(
signMessage,
senderAddress,
network,
displayedProperties,
tabID: sender.tab.id
})
break
Expand Down
9 changes: 8 additions & 1 deletion src/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ export default class SignRequestQueue {
this.unqueueSignRequest('') // to reset the icon in the beginning
}

queueSignRequest({ signMessage, senderAddress, tabID, network }) {
queueSignRequest({
signMessage,
senderAddress,
network,
displayedProperties,
tabID
}) {
this.queue.push({
signMessage,
senderAddress,
network,
displayedProperties,
id: Date.now(),
tabID
})
Expand Down
Loading

0 comments on commit bba1eea

Please sign in to comment.