import { createSlice as e } from "@reduxjs/toolkit"
import {
PROFILE_SECTIONS as t,
UI_STATE_KEY as o,
UI_USER_PROFILE_STATE_KEY as r,
} from "./ui.constants"
import { last as s } from "../lib/array"
export const USER_PROFILE_INITIAL_STATE = {
currentSection: { section: t.ROOT, params: null },
sectionsStack: [],
sections: {
wallet: { config: null, balance: null, transactions: [], loading: !1, error: "" },
developers: { visible: !1 },
updates: { visible: !1 },
software: {
appName: "",
appVersion: "",
platformVersion: "",
runtimes: {},
dependencies: null,
},
},
}
export const uiUserProfileSlice = e({
name: r,
initialState: USER_PROFILE_INITIAL_STATE,
reducers: {
setProfileCurrentSection: (e, { payload: o }) => {
const r =
"string" == typeof o ? { section: o, params: null } : { ...e.currentSection, ...(o || {}) }
;((e.currentSection = r),
(e.sectionsStack = r.section === t.ROOT ? [] : [...e.sectionsStack, r]))
},
profileGoBack: (e) => {
const o = e.sectionsStack.slice(0, -1),
r = s(o)
r && r.section !== t.ROOT
? ((e.sectionsStack = o), (e.currentSection = r))
: ((e.sectionsStack = USER_PROFILE_INITIAL_STATE.sectionsStack),
(e.currentSection = USER_PROFILE_INITIAL_STATE.currentSection))
},
setProfileWalletConfig: (e, { payload: t }) => {
e.sections.wallet.config = t
},
setProfileWalletLoading: (e, { payload: t }) => {
e.sections.wallet.loading = t
},
setProfileWalletError: (e, { payload: t }) => {
e.sections.wallet.error = t
},
setProfileWalletBalance: (e, { payload: t }) => {
e.sections.wallet.balance = t
},
setProfileWalletTransactions: (e, { payload: t }) => {
e.sections.wallet.transactions = t || []
},
setProfileSoftwareVersion: (e, { payload: t }) => {
;((e.sections.software.appName = t.appName || ""),
(e.sections.software.appVersion = t.appVersion || ""),
(e.sections.software.platformVersion = t.platformVersion || ""),
(e.sections.software.runtimes = t.runtimes || {}))
},
setProfileSoftwareDependencies: (e, { payload: t }) => {
e.sections.software.dependencies = t
},
},
})
export const getUserProfile = (e) => e[o][r]
export const getProfileCurrentSection = (e) => getUserProfile(e).currentSection
export const getProfileWalletConfig = (e) => getUserProfile(e).sections.wallet.config
export const getProfileWalletLoading = (e) => getUserProfile(e).sections.wallet.loading
export const getProfileWalletBalance = (e) => getUserProfile(e).sections.wallet.balance
export const getProfileWalletTransactions = (e) => getUserProfile(e).sections.wallet.transactions
export const getProfileWalletError = (e) => getUserProfile(e).sections.wallet.error
export const getProfileDevelopersVisible = (e) => getUserProfile(e).sections.developers.visible
export const getProfileUpdatesVisible = (e) => getUserProfile(e).sections.updates.visible
export const getProfileSoftwareVersion = (e) => getUserProfile(e).sections.software
export const {
profileGoBack: profileGoBack,
setProfileCurrentSection: setProfileCurrentSection,
setProfileWalletConfig: setProfileWalletConfig,
setProfileWalletError: setProfileWalletError,
setProfileWalletLoading: setProfileWalletLoading,
setProfileWalletBalance: setProfileWalletBalance,
setProfileWalletTransactions: setProfileWalletTransactions,
setProfileSoftwareVersion: setProfileSoftwareVersion,
setProfileSoftwareDependencies: setProfileSoftwareDependencies,
} = uiUserProfileSlice.actions
export const getUserProfileInitialState = uiUserProfileSlice.getInitialState
export const userProfileReducer = uiUserProfileSlice.reducer