Skip to content

Commit 6bfa4d5

Browse files
authored
Merge pull request #943 from mars-protocol/develop
v2.3.5
2 parents 2b4c0db + 4af817a commit 6bfa4d5

File tree

14 files changed

+249
-128
lines changed

14 files changed

+249
-128
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mars-v2-frontend",
3-
"version": "2.3.4",
3+
"version": "2.3.5",
44
"homepage": "./",
55
"private": false,
66
"license": "SEE LICENSE IN LICENSE FILE",
@@ -22,7 +22,7 @@
2222
"dependencies": {
2323
"@cosmjs/cosmwasm-stargate": "^0.32.3",
2424
"@delphi-labs/shuttle-react": "^3.22.0",
25-
"@keplr-wallet/cosmos": "^0.12.82",
25+
"@keplr-wallet/cosmos": "^0.12.88",
2626
"@tailwindcss/container-queries": "^0.1.1",
2727
"@tanstack/react-table": "^8.16.0",
2828
"@tippyjs/react": "^4.2.6",
@@ -41,7 +41,7 @@
4141
"react-draggable": "^4.4.6",
4242
"react-helmet-async": "^2.0.4",
4343
"react-qr-code": "^2.0.12",
44-
"react-router-dom": "^6.23.0",
44+
"react-router-dom": "^6.23.1",
4545
"react-spring": "^9.7.3",
4646
"react-toastify": "^10.0.5",
4747
"react-use-clipboard": "^1.0.9",
@@ -55,9 +55,9 @@
5555
"@types/debounce-promise": "^3.1.9",
5656
"@types/lodash.debounce": "^4.0.9",
5757
"@types/lodash.throttle": "^4.1.9",
58-
"@types/node": "^20.12.7",
58+
"@types/node": "^20.12.11",
5959
"@types/react": "18.3.1",
60-
"@types/react-dom": "18.2.25",
60+
"@types/react-dom": "18.3.0",
6161
"@types/react-helmet": "^6.1.11",
6262
"autoprefixer": "^10.4.19",
6363
"dotenv": "^16.4.5",

public/images/wallets/metamask.png

4.48 KB
Loading

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/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],

src/components/portfolio/Account/Balances.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import Card from 'components/common/Card'
66
import TableSkeleton from 'components/common/Table/TableSkeleton'
77
import Text from 'components/common/Text'
88
import useLendingMarketAssetsTableData from 'components/earn/lend/Table/useLendingMarketAssetsTableData'
9-
import useAccount from 'hooks/accounts/useAccount'
109

1110
interface Props {
12-
accountId: string
11+
isUsersAccount?: boolean
12+
account: Account
1313
}
1414

1515
function Content(props: Props) {
16-
const { data: account } = useAccount(props.accountId, true)
17-
16+
const { isUsersAccount, account } = props
1817
const data = useBorrowMarketAssetsTableData()
1918
const borrowAssets = useMemo(() => data?.allAssets || [], [data])
2019
const { allAssets: lendingAssets } = useLendingMarketAssetsTableData()
@@ -29,6 +28,7 @@ function Content(props: Props) {
2928
account={account}
3029
borrowingData={borrowAssets}
3130
lendingData={lendingAssets}
31+
isUsersAccount={isUsersAccount}
3232
showLiquidationPrice
3333
hideCard
3434
/>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { useCallback, useMemo } from 'react'
2+
3+
import AccountFundFullPage from 'components/account/AccountFund/AccountFundFullPage'
4+
import Button from 'components/common/Button'
5+
import { ArrowDownLine, ArrowUpLine, TrashBin } from 'components/common/Icons'
6+
import useAllAssets from 'hooks/assets/useAllAssets'
7+
import usePrices from 'hooks/prices/usePrices'
8+
import useStore from 'store'
9+
import { calculateAccountBalanceValue } from 'utils/accounts'
10+
11+
interface Props {
12+
account: Account
13+
}
14+
15+
export default function ManageAccount(props: Props) {
16+
const { account } = props
17+
const assets = useAllAssets()
18+
const { data: prices } = usePrices()
19+
const isHls = account.kind === 'high_levered_strategy'
20+
const positionBalance = useMemo(
21+
() => (!account ? null : calculateAccountBalanceValue(account, prices, assets)),
22+
[account, assets, prices],
23+
)
24+
const deleteAccountHandler = useCallback(() => {
25+
if (!account) return
26+
useStore.setState({ accountDeleteModal: account })
27+
}, [account])
28+
29+
return (
30+
<div className='flex flex-wrap justify-center w-full gap-4 md:justify-end'>
31+
{!isHls && (
32+
<>
33+
<Button
34+
text='Fund'
35+
color='tertiary'
36+
leftIcon={<ArrowUpLine />}
37+
disabled={!positionBalance}
38+
onClick={() => {
39+
if (!positionBalance) return
40+
if (positionBalance.isLessThanOrEqualTo(0)) {
41+
useStore.setState({
42+
focusComponent: {
43+
component: <AccountFundFullPage />,
44+
onClose: () => {
45+
useStore.setState({ getStartedModal: true })
46+
},
47+
},
48+
})
49+
return
50+
}
51+
useStore.setState({ fundAndWithdrawModal: 'fund' })
52+
}}
53+
/>
54+
<Button
55+
color='tertiary'
56+
leftIcon={<ArrowDownLine />}
57+
text='Withdraw'
58+
onClick={() => {
59+
useStore.setState({ fundAndWithdrawModal: 'withdraw' })
60+
}}
61+
disabled={!positionBalance || positionBalance.isLessThanOrEqualTo(0)}
62+
/>
63+
</>
64+
)}
65+
<Button
66+
color='tertiary'
67+
leftIcon={<TrashBin />}
68+
text='Delete'
69+
disabled={!account}
70+
onClick={() => {
71+
deleteAccountHandler()
72+
}}
73+
/>
74+
</div>
75+
)
76+
}

src/components/portfolio/Account/PerpPositions.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import AccountPerpPositionTable from 'components/account/AccountPerpPositionTabl
44
import Card from 'components/common/Card'
55
import TableSkeleton from 'components/common/Table/TableSkeleton'
66
import Text from 'components/common/Text'
7-
import useAccount from 'hooks/accounts/useAccount'
87

98
interface Props {
10-
accountId: string
9+
account: Account
1110
}
1211

1312
function Content(props: Props) {
14-
const { data: account } = useAccount(props.accountId, true)
15-
16-
if (!account || account.perps.length === 0) return null
13+
const { account } = props
14+
if (account.perps.length === 0) return null
1715

1816
return (
1917
<Skeleton>

src/components/portfolio/Account/Strategies.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ import AccountStrategiesTable from 'components/account/AccountStrategiesTable'
44
import Card from 'components/common/Card'
55
import TableSkeleton from 'components/common/Table/TableSkeleton'
66
import Text from 'components/common/Text'
7-
import useAccount from 'hooks/accounts/useAccount'
87

98
interface Props {
10-
accountId: string
9+
account: Account
1110
}
1211

1312
function Content(props: Props) {
14-
const { data: account } = useAccount(props.accountId, true)
13+
const { account } = props
1514

16-
if (!account || account?.vaults.length === 0) {
15+
if (account.vaults.length === 0) {
1716
return null
1817
}
1918

0 commit comments

Comments
 (0)