Skip to content

Commit 9a7170c

Browse files
authored
Merge branch 'develop' into metamask-integration
2 parents 9b87fda + 86a45da commit 9a7170c

File tree

20 files changed

+863
-641
lines changed

20 files changed

+863
-641
lines changed

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@
3232
"ibc-domains-sdk": "^1.1.0",
3333
"lodash.debounce": "^4.0.8",
3434
"lodash.throttle": "^4.1.1",
35+
"mobx": "^6.12.3",
3536
"moment": "^2.30.1",
36-
"next": "^14.2.2",
37-
"react": "^18.2.0",
37+
"next": "^14.2.3",
38+
"react": "^18.3.1",
3839
"react-device-detect": "^2.2.3",
3940
"react-dom": "^18.2.0",
4041
"react-draggable": "^4.4.6",
4142
"react-helmet-async": "^2.0.4",
4243
"react-qr-code": "^2.0.12",
43-
"react-router-dom": "^6.22.3",
44+
"react-router-dom": "^6.23.1",
4445
"react-spring": "^9.7.3",
4546
"react-toastify": "^10.0.5",
4647
"react-use-clipboard": "^1.0.9",
@@ -54,15 +55,15 @@
5455
"@types/debounce-promise": "^3.1.9",
5556
"@types/lodash.debounce": "^4.0.9",
5657
"@types/lodash.throttle": "^4.1.9",
57-
"@types/node": "^20.12.7",
58-
"@types/react": "18.2.79",
59-
"@types/react-dom": "18.2.25",
58+
"@types/node": "^20.12.11",
59+
"@types/react": "18.3.1",
60+
"@types/react-dom": "18.3.0",
6061
"@types/react-helmet": "^6.1.11",
6162
"autoprefixer": "^10.4.19",
6263
"dotenv": "^16.4.5",
6364
"dotenv-cli": "^7.4.1",
6465
"eslint": "^8.57.0",
65-
"eslint-config-next": "^14.1.4",
66+
"eslint-config-next": "^14.2.3",
6667
"eslint-plugin-import": "^2.29.1",
6768
"husky": "^9.0.11",
6869
"identity-obj-proxy": "^3.0.0",

src/api/vaults/getDepositedVaults.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ async function getUnlocksAtTimestamp(
4040
60,
4141
)) as VaultExtensionResponse
4242

43+
const lockingVault: any = {
44+
vault: {
45+
address: '',
46+
},
47+
locking: {
48+
locked: {
49+
vault: 0,
50+
base: 0,
51+
coins: [],
52+
},
53+
unlocking: [
54+
{
55+
base: 0,
56+
timestamp: 0,
57+
coins: [],
58+
},
59+
],
60+
},
61+
}
62+
4363
return Number(vaultExtension.release_at.at_time) / 1e6
4464
} catch (ex) {
4565
throw ex

src/components/Modals/Account/AccountDeleteModal.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { useCallback, useMemo } from 'react'
22
import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom'
3+
import { useSWRConfig } from 'swr'
34

45
import AccountDeleteAlertDialog from 'components/Modals/Account/AccountDeleteAlertDialog'
56
import { ArrowRight, ExclamationMarkCircled } from 'components/common/Icons'
67
import Text from 'components/common/Text'
78
import AssetBalanceRow from 'components/common/assets/AssetBalanceRow'
89
import useAllAssets from 'hooks/assets/useAllAssets'
10+
import useChainConfig from 'hooks/chain/useChainConfig'
911
import useStore from 'store'
1012
import { BNCoin } from 'types/classes/BNCoin'
1113
import { byDenom } from 'utils/array'
@@ -26,7 +28,10 @@ export default function AccountDeleteController() {
2628

2729
function AccountDeleteModal(props: Props) {
2830
const modal = props.modal
31+
const chainConfig = useChainConfig()
2932
const deleteAccount = useStore((s) => s.deleteAccount)
33+
const { mutate } = useSWRConfig()
34+
const { address: urlAddress } = useParams()
3035
const navigate = useNavigate()
3136
const { pathname } = useLocation()
3237
const { address } = useParams()
@@ -37,10 +42,19 @@ function AccountDeleteModal(props: Props) {
3742
useStore.setState({ accountDeleteModal: null })
3843
}, [])
3944

40-
const deleteAccountHandler = useCallback(() => {
45+
const deleteAccountHandler = useCallback(async () => {
4146
const options = { accountId: modal.id, lends: modal.lends }
42-
deleteAccount(options)
43-
navigate(getRoute(getPage(pathname), searchParams, address))
47+
const path = getPage(pathname)
48+
const isDeleted = await deleteAccount(options)
49+
if (isDeleted) {
50+
mutate(`chains/${chainConfig.id}/wallets/${urlAddress}/account-ids`)
51+
if (path.includes('portfolio')) {
52+
// If the current page is the portfolio accounts detail page. Reroute the user to the portfolio overview page.
53+
navigate(getRoute('portfolio', searchParams, urlAddress))
54+
} else {
55+
navigate(getRoute(path, searchParams, address))
56+
}
57+
}
4458
closeDeleteAccountModal()
4559
}, [
4660
modal.id,
@@ -50,6 +64,9 @@ function AccountDeleteModal(props: Props) {
5064
pathname,
5165
searchParams,
5266
address,
67+
urlAddress,
68+
chainConfig.id,
69+
mutate,
5370
closeDeleteAccountModal,
5471
])
5572

src/components/Modals/Settings/index.tsx

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ import { useShuttle } from '@delphi-labs/shuttle-react'
22
import classNames from 'classnames'
33
import { useCallback, useMemo, useState } from 'react'
44

5-
import Modal from 'components/Modals/Modal'
6-
import SettingsOptions from 'components/Modals/Settings/SettingsOptions'
7-
import SettingsSwitch from 'components/Modals/Settings/SettingsSwitch'
8-
import WalletSelect from 'components/Wallet/WalletSelect'
5+
import AssetImage from 'components/common/assets/AssetImage'
96
import Button from 'components/common/Button'
107
import { ArrowCircle, Enter } from 'components/common/Icons'
118
import NumberInput from 'components/common/NumberInput'
129
import Select from 'components/common/Select'
1310
import Text from 'components/common/Text'
1411
import TextInput from 'components/common/TextInput'
1512
import { TextLink } from 'components/common/TextLink'
16-
import AssetImage from 'components/common/assets/AssetImage'
13+
import Modal from 'components/Modals/Modal'
14+
import SettingsOptions from 'components/Modals/Settings/SettingsOptions'
15+
import SettingsSwitch from 'components/Modals/Settings/SettingsSwitch'
1716
import chains from 'configs/chains'
1817
import { DEFAULT_SETTINGS } from 'constants/defaultSettings'
1918
import { LocalStorageKeys } from 'constants/localStorageKeys'
@@ -30,6 +29,8 @@ import useStore from 'store'
3029
import { getCurrentChainId } from 'utils/getCurrentChainId'
3130
import { BN } from 'utils/helpers'
3231

32+
import { Callout, CalloutType } from '../../common/Callout'
33+
3334
const slippages = [0.02, 0.03]
3435

3536
export default function SettingsModal() {
@@ -269,6 +270,11 @@ export default function SettingsModal() {
269270
[setValidRest, chainId, setRestEndpoint],
270271
)
271272

273+
const hasEndpointsChangedValid = useMemo(
274+
() => (tempRestEndpoint !== '' && validRest) || (tempRpcEndpoint !== '' && validRpc),
275+
[tempRestEndpoint, tempRpcEndpoint, validRest, validRpc],
276+
)
277+
272278
const showResetModal = useCallback(() => {
273279
showResetDialog({
274280
icon: (
@@ -288,29 +294,16 @@ export default function SettingsModal() {
288294
}, [showResetDialog, handleResetSettings])
289295

290296
const handleCloseModal = useCallback(() => {
291-
if (
292-
(tempRpcEndpoint !== '' || tempRestEndpoint !== '') &&
293-
validRest &&
294-
validRpc &&
295-
currentWallet
296-
) {
297+
if (hasEndpointsChangedValid && currentWallet) {
297298
disconnectWallet(currentWallet)
298-
useStore.setState({
299-
client: undefined,
300-
address: undefined,
301-
userDomain: undefined,
302-
balances: [],
303-
focusComponent: {
304-
component: <WalletSelect />,
305-
},
306-
})
299+
window.location.reload()
307300
}
308301
setTempRestEndpoint('')
309302
setTempRpcEndpoint('')
310303
setValidRest(true)
311304
setValidRpc(true)
312305
useStore.setState({ settingsModal: false })
313-
}, [tempRpcEndpoint, tempRestEndpoint, currentWallet, disconnectWallet, validRest, validRpc])
306+
}, [hasEndpointsChangedValid, currentWallet, disconnectWallet])
314307

315308
if (!modal) return null
316309

@@ -462,7 +455,7 @@ export default function SettingsModal() {
462455
className='pb-6'
463456
fullwidth
464457
>
465-
<div className='flex flex-wrap w-full gap-4'>
458+
<div className='flex flex-wrap w-full gap-4 items-stretch'>
466459
<TextInput
467460
label='RPC'
468461
placeholder='https://'
@@ -487,6 +480,11 @@ export default function SettingsModal() {
487480
errorMessage={`Invalid ${chainId} REST Endpoint. Failed to fetch the latest block.`}
488481
className='w-full'
489482
/>
483+
{hasEndpointsChangedValid && (
484+
<Callout type={CalloutType.INFO} className='w-full'>
485+
The app will reload and you will have to re-connect the wallet.
486+
</Callout>
487+
)}
490488
</div>
491489
</SettingsOptions>
492490
<div className='flex flex-wrap justify-center w-full gap-4 md:justify-between md:flex-nowrap'>

src/components/Wallet/WalletConnectProvider.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,29 @@ import {
1616
import { FC } from 'react'
1717

1818
import chains from 'configs/chains'
19+
import { LocalStorageKeys } from 'constants/localStorageKeys'
1920
import { WALLETS } from 'constants/wallets'
2021
import { WalletID } from 'types/enums'
2122

2223
type Props = {
2324
children?: React.ReactNode
2425
}
2526

27+
function getLocalStorageEndpoint(key: string, fallback: string) {
28+
if (typeof window !== 'undefined') return localStorage.getItem(key) ?? fallback
29+
return fallback
30+
}
31+
2632
function mapChainConfigToChainInfo(chainConfig: ChainConfig): ChainInfo {
27-
const chainInfo: ChainInfo = {
28-
rpc: chainConfig.endpoints.rpc,
29-
rest: chainConfig.endpoints.rest,
33+
return {
34+
rpc: getLocalStorageEndpoint(
35+
`${chainConfig.id}/${LocalStorageKeys.RPC_ENDPOINT}`,
36+
chainConfig.endpoints.rpc,
37+
),
38+
rest: getLocalStorageEndpoint(
39+
`${chainConfig.id}/${LocalStorageKeys.REST_ENDPOINT}`,
40+
chainConfig.endpoints.rest,
41+
),
3042
explorer: chainConfig.endpoints.explorer,
3143
explorerName: chainConfig.explorerName,
3244
chainId: chainConfig.id,
@@ -36,15 +48,11 @@ function mapChainConfigToChainInfo(chainConfig: ChainConfig): ChainInfo {
3648
defaultCurrency: chainConfig.defaultCurrency,
3749
features: ['ibc-transfer', 'ibc-go'],
3850
}
39-
40-
return chainInfo
4151
}
4252

4353
function getSupportedChainsInfos(walletId: WalletID) {
4454
return WALLETS[walletId].supportedChains.map((chain) => {
45-
const chainInfo = mapChainConfigToChainInfo(chains[chain])
46-
47-
return chainInfo
55+
return mapChainConfigToChainInfo(chains[chain])
4856
})
4957
}
5058

src/components/account/AccountBalancesTable/index.tsx

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import { getPage, getRoute } from 'utils/route'
1515

1616
interface Props {
1717
account: Account
18-
isHls?: boolean
1918
lendingData: LendingMarketTableData[]
2019
borrowingData: BorrowMarketTableData[]
2120
hideCard?: boolean
2221
tableBodyClassName?: string
2322
showLiquidationPrice?: boolean
23+
isUsersAccount?: boolean
2424
}
2525

2626
export default function AccountBalancesTable(props: Props) {
@@ -32,23 +32,24 @@ export default function AccountBalancesTable(props: Props) {
3232
tableBodyClassName,
3333
hideCard,
3434
showLiquidationPrice,
35+
isUsersAccount,
3536
} = props
3637
const currentAccount = useCurrentAccount()
3738
const navigate = useNavigate()
3839
const { pathname } = useLocation()
3940
const address = useStore((s) => s.address)
4041
const updatedAccount = useStore((s) => s.updatedAccount)
42+
const isHls = account.kind === 'high_levered_strategy'
4143
const accountBalanceData = useAccountBalanceData({
4244
account,
4345
updatedAccount,
4446
lendingData,
4547
borrowingData,
46-
isHls: props.isHls,
48+
isHls,
4749
})
48-
4950
const columns = useAccountBalancesColumns(account, showLiquidationPrice)
5051

51-
if (accountBalanceData.length === 0)
52+
if (accountBalanceData.length === 0) {
5253
return (
5354
<ConditionalWrapper
5455
condition={!hideCard}
@@ -59,28 +60,34 @@ export default function AccountBalancesTable(props: Props) {
5960
)}
6061
>
6162
<div className='w-full p-4'>
62-
<ActionButton
63-
className='w-full'
64-
text='Fund this Account'
65-
color='tertiary'
66-
onClick={() => {
67-
if (currentAccount?.id !== account.id) {
68-
navigate(getRoute(getPage(pathname), searchParams, address, account.id))
69-
}
70-
useStore.setState({
71-
focusComponent: {
72-
component: <AccountFundFullPage />,
73-
onClose: () => {
74-
useStore.setState({ getStartedModal: true })
63+
{isUsersAccount && !isHls ? (
64+
<ActionButton
65+
className='w-full'
66+
text='Fund this Account'
67+
color='tertiary'
68+
onClick={() => {
69+
if (currentAccount?.id !== account.id) {
70+
navigate(getRoute(getPage(pathname), searchParams, address, account.id))
71+
}
72+
useStore.setState({
73+
focusComponent: {
74+
component: <AccountFundFullPage />,
75+
onClose: () => {
76+
useStore.setState({ getStartedModal: true })
77+
},
7578
},
76-
},
77-
})
78-
}}
79-
/>
79+
})
80+
}}
81+
/>
82+
) : (
83+
<Text size='sm' className='text-center'>
84+
This account has no balances.
85+
</Text>
86+
)}
8087
</div>
8188
</ConditionalWrapper>
8289
)
83-
90+
}
8491
return (
8592
<Table
8693
title={

src/components/account/AccountSummary/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { DEFAULT_SETTINGS } from 'constants/defaultSettings'
1212
import { LocalStorageKeys } from 'constants/localStorageKeys'
1313
import { BN_ZERO } from 'constants/math'
1414
import useAllAssets from 'hooks/assets/useAllAssets'
15+
import useHealthComputer from 'hooks/health-computer/useHealthComputer'
1516
import useHLSStakingAssets from 'hooks/hls/useHLSStakingAssets'
1617
import useLocalStorage from 'hooks/localStorage/useLocalStorage'
1718
import usePrices from 'hooks/prices/usePrices'
18-
import useHealthComputer from 'hooks/health-computer/useHealthComputer'
1919
import useVaultAprs from 'hooks/vaults/useVaultAprs'
2020
import useStore from 'store'
2121
import { calculateAccountApr, calculateAccountLeverage } from 'utils/accounts'
@@ -117,7 +117,6 @@ export default function AccountSummary(props: Props) {
117117
borrowingData={borrowAssetsData}
118118
lendingData={lendingAssetsData}
119119
hideCard
120-
isHls={isHls}
121120
/>
122121
) : null,
123122
isOpen: accountSummaryTabs[1],

0 commit comments

Comments
 (0)