-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/v2-v3-migration #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 75 commits
d328e69
971273b
8ee2ef4
b9db77f
d3a0882
95cb336
12b0524
f27c88b
739bc0b
6809c59
9c8406b
64fb9a3
4aa2f61
5988980
434ae88
6bff562
761bd91
4326bed
cb5f408
5074fa9
e27f098
6aae480
a1bde72
9fe814e
323e458
550d311
becdf08
3df5f19
5e5fab4
0b461c7
62c1240
cca4ac6
8d4428b
7350587
1da244c
d1142fc
c664a55
b8fba94
b478c8f
6a6f11b
87bd9d6
bacfe4f
136084c
d446e84
4c8a951
632f1b2
8ee8374
94cafd2
9a35903
eb51ad3
ea94643
0e04f5e
4eca623
9551101
733bb29
2e67b4d
c14c6c1
3bed812
3a2598f
02c72f8
7854b91
dc9f5b1
c335e4f
061f6d8
2407330
5b3eaff
0697d17
2a14e60
8b803a8
1641f7d
f19d814
8ed87a7
f6e3698
4d71cd6
5d314d7
201ef6b
8b38310
c08266c
7896f15
92c93b8
5bfbdc1
dda5648
837c5c1
9b244bd
cf58cab
4bad33a
5b965d4
7e188bf
2005038
f57a343
4e615b9
b8fe477
a457ae3
3e86a06
86c4233
5357b50
670374e
a1a88b4
5629d64
34dec07
f6fcf36
d0787c7
f6e195b
5ebf8c6
f809aba
28d8a70
8b81447
519d062
5cbd7d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import { Trans } from '@lingui/macro'; | ||
| import { Box, Divider } from '@mui/material'; | ||
| import { useEffect } from 'react'; | ||
| import { ConnectWalletPaper } from 'src/components/ConnectWalletPaper'; | ||
| import { ContentContainer } from 'src/components/ContentContainer'; | ||
| import { MigrateV3Modal } from 'src/components/transactions/MigrateV3/MigrateV3Modal'; | ||
| import { useAppDataContext } from 'src/hooks/app-data-provider/useAppDataProvider'; | ||
| import { usePermissions } from 'src/hooks/usePermissions'; | ||
| import { useUserReserves } from 'src/hooks/useUserReserves'; | ||
| import { MainLayout } from 'src/layouts/MainLayout'; | ||
| import { useWeb3Context } from 'src/libs/hooks/useWeb3Context'; | ||
| import { DashboardContentNoData } from 'src/modules/dashboard/DashboardContentNoData'; | ||
| import { MigrationBottomPanel } from 'src/modules/migration/MigrationBottomPanel'; | ||
| import { MigrationListItem } from 'src/modules/migration/MigrationListItem'; | ||
| import { MigrationListItemLoader } from 'src/modules/migration/MigrationListItemLoader'; | ||
| import { MigrationLists } from 'src/modules/migration/MigrationLists'; | ||
| import { MigrationTopPanel } from 'src/modules/migration/MigrationTopPanel'; | ||
| import { usePoolDataV3Subscription, useRootStore } from 'src/store/root'; | ||
|
|
||
| export default function V3Migration() { | ||
| const { loading } = useAppDataContext(); | ||
| const { currentAccount, loading: web3Loading } = useWeb3Context(); | ||
| const { isPermissionsLoading } = usePermissions(); | ||
| const setCurrentMarketForMigration = useRootStore((state) => state.setCurrentMarketForMigration); | ||
|
|
||
| const { user, borrowPositions } = useUserReserves(); | ||
|
|
||
| const { | ||
| toggleMigrationSelectedSupplyAsset: toggleSelectedSupplyPosition, | ||
| selectedMigrationSupplyAssets: selectedSupplyAssets, | ||
| toggleMigrationSelectedBorrowAsset: toggleSelectedBorrowPosition, | ||
| selectedMigrationBorrowAssets: selectedBorrowAssets, | ||
| } = useRootStore(); | ||
|
|
||
| useEffect(() => { | ||
| if (setCurrentMarketForMigration) { | ||
| setCurrentMarketForMigration(); | ||
| } | ||
| }, [setCurrentMarketForMigration]); | ||
|
|
||
| usePoolDataV3Subscription(); | ||
|
|
||
| return ( | ||
| <> | ||
| <MigrationTopPanel /> | ||
|
|
||
| {currentAccount && !isPermissionsLoading ? ( | ||
| <ContentContainer> | ||
| <MigrationLists | ||
| loading={loading} | ||
| totalSuppliesUSD={user.totalCollateralUSD} | ||
| totalBorrowsUSD={user.totalBorrowsUSD} | ||
| isSupplyPositionsAvailable={!!user.userReservesData.length} | ||
| isBorrowPositionsAvailable={!!borrowPositions.length} | ||
| onSelectAllSupplies={() => | ||
| user.userReservesData.map((reserve) => | ||
| toggleSelectedSupplyPosition(reserve.underlyingAsset) | ||
| ) | ||
| } | ||
| onSelectAllBorrows={() => | ||
| borrowPositions.map((reserve) => | ||
| toggleSelectedBorrowPosition(reserve.underlyingAsset) | ||
| ) | ||
| } | ||
| suppliesPositions={ | ||
| <> | ||
| {loading ? ( | ||
| <> | ||
| <MigrationListItemLoader /> | ||
| <MigrationListItemLoader /> | ||
| </> | ||
| ) : !!user.userReservesData.length ? ( | ||
| user.userReservesData.map((reserve) => ( | ||
| <MigrationListItem | ||
| key={reserve.underlyingAsset} | ||
| checked={selectedSupplyAssets[reserve.underlyingAsset]} | ||
| reserveIconSymbol={reserve.reserve.iconSymbol} | ||
| reserveName={reserve.reserve.name} | ||
| reserveSymbol={reserve.reserve.symbol} | ||
| amount={reserve.underlyingBalance} | ||
| amountInUSD={reserve.underlyingBalanceUSD} | ||
| onCheckboxClick={() => toggleSelectedSupplyPosition(reserve.underlyingAsset)} | ||
| /> | ||
| )) | ||
| ) : ( | ||
| <Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}> | ||
| <DashboardContentNoData text={<Trans>Nothing supplied yet</Trans>} /> | ||
| </Box> | ||
| )} | ||
| </> | ||
| } | ||
| borrowsPositions={ | ||
| <> | ||
| {loading ? ( | ||
| <> | ||
| <MigrationListItemLoader /> | ||
| <MigrationListItemLoader /> | ||
| </> | ||
| ) : !!borrowPositions.length ? ( | ||
| borrowPositions.map((reserve) => ( | ||
| <MigrationListItem | ||
| key={reserve.underlyingAsset} | ||
| checked={selectedBorrowAssets[reserve.underlyingAsset]} | ||
| reserveIconSymbol={reserve.reserve.iconSymbol} | ||
| reserveName={reserve.reserve.name} | ||
| reserveSymbol={reserve.reserve.symbol} | ||
| amount={reserve.totalBorrows} | ||
| amountInUSD={reserve.totalBorrowsUSD} | ||
| onCheckboxClick={() => toggleSelectedBorrowPosition(reserve.underlyingAsset)} | ||
| /> | ||
| )) | ||
| ) : ( | ||
| <Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}> | ||
| <DashboardContentNoData text={<Trans>Nothing borrowed yet</Trans>} /> | ||
| </Box> | ||
| )} | ||
| </> | ||
| } | ||
| /> | ||
|
|
||
| <Divider sx={{ my: 10 }} /> | ||
|
|
||
| <MigrationBottomPanel | ||
| hfV2Current={'1.2'} // TODO: need value | ||
| hfV2AfterChange={'2'} // TODO: need value | ||
| hfV3Current={'1.2'} // TODO: need value | ||
| hfV3AfterChange={'2'} // TODO: need value | ||
| disableButton={ | ||
| !Object.keys(selectedSupplyAssets).length && !Object.keys(selectedBorrowAssets).length | ||
| } | ||
| loading={loading} | ||
| /> | ||
| </ContentContainer> | ||
| ) : ( | ||
| <ConnectWalletPaper | ||
| loading={web3Loading} | ||
| description={<Trans> Please connect your wallet to see migration tool.</Trans>} | ||
| /> | ||
| )} | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| V3Migration.getLayout = function getLayout(page: React.ReactElement) { | ||
| return ( | ||
| <MainLayout> | ||
| {page} | ||
| <MigrateV3Modal /> | ||
| </MainLayout> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { Trans } from '@lingui/macro'; | ||
| import { useTransactionHandler } from 'src/helpers/useTransactionHandler'; | ||
| import { useRootStore } from 'src/store/root'; | ||
|
|
||
| import { TxActionsWrapper } from '../TxActionsWrapper'; | ||
|
|
||
| export type MigrateV3ActionsProps = { | ||
| isWrongNetwork: boolean; | ||
| blocked: boolean; | ||
| }; | ||
|
|
||
| export const MigrateV3Actions = ({ isWrongNetwork, blocked }: MigrateV3ActionsProps) => { | ||
| const migrateWithPermits = useRootStore((store) => store.migrateWithPermits); | ||
| const migrateWithoutPermits = useRootStore((store) => store.migrateWithoutPermits); | ||
| const getApprovePermitsForSelectedAssets = useRootStore( | ||
| (store) => store.getApprovePermitsForSelectedAssets | ||
| ); | ||
| const { approval, action, loadingTxns, requiresApproval, mainTxState, approvalTxState } = | ||
| useTransactionHandler({ | ||
| handleGetTxns: async () => migrateWithoutPermits(), | ||
| handleGetPermitTxns: async (signatures, deadline) => migrateWithPermits(signatures, deadline), | ||
| tryPermit: true, | ||
| }); | ||
|
|
||
| const handleApproval = async () => { | ||
| const approvePermitsForSelectedAssets = await getApprovePermitsForSelectedAssets(); | ||
| approval(approvePermitsForSelectedAssets); | ||
| }; | ||
|
|
||
| return ( | ||
| <TxActionsWrapper | ||
| requiresApproval={requiresApproval} | ||
| preparingTransactions={loadingTxns} | ||
| mainTxState={mainTxState} | ||
| approvalTxState={approvalTxState} | ||
| isWrongNetwork={isWrongNetwork} | ||
| handleAction={action} | ||
| handleApproval={handleApproval} | ||
| blocked={blocked} | ||
| actionText={<Trans>Migrate</Trans>} | ||
| actionInProgressText={<Trans>Migrating</Trans>} | ||
| /> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import React from 'react'; | ||
| import { BasicModal } from 'src/components/primitives/BasicModal'; | ||
| import { ModalType, useModalContext } from 'src/hooks/useModal'; | ||
|
|
||
| import { MigrateV3ModalContent } from './MigrateV3ModalContent'; | ||
|
|
||
| export const MigrateV3Modal = () => { | ||
| const { type, close } = useModalContext(); | ||
|
|
||
| return ( | ||
| <BasicModal open={type === ModalType.V3Migration} setOpen={close}> | ||
| <MigrateV3ModalContent /> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you using a different approach here? Checkout other modals - usually they do sth like: Which will take care of layout & properly handle networkState
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I didn't understanad that part properly, will check
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now I think I do understand, but it's again the same issue, why do we have wrong network state coupled with underlying asset and what is underlying asset in that case? If I'm reading correctly I need to adapt underlyingAsset to have an array instead of a single one, while it would be way simplier and usefull to expose switching network globally. Switching network and fetching balances are not exactly part of the same logic at least for migration. |
||
| </BasicModal> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { Box, Typography } from '@mui/material'; | ||
| import { ReactNode } from 'react'; | ||
| import { FormattedNumber } from 'src/components/primitives/FormattedNumber'; | ||
| import { Row } from 'src/components/primitives/Row'; | ||
| import { TokenIcon } from 'src/components/primitives/TokenIcon'; | ||
|
|
||
| export type Asset = { | ||
| underlyingAsset: string; | ||
| iconSymbol: string; | ||
| symbol: string; | ||
| amount: string; | ||
| amountInUSD: string; | ||
| }; | ||
|
|
||
| interface MigrateV3ModalAssetsListProps { | ||
| caption: ReactNode; | ||
| assets: (Asset | undefined)[]; | ||
| } | ||
|
|
||
| export const MigrateV3ModalAssetsList = ({ caption, assets }: MigrateV3ModalAssetsListProps) => { | ||
| return ( | ||
| <Row | ||
| caption={caption} | ||
| captionVariant="description" | ||
| align="flex-start" | ||
| sx={{ mb: 6, '&:last-of-type': { mb: 0 } }} | ||
| > | ||
| {!!assets.length ? ( | ||
| <Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-end' }}> | ||
| {assets.map((asset) => | ||
| asset ? ( | ||
| <Box | ||
| key={asset.underlyingAsset} | ||
| sx={{ mb: 2, display: 'flex', alignItems: 'flex-end', flexDirection: 'column' }} | ||
| > | ||
| <Box sx={{ display: 'flex', alignItems: 'center' }}> | ||
| <TokenIcon symbol={asset.symbol} sx={{ mr: 1, fontSize: '16px' }} /> | ||
| <FormattedNumber value={asset.amount} variant="secondary14" compact /> | ||
| <Typography ml={1} variant="secondary14"> | ||
| {asset.symbol} | ||
| </Typography> | ||
| </Box> | ||
| <FormattedNumber | ||
| value={asset.amountInUSD} | ||
| variant="helperText" | ||
| compact | ||
| symbol="USD" | ||
| color="text.secondary" | ||
| /> | ||
| </Box> | ||
| ) : ( | ||
| <></> | ||
| ) | ||
| )} | ||
| </Box> | ||
| ) : ( | ||
| <Typography>—</Typography> | ||
| )} | ||
| </Row> | ||
| ); | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.