diff --git a/data/networks-local.js b/data/networks-local.js index d74dba797e..c2b5329143 100644 --- a/data/networks-local.js +++ b/data/networks-local.js @@ -10,6 +10,7 @@ module.exports = [ bech32_prefix: 'cosmos', address_prefix: 'cosmos', address_creator: 'cosmos', + network_type: 'cosmos', ledger_app: 'cosmos', source_class_name: 'source/cosmosV2-source', block_listener_class_name: 'block-listeners/cosmos-node-subscription', diff --git a/data/networks.js b/data/networks.js index 498febe6d2..c2569ae4cb 100644 --- a/data/networks.js +++ b/data/networks.js @@ -10,6 +10,7 @@ module.exports = [ address_prefix: 'cosmos', address_creator: 'cosmos', ledger_app: 'cosmos', + network_type: 'cosmos', source_class_name: 'source/cosmosV2-source', block_listener_class_name: 'block-listeners/cosmos-node-subscription', testnet: true, @@ -32,7 +33,11 @@ module.exports = [ stakingDenom: 'MUON', enabled: true, icon: 'https://app.lunie.io/img/networks/cosmos-hub-mainnet.png', - slug: 'cosmos-hub-testnet' + slug: 'cosmos-hub-testnet', + powered: { + name: 'Figment', + picture: 'https://s3.amazonaws.com/keybase_processed_uploads/bd5fb87f241bd78a9c4bceaaa849ca05_360_360.jpg' + } }, { id: 'cosmos-hub-mainnet', @@ -44,6 +49,7 @@ module.exports = [ bech32_prefix: 'cosmos', address_prefix: 'cosmos', address_creator: 'cosmos', + network_type: 'cosmos', ledger_app: 'cosmos', source_class_name: 'source/cosmosV2-source', block_listener_class_name: 'block-listeners/cosmos-node-subscription', @@ -67,7 +73,12 @@ module.exports = [ stakingDenom: 'ATOM', enabled: true, icon: 'https://app.lunie.io/img/networks/cosmos-hub-mainnet.png', - slug: 'cosmos-hub' + slug: 'cosmos-hub', + powered: { + name: 'Figment', + providerAddress: 'cosmosvaloper1hjct6q7npsspsg3dgvzk3sdf89spmlpfdn6m9d', + picture: 'https://s3.amazonaws.com/keybase_processed_uploads/bd5fb87f241bd78a9c4bceaaa849ca05_360_360.jpg' + } }, { id: 'terra-mainnet', @@ -79,6 +90,7 @@ module.exports = [ address_prefix: 'terra', address_creator: 'cosmos', ledger_app: 'cosmos', + network_type: 'cosmos', source_class_name: 'source/terraV3-source', block_listener_class_name: 'block-listeners/cosmos-node-subscription', testnet: false, @@ -113,6 +125,7 @@ module.exports = [ address_prefix: 'terra', address_creator: 'cosmos', ledger_app: 'cosmos', + network_type: 'cosmos', source_class_name: 'source/terraV3-source', block_listener_class_name: 'block-listeners/cosmos-node-subscription', testnet: true, @@ -147,6 +160,7 @@ module.exports = [ address_prefix: 'emoney', address_creator: 'cosmos', ledger_app: 'cosmos', + network_type: 'cosmos', source_class_name: 'source/emoneyV0-source', block_listener_class_name: 'block-listeners/cosmos-node-subscription', testnet: true, @@ -181,6 +195,7 @@ module.exports = [ address_prefix: '0x', address_creator: 'ethereum', ledger_app: 'ethereum', + network_type: 'ethereum', source_class_name: 'source/livepeerV0-source', block_listener_class_name: 'block-listeners/livepeer-node-polling', testnet: false, diff --git a/lib/reducers/cosmosV0-reducers.js b/lib/reducers/cosmosV0-reducers.js index 738c62b799..001b332490 100644 --- a/lib/reducers/cosmosV0-reducers.js +++ b/lib/reducers/cosmosV0-reducers.js @@ -298,6 +298,25 @@ function gasPriceReducer(gasPrice) { } } +// delegations rewards in Tendermint are located in events as strings with this form: +// amount: {"15000umuon"}, or in multidenom networks they look like this: +// amount: {"15000ungm,100000uchf,110000ueur,2000000ujpy"} +// That is why we need this separate function to extract those amounts in this format +function rewardCoinReducer(reward, stakingDenom) { + const numBit = reward.match(/[0-9]+/gi) + const stringBit = reward.match(/[a-z]+/gi) + const multiDenomRewardsArray = reward.split(`,`) + if (multiDenomRewardsArray.length > 1) { + return multiDenomRewardsArray + .map(reward => rewardCoinReducer(reward)) + .filter(({ denom }) => denom === denomLookup(stakingDenom))[0] + } + return { + denom: denomLookup(stringBit), + amount: BigNumber(numBit).div(1000000) + } +} + function balanceReducer(coin, gasPrices) { return { ...coin, @@ -558,7 +577,13 @@ function getMessageType(type) { } // function to map cosmos messages to our details format -function transactionDetailsReducer(type, message, reducers, transaction) { +function transactionDetailsReducer( + type, + message, + reducers, + transaction, + stakingDenom +) { let details switch (type) { case lunieMessageTypes.SEND: @@ -574,7 +599,12 @@ function transactionDetailsReducer(type, message, reducers, transaction) { details = unstakeDetailsReducer(message, reducers) break case lunieMessageTypes.CLAIM_REWARDS: - details = claimRewardsDetailsReducer(transaction.tx.value.msg) + details = claimRewardsDetailsReducer( + transaction.tx.value.msg, + reducers, + transaction, + stakingDenom + ) break case lunieMessageTypes.SUBMIT_PROPOSAL: details = submitProposalDetailsReducer(message, reducers) @@ -625,18 +655,29 @@ function unstakeDetailsReducer(message, reducers) { } } -function claimRewardsDetailsReducer(messages) { +function claimRewardsDetailsReducer( + messages, + reducers, + transaction, + stakingDenom +) { return { from: messages .filter(msg => msg.type.split(`/`)[1] === `MsgWithdrawDelegationReward`) .map(msg => msg.value.validator_address), - amount: { - amount: 0, - denom: `` - } + amount: claimRewardsAmountReducer(transaction, reducers, stakingDenom) } } +function claimRewardsAmountReducer(transaction, reducers, stakingDenom) { + return reducers.rewardCoinReducer( + transaction.events + .find(event => event.type === `transfer`) + .attributes.find(attribute => attribute.key === `amount`).value, + stakingDenom + ) +} + function submitProposalDetailsReducer(message, reducers) { return { proposalType: message.content.type, @@ -670,6 +711,7 @@ module.exports = { delegationReducer, coinReducer, gasPriceReducer, + rewardCoinReducer, balanceReducer, transactionReducer, undelegationReducer, diff --git a/lib/reducers/terraV3-reducers.js b/lib/reducers/terraV3-reducers.js index 59c3105ed7..fa7cac6dcc 100644 --- a/lib/reducers/terraV3-reducers.js +++ b/lib/reducers/terraV3-reducers.js @@ -27,11 +27,13 @@ function undelegationEndTimeReducer(transaction) { function balanceReducer(coin, fiatValue, gasPrices) { return { ...coin, - fiatValue: { - amount: fiatValue.amount || 0, - denom: fiatValue.denom || '', - symbol: fiatValue.symbol || '' - }, + fiatValue: fiatValue + ? { + amount: fiatValue.amount || 0, + denom: fiatValue.denom || '', + symbol: fiatValue.symbol || '' + } + : null, gasPrice: gasPriceReducer( gasPrices.find(gasprice => denomLookup(gasprice.denom) === coin.denom) ).price diff --git a/lib/schema.js b/lib/schema.js index a6bda327cb..0fce5016cd 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -117,6 +117,7 @@ const typeDefs = gql` bech32_prefix: String address_prefix: String address_creator: String + network_type: String ledger_app: String testnet: Boolean feature_session: Boolean @@ -139,6 +140,7 @@ const typeDefs = gql` enabled: Boolean icon: String slug: String + powered: Powered } type Delegation { @@ -260,6 +262,12 @@ const typeDefs = gql` sequence: String } + type Powered { + name: String + providerAddress: String + picture: String + } + type Overview { networkId: String! address: String! diff --git a/lib/source/cosmosV0-source.js b/lib/source/cosmosV0-source.js index eb248f2a9c..2494333d2b 100644 --- a/lib/source/cosmosV0-source.js +++ b/lib/source/cosmosV0-source.js @@ -131,7 +131,7 @@ class CosmosV0API extends RESTDataSource { ? this.reducers.transactionsReducerV2( txs, this.reducers, - this.getStakingDenom() + await this.getStakingDenom() ) : [] } diff --git a/lib/source/terraV3-source.js b/lib/source/terraV3-source.js index 4c6ec609e9..d46d3ceeaa 100644 --- a/lib/source/terraV3-source.js +++ b/lib/source/terraV3-source.js @@ -125,7 +125,9 @@ class TerraV3API extends CosmosV2API { return coins.map(coin => { return this.reducers.balanceReducer( coin, - fiatBalances.find(({ denom }) => denom === coin.denom).fiatValue, + fiatBalances + ? fiatBalances.find(({ denom }) => denom === coin.denom).fiatValue + : null, this.gasPrices ) }) diff --git a/tests/network-configs.test.js b/tests/network-configs.test.js index 333b46117f..5a6827a554 100644 --- a/tests/network-configs.test.js +++ b/tests/network-configs.test.js @@ -10,6 +10,7 @@ const schema = Joi.object({ bech32_prefix: Joi.string(), address_prefix: Joi.string(), address_creator: Joi.string(), + network_type: Joi.string(), ledger_app: Joi.string(), source_class_name: Joi.string(), block_listener_class_name: Joi.string(), @@ -34,7 +35,14 @@ const schema = Joi.object({ enabled: Joi.boolean(), experimental: Joi.boolean().optional(), icon: Joi.string().optional(), - slug: Joi.string().optional() + slug: Joi.string().optional(), + powered: Joi.object() + .keys({ + name: Joi.string().optional(), + providerAddress: Joi.string().optional(), + picture: Joi.string().optional() + }) + .optional() }) describe('Network configs', function() {