Skip to content
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

[web] Show DetailModal on DeFiProtocolItem click #424

Merged
merged 4 commits into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 16 additions & 65 deletions apps/web/src/dashboard/DashboardMain.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Wallet } from '@bento/common';
import { OpenSeaAsset } from '@bento/core';
import styled from '@emotion/styled';
import { Avatar, Text, useTheme } from '@geist-ui/core';
import groupBy from 'lodash.groupby';
import { useTranslation } from 'next-i18next';
import React, { useEffect, useMemo, useState } from 'react';
Expand All @@ -10,7 +9,6 @@ import { AnimatedTab } from '@/components/AnimatedTab';
import { Checkbox, Skeleton } from '@/components/system';
import { useLazyEffect } from '@/hooks/useLazyEffect';
import { useLocalStorage } from '@/hooks/useLocalStorage';
import { formatUsername } from '@/utils/format';

import { DeFiProtocolItem } from '@/dashboard/components/list-items/DeFiProtocolItem';
import { WalletBalanceItem } from '@/dashboard/components/list-items/WalletBalanceItem';
Expand All @@ -26,15 +24,16 @@ import { Colors } from '@/styles';
import { Analytics } from '@/utils';

import { DeFiStakingItem } from './components/DeFiStakingItem';
import { DetailModalParams } from './components/DetailModal';
import { EmptyBalance } from './components/EmptyBalance';
import { InlineBadge } from './components/InlineBadge';
import { Tab } from './components/Tab';
import { TokenDetailModalParams } from './components/TokenDetailModal';
import { Breakpoints } from './constants/breakpoints';
import { KlaytnNFTAsset, useKlaytnNFTs } from './hooks/useKlaytnNFTs';
import { AssetRatioSection } from './sections/AssetRatioSection';
import { BadgeListSection } from './sections/BadgeListSection';
import { NFTListSection } from './sections/NFTListSection';
import { UserProfileSection } from './sections/UserProfileSection';
import { WalletListSection } from './sections/WalletListSection';

enum DashboardTabType {
Expand All @@ -57,10 +56,8 @@ type DashboardMainProps = {
revalidateProfile: () => Promise<void>;
revalidateWallets: () => Promise<Wallet[] | undefined>;
setAddWalletModalVisible: React.Dispatch<React.SetStateAction<boolean>>;
setTokenDetailModalVisible: React.Dispatch<React.SetStateAction<boolean>>;
setTokenDetailModalParams: React.Dispatch<
React.SetStateAction<TokenDetailModalParams>
>;
setDetailModalVisible: React.Dispatch<React.SetStateAction<boolean>>;
setDetailModalParams: React.Dispatch<React.SetStateAction<DetailModalParams>>;
};

export const DashboardMain: React.FC<DashboardMainProps> = ({
Expand All @@ -70,8 +67,8 @@ export const DashboardMain: React.FC<DashboardMainProps> = ({
revalidateProfile,
revalidateWallets,
setAddWalletModalVisible,
setTokenDetailModalVisible,
setTokenDetailModalParams,
setDetailModalVisible,
setDetailModalParams,
}) => {
const { t, i18n } = useTranslation('dashboard');
const currentLanguage = i18n.resolvedLanguage || i18n.language || 'en';
Expand Down Expand Up @@ -188,34 +185,12 @@ export const DashboardMain: React.FC<DashboardMainProps> = ({
[netWorthInProtocols, netWorthInWallet],
);

const { palette } = useTheme();

return (
<React.Fragment>
<div style={{ width: '100%', height: 32 }} />

<DashboardWrapper>
<ProfileContainer>
{profile.images?.[0] ? (
<Avatar src={profile.images[0]} scale={3} />
) : (
<Avatar
text={(profile.display_name || profile.username)[0]}
scale={3}
/>
)}

<div>
<Text h3 style={{ color: palette.accents_8, lineHeight: 1 }}>
{profile.display_name}
</Text>
<Text
style={{ marginTop: 6, color: palette.accents_6, lineHeight: 1 }}
>
{formatUsername(profile.username)}
</Text>
</div>
</ProfileContainer>
<UserProfileSection profile={profile} />

<DashboardContentWrapper>
<TabContainer>
Expand Down Expand Up @@ -330,8 +305,8 @@ export const DashboardMain: React.FC<DashboardMainProps> = ({
platform: item.platform,
address: item.tokenAddress ?? undefined,
});
setTokenDetailModalVisible((prev) => !prev);
setTokenDetailModalParams({
setDetailModalVisible((prev) => !prev);
setDetailModalParams({
tokenBalance: item,
});
}}
Expand Down Expand Up @@ -378,23 +353,13 @@ export const DashboardMain: React.FC<DashboardMainProps> = ({
key={`${service.chain}-${service.serviceId}`}
valuation={valuation}
currentLanguage={currentLanguage}
>
<ul>
{service.protocols.map((protocol) => (
<React.Fragment
key={`${service.serviceId}-${protocol.protocolId}`}
>
{protocol.accounts.map((account) => (
<DeFiStakingItem
key={`${service.serviceId}-${protocol.protocolId}-${account.account}`}
info={protocol.info}
protocol={account}
/>
))}
</React.Fragment>
))}
</ul>
</DeFiProtocolItem>
onClick={() => {
setDetailModalVisible((prev) => !prev);
setDetailModalParams({
service,
});
}}
/>
);
})}
</Collapse>
Expand Down Expand Up @@ -451,20 +416,6 @@ const DashboardWrapper = styled.div`
flex-direction: column;
gap: 32px;
`;
const ProfileContainer = styled.div`
padding: 0 32px;
display: flex;
align-items: center;
gap: 16px;

@media (max-width: ${Breakpoints.Tablet}px) {
padding: 0 24px;
}

@media (max-width: ${Breakpoints.Mobile}px) {
padding: 0;
}
`;

const TabContainer = styled.div`
padding: 0 32px;
Expand Down
27 changes: 13 additions & 14 deletions apps/web/src/dashboard/DashboardMainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ import { formatUsername } from '@/utils/format';
import { UserProfile } from '@/profile/types/UserProfile';
import { Analytics, Supabase } from '@/utils';

import { TokenDetailModalParams } from './components/TokenDetailModal';
import { DetailModalParams } from './components/DetailModal';

const DynamicDashboardMain = dynamic(() => import('./DashboardMain'));
const DynmaicAddWalletModal = dynamic(
() => import('./components/AddWalletModal'),
);
const DynamicTokenDetailModal = dynamic(
() => import('./components/TokenDetailModal'),
);
const DynamicDetailModal = dynamic(() => import('./components/DetailModal'));

type Props =
| {
Expand Down Expand Up @@ -278,10 +276,11 @@ const DashboardPage = ({

const [isAddWalletModalVisible, setAddWalletModalVisible] =
useState<boolean>(false);
const [isTokenDetailModalVisible, setTokenDetailModalVisible] =
const [isDetailModalVisible, setDetailModalVisible] =
useState<boolean>(false);
const [tokenDetailModalParams, setTokenDetailModalParams] =
useState<TokenDetailModalParams>({});
const [detailModalParams, setDetailModalParams] = useState<DetailModalParams>(
{},
);

const hasWallet = !!session && wallets.length > 0;

Expand Down Expand Up @@ -388,22 +387,22 @@ const DashboardPage = ({
revalidateProfile={revalidateProfile}
revalidateWallets={revalidateWallets}
setAddWalletModalVisible={setAddWalletModalVisible}
setTokenDetailModalVisible={setTokenDetailModalVisible}
setTokenDetailModalParams={setTokenDetailModalParams}
setDetailModalVisible={setDetailModalVisible}
setDetailModalParams={setDetailModalParams}
/>

<DynmaicAddWalletModal
visible={isAddWalletModalVisible}
onDismiss={() => setAddWalletModalVisible((prev) => !prev)}
revalidateWallets={revalidateWallets}
/>
<DynamicTokenDetailModal
visible={isTokenDetailModalVisible}
<DynamicDetailModal
visible={isDetailModalVisible}
onDismiss={() => {
setTokenDetailModalVisible((prev) => !prev);
setTokenDetailModalParams({});
setDetailModalVisible((prev) => !prev);
setDetailModalParams({});
}}
{...tokenDetailModalParams}
{...detailModalParams}
/>
</PageContainer>
</>
Expand Down
Loading