Skip to content

Commit ae0cf3b

Browse files
authored
Merge pull request #589 from curvefi/feat/user-profile
feat: user profile
2 parents 92e24fa + 366f1c9 commit ae0cf3b

File tree

105 files changed

+745
-481
lines changed

Some content is hidden

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

105 files changed

+745
-481
lines changed

apps/dao/src/components/ConnectWallet.tsx

Lines changed: 2 additions & 1 deletion
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((state) => state.theme)
1617

1718
const loading = isLoading(connectState)
1819

apps/dao/src/hooks/usePageOnMount.ts

Lines changed: 5 additions & 1 deletion
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((state) => state.setLocale)
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

Lines changed: 3 additions & 15 deletions
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,41 +27,29 @@ 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 = useUserProfileStore((state) => state.locale)
34+
3635
const location = useLocation()
3736
const { rLocalePathname } = getLocaleFromUrl()
3837
const { params: routerParams } = routerProps ?? {}
3938

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

43-
const theme = themeType == 'default' ? 'light' : (themeType as ThemeKey)
4442
return (
4543
<NewHeader<ChainId>
4644
networkName={rNetwork}
4745
mainNavRef={mainNavRef}
48-
locale={locale}
4946
isMdUp={isMdUp}
5047
currentApp="dao"
5148
pages={useMemo(
5249
() => _parseRouteAndIsActive(APP_LINK.dao.pages, rLocalePathname, routerPathname, routerNetwork),
5350
[rLocalePathname, routerNetwork, routerPathname],
5451
)}
55-
themes={[
56-
theme,
57-
useCallback(
58-
(selectedThemeType: ThemeKey) =>
59-
setAppCache('themeType', selectedThemeType == 'light' ? 'default' : selectedThemeType),
60-
[setAppCache],
61-
),
62-
]}
6352
ChainProps={{
64-
theme,
6553
options: visibleNetworksList,
6654
disabled: isLoading(connectState, CONNECT_STAGE.SWITCH_NETWORK),
6755
chainId: rChainId,

apps/dao/src/layout/index.tsx

Lines changed: 3 additions & 1 deletion
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((state) => state.locale)
2729

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

apps/dao/src/pages/_app.tsx

Lines changed: 13 additions & 15 deletions
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,10 @@ function CurveApp({ Component }: AppProps) {
4746
const onboard = useStore((state) => state.wallet.onboard)
4847
const isPageVisible = useStore((state) => state.isPageVisible)
4948

49+
const theme = useUserProfileStore((state) => state.theme)
50+
const locale = useUserProfileStore((state) => state.locale)
51+
const setLocale = useUserProfileStore((state) => state.setLocale)
52+
5053
const [appLoaded, setAppLoaded] = useState(false)
5154

5255
const handleResizeListener = useCallback(() => {
@@ -57,8 +60,8 @@ function CurveApp({ Component }: AppProps) {
5760
useEffect(() => {
5861
if (!pageWidth) return
5962

60-
document.body.className = `theme-${themeType} ${pageWidth} ${getIsMobile() ? '' : 'scrollSmooth'}`
61-
document.body.setAttribute('data-theme', themeType || '')
63+
document.body.className = `theme-${theme} ${pageWidth} ${getIsMobile() ? '' : 'scrollSmooth'}`
64+
document.body.setAttribute('data-theme', theme)
6265
document.documentElement.lang = locale
6366
})
6467

@@ -67,12 +70,6 @@ function CurveApp({ Component }: AppProps) {
6770
updateShowScrollButton(window.scrollY)
6871
}
6972

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-
7673
// init locale
7774
const { rLocale } = getLocaleFromUrl()
7875
const parsedLocale = rLocale?.value ?? 'en'
@@ -81,10 +78,11 @@ function CurveApp({ Component }: AppProps) {
8178
let data = await import(`@/locales/${parsedLocale}/messages`)
8279
dynamicActivate(parsedLocale, data)
8380
})()
84-
updateAppLocale(parsedLocale, updateGlobalStoreByKey)
81+
setLocale(parsedLocale)
82+
updateAppLocale(parsedLocale)
8583

8684
// init onboard
87-
const onboardInstance = initOnboard(connectWalletLocales, locale, themeType, networks)
85+
const onboardInstance = initOnboard(connectWalletLocales, locale, theme, networks)
8886
updateWalletStoreByKey('onboard', onboardInstance)
8987

9088
const handleVisibilityChange = () => {
@@ -148,8 +146,8 @@ function CurveApp({ Component }: AppProps) {
148146
)
149147

150148
return (
151-
<div suppressHydrationWarning style={{ ...(themeType === 'chad' && ChadCssProperties) }}>
152-
<ThemeProvider theme={themeType === 'default' ? 'light' : themeType}>
149+
<div suppressHydrationWarning style={{ ...(theme === 'chad' && ChadCssProperties) }}>
150+
<ThemeProvider theme={theme}>
153151
{typeof window === 'undefined' || !appLoaded ? null : (
154152
<HashRouter>
155153
<I18nProvider i18n={i18n}>

apps/dao/src/store/createAppSlice.ts

Lines changed: 0 additions & 27 deletions
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

Lines changed: 0 additions & 10 deletions
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

Lines changed: 4 additions & 2 deletions
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((state) => state.setMaxSlippage)
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

Lines changed: 7 additions & 5 deletions
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,9 @@ const ChartOhlcWrapper: React.FC<ChartOhlcWrapperProps> = ({ rChainId, userActiv
4039
(state) => state.loanCollateralRemove.detailInfo[loanCollateralRemoveActiveKey]?.prices ?? null,
4140
)
4241

42+
const theme = useUserProfileStore((state) => state.theme)
43+
const isAdvancedMode = useUserProfileStore((state) => state.isAdvancedMode)
44+
4345
const isMdUp = useStore((state) => state.layout.isMdUp)
4446
const {
4547
chartLlammaOhlc,
@@ -377,7 +379,7 @@ const ChartOhlcWrapper: React.FC<ChartOhlcWrapperProps> = ({ rChainId, userActiv
377379
chartStatus={currentChart.fetchStatus}
378380
chartHeight={chartHeight}
379381
chartExpanded={chartExpanded}
380-
themeType={themeType}
382+
themeType={theme}
381383
ohlcData={currentChart.data}
382384
volumeData={chartLlammaOhlc.volumeData}
383385
oraclePriceData={oraclePriceData}
@@ -405,7 +407,7 @@ const ChartOhlcWrapper: React.FC<ChartOhlcWrapperProps> = ({ rChainId, userActiv
405407
</LpEventsWrapperExpanded>
406408
</ExpandedWrapper>
407409
) : (
408-
<Wrapper className={!isAdvanceMode ? 'normal-mode' : ''} chartExpanded={chartExpanded}>
410+
<Wrapper className={isAdvancedMode ? '' : 'normal-mode'} chartExpanded={chartExpanded}>
409411
<SelectorRow>
410412
<SelectorButton
411413
variant={'text'}
@@ -437,7 +439,7 @@ const ChartOhlcWrapper: React.FC<ChartOhlcWrapperProps> = ({ rChainId, userActiv
437439
chartStatus={currentChart.fetchStatus}
438440
chartHeight={chartHeight}
439441
chartExpanded={false}
440-
themeType={themeType}
442+
themeType={theme}
441443
ohlcData={currentChart.data}
442444
volumeData={chartLlammaOhlc.volumeData}
443445
oraclePriceData={oraclePriceData}

0 commit comments

Comments
 (0)