Skip to content

Commit

Permalink
Merge pull request #70 from luniehq/Benji/30-API-Moniker-Query
Browse files Browse the repository at this point in the history
Benji/30 api moniker query
  • Loading branch information
faboweb authored Jul 18, 2019
2 parents afe21e5 + ea0c2c1 commit ee8b5b9
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 132 deletions.
11 changes: 8 additions & 3 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const dev = process.env.NODE_ENV === `development`;
const dev = process.env.NODE_ENV === `development`

const stargate =
process.env.STARGATE ||
(dev ? `https://localhost:9071` : `https://stargate.lunie.io`)

export default {
name: `Lunie`,
Expand All @@ -7,7 +11,8 @@ export default {
sentry_dsn: process.env.SENTRY_DSN || '',
default_gas_price: dev ? 1e-9 : 2.5e-8, // recommended from Cosmos Docs
version: process.env.RELEASE,
stargate,

// Ledger
CosmosAppTestModeAllowed: false,
};
CosmosAppTestModeAllowed: false
}
1 change: 1 addition & 0 deletions pending/Benji_30-API-Moniker-Query
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Added] [#30](https://github.com/cosmos/lunie/issues/30) Fetch and display monikers in extension @thebkr7
9 changes: 7 additions & 2 deletions src/components/SessionApprove.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<LiAnyTransaction
v-if="tx"
:address="senderAddress"
:validators="delegates"
:validators="validators"
:transaction="tx"
:hide-meta-data="true"
validators-url="https://lunie.io/#/staking/validators/"
Expand Down Expand Up @@ -85,6 +85,7 @@ import Bech32 from 'common/Bech32'
import { required } from 'vuelidate/lib/validators'
import { parseTx, parseFee, parseValueObj } from '../scripts/parsers.js'
import { atoms } from 'scripts/num.js'
import { getValidatorsData } from '../store/actions.js'
export default {
name: `session-approve`,
Expand All @@ -98,10 +99,14 @@ export default {
TmFormMsg
},
data: () => ({
delegates: [],
validators: [],
password: null,
passwordError: false
}),
async mounted() {
const validatorsObject = await getValidatorsData(this.tx.tx)
this.validators = validatorsObject
},
computed: {
...mapGetters(['signRequest']),
tx() {
Expand Down
59 changes: 59 additions & 0 deletions src/store/actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import config from '../../config.js'

export const createSeed = () => {
return new Promise(resolve => {
chrome.runtime.sendMessage({ type: 'GET_SEED' }, function(seed) {
Expand Down Expand Up @@ -64,6 +66,63 @@ export const getSignRequest = ({ commit }) => {
})
}

export const getValidatorsData = async validatorAddress => {
const txMessage = validatorAddress.value.msg[0]
if (
txMessage.type === 'cosmos-sdk/MsgDelegate' ||
txMessage.type === 'cosmos-sdk/MsgUndelegate'
) {
const validatorAddress = txMessage.value.validator_address
const validatorToMoniker = await fetchValidatorData(validatorAddress)

return [
{
operator_address: validatorAddress,
description: {
moniker: validatorToMoniker
}
}
]
}
if (txMessage.type === 'cosmos-sdk/MsgBeginRedelegate') {
const validator_src_address = txMessage.value.validator_src_address
const validator_src_moniker = await fetchValidatorData(
validator_src_address
)
const validator_dst_address = txMessage.value.validator_dst_address
const validator_dst_moniker = await fetchValidatorData(
validator_dst_address
)

return [
{
operator_address: validator_src_address,
description: {
moniker: validator_src_moniker
}
},
{
operator_address: validator_dst_address,
description: {
moniker: validator_dst_moniker
}
}
]
}
return []
}

const fetchValidatorData = async validatorAddress => {
return fetch(`${config.stargate}/staking/validators/${validatorAddress}`)
.then(async function(response) {
const validatorObject = await response.json()
return validatorObject.description.moniker
})
.catch(function(error) {
console.log('Error: ', error)
})
}

export const approveSignRequest = (
{ commit },
{ signMessage, senderAddress, password, id }
Expand Down
1 change: 0 additions & 1 deletion test/e2e/create-account.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ test('Restores an account with backup code when has no accounts', async () => {
signupData.seedPhrase
)
await page.click('div.session-footer button')

const accountRenders = await page.$eval('h3', el => el.textContent)
expect(accountRenders).toEqual(signupData.name)

Expand Down
Loading

0 comments on commit ee8b5b9

Please sign in to comment.