Skip to content

Commit

Permalink
Merge branch 'main' of github.com:curvefi/curve-frontend into feat/mi…
Browse files Browse the repository at this point in the history
…nt-markets
  • Loading branch information
DanielSchiavini committed Jan 27, 2025
2 parents e7f5dc5 + ffd96b9 commit 4ff3b7c
Show file tree
Hide file tree
Showing 25 changed files with 172 additions and 189 deletions.
2 changes: 1 addition & 1 deletion apps/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"typescript": "*"
},
"dependencies": {
"@curvefi/api": "^2.65.29",
"@curvefi/api": "^2.66.1",
"@curvefi/lending-api": "^2.4.1",
"@curvefi/stablecoin-api": "^1.5.8",
"@hookform/error-message": "^2.0.1",
Expand Down
29 changes: 8 additions & 21 deletions apps/main/src/dao/store/createAppSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export interface AppSlice extends SliceState {
updateShowScrollButton(scrollY: number): void
updateGlobalStoreByKey: <T>(key: DefaultStateKeys, value: T) => void

setAppStateByActiveKey<T>(sliceKey: SliceKey, key: StateKey, activeKey: string, value: T, showLog?: boolean): void
setAppStateByKey<T>(sliceKey: SliceKey, key: StateKey, value: T, showLog?: boolean): void
setAppStateByKeys<T>(sliceKey: SliceKey, sliceState: Partial<T>, showLog?: boolean): void
resetAppState<T>(sliceKey: SliceKey, defaultState: T, showLog?: boolean): void
setAppStateByActiveKey<T>(sliceKey: SliceKey, key: StateKey, activeKey: string, value: T): void
setAppStateByKey<T>(sliceKey: SliceKey, key: StateKey, value: T): void
setAppStateByKeys<T>(sliceKey: SliceKey, sliceState: Partial<T>): void
resetAppState<T>(sliceKey: SliceKey, defaultState: T): void
}

const DEFAULT_STATE = {
Expand Down Expand Up @@ -134,54 +134,41 @@ const createAppSlice = (set: SetState<State>, get: GetState<State>): AppSlice =>
)
},

setAppStateByActiveKey: <T>(sliceKey: SliceKey, key: StateKey, activeKey: string, value: T, showLog?: boolean) => {
setAppStateByActiveKey: <T>(sliceKey: SliceKey, key: StateKey, activeKey: string, value: T) => {
set(
produce((state) => {
const storedValues = state[sliceKey][key]
const storedActiveKeyValues = storedValues[activeKey]
if (typeof storedValues === 'undefined') {
const parsedValue = { [activeKey]: value }
if (!isEqual(storedActiveKeyValues, parsedValue)) {
if (showLog) {
log(`%c state: ${key}`, 'background: #222; color: #bada55', parsedValue)
}
state[sliceKey][key] = parsedValue
}
} else if (typeof storedValues === 'object') {
const parsedValue = { ...storedValues, [activeKey]: value }
if (!isEqual(storedActiveKeyValues, parsedValue)) {
if (showLog) {
log(`%c state: ${key}`, 'background: #222; color: #bada55', parsedValue)
}
state[sliceKey][key] = parsedValue
}
}
}),
)
},
setAppStateByKey: <T>(sliceKey: SliceKey, key: StateKey, value: T, showLog?: boolean) => {
setAppStateByKey: <T>(sliceKey: SliceKey, key: StateKey, value: T) => {
set(
produce((state) => {
const storedValue = state[sliceKey][key]
if (!isEqual(storedValue, value)) {
if (showLog) {
log(`%c state: ${key}`, 'background: #222; color: #bada55', value)
}
state[sliceKey][key] = value
}
}),
)
},
setAppStateByKeys: <T>(sliceKey: SliceKey, sliceState: T, showLog?: boolean) => {
setAppStateByKeys: <T>(sliceKey: SliceKey, sliceState: T) => {
for (const key in sliceState) {
const value = sliceState[key]
set(
produce((state) => {
const storedValue = state[sliceKey][key]
if (!isEqual(storedValue, value)) {
if (showLog) {
log(`%c state: ${key}`, 'background: #222; color: #bada55', value)
}
if (!isEqual(state[sliceKey][key], value)) {
state[sliceKey][key] = value
}
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/main/src/dex/components/PageCreatePool/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export const STABLESWAP_MIN_MAX_PARAMETERS = (swapFee: number) => ({
},
a: {
min: 1,
max: 5000,
max: 20000,
},
maExpTime: {
min: 60,
Expand Down
111 changes: 50 additions & 61 deletions apps/main/src/dex/components/PagePoolList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const PoolList = ({
const fetchPoolsRewardsApy = useStore((state) => state.pools.fetchPoolsRewardsApy)
const setFormValues = useStore((state) => state.poolList.setFormValues)
const { initCampaignRewards, initiated } = useStore((state) => state.campaigns)
const provider = useStore((state) => state.wallet.getProvider(''))
const network = useStore((state) => state.networks.networks[rChainId])

const [showDetail, setShowDetail] = useState('')
Expand Down Expand Up @@ -183,71 +182,61 @@ const PoolList = ({
updatePath={updatePath}
/>

{!provider ? (
<ConnectWalletWrapper>
<ConnectWallet
description={t`Connect wallet to view pool list`}
connectText={t`Connect Wallet`}
loadingText={t`Connecting`}
<Table cellPadding={0} cellSpacing={0}>
{isXSmDown ? (
<TableHeadMobile showInPoolColumn={showInPoolColumn} />
) : (
<TableHead
columnKeys={columnKeys}
isLite={isLite}
isReadyRewardsApy={!!rewardsApyMapper}
isReadyTvl={!!tvlMapper}
isReadyVolume={!!volumeMapper}
searchParams={searchParams}
tableLabels={tableLabels}
updatePath={updatePath}
/>
</ConnectWalletWrapper>
) : (
<Table cellPadding={0} cellSpacing={0}>
{isXSmDown ? (
<TableHeadMobile showInPoolColumn={showInPoolColumn} />
) : (
<TableHead
columnKeys={columnKeys}
isLite={isLite}
isReadyRewardsApy={!!rewardsApyMapper}
isReadyTvl={!!tvlMapper}
isReadyVolume={!!volumeMapper}
)}
<Tbody $borderBottom>
{isReadyWithApiData && formStatus.noResult ? (
<TableRowNoResult
colSpan={colSpan}
searchParams={searchParams}
tableLabels={tableLabels}
signerAddress={signerAddress}
updatePath={updatePath}
/>
) : isReady && Array.isArray(result) ? (
<>
{result.map((poolId: string, index: number) => (
<PoolRow
key={poolId}
index={index}
columnKeys={columnKeys}
isLite={isLite}
poolId={poolId}
rChainId={rChainId}
searchParams={searchParams}
imageBaseUrl={network?.imageBaseUrl ?? ''}
showInPoolColumn={showInPoolColumn}
tableLabels={tableLabels}
searchTermMapper={searchTermMapper}
showDetail={showDetail}
setShowDetail={setShowDetail}
curve={curve}
/>
))}
</>
) : (
<tr>
<td colSpan={colSpan}>
<SpinnerWrapper>
<Spinner />
</SpinnerWrapper>
</td>
</tr>
)}
<Tbody $borderBottom>
{isReadyWithApiData && formStatus.noResult ? (
<TableRowNoResult
colSpan={colSpan}
searchParams={searchParams}
signerAddress={signerAddress}
updatePath={updatePath}
/>
) : isReady && Array.isArray(result) ? (
<>
{result.map((poolId: string, index: number) => (
<PoolRow
key={poolId}
index={index}
columnKeys={columnKeys}
isLite={isLite}
poolId={poolId}
rChainId={rChainId}
searchParams={searchParams}
imageBaseUrl={network?.imageBaseUrl ?? ''}
showInPoolColumn={showInPoolColumn}
tableLabels={tableLabels}
searchTermMapper={searchTermMapper}
showDetail={showDetail}
setShowDetail={setShowDetail}
curve={curve}
/>
))}
</>
) : (
<tr>
<td colSpan={colSpan}>
<SpinnerWrapper>
<Spinner />
</SpinnerWrapper>
</td>
</tr>
)}
</Tbody>
</Table>
)}
</Tbody>
</Table>
</>
)
}
Expand Down
4 changes: 2 additions & 2 deletions apps/main/src/dex/components/PageRouterSwap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import orderBy from 'lodash/orderBy'
import uniq from 'lodash/uniq'

import { NETWORK_TOKEN } from '@main/constants'
import { log } from '@ui-kit/lib'
import { log, LogStatus } from '@ui-kit/lib'
import { weiToEther } from '@ui-kit/utils'
import { Pool, UserBalancesMapper, PoolData, UsdRatesMapper } from '@main/types/main.types'

Expand Down Expand Up @@ -65,7 +65,7 @@ export function parseRouterRoutes(
try {
pool = getPool(route.poolId)
} catch (error) {
log('routerBestRouteAndOutput missing poolName', route)
log('routerBestRouteAndOutput missing poolName', LogStatus.ERROR, route.poolId)
}
}

Expand Down
8 changes: 4 additions & 4 deletions apps/main/src/dex/hooks/usePageOnMount.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { Location, NavigateFunction, Params } from 'react-router'
import type { ConnectState } from '@ui/utils'
import { isFailure, isLoading, isSuccess } from '@ui/utils'
import type { INetworkName } from '@curvefi/api/lib/interfaces'

import { ethers } from 'ethers'
import { useCallback, useEffect } from 'react'
import { useConnectWallet, useSetChain, useSetLocale, getWalletSignerAddress } from '@ui-kit/features/connect-wallet'
import { getWalletSignerAddress, useConnectWallet, useSetChain, useSetLocale } from '@ui-kit/features/connect-wallet'

import { CONNECT_STAGE, REFRESH_INTERVAL, ROUTE } from '@main/constants'
import { dynamicActivate, updateAppLocale } from '@ui-kit/lib/i18n'
import { getStorageValue, setStorageValue } from '@main/utils/storage'
import { useNetworkFromUrl, useParsedParams } from '@main/utils/utilsRouter'
import { getWalletChainId } from '@main/store/createWalletSlice'
import { initCurveJs } from '@main/utils/utilsCurvejs'
import { isFailure, isLoading, isSuccess } from '@ui/utils'
import useStore from '@main/store/useStore'
import { useUserProfileStore } from '@ui-kit/features/user-profile'
import { ChainId, PageProps, Wallet } from '@main/types/main.types'
Expand Down Expand Up @@ -47,8 +47,8 @@ function usePageOnMount(params: Params, location: Location, navigate: NavigateFu
updateGlobalStoreByKey('isLoadingApi', true)
updateGlobalStoreByKey('isLoadingCurve', true) // remove -> use connectState

if (useWallet && wallet && chainId) {
const api = await initCurveJs(chainId, wallet)
if (chainId) {
const api = await initCurveJs(chainId, (useWallet && wallet) || undefined)
setNetworkConfigs(api)
updateCurveJs(api, prevCurveApi, wallet)
updateConnectState('success', '')
Expand Down
2 changes: 2 additions & 0 deletions apps/main/src/dex/hooks/usePoolAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ const usePoolAlert = (poolAddress: string | undefined, hasVyperVulnerability: bo
'0x960ea3e3c7fb317332d990873d354e18d7645590': possibleVyperExploitedAlert(), // tricrypto
// avalanche
'0xb755b949c126c04e0348dd881a5cf55d424742b2': atricryptoAlert(),
// sonic
'0x38dd6b3c096c8cbe649fa0039cc144f333be8e61': crossCurveAlert([{label: 'Mint s-tokens', url: 'https://app.crosscurve.fi/liquidity?pool=0x38dd6b3c096c8cbe649fa0039cc144f333be8e61&action=deposit&type=curve'}, {label: 'Redeem s-tokens', url: 'https://app.crosscurve.fi/liquidity?pool=0x38dd6b3c096c8cbe649fa0039cc144f333be8e61&action=withdraw&type=curve'}, {label: 'Cross-chain swap', url: 'https://app.crosscurve.fi/swap?inputChainId=7&inputToken=0x11cdb42b0eb46d95f990bedd4695a6e3fa034978&outputChainId=13&outputToken=0xd533a949740bb3306d119cc777fa900ba034cd52' }]), // CrossCurve xCRV
}

if (poolAddress) {
Expand Down
1 change: 1 addition & 0 deletions apps/main/src/dex/store/createPoolsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ const createPoolsSlice = (set: SetState<State>, get: GetState<State>): PoolsSlic
},
fetchBasePools: async (curve: CurveApi) => {
const chainId = curve.chainId
if (curve.isNoRPC) return
set(
produce((state: State) => {
state.pools.basePoolsLoading = true
Expand Down
8 changes: 6 additions & 2 deletions apps/main/src/dex/utils/utilsCurvejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import cloneDeep from 'lodash/cloneDeep'
import { FORMAT_OPTIONS, formatNumber } from '@ui/utils'
import { CurveApi, ChainId, Pool, RewardsApy, Wallet } from '@main/types/main.types'

export async function initCurveJs(chainId: ChainId, wallet: Wallet) {
export async function initCurveJs(chainId: ChainId, wallet?: Wallet) {
const curveApi = cloneDeep((await import('@curvefi/api')).default) as CurveApi
await curveApi.init('Web3', { network: { chainId }, externalProvider: getWalletProvider(wallet) }, { chainId })
if (wallet) {
await curveApi.init('Web3', { network: { chainId }, externalProvider: getWalletProvider(wallet) }, { chainId })
} else {
await curveApi.init('NoRPC', 'NoRPC', { chainId })
}
return curveApi
}

Expand Down
2 changes: 1 addition & 1 deletion apps/main/src/lend/store/createMarketListSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ const createMarketListSlice = (set: SetState<State>, get: GetState<State>): Mark
fns.map(({ fn, key, isTvl }) => fn(key, api, isTvl ? Object.values(marketMapping) : cMarkets, shouldRefetch)),
)
if (!initialLoaded) sliceState.setStateByKey('initialLoaded', true)
logSuccess(['market-list-slice', 'setFormValues'], sorted.result)
logSuccess(['market-list-slice', 'setFormValues'], sorted.result.length)
},

// slice helpers
Expand Down
1 change: 0 additions & 1 deletion apps/main/src/loan/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const ROUTE = {
PAGE_CREATE: '/create',
PAGE_MANAGE: '/manage',
PAGE_404: '/404',
PAGE_PEGKEEPERS: '/pegkeepers',
}

export const REFRESH_INTERVAL = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const ChainSwitcher = <TChainId extends number>({
return (
<>
<IconButton size="small" disabled={disabled} onClick={onClick} data-testid="btn-change-chain">
<ChainSwitcherIcon chain={selectedNetwork} />
{selectedNetwork && <ChainSwitcherIcon chain={selectedNetwork} />}
{options.length > 1 && <KeyboardArrowDownIcon />}
</IconButton>

Expand Down
2 changes: 1 addition & 1 deletion packages/curve-ui-kit/src/lib/api/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const queryCache = new QueryCache({
logError(query.queryKey, error, error.message)
},
onSuccess: (data, query) => {
logSuccess(query.queryKey, data ? { data } : '')
logSuccess(query.queryKey, ...[data ? [data] : []])
},
})

Expand Down
Loading

0 comments on commit 4ff3b7c

Please sign in to comment.