Skip to content

Commit

Permalink
Together with 3584: Ana/change fiatvalue to object (#360)
Browse files Browse the repository at this point in the history
* change fiatvalue to object

* handle when selected currency is eur

* include ngm fiatvalue fix
  • Loading branch information
Bitcoinera authored Feb 28, 2020
1 parent e2d941e commit d47a54a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
6 changes: 5 additions & 1 deletion lib/reducers/terraV3-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ function undelegationEndTimeReducer(transaction) {
function balanceReducer(coin, fiatValue, gasPrices) {
return {
...coin,
fiatValue: fiatValue || 0,
fiatValue: {
amount: fiatValue.amount || 0,
denom: fiatValue.denom || '',
symbol: fiatValue.symbol || ''
},
gasPrice: gasPriceReducer(
gasPrices.find(gasprice => denomLookup(gasprice.denom) === coin.denom)
).price
Expand Down
8 changes: 7 additions & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ const typeDefs = gql`
amount: String
}
type FiatValue {
amount: String
denom: String
symbol: String
}
type Balance {
denom: String!
amount: String!
fiatValue: String
fiatValue: FiatValue
gasPrice: String
}
Expand Down
27 changes: 15 additions & 12 deletions lib/source/emoneyV0-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,23 @@ class EMoneyV0API extends TerraV3API {
if (denom === 'NGM') {
const eurValue = this.reducers.coinReducer(balance).amount * 0.5 // 0.50€ is the price the NGM tokens will be first sold. Therefore, the official value until they reach an exchange
if (selectedFiatCurrency === `EUR`) {
return parseFloat(eurValue)
.toFixed(6)
.toString()
.concat(`€`)
return {
amount: parseFloat(eurValue).toFixed(6),
denom: `EUR`,
symbol: `€`
}
} else {
const { rates } = await this.fetchExchangeRates(
selectedFiatCurrency,
`EUR`
)
const fiatValue = eurValue / rates[`EUR`]
const currencySign = this.getCurrencySign(selectedFiatCurrency)
return parseFloat(fiatValue)
.toFixed(6)
.toString()
.concat(`${currencySign}`)
return {
amount: parseFloat(fiatValue).toFixed(6),
denom: selectedFiatCurrency,
symbol: currencySign
}
}
// For all other balances we use the public API https://exchangeratesapi.io/ to add all balances into
// a single fiat currency value, the selectedFiatCurrency
Expand All @@ -125,10 +127,11 @@ class EMoneyV0API extends TerraV3API {
)
// Finally we get the proper currency sign to display
const currencySign = this.getCurrencySign(selectedFiatCurrency)
return parseFloat(totalFiatValue)
.toFixed(6)
.toString()
.concat(`${currencySign}`)
return {
amount: parseFloat(totalFiatValue).toFixed(6),
denom: selectedFiatCurrency,
symbol: currencySign
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/source/terraV3-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ class TerraV3API extends CosmosV2API {

async calculateFiatValues(balances, fiatCurrency) {
return Promise.all(
balances.map(balance => ({
balances.map(async balance => ({
denom: this.reducers.coinReducer(balance).denom,
fiatValue: this.calculateFiatValue
? this.calculateFiatValue(balance, fiatCurrency)
? await this.calculateFiatValue(balance, fiatCurrency)
: null
}))
)
Expand Down

0 comments on commit d47a54a

Please sign in to comment.