Skip to content

Commit

Permalink
Merge pull request #94 from protofire/hotfix/earning-decimals
Browse files Browse the repository at this point in the history
(Hotfix) Earning decimals
  • Loading branch information
Agupane committed Jul 16, 2019
2 parents 1056af7 + dddbb35 commit a99d282
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ UNSUBSCRIBE_EMAIL_URL=http://livepeer.tools/account
APOLLO_API_URL=https://api.thegraph.com/subgraphs/name/graphprotocol/livepeer
MINUTES_TO_WAIT_AFTER_LAST_SENT_EMAIL=500
MINUTES_TO_WAIT_AFTER_LAST_SENT_TELEGRAM=500
EARNING_DECIMALS=6
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.2] - 2019-07-16
### Fixes
- Change displayed decimals of earnings to 6

## [1.2.1] - 2019-07-11
### Fixes
- Unsubscribe link in notifications
Expand Down
8 changes: 6 additions & 2 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ const envVarsSchema = Joi.object({
.required(),
MINUTES_TO_WAIT_AFTER_LAST_SENT_TELEGRAM: Joi.string()
.description('Minutes to wait after last sent telegram')
.required()
.required(),
EARNING_DECIMALS: Joi.number()
.description('Amount of decimals to display in the earnings')
.default(6)
})
.unknown()
.required()
Expand Down Expand Up @@ -132,7 +135,8 @@ const config = {
thresholdSendNotification: envVars.THRESHOLD_SEND_NOTIFICATION,
apolloApiUrl: envVars.APOLLO_API_URL,
minutesToWaitAfterLastSentEmail: envVars.MINUTES_TO_WAIT_AFTER_LAST_SENT_EMAIL,
minutesToWaitAfterLastSentTelegram: envVars.MINUTES_TO_WAIT_AFTER_LAST_SENT_TELEGRAM
minutesToWaitAfterLastSentTelegram: envVars.MINUTES_TO_WAIT_AFTER_LAST_SENT_TELEGRAM,
earningDecimals: envVars.EARNING_DECIMALS
}

module.exports = config
2 changes: 1 addition & 1 deletion server/helpers/sendDelegateEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const sendEmail = async data => {
if (!['test'].includes(config.env)) {
try {
await sgMail.send(msg)
console.log(`Email sended to ${email} successfully`)
console.log(`Email sent to ${email} successfully`)
} catch (err) {
console.error('error on email')
console.error(err)
Expand Down
7 changes: 4 additions & 3 deletions server/helpers/sendDelegatorEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const {
sendgridTemplateIdClaimRewardCallPayAttention,
sendgridTemplateIdClaimRewardUnbondedState,
sendgridTemplateIdClaimRewardUnbondingState,
sendgridTemplateIdNotificationDelegateChangeRules
sendgridTemplateIdNotificationDelegateChangeRules,
earningDecimals
} = config

const sendEmail = async data => {
Expand Down Expand Up @@ -83,7 +84,7 @@ const sendEmail = async data => {
try {
console.log(`Trying to send email to ${email}`)
await sgMail.send(msg)
console.log(`Email sended to ${email} successfully`)
console.log(`Email sent to ${email} successfully`)
} catch (err) {
console.error(`There was an error trying to send email to ${email}`)
console.error(err)
Expand Down Expand Up @@ -114,7 +115,7 @@ const sendDelegatorNotificationEmail = async (
: sendgridTemplateIdClaimRewardCallPayAttention

// Calculate lpt earned tokens
const lptEarned = formatBalance(delegatorNextReward, 2, 'wei')
const lptEarned = formatBalance(delegatorNextReward, earningDecimals, 'wei')

const dateYesterday = moment()
.subtract(1, 'days')
Expand Down
5 changes: 3 additions & 2 deletions server/helpers/sendTelegramClaimRewardCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const sendTelegramClaimRewardCall = async data => {
parse_mode: 'HTML'
})
console.log(
`[Telegram bot] - Telegram sended to chatId ${chatId} successfully. Body of the message: ${body}`
`[Telegram bot] - Telegram sent to chatId ${chatId} successfully. Body of the message: ${body}`
)
} catch (err) {
console.error(err)
Expand All @@ -43,6 +43,7 @@ const sendTelegramClaimRewardCall = async data => {
}

const getTelegramClaimRewardCallBody = async subscriber => {
const { earningDecimals } = config
const delegatorService = getDelegatorService()
const protocolService = getProtocolService()

Expand Down Expand Up @@ -73,7 +74,7 @@ const getTelegramClaimRewardCallBody = async subscriber => {
const earningNextReturn = await delegatorService.getDelegatorNextReward(delegator.address)

// Calculate earned lpt
const lptEarned = formatBalance(earningNextReturn, 2, 'wei')
const lptEarned = formatBalance(earningNextReturn, earningDecimals, 'wei')

const dateYesterday = moment()
.subtract(1, 'days')
Expand Down
2 changes: 1 addition & 1 deletion server/helpers/sendTelegramDidRewardCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const sendTelegramClaimRewardCall = async data => {
})

console.log(
`[Telegram bot] - Telegram sended to chatId ${chatId} successfully. Body of the message: ${body}`
`[Telegram bot] - Telegram sent to chatId ${chatId} successfully. Body of the message: ${body}`
)
bot = null
} catch (err) {
Expand Down

0 comments on commit a99d282

Please sign in to comment.