Skip to content

Commit

Permalink
feat - added translation support all existing alerts/toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyncee59 committed May 22, 2018
1 parent 1cc65ae commit 955414a
Show file tree
Hide file tree
Showing 21 changed files with 312 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'

import { actions, selectors } from 'data'
import Alerts from './template.js'

Expand Down

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions packages/blockchain-wallet-v4-frontend/src/data/auth/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Either from 'data.either'
import * as actions from '../actions.js'
import * as actionTypes from '../actionTypes.js'
import * as selectors from '../selectors.js'
import * as C from 'services/AlertService'
import { askSecondPasswordEnhancer, promptForSecondPassword, forceSyncWallet } from 'services/SagaService'
import { Types } from 'blockchain-wallet-v4/src'

Expand All @@ -30,7 +31,7 @@ export default ({ api, coreSagas }) => {
yield put(actions.modals.showModal('Welcome', { walletMillions }))
} else {
yield put(actions.logs.logInfoMessage(logLocation, 'welcomeSaga', 'login success'))
yield put(actions.alerts.displaySuccess('Login successful'))
yield put(actions.alerts.displaySuccess(C.LOGIN_SUCCESS))
}
}

Expand Down Expand Up @@ -75,7 +76,7 @@ export default ({ api, coreSagas }) => {
yield fork(reportStats, mobileLogin)
yield fork(logoutRoutine, yield call(setLogoutEventListener))
if (!firstLogin) {
yield put(actions.alerts.displaySuccess('Login successful'))
yield put(actions.alerts.displaySuccess(C.LOGIN_SUCCESS))
}
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'loginRoutineSaga', e))
Expand Down Expand Up @@ -124,7 +125,7 @@ export default ({ api, coreSagas }) => {

if (authRequired.isRight && authRequired.value) {
// auth errors (polling)
yield put(actions.alerts.displayInfo('Authorization required. Please check your mailbox.'))
yield put(actions.alerts.displayInfo(C.AUTHORIZATION_REQUIRED_INFO))
const authorized = yield call(pollingSession, session)
if (authorized) {
try {
Expand All @@ -133,7 +134,7 @@ export default ({ api, coreSagas }) => {
} catch (e) {
if (e.auth_type > 0) {
yield put(actions.auth.setAuthType(e.auth_type))
yield put(actions.alerts.displayInfo('2FA required'))
yield put(actions.alerts.displayInfo(C.TWOFA_REQUIRED_INFO))
yield put(actions.auth.loginFailure())
} else {
yield put(actions.auth.loginFailure('wrong_wallet_password'))
Expand All @@ -152,7 +153,7 @@ export default ({ api, coreSagas }) => {
// dispatch state change to show form
yield put(actions.auth.loginFailure())
yield put(actions.auth.setAuthType(error.auth_type))
yield put(actions.alerts.displayInfo('2FA required'))
yield put(actions.alerts.displayInfo(C.TWOFA_REQUIRED_INFO))
} else if (error.message) {
yield put(actions.auth.loginFailure(error.message))
} else {
Expand Down Expand Up @@ -181,40 +182,40 @@ export default ({ api, coreSagas }) => {
const register = function * (action) {
try {
yield put(actions.auth.registerLoading())
yield put(actions.alerts.displayInfo('Creating wallet...'))
yield put(actions.alerts.displayInfo(C.CREATE_WALLET_INFO))
yield call(coreSagas.wallet.createWalletSaga, action.payload)
yield put(actions.alerts.displaySuccess('Wallet successfully created.'))
yield put(actions.alerts.displaySuccess(C.REGISTER_SUCCESS))
yield call(loginRoutineSaga, false, true)
yield put(actions.auth.registerSuccess())
} catch (e) {
yield put(actions.auth.registerFailure(e))
yield put(actions.logs.logErrorMessage(logLocation, 'register', e))
yield put(actions.alerts.displayError('Wallet could not be created.'))
yield put(actions.alerts.displayError(C.REGISTER_ERROR))
}
}

const restore = function * (action) {
try {
yield put(actions.auth.restoreLoading())
yield put(actions.alerts.displayInfo('Restoring wallet...'))
yield put(actions.alerts.displayInfo(C.RESTORE_WALLET_INFO))
yield call(coreSagas.wallet.restoreWalletSaga, action.payload)
yield put(actions.alerts.displaySuccess('Your wallet has been successfully restored.'))
yield put(actions.alerts.displaySuccess(C.RESTORE_SUCCESS))
yield call(loginRoutineSaga, false, true)
yield put(actions.auth.restoreSuccess())
} catch (e) {
yield put(actions.auth.restoreFailure())
yield put(actions.logs.logErrorMessage(logLocation, 'restore', e))
yield put(actions.alerts.displayError('Error restoring your wallet.'))
yield put(actions.alerts.displayError(C.RESTORE_ERROR))
}
}

const remindGuid = function * (action) {
try {
yield call(coreSagas.wallet.remindWalletGuidSaga, action.payload)
yield put(actions.alerts.displaySuccess('Your wallet guid has been sent to your email address.'))
yield put(actions.alerts.displaySuccess(C.GUID_SENT_SUCCESS))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'remindGuid', e))
yield put(actions.alerts.displayError('Error sending email.'))
yield put(actions.alerts.displayError(C.GUID_SENT_ERROR))
}
}

Expand All @@ -224,7 +225,7 @@ export default ({ api, coreSagas }) => {
const response = yield call(coreSagas.wallet.resetWallet2fa, action.payload)
if (response.success) {
yield put(actions.auth.reset2faSuccess())
yield put(actions.alerts.displayInfo('Reset 2-step authentication has been successfully submitted.'))
yield put(actions.alerts.displayInfo(C.RESET_TWOFA_INFO))
} else {
yield put(actions.core.data.misc.fetchCaptcha())
yield put(actions.auth.reset2faFailure())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as A from './actions'
import * as S from './selectors'
import * as actions from '../../actions'
import * as selectors from '../../selectors'
import * as C from 'services/AlertService'
import { promptForSecondPassword } from 'services/SagaService'
import { getCoinFromPair, getPairFromCoin, getMinimum, getMaximum,
convertStandardToBase, isAmountBelowMinimum, isAmountAboveMaximum, calculateFinalAmount, selectFee,
Expand Down Expand Up @@ -267,7 +268,7 @@ export default ({ api, coreSagas }) => {
// We update the payment in the state
yield put(A.secondStepPaymentSent(paymentValue))
} catch (e) {
yield put(actions.alerts.displayError('The transaction failed to send. Please try again later.'))
yield put(actions.alerts.displayError(C.EXCHANGE_TRANSACTION_ERROR))
yield put(actions.logs.logErrorMessage(logLocation, 'secondStepSubmitClicked', e))
}
}
Expand Down Expand Up @@ -301,7 +302,7 @@ export default ({ api, coreSagas }) => {
}
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'startPollingTradeStatus', e))
yield put(actions.alerts.displayError('Failed to refresh trade status.'))
yield put(actions.alerts.displayError(C.EXCHANGE_REFRESH_TRADE_ERROR))
} finally {
if (yield cancelled()) {
yield put(actions.logs.logInfoMessage(logLocation, 'startPollingTradeStatus', 'trade polling cancelled'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { cancel, call, fork, put, race, select, take } from 'redux-saga/effects'
import { delay } from 'redux-saga'
import { any, equals, identity, isNil, path, prop } from 'ramda'
import { actions, actionTypes, selectors } from 'data'
import * as C from 'services/AlertService'

export default ({ api, coreSagas }) => {
const logLocation = 'components/exchangeHistory/sagas'
Expand Down Expand Up @@ -44,13 +45,12 @@ export default ({ api, coreSagas }) => {
})
}
} catch (e) {
const orderId = path(['quote', 'orderId'], trade)
yield put(actions.alerts.displayError(`Could not fetch trade [${orderId}] status.`))
yield put(actions.alerts.displayError(C.EXCHANGE_REFRESH_TRADE_ERROR))
yield put(actions.logs.logErrorMessage(logLocation, 'exchangeHistoryInitialized', e))
}
}
} catch (e) {
yield put(actions.alerts.displayError(`Could not fetch all trades statuses.`))
yield put(actions.alerts.displayError(C.EXCHANGE_REFRESH_TRADES_ERROR))
yield put(actions.logs.logErrorMessage(logLocation, 'exchangeHistoryInitialized', e))
}
}
Expand All @@ -62,7 +62,7 @@ export default ({ api, coreSagas }) => {
yield call(delay, 5000)
}
} catch (e) {
yield put(actions.alerts.displayError('Unable to poll for trade status.'))
yield put(actions.alerts.displayError(C.EXCHANGE_REFRESH_TRADE_ERROR))
yield put(actions.logs.logErrorMessage(logLocation, 'startPollingTradeStatus', e))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { call, select, put } from 'redux-saga/effects'
import { identity, prop } from 'ramda'
import { formValueSelector } from 'redux-form'
import * as actions from '../../actions'
import * as C from 'services/AlertService'
import { promptForSecondPassword, promptForInput } from 'services/SagaService'
import settings from 'config'
import { utils } from 'blockchain-wallet-v4/src'
Expand Down Expand Up @@ -31,13 +32,13 @@ export default ({ api, coreSagas }) => {
.sign(password)
.publish()
.done()
yield put(actions.alerts.displaySuccess(`Swept address funds to ${to.label}`))
yield put(actions.alerts.displaySuccess(C.SWEEP_SUCCESS, { label: to.label }))
} catch (error) {
yield put(actions.logs.logErrorMessage(logLocation, 'sweepImportedToAccount', error))
if (error.message === 'empty_addresses') {
yield put(actions.alerts.displaySuccess('The imported address does not have funds.'))
yield put(actions.alerts.displaySuccess(C.SWEEP_ERROR_EMPTY_ADDRESS))
} else {
yield put(actions.alerts.displayError('Could not sweep address.'))
yield put(actions.alerts.displayError(C.SWEEP_ERROR))
}
}
}
Expand All @@ -50,28 +51,28 @@ export default ({ api, coreSagas }) => {
try {
const key = priv || address
yield call(coreSagas.wallet.importLegacyAddress, { key, password, bipPass })
yield put(actions.alerts.displaySuccess('Address added succesfully.'))
yield put(actions.alerts.displaySuccess(C.IMPORT_LEGACY_SUCCESS))
yield sweepImportedToAccount(priv, to, password)
yield call(coreSagas.wallet.refetchContextData)
yield put(actions.modals.closeAllModals())
} catch (error) {
yield put(actions.logs.logErrorMessage(`${logLocation} importLegacyAddress`, error))
switch (error.message) {
case 'present_in_wallet':
yield put(actions.alerts.displayError('This address already exists in your wallet.'))
yield put(actions.alerts.displayError(C.ADDRESS_DOES_NOT_EXIST_ERROR))
break
case 'unknown_key_format':
yield put(actions.alerts.displayError('This address format is not supported.'))
yield put(actions.alerts.displayError(C.ADDRESS_FORMAT_NOT_SUPPORTED_ERROR))
break
case 'wrong_bip38_pass':
yield put(actions.alerts.displayError('Incorrect BIP38 password.'))
yield put(actions.alerts.displayError(C.INCORRECT_BIP38_PASSWORD_ERROR))
break
case 'needs_bip38':
let bipPass = yield call(promptForInput, { title: 'Enter BIP38 Password', secret: true })
yield call(importLegacyAddress, address, priv, password, bipPass, to)
break
default:
yield put(actions.alerts.displayError('Error adding address.'))
yield put(actions.alerts.displayError(C.ADDRESS_ADD_ERROR))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as actions from '../../actions'
import * as selectors from '../../selectors'
import settings from 'config'
import { initialize, change } from 'redux-form'
import * as C from 'services/AlertService'
import { promptForSecondPassword } from 'services/SagaService'
import { Exchange, Remote } from 'blockchain-wallet-v4/src'

Expand Down Expand Up @@ -125,10 +126,10 @@ export default ({ coreSagas }) => {
payment = yield payment.publish()
yield put(A.sendBchPaymentUpdated(Remote.of(payment.value())))
yield put(actions.router.push('/bch/transactions'))
yield put(actions.alerts.displaySuccess('Your bitcoin cash transaction is now pending.'))
yield put(actions.alerts.displaySuccess(C.SEND_BCH_SUCCESS))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'secondStepSubmitClicked', e))
yield put(actions.alerts.displayError('Your bitcoin cash transaction failed to send. Please try again.'))
yield put(actions.alerts.displayError(C.SEND_BCH_ERROR))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as S from './selectors'
import * as actions from '../../actions'
import * as selectors from '../../selectors'
import settings from 'config'

import { initialize, change } from 'redux-form'
import * as C from 'services/AlertService'
import { promptForSecondPassword } from 'services/SagaService'
import { Exchange, Remote } from 'blockchain-wallet-v4/src'

Expand Down Expand Up @@ -208,10 +208,10 @@ export default ({ coreSagas }) => {
yield put(actions.core.wallet.setTransactionNote(payment.value().txId, payment.value().description))
}
yield put(actions.router.push('/btc/transactions'))
yield put(actions.alerts.displaySuccess('Your bitcoin has been sent!'))
yield put(actions.alerts.displaySuccess(C.SEND_BTC_SUCCESS))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'secondStepSubmitClicked', e))
yield put(actions.alerts.displayError('Failed to send bitcoin.'))
yield put(actions.alerts.displayError(C.SEND_BTC_ERROR))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as S from './selectors'
import * as actions from '../../actions'
import * as selectors from '../../selectors'
import settings from 'config'

import { initialize, change } from 'redux-form'
import * as C from 'services/AlertService'
import { promptForSecondPassword } from 'services/SagaService'
import { Exchange, Remote } from 'blockchain-wallet-v4/src'

Expand Down Expand Up @@ -101,10 +101,10 @@ export default ({ coreSagas }) => {
payment = yield payment.publish()
yield put(A.sendEthPaymentUpdated(Remote.of(payment.value())))
yield put(actions.router.push('/eth/transactions'))
yield put(actions.alerts.displaySuccess('Your ether transaction is now pending.'))
yield put(actions.alerts.displaySuccess(C.SEND_ETH_SUCCESS))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'secondStepSubmitClicked', e))
yield put(actions.alerts.displayError('Your ether transaction failed to send. Please try again.'))
yield put(actions.alerts.displayError(C.SEND_ETH_ERROR))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { put, call, select } from 'redux-saga/effects'
import * as A from './actions.js'
import * as actions from '../../actions.js'
import * as selectors from '../../selectors.js'

import * as C from 'services/AlertService'
import { promptForSecondPassword } from 'services/SagaService'
import { Types } from 'blockchain-wallet-v4/src'
import * as signer from 'blockchain-wallet-v4/src/signer'
Expand All @@ -23,7 +23,7 @@ export default ({ coreSagas }) => {
yield put(A.messageSigned(signed))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'signMessage', e))
yield put(actions.alerts.displayError('Failed to sign message.'))
yield put(actions.alerts.displayError(C.MESSAGE_SIGN_ERROR))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { call, put } from 'redux-saga/effects'
import * as actions from '../../actions.js'
import * as C from 'services/AlertService'
import { promptForInput } from 'services/SagaService'

export default ({ coreSagas }) => {
Expand All @@ -10,11 +11,11 @@ export default ({ coreSagas }) => {
const { index, label } = action.payload
const newLabel = yield call(promptForInput, { title: 'Rename Bitcoin Cash Wallet', initial: label })
yield put(actions.core.kvStore.bch.setAccountLabel(index, newLabel))
yield put(actions.alerts.displaySuccess('BCH wallet name updated.'))
yield put(actions.alerts.displaySuccess(C.RENAME_BCH_WALLET_SUCCESS))
} catch (e) {
if (e.message === 'PROMPT_INPUT_CANCEL') return
yield put(actions.logs.logErrorMessage(logLocation, 'editBchAccountLabel', e))
yield put(actions.alerts.displayError('Failed to update Bitcoin Cash account label.'))
yield put(actions.alerts.displayError(C.RENAME_BCH_WALLET_ERROR))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as A from './actions'
import * as actions from '../../actions'
import * as selectors from '../../selectors.js'
import { merge, path, prop, equals, head } from 'ramda'
import * as C from 'services/AlertService'
import * as service from 'services/CoinifyService'

export default ({ coreSagas }) => {
Expand All @@ -21,7 +22,7 @@ export default ({ coreSagas }) => {
}
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'coinifySignup', e))
yield put(actions.alerts.displayError('Failed to create Coinify account.'))
yield put(actions.alerts.displayError(C.COINIFY_SIGNUP_ERROR))
}
}

Expand Down

0 comments on commit 955414a

Please sign in to comment.