Skip to content

Commit

Permalink
chore(redux): convert modules/transferEth to slice (#6296)
Browse files Browse the repository at this point in the history
  • Loading branch information
mperdomo-bc committed Feb 22, 2024
1 parent 0608eb8 commit 7fc497d
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ import * as profile from './profile/actionTypes'
import * as rates from './rates/actionTypes'
import * as securityCenter from './securityCenter/actionTypes'
import * as settings from './settings/actionTypes'
import * as transferEth from './transferEth/actionTypes'

export { addressesBch, profile, rates, securityCenter, settings, transferEth }
export { addressesBch, profile, rates, securityCenter, settings }
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import * as profile from './profile/actions'
import * as rates from './rates/actions'
import * as securityCenter from './securityCenter/actions'
import * as settings from './settings/actions'
import * as transferEth from './transferEth/actions'
import { actions as transferEth } from './transferEth/transferEthSlice'

export { addressesBch, profile, rates, securityCenter, settings, transferEth }

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { takeLatest } from 'redux-saga/effects'

import * as AT from './actionTypes'
import sagas from './sagas'
import { actions } from './transferEthSlice'

export default ({ coreSagas, networks }) => {
const transferEthSagas = sagas({ coreSagas, networks })

return function* transferEthSaga() {
yield takeLatest(AT.CONFIRM_TRANSFER_ETH, transferEthSagas.confirmTransferEth)
yield takeLatest(AT.TRANSFER_ETH_INITIALIZED, transferEthSagas.initialized)
yield takeLatest(actions.confirmTransferEth, transferEthSagas.confirmTransferEth)
yield takeLatest(actions.transferEthInitialized, transferEthSagas.initialized)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import { actions } from 'data'
import * as C from 'services/alerts'
import { promptForSecondPassword } from 'services/sagas'

import * as A from './actions'
import * as S from './selectors'
import { actions as A } from './transferEthSlice'

export const logLocation = 'modules/transferEth/sagas'

export default ({ coreSagas, networks }) => {
const initialized = function* ({ payload }: ReturnType<typeof A.initialized>) {
const initialized = function* ({ payload }: ReturnType<typeof A.transferEthInitialized>) {
try {
yield put(A.transferEthPaymentUpdatedLoading())
let payment: EthPaymentType = coreSagas.payment.eth.create({
network: networks.eth
})
let payment: EthPaymentType = coreSagas.payment.eth.create({ network: networks.eth })
payment = yield payment.init({ coin: 'ETH' })
payment = yield payment.from(payload.from, payload.type)
yield put(A.transferEthPaymentUpdatedSuccess(payment.value()))
Expand All @@ -25,7 +23,7 @@ export default ({ coreSagas, networks }) => {
}
}

const confirmTransferEth = function* (action) {
const confirmTransferEth = function* (action: ReturnType<typeof A.confirmTransferEth>) {
try {
yield put(actions.form.startSubmit('transferEth'))
const { effectiveBalance, to } = action.payload
Expand All @@ -42,19 +40,11 @@ export default ({ coreSagas, networks }) => {
yield payment.publish()
yield put(actions.modals.closeAllModals())
yield put(actions.router.push('/coins/ETH'))
yield put(
actions.alerts.displaySuccess(C.SEND_COIN_SUCCESS, {
coinName: 'Ethereum'
})
)
yield put(actions.alerts.displaySuccess(C.SEND_COIN_SUCCESS, { coinName: 'Ethereum' }))
yield put(actions.form.stopSubmit('transferEth'))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'confirmTransferEth', e))
yield put(
actions.alerts.displayError(C.SEND_COIN_ERROR, {
coinName: 'Ethereum'
})
)
yield put(actions.alerts.displayError(C.SEND_COIN_ERROR, { coinName: 'Ethereum' }))
yield put(actions.form.stopSubmit('transferEth'))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'

import { Remote } from '@core'

import { TransferEthState } from './types'

const initialState: TransferEthState = {
payment: Remote.NotAsked
}

const trasnferEthSlice = createSlice({
initialState,
name: 'transferEth',
reducers: {
confirmTransferEth: (
state,
action: PayloadAction<{ effectiveBalance: string | number; to: string | number }>
) => {},
transferEthInitialized: (state, action: PayloadAction<{ from: string; type: 'LEGACY' }>) => {
state.payment = Remote.NotAsked
},
transferEthPaymentUpdatedFailure: (state, action) => {
state.payment = Remote.Failure(action.payload)
},
transferEthPaymentUpdatedLoading: (state) => {
state.payment = Remote.Loading
},
transferEthPaymentUpdatedSuccess: (state, action) => {
state.payment = Remote.Success(action.payload)
}
}
})

export const { actions } = trasnferEthSlice
export const transferEthReducer = trasnferEthSlice.reducer
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { modalReducer } from './modals/slice'
import profile from './modules/profile/reducers'
import rates from './modules/rates/reducers'
import securityCenter from './modules/settings/reducers'
import { transferEthReducer } from './modules/transferEth/reducers'
import { transferEthReducer } from './modules/transferEth/transferEthSlice'
import { networkConfigReducer as networkConfig } from './networkConfig/slice'
import { preferencesReducer } from './preferences/reducers'
import { pricesReducer as prices } from './prices/slice'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DEFAULTS = {

class TransferEthContainer extends React.PureComponent<Props> {
componentDidMount() {
this.props.transferEthActions.initialized({
this.props.transferEthActions.transferEthInitialized({
from: this.props.legacyEthAddr,
type: 'LEGACY'
})
Expand Down

0 comments on commit 7fc497d

Please sign in to comment.