diff --git a/data/network-capabilities.js b/data/network-capabilities.js index 92269904e8..1d29768056 100644 --- a/data/network-capabilities.js +++ b/data/network-capabilities.js @@ -67,6 +67,23 @@ const getNetworkCapabilities = { action_vote: false, action_proposal: false }, + "emoney-mainnet": { + feature_session: true, + feature_explore: true, + feature_portfolio: true, + feature_validators: true, + feature_proposals: false, + feature_activity: true, + feature_explorer: true, + action_send: true, + action_claim_rewards: true, + action_delegate: true, + action_redelegate: true, + action_undelegate: true, + action_deposit: false, + action_vote: false, + action_proposal: false + }, "emoney-testnet": { feature_session: true, feature_explore: true, diff --git a/data/networks.js b/data/networks.js index fdf7a5f499..da1a535e5d 100644 --- a/data/networks.js +++ b/data/networks.js @@ -98,6 +98,27 @@ module.exports = [ icon: 'https://app.lunie.io/img/networks/terra-testnet.png', slug: 'terra-testnet' }, + { + id: 'emoney-mainnet', + title: 'e-Money', + chain_id: 'emoney-1', + api_url: 'https://emoney.validator.network/light', + rpc_url: 'wss://emoney.validator.network/websocket', + bech32_prefix: 'emoney', + 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, + ...getNetworkCapabilities[`emoney-mainnet`], + default: false, + stakingDenom: 'NGM', + enabled: true, + icon: 'https://app.lunie.io/img/networks/emoney-mainnet.png', + slug: 'emoney' + }, { id: 'emoney-testnet', title: 'e-Money Testnet', diff --git a/lib/block-listeners/cosmos-node-subscription.js b/lib/block-listeners/cosmos-node-subscription.js index 0bfa2d0400..217e4c32d9 100644 --- a/lib/block-listeners/cosmos-node-subscription.js +++ b/lib/block-listeners/cosmos-node-subscription.js @@ -7,6 +7,7 @@ const { const Sentry = require('@sentry/node') const database = require('../database') const config = require('../../config.js') +const { pollForValidators } = require('./emoney-release-validators-poller') const POLLING_INTERVAL = 1000 const EXPECTED_MAX_BLOCK_WINDOW = 120000 @@ -31,6 +32,15 @@ class CosmosNodeSubscription { } async pollForNewBlock() { + if (this.network.id === `emoney-mainnet`) { + const validators = await pollForValidators(this.network) + if (!validators || validators.length <= 0) { + setTimeout(async () => { + this.pollForNewBlock() + }, POLLING_INTERVAL) + return + } + } const cosmosAPI = new this.CosmosApiClass(this.network, this.store) await this.checkForNewBlock(cosmosAPI) diff --git a/lib/block-listeners/emoney-release-validators-poller.js b/lib/block-listeners/emoney-release-validators-poller.js new file mode 100644 index 0000000000..208c9e8d59 --- /dev/null +++ b/lib/block-listeners/emoney-release-validators-poller.js @@ -0,0 +1,8 @@ +async function pollForValidators(eMoneyNetwork) { + const { result } = await global.fetch( + `${eMoneyNetwork.api_url}/staking/validators` + ) + return result +} + +module.exports = { pollForValidators } diff --git a/lib/reducers/cosmosV0-reducers.js b/lib/reducers/cosmosV0-reducers.js index d9fd36c1ad..238a10ca3d 100644 --- a/lib/reducers/cosmosV0-reducers.js +++ b/lib/reducers/cosmosV0-reducers.js @@ -262,7 +262,10 @@ function denomLookup(denom) { eeur: 'eEUR', echf: 'eCHF', ejpy: 'eJPY', - eusd: 'eUSD' + eusd: 'eUSD', + edkk: 'eDKK', + enok: 'eNOK', + esek: 'eSEK' } return lookup[denom] ? lookup[denom] : denom.toUpperCase() } @@ -780,10 +783,12 @@ function claimRewardsDetailsReducer( function claimRewardsAmountReducer(transaction, reducers, stakingDenom) { if (!transaction.success) { - return { - amoun: 0, - denom: stakingDenom - } + return [ + { + amoun: 0, + denom: stakingDenom + } + ] } return reducers.rewardCoinReducer( transaction.events diff --git a/lib/source/emoneyV0-source.js b/lib/source/emoneyV0-source.js index c891df2bbe..05917ff56e 100644 --- a/lib/source/emoneyV0-source.js +++ b/lib/source/emoneyV0-source.js @@ -4,7 +4,8 @@ const fetch = require('node-fetch') const Sentry = require('@sentry/node') const fiatExchangeRateApi = `https://api.exchangeratesapi.io/latest?` -const EMoneyAPIUrl = `https://beta-api.e-money.com/v1/` +const EMoneyAPIUrlMainnet = `https://api.e-money.com/v1/` +const EMoneyAPIUrlTestnet = `https://beta-api.e-money.com/v1/` const gasPrices = [ { denom: 'echf', @@ -27,12 +28,25 @@ const gasPrices = [ price: '0.800' } ] -const supportedFiatCurrencies = new Set(['EUR', 'USD', 'GBP', 'CHF', 'JPY']) +const supportedFiatCurrencies = new Set([ + 'EUR', + 'USD', + 'GBP', + 'CHF', + 'JPY', + 'DKK', + 'NOK', + 'SEK' +]) class EMoneyV0API extends TerraV3API { setReducers() { this.reducers = require('../reducers/emoneyV0-reducers') this.gasPrices = gasPrices + this.apiURL = + this.networkId === 'emoney-mainnet' + ? EMoneyAPIUrlMainnet + : EMoneyAPIUrlTestnet } // additional block handling by network @@ -62,9 +76,9 @@ class EMoneyV0API extends TerraV3API { await Promise.all([ this.getTokensInflations(), this.getTotalBackedValues() - ]).then(async ([inflatations, totalBackedValues]) => { + ]).then(async ([inflations, totalBackedValues]) => { store.totalNetworkAnnualRewards = await this.reducers.getTotalNetworkAnnualRewards( - inflatations, + inflations, totalBackedValues ) }) @@ -83,7 +97,7 @@ class EMoneyV0API extends TerraV3API { // Here we query for the current inflation rates for all the backed tokens async getTokensInflations() { const inflations = await this.get(`inflation/current`) - return inflations.result.assets.filter(asset => asset.denom !== `x3chf`) + return inflations.result.assets } // Here we query for the current total supply for all the backed tokens @@ -141,7 +155,7 @@ class EMoneyV0API extends TerraV3API { // firt check if the selectedFiatCurrency is a supported currency if (!supportedFiatCurrencies.has(selectedFiatCurrency)) { throw new Error( - 'We currently only support "EUR", "USD", "GBP", "CHF" and "JPY" as fiat currencies. Remember they should be written in uppercases' + 'We currently only support "EUR", "USD", "GBP", "DKK", "NOK", "SEK", "CHF" and "JPY" as fiat currencies. Remember they should be written in uppercases' ) } @@ -164,11 +178,11 @@ class EMoneyV0API extends TerraV3API { } async fetchEmoneyTokenExchangeRates() { - const rates = await fetch(`${EMoneyAPIUrl}rates.json`) + const rates = await fetch(`${this.apiURL}rates.json`) .then(r => r.json()) .catch(err => { Sentry.withScope(function(scope) { - scope.setExtra('fetch', `${EMoneyAPIUrl}rates.json`) + scope.setExtra('fetch', `${this.apiURL}rates.json`) Sentry.captureException(err) }) })