Skip to content

Commit c17ec05

Browse files
author
Alunara
committed
feat: add user profile (dev only)
1 parent 0ff91e9 commit c17ec05

File tree

102 files changed

+706
-410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+706
-410
lines changed

apps/dao/src/components/ConnectWallet.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isLoading } from '@/ui/utils'
22
import useStore from '@/store/useStore'
3+
import { useUserProfileStore } from '@ui-kit/features/user-profile'
34

45
import ConnectWalletPrompt from '@/ui/ConnectWalletPrompt'
56

@@ -12,7 +13,7 @@ type ConnectWalletProps = {
1213
const ConnectWallet: React.FC<ConnectWalletProps> = ({ description, connectText, loadingText }) => {
1314
const updateConnectWalletStateKeys = useStore((state) => state.wallet.updateConnectWalletStateKeys)
1415
const connectState = useStore((state) => state.connectState)
15-
const theme = useStore((state) => state.themeType)
16+
const { theme } = useUserProfileStore()
1617

1718
const loading = isLoading(connectState)
1819

apps/dao/src/hooks/usePageOnMount.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { helpers } from '@/lib/curvejs'
1414
import { isFailure, isLoading, isSuccess } from '@/ui/utils'
1515
import networks from '@/networks'
1616
import useStore from '@/store/useStore'
17+
import { useUserProfileStore } from '@ui-kit/features/user-profile'
1718

1819
function usePageOnMount(params: Params, location: Location, navigate: NavigateFunction, chainIdNotRequired?: boolean) {
1920
const [{ wallet }, connect, disconnect] = useConnectWallet()
@@ -26,6 +27,8 @@ function usePageOnMount(params: Params, location: Location, navigate: NavigateFu
2627
const updateCurveJs = useStore((state) => state.updateCurveJs)
2728
const updateGlobalStoreByKey = useStore((state) => state.updateGlobalStoreByKey)
2829

30+
const { setLocale } = useUserProfileStore()
31+
2932
const walletChainId = getWalletChainId(wallet)
3033
const walletSignerAddress = getWalletSignerAddress(wallet)
3134
const parsedParams = parseParams(params, chainIdNotRequired)
@@ -219,7 +222,8 @@ function usePageOnMount(params: Params, location: Location, navigate: NavigateFu
219222
let data = await import(`@/locales/${rLocale}/messages`)
220223
dynamicActivate(rLocale, data)
221224
})()
222-
updateAppLocale(rLocale, updateGlobalStoreByKey)
225+
setLocale(rLocale)
226+
updateAppLocale(rLocale)
223227
updateWalletLocale(rLocale)
224228
} else if (walletChainId && curve && curve.chainId === walletChainId && parsedParams.rChainId !== walletChainId) {
225229
// switch network if url network is not same as wallet

apps/dao/src/layout/Header.tsx

+4-13
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import useLayoutHeight from '@/hooks/useLayoutHeight'
1010
import useStore from '@/store/useStore'
1111
import { Header as NewHeader, useHeaderHeight } from '@/common/widgets/Header'
1212
import { NavigationSection } from '@/common/widgets/Header/types'
13-
import { ThemeKey } from 'curve-ui-kit/src/themes/basic-theme'
1413
import { APP_LINK } from '@ui-kit/shared/routes'
1514
import { GlobalBannerProps } from '@/ui/Banner/GlobalBanner'
15+
import { useUserProfileStore } from '@ui-kit/features/user-profile'
1616

1717
type HeaderProps = { sections: NavigationSection[]; BannerProps: GlobalBannerProps }
1818

@@ -27,19 +27,17 @@ export const Header = ({ sections, BannerProps }: HeaderProps) => {
2727
const connectState = useStore((state) => state.connectState)
2828
const isMdUp = useStore((state) => state.layout.isMdUp)
2929
const bannerHeight = useStore((state) => state.layoutHeight.globalAlert)
30-
const locale = useStore((state) => state.locale)
3130
const routerProps = useStore((state) => state.routerProps)
32-
const themeType = useStore((state) => state.themeType)
33-
const setAppCache = useStore((state) => state.setAppCache)
3431
const updateConnectState = useStore((state) => state.updateConnectState)
3532

33+
const { locale, theme, setTheme } = useUserProfileStore()
34+
3635
const { rLocalePathname } = getLocaleFromUrl()
3736
const { params: routerParams, location } = routerProps ?? {}
3837

3938
const routerNetwork = routerParams?.network ?? 'ethereum'
4039
const routerPathname = location?.pathname ?? ''
4140

42-
const theme = themeType == 'default' ? 'light' : (themeType as ThemeKey)
4341
return (
4442
<NewHeader<ChainId>
4543
networkName={rNetwork}
@@ -51,14 +49,7 @@ export const Header = ({ sections, BannerProps }: HeaderProps) => {
5149
() => _parseRouteAndIsActive(APP_LINK.dao.pages, rLocalePathname, routerPathname, routerNetwork),
5250
[rLocalePathname, routerNetwork, routerPathname],
5351
)}
54-
themes={[
55-
theme,
56-
useCallback(
57-
(selectedThemeType: ThemeKey) =>
58-
setAppCache('themeType', selectedThemeType == 'light' ? 'default' : selectedThemeType),
59-
[setAppCache],
60-
),
61-
]}
52+
themes={[theme, setTheme]}
6253
ChainProps={{
6354
theme,
6455
options: visibleNetworksList,

apps/dao/src/layout/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import useStore from '@/store/useStore'
1313

1414
import Header from '@/layout/Header'
1515
import { Footer } from 'curve-ui-kit/src/widgets/Footer'
16+
import { useUserProfileStore } from '@ui-kit/features/user-profile'
1617

1718
const BaseLayout = ({ children }: { children: React.ReactNode }) => {
1819
const [{ wallet }] = useConnectWallet()
@@ -23,7 +24,8 @@ const BaseLayout = ({ children }: { children: React.ReactNode }) => {
2324
const layoutHeight = useStore((state) => state.layoutHeight)
2425
const updateConnectState = useStore((state) => state.updateConnectState)
2526
const updateLayoutHeight = useStore((state) => state.updateLayoutHeight)
26-
const locale = useStore((state) => state.locale)
27+
28+
const { locale } = useUserProfileStore()
2729

2830
useEffect(() => {
2931
updateLayoutHeight('globalAlert', globalAlertHeight)

apps/dao/src/pages/_app.tsx

+11-15
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ThemeProvider } from 'curve-ui-kit/src/shared/ui/ThemeProvider'
1414

1515
import { dynamicActivate, initTranslation, updateAppLocale } from '@ui-kit/lib/i18n'
1616
import { connectWalletLocales, initOnboard } from '@ui-kit/features/connect-wallet'
17-
import { getLocaleFromUrl, getStorageValue } from '@/utils'
17+
import { getLocaleFromUrl } from '@/utils'
1818
import { getIsMobile, getPageWidthClassName, isSuccess } from '@/ui/utils'
1919
import { messages as messagesEn } from '@/locales/en/messages.js'
2020
import networks from '@/networks'
@@ -25,15 +25,14 @@ import usePageVisibleInterval from '@/hooks/usePageVisibleInterval'
2525
import Page from '@/layout'
2626
import GlobalStyle from '@/globalStyle'
2727
import { ChadCssProperties } from '@ui-kit/themes/typography'
28+
import { useUserProfileStore } from '@ui-kit/features/user-profile'
2829

2930
i18n.load({ en: messagesEn })
3031
i18n.activate('en')
3132

3233
function CurveApp({ Component }: AppProps) {
3334
const connectState = useStore((state) => state.connectState)
34-
const locale = useStore((state) => state.locale)
3535
const pageWidth = useStore((state) => state.layout.pageWidth)
36-
const themeType = useStore((state) => state.themeType)
3736
const setPageWidth = useStore((state) => state.layout.setLayoutWidth)
3837
const updateShowScrollButton = useStore((state) => state.updateShowScrollButton)
3938
const updateGlobalStoreByKey = useStore((state) => state.updateGlobalStoreByKey)
@@ -47,6 +46,8 @@ function CurveApp({ Component }: AppProps) {
4746
const onboard = useStore((state) => state.wallet.onboard)
4847
const isPageVisible = useStore((state) => state.isPageVisible)
4948

49+
const { locale, setLocale, theme } = useUserProfileStore()
50+
5051
const [appLoaded, setAppLoaded] = useState(false)
5152

5253
const handleResizeListener = useCallback(() => {
@@ -57,8 +58,8 @@ function CurveApp({ Component }: AppProps) {
5758
useEffect(() => {
5859
if (!pageWidth) return
5960

60-
document.body.className = `theme-${themeType} ${pageWidth} ${getIsMobile() ? '' : 'scrollSmooth'}`
61-
document.body.setAttribute('data-theme', themeType || '')
61+
document.body.className = `theme-${theme} ${pageWidth} ${getIsMobile() ? '' : 'scrollSmooth'}`
62+
document.body.setAttribute('data-theme', theme)
6263
document.documentElement.lang = locale
6364
})
6465

@@ -67,12 +68,6 @@ function CurveApp({ Component }: AppProps) {
6768
updateShowScrollButton(window.scrollY)
6869
}
6970

70-
const { themeType } = getStorageValue('APP_CACHE') ?? {}
71-
72-
// init theme
73-
const darkModeQuery = window.matchMedia('(prefers-color-scheme: dark)')
74-
updateGlobalStoreByKey('themeType', themeType ? themeType : darkModeQuery.matches ? 'dark' : 'default')
75-
7671
// init locale
7772
const { rLocale } = getLocaleFromUrl()
7873
const parsedLocale = rLocale?.value ?? 'en'
@@ -81,10 +76,11 @@ function CurveApp({ Component }: AppProps) {
8176
let data = await import(`@/locales/${parsedLocale}/messages`)
8277
dynamicActivate(parsedLocale, data)
8378
})()
84-
updateAppLocale(parsedLocale, updateGlobalStoreByKey)
79+
setLocale(parsedLocale)
80+
updateAppLocale(parsedLocale)
8581

8682
// init onboard
87-
const onboardInstance = initOnboard(connectWalletLocales, locale, themeType, networks)
83+
const onboardInstance = initOnboard(connectWalletLocales, locale, theme, networks)
8884
updateWalletStoreByKey('onboard', onboardInstance)
8985

9086
const handleVisibilityChange = () => {
@@ -148,8 +144,8 @@ function CurveApp({ Component }: AppProps) {
148144
)
149145

150146
return (
151-
<div suppressHydrationWarning style={{ ...(themeType === 'chad' && ChadCssProperties) }}>
152-
<ThemeProvider theme={themeType === 'default' ? 'light' : themeType}>
147+
<div suppressHydrationWarning style={{ ...(theme === 'chad' && ChadCssProperties) }}>
148+
<ThemeProvider theme={theme}>
153149
{typeof window === 'undefined' || !appLoaded ? null : (
154150
<HashRouter>
155151
<I18nProvider i18n={i18n}>

apps/dao/src/store/createAppSlice.ts

-27
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
import type { GetState, SetState } from 'zustand'
22
import type { State } from '@/store/useStore'
33
import type { ConnectState } from '@/ui/utils'
4-
import type { Locale } from '@ui-kit/lib/i18n'
54

65
import isEqual from 'lodash/isEqual'
76
import produce from 'immer'
87

98
import { log } from '@ui-kit/lib'
10-
import { setStorageValue } from '@/utils'
119

1210
export type DefaultStateKeys = keyof typeof DEFAULT_STATE
1311
export type SliceKey = keyof State | ''
1412
export type StateKey = string
15-
export type Theme = 'dark' | 'default' | 'chad'
1613
export type LayoutHeight = {
1714
globalAlert: number
1815
mainNav: number
1916
secondaryNav: number
2017
footer: number
2118
}
2219

23-
type AppCacheKeys = 'themeType'
24-
2520
type SliceState = {
2621
connectState: ConnectState
2722
curve: CurveApi | null
@@ -31,21 +26,16 @@ type SliceState = {
3126
isPageVisible: boolean
3227
layoutHeight: LayoutHeight
3328
loaded: boolean
34-
locale: Locale['value']
35-
maxSlippage: string
3629
routerProps: RouterProps | null
3730
showScrollButton: boolean
38-
themeType: Theme
3931
}
4032

4133
// prettier-ignore
4234
export interface AppSlice extends SliceState {
43-
setThemeType: (themeType: Theme) => void
4435
updateConnectState(status: ConnectState['status'], stage: ConnectState['stage'], options?: ConnectState['options']): void
4536
updateCurveJs(curveApi: CurveApi, prevCurveApi: CurveApi | null, wallet: Wallet | null): Promise<void>
4637
updateLayoutHeight: (key: keyof LayoutHeight, value: number | null) => void
4738
updateShowScrollButton(scrollY: number): void
48-
setAppCache<T>(key: AppCacheKeys, value: T): void
4939
updateGlobalStoreByKey: <T>(key: DefaultStateKeys, value: T) => void
5040

5141
setAppStateByActiveKey<T>(sliceKey: SliceKey, key: StateKey, activeKey: string, value: T, showLog?: boolean): void
@@ -62,31 +52,20 @@ const DEFAULT_STATE = {
6252
isLoadingCurve: true,
6353
isPageVisible: true,
6454
loaded: false,
65-
locale: 'en' as const,
6655
pageWidth: null,
6756
layoutHeight: {
6857
globalAlert: 0,
6958
mainNav: 0,
7059
secondaryNav: 0,
7160
footer: 0,
7261
},
73-
maxSlippage: '',
7462
routerProps: null,
7563
showScrollButton: false,
76-
themeType: 'default' as const,
7764
}
7865

7966
const createAppSlice = (set: SetState<State>, get: GetState<State>): AppSlice => ({
8067
...DEFAULT_STATE,
8168

82-
setThemeType: (themeType: Theme) => {
83-
set(
84-
produce((state: State) => {
85-
state.themeType = themeType
86-
}),
87-
)
88-
setStorageValue('APP_CACHE', { themeType })
89-
},
9069
updateConnectState: (
9170
status: ConnectState['status'],
9271
stage: ConnectState['stage'],
@@ -146,12 +125,6 @@ const createAppSlice = (set: SetState<State>, get: GetState<State>): AppSlice =>
146125
)
147126
}
148127
},
149-
setAppCache: <T>(key: AppCacheKeys, value: T) => {
150-
get().updateGlobalStoreByKey(key, value)
151-
setStorageValue('APP_CACHE', {
152-
themeType: key === 'themeType' ? value : get().themeType || 'default',
153-
})
154-
},
155128
updateGlobalStoreByKey: <T>(key: DefaultStateKeys, value: T) => {
156129
set(
157130
produce((state) => {

apps/dao/src/utils/utilsStorage.ts

-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { Theme } from '@/store/createAppSlice'
2-
31
import merge from 'lodash/merge'
42

53
import dayjs from '@ui-kit/lib/dayjs'
@@ -24,20 +22,12 @@ export function getStorageValue(key: Key) {
2422

2523
if (key === 'APP_CACHE') {
2624
return {
27-
themeType: getTheme(parsedStoredValue.themeType),
2825
timestamp: parsedStoredValue.timestamp ?? '',
2926
walletName: getWalletName(parsedStoredValue.walletName, parsedStoredValue.timestamp),
3027
}
3128
}
3229
}
3330

34-
function getTheme(svThemeType: string | undefined) {
35-
if (svThemeType) {
36-
const foundThemeType = ['default', 'dark', 'chad'].find((t) => t === svThemeType) as Theme
37-
return (foundThemeType || 'default') as Theme
38-
}
39-
}
40-
4131
function getWalletName(walletName: string | undefined, timestamp: string | undefined) {
4232
const isStaled = walletName && timestamp && dayjs().diff(+timestamp, 'days') > 5
4333
return isStaled || !walletName ? '' : walletName

apps/lend/src/components/AdvancedSettings.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Icon from '@/ui/Icon'
1717
import IconTooltip from '@/ui/Tooltip/TooltipIcon'
1818
import ModalDialog, { OpenDialogIconButton } from '@/ui/Dialog'
1919
import InputProvider, { InputField } from '@/ui/InputComp'
20+
import { useUserProfileStore } from '@ui-kit/features/user-profile'
2021

2122
type FormValues = {
2223
selected: string
@@ -57,13 +58,14 @@ function getDefaultFormValuesState(formValues: FormValues, propsMaxSlippage: str
5758
export const AdvancedSettings = ({ className, buttonIcon, maxSlippage }: React.PropsWithChildren<Props>) => {
5859
const overlayTriggerState = useOverlayTriggerState({})
5960
const isMobile = useStore((state) => state.isMobile)
60-
const updateGlobalStoreByKey = useStore((state) => state.updateGlobalStoreByKey)
61+
62+
const { setMaxSlippage } = useUserProfileStore()
6163

6264
const [formValues, setFormValues] = useState(DEFAULT_FORM_VALUES)
6365

6466
const handleSave = () => {
6567
const updatedCustomSlippage = formValues.selected === 'custom' ? formValues.customValue : formValues.selected
66-
updateGlobalStoreByKey('maxSlippage', updatedCustomSlippage)
68+
setMaxSlippage(updatedCustomSlippage)
6769
if (isMobile) {
6870
delayAction(overlayTriggerState.close)
6971
} else {

apps/lend/src/components/ChartOhlcWrapper/index.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ import PoolActivity from '@/components/ChartOhlcWrapper/PoolActivity'
1616
import TextCaption from '@/ui/TextCaption'
1717
import AlertBox from '@/ui/AlertBox'
1818
import { useOneWayMarket } from '@/entities/chain'
19+
import { useUserProfileStore } from '@ui-kit/features/user-profile'
1920

2021
const ChartOhlcWrapper: React.FC<ChartOhlcWrapperProps> = ({ rChainId, userActiveKey, rOwmId }) => {
2122
const market = useOneWayMarket(rChainId, rOwmId).data
22-
const isAdvanceMode = useStore((state) => state.isAdvanceMode)
23-
const themeType = useStore((state) => state.themeType)
2423
const borrowMoreActiveKey = useStore((state) => state.loanBorrowMore.activeKey)
2524
const loanRepayActiveKey = useStore((state) => state.loanRepay.activeKey)
2625
const loanCollateralAddActiveKey = useStore((state) => state.loanCollateralAdd.activeKey)
@@ -40,6 +39,8 @@ const ChartOhlcWrapper: React.FC<ChartOhlcWrapperProps> = ({ rChainId, userActiv
4039
(state) => state.loanCollateralRemove.detailInfo[loanCollateralRemoveActiveKey]?.prices ?? null,
4140
)
4241

42+
const { isAdvancedMode, theme } = useUserProfileStore()
43+
4344
const isMdUp = useStore((state) => state.layout.isMdUp)
4445
const {
4546
chartLlammaOhlc,
@@ -377,7 +378,7 @@ const ChartOhlcWrapper: React.FC<ChartOhlcWrapperProps> = ({ rChainId, userActiv
377378
chartStatus={currentChart.fetchStatus}
378379
chartHeight={chartHeight}
379380
chartExpanded={chartExpanded}
380-
themeType={themeType}
381+
themeType={theme}
381382
ohlcData={currentChart.data}
382383
volumeData={chartLlammaOhlc.volumeData}
383384
oraclePriceData={oraclePriceData}
@@ -405,7 +406,7 @@ const ChartOhlcWrapper: React.FC<ChartOhlcWrapperProps> = ({ rChainId, userActiv
405406
</LpEventsWrapperExpanded>
406407
</ExpandedWrapper>
407408
) : (
408-
<Wrapper className={!isAdvanceMode ? 'normal-mode' : ''} chartExpanded={chartExpanded}>
409+
<Wrapper className={!isAdvancedMode ? 'normal-mode' : ''} chartExpanded={chartExpanded}>
409410
<SelectorRow>
410411
<SelectorButton
411412
variant={'text'}
@@ -437,7 +438,7 @@ const ChartOhlcWrapper: React.FC<ChartOhlcWrapperProps> = ({ rChainId, userActiv
437438
chartStatus={currentChart.fetchStatus}
438439
chartHeight={chartHeight}
439440
chartExpanded={false}
440-
themeType={themeType}
441+
themeType={theme}
441442
ohlcData={currentChart.data}
442443
volumeData={chartLlammaOhlc.volumeData}
443444
oraclePriceData={oraclePriceData}

0 commit comments

Comments
 (0)