Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(redux): convert preferences to redux slice #6297

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import * as components from './components/actionTypes'
import { actionTypes as form } from './form/actionTypes'
import * as middleware from './middleware/actionTypes'
import * as modules from './modules/actionTypes'
import * as preferences from './preferences/actionTypes'
import * as router from './router/actionTypes'
import * as wallet from './wallet/actionTypes'

export { components, core, form, middleware, modules, preferences, router, wallet }
export { components, core, form, middleware, modules, router, wallet }
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as ws from './middleware/webSocket/coins/actions'
import { actions as misc } from './misc/slice'
import { actions as modals } from './modals/slice'
import * as modules from './modules/actions'
import * as preferences from './preferences/actions'
import { actions as preferences } from './preferences/slice'
import { actions as prices } from './prices/slice'
import { actions as session } from './session/slice'
import { actions as signup } from './signup/slice'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,9 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne

const switchFix = function* ({ payload }: ReturnType<typeof A.switchFix>) {
yield put(actions.form.change(FORM_BS_CHECKOUT, 'fix', payload.fix))
yield put(actions.preferences.setBSCheckoutFix(payload.orderType, payload.fix))
yield put(
actions.preferences.setBSCheckoutFix({ fix: payload.fix, orderType: payload.orderType })
)
const newAmount = new BigNumber(payload.amount).isGreaterThan(0) ? payload.amount : undefined
yield put(actions.form.change(FORM_BS_CHECKOUT, 'amount', newAmount))
yield put(actions.form.focus(FORM_BS_CHECKOUT, 'amount'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'

import { CoinType, TimeRange } from '@core/types'

const initialState = {
import { CoinPayload, PriceChartType, TimePayload } from './types'

const initialState: PriceChartType = {
coin: 'BTC',
time: TimeRange.ALL
}

type CoinPayload = {
coin: CoinType
}

type InitializedPayload = {
coin: CoinType
time: TimeRange
}

type TimePayload = {
time: TimeRange
}

const priceChartSlice = createSlice({
initialState,
name: 'priceChart',
Expand All @@ -32,7 +21,7 @@ const priceChartSlice = createSlice({
},
initialized: {
prepare: (coin: CoinType, time: TimeRange) => ({ payload: { coin, time } }),
reducer: (state, action: PayloadAction<InitializedPayload>) => {
reducer: (state, action: PayloadAction<PriceChartType>) => {
state.coin = action.payload.coin
state.time = action.payload.time
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { CoinType, TimeRange } from '@core/types'

export type CoinPayload = {
coin: CoinType
}

export type TimePayload = {
time: TimeRange
}

export type PriceChartType = CoinPayload & TimePayload
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default () => {
const cookieLang = cookies.get('clang')
const lang = urlLang?.language || cookieLang
if (lang) {
yield put(actions.preferences.setLanguage(lang, false))
yield put(actions.preferences.setLanguage({ language: lang, showAlert: false }))
}
} catch (e) {
// do nothing, app will fallback to english
Expand Down

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,12 @@
import { takeLatest } from 'redux-saga/effects'

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

export default () => {
const preferencesSagas = sagas()

return function* preferencesSaga() {
yield takeLatest(AT.SET_LANGUAGE, preferencesSagas.setLanguage)
yield takeLatest(AT.SET_LINK_HANDLING, preferencesSagas.setLinkHandling)
yield takeLatest(actions.setLanguage, preferencesSagas.setLanguage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,7 @@ export default () => {
}
}

const setLinkHandling = function () {
// Register BTC links
// @ts-ignore
window.navigator.registerProtocolHandler('bitcoin', '/#/open/%s', 'Blockchain')

// Register BCH links
// @ts-ignore
window.navigator.registerProtocolHandler('web+bitcoincash', '/#/open/%s', 'Blockchain')
}

return {
setLanguage,
setLinkHandling
setLanguage
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import { TimeRange } from '@core/types'
import { RootState } from 'data/rootReducer'

export const getCoinDisplayed = (state: RootState) => state.preferences.coinDisplayed
export const getLanguage = (state: RootState) => state.preferences.language
export const getPriceChart = (state: RootState) => {
// 🆕 Migrate old time ranges
// 1day, 1week, 1month, 1year
// to
// day, week, month, year
if (state.preferences?.priceChart?.time?.includes('1')) {
return {
...state.preferences.priceChart,
time: state.preferences.priceChart.time.split('1')[1] as TimeRange
}
}
return state.preferences.priceChart
}
export const getBSCheckoutPreferences = (state: RootState) => state.preferences.sbCheckout
export const getShowAirdropClaimModal = (state: RootState) =>
state.preferences.showAirdropClaimModal
Expand Down
Loading
Loading