Skip to content

Commit

Permalink
update mobile ui
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhochu committed Jan 5, 2024
1 parent ae54ea4 commit d3bc47e
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 39 deletions.
51 changes: 30 additions & 21 deletions components/CustomTable/CustomTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from "styled-components";
import React, { useEffect } from "react";
import React, { useEffect, useRef } from "react";
import { twMerge } from "tailwind-merge";
import CustomPagination from "./CustomPagination";
import CustomTableMobile from "./CustomTableMobile";
Expand Down Expand Up @@ -47,6 +47,7 @@ const CustomTable = ({
selectedRowIndex,
}: Props) => {
const isMobile = isMobileDevice();
const headersRef = useRef<any>([]);

if (isMobile) {
return (
Expand Down Expand Up @@ -116,29 +117,33 @@ const CustomTable = ({
}
return { text, size: d.size };
});

const headersWidth = headersRef.current.map((d) => d.getBoundingClientRect().width);
const headerNode = (
<div className="custom-table-thead">
<div className="custom-table-tr">
{headers?.map((d, i) => {
const styles: { flex?: string } = {};
if (d.size) {
styles.flex = `0 0 ${d.size}px`;
}
const keyId = typeof d.text === "string" ? d.text : i;
return (
<div key={keyId} className="custom-table-th text-gray-400" style={styles}>
{d.text}
</div>
);
})}
</div>
<div className="custom-table-tr custom-table-header-row">
{headers?.map((d, i) => {
const styles: { flex?: string } = {};
if (d.size) {
styles.flex = `0 0 ${d.size}px`;
}
const keyId = typeof d.text === "string" ? d.text : i;

const assignRef = (el) => {
headersRef.current[i] = el;
};
return (
<div key={keyId} className="custom-table-th text-gray-400" style={styles} ref={assignRef}>
{d.text}
</div>
);
})}
</div>
);

let bodyNodes;
if (data?.length) {
bodyNodes = data?.map((d, i) => {
const tdNode = columns?.map((col) => {
const tdNode = columns?.map((col, colIndex) => {
let content = null;
if (typeof col.cell === "function") {
content = col.cell({
Expand All @@ -148,8 +153,12 @@ const CustomTable = ({
content = d[col.accessorKey];
}
const styles: { flex?: string } = {};
if (col.size) {
styles.flex = `0 0 ${col.size}px`;
const colSize = headersWidth[colIndex];
// if (col.size) {
// styles.flex = `0 0 ${col.size}px`;
// }
if (colSize) {
styles.flex = `0 0 ${colSize}px`;
}
return (
<div className="custom-table-td" key={col.id || col.header} style={styles}>
Expand Down Expand Up @@ -238,15 +247,15 @@ const StyledTable = styled.div`
.custom-table-th {
text-align: left;
padding: 10px 5px;
padding: 10px 5px 10px 0;
}
}
.custom-table-tbody {
min-height: 85px;
.custom-table-td {
padding: 15px 5px;
padding: 15px 5px 15px 0;
justify-content: center;
display: flex;
flex-direction: column;
Expand Down
3 changes: 2 additions & 1 deletion components/Header/stats/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export const Stat = ({
onClick?: () => void;
}) => {
return (
<div onClick={() => onClick && onClick()} style={{ minHeight: 81 }} className="md:w-[351px]">
<div onClick={() => onClick && onClick()} style={{ minHeight: 81 }}>
{/* <div onClick={() => onClick && onClick()} style={{ minHeight: 81 }} className="md:w-[351px]"> */}
<div className="flex items-center gap-1">
{typeof title === "string" ? <div className="h6 text-gray-300">{title}</div> : title}
{titleTooltip && <ReactToolTip content={titleTooltip} />}
Expand Down
12 changes: 7 additions & 5 deletions screens/Dashboard/dashboardOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const DashboardOverview = ({ suppliedRows, borrowedRows }) => {
});
};

const hasMultiHealths = userHealth?.allHealths?.length > 1 && userHealth?.hasBorrow;
return (
<>
<div className="flex gap-2 justify-between items-center mb-4 lg3:hidden">
Expand All @@ -125,14 +126,15 @@ const DashboardOverview = ({ suppliedRows, borrowedRows }) => {
</div>
<ContentBox className="mb-8">
<div className="lg3:flex lg3:justify-between">
<div className="mb-4 lg3:max-w-[640px] lg3:mb-0">
<div className="flex gap-2 justify-between lg3:gap-6 lg3:gap-8">
<div className="gap-6 flex flex-col flex-2">
<div className={`mb-4 lg3:mb-0 ${!hasMultiHealths && "lg3:max-w-[640px]"}`}>
{/* <div className="mb-4 lg3:max-w-[640px] lg3:mb-0"> */}
<div className="flex gap-6 lg3:justify-between lg3:gap-6 lg3:gap-8">
<div className="gap-6 flex flex-col">
<UserLiquidity />
<UserDailyRewards />
</div>

<div className="gap-6 flex flex-col flex-1">
<div className="gap-6 flex flex-col">
<APY />
<div className="flex flex-col">
{/* <OverviewItem */}
Expand Down Expand Up @@ -199,7 +201,7 @@ const DashboardOverview = ({ suppliedRows, borrowedRows }) => {

<div className="relative flex xsm2:flex-col xsm:items-center items-end gap-4">
<HealthFactor userHealth={userHealthCur} />
{userHealth?.allHealths?.length > 1 && userHealth?.hasBorrow ? (
{hasMultiHealths ? (
<div className="lp-healths flex flex-col items-center gap-2 mt-4">
{userHealth.allHealths.map((value: any) => {
const isActive = value.id === userHealthCur?.id;
Expand Down
37 changes: 28 additions & 9 deletions screens/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,30 @@ const StyledSupplyBorrow = styled.div`
const yourSuppliedColumns = [
{
header: "Assets",
size: 160,
cell: ({ originalData }) => {
const { metadata } = originalData || {};
const { icon, tokens, symbol } = metadata || {};
let iconImg;
let symbolNode = "";
let symbolNode = symbol;
if (icon) {
symbolNode = symbol;
iconImg = (
<img
src={icon}
width={26}
height={26}
alt="token"
className="rounded-full w-[26px] h-[26px]"
style={{ marginRight: 3 }}
style={{ marginRight: 6, marginLeft: 3 }}
/>
);
} else if (tokens?.length) {
symbolNode = "";
iconImg = (
<div className="grid" style={{ marginRight: 2, gridTemplateColumns: "15px 12px" }}>
<div
className="grid"
style={{ marginRight: 2, gridTemplateColumns: "15px 12px", paddingLeft: 5 }}
>
{tokens?.map((d, i) => {
const isLast = i === tokens.length - 1;
symbolNode += `${d.metadata.symbol}${!isLast ? "-" : ""}`;
Expand All @@ -129,7 +133,12 @@ const yourSuppliedColumns = [
return (
<div className="flex gap-2 items-center">
{iconImg}
<div className="truncate" title={symbolNode}>
<div
title={symbolNode}
style={{
whiteSpace: "normal",
}}
>
{symbolNode}
</div>
</div>
Expand Down Expand Up @@ -244,11 +253,11 @@ const YourSupplied = ({ suppliedRows, accountId, total }) => {

const StyledCustomTable = styled(CustomTable)`
.custom-table-tbody {
margin: -2px -30px 0;
margin-top: -2px;
.custom-table-row {
padding-left: 30px;
padding-right: 30px;
//padding-left: 20px;
//padding-right: 20px;
cursor: pointer;
.custom-table-action {
Expand All @@ -270,11 +279,21 @@ const StyledCustomTable = styled(CustomTable)`
}
}
}
.custom-table-thead,
.custom-table-tbody {
margin: 0 -30px;
}
.custom-table-header-row,
.custom-table-row {
padding: 0 20px;
}
`;

const yourBorrowedColumns = [
{
header: "Assets",
size: 140,
cell: ({ originalData }) => {
return (
<div className="flex gap-2 items-center">
Expand All @@ -292,7 +311,7 @@ const yourBorrowedColumns = [
},
{
header: "Collateral Type",
size: 140,
size: 130,
cell: ({ originalData }) => {
const { collateralType, metadataLP } = originalData || {};
let tokenNames = "";
Expand Down
45 changes: 42 additions & 3 deletions screens/Dashboard/supplyBorrowListMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,45 @@ const StyledTabActiveBall = styled.div`
`;

const SupplyItem = ({ data }) => {
const { canUseAsCollateral } = data || {};
const { canUseAsCollateral, metadata } = data || {};
const { icon, tokens, symbol } = metadata || {};
let iconImg;
let symbolNode = symbol;
if (icon) {
iconImg = <img src={icon} width={26} height={26} alt="token" className="rounded-full" />;
} else if (tokens?.length) {
symbolNode = "";
iconImg = (
<div className="grid" style={{ marginRight: 2, gridTemplateColumns: "15px 12px" }}>
{tokens?.map((d, i) => {
const isLast = i === tokens.length - 1;
symbolNode += `${d.metadata.symbol}${!isLast ? "-" : ""}`;
return (
<img
key={d.metadata.symbol}
src={d.metadata?.icon}
width={20}
height={20}
alt="token"
className="rounded-full w-[20px] h-[20px] -m-1"
style={{ maxWidth: "none" }}
/>
);
})}
</div>
);
}

return (
<div>
<div
className="flex justify-between border-b"
style={{ padding: "16px", borderColor: "#31344C" }}
>
<div className="flex gap-2 items-center">
<img src={data?.icon} width={26} height={26} alt="token" className="rounded-full" />
{iconImg}
<div className="flex flex-col">
<div className="truncate h4b">{data?.symbol}</div>
<div className="truncate h4b">{symbolNode}</div>
{hiddenAssets.includes(data?.tokenId || "") ? null : (
<MarketButton
tokenId={data?.tokenId}
Expand Down Expand Up @@ -183,6 +211,12 @@ const SupplyItem = ({ data }) => {
};

const BorrowItem = ({ data }) => {
const { metadataLP, collateralType } = data || {};
let tokenNames = "";
metadataLP?.tokens?.forEach((d, i) => {
const isLast = i === metadataLP.tokens.length - 1;
tokenNames += `${d.metadata.symbol}${!isLast ? "-" : ""}`;
});
return (
<div>
<div
Expand All @@ -193,6 +227,11 @@ const BorrowItem = ({ data }) => {
<img src={data?.icon} width={26} height={26} alt="token" className="rounded-full" />
<div className="flex flex-col">
<div className="truncate h4b">{data?.symbol}</div>
{tokenNames && (
<div className="text-gray-300" style={{ fontSize: 12 }}>
{tokenNames}
</div>
)}
<MarketButton
tokenId={data?.tokenId}
style={{
Expand Down

0 comments on commit d3bc47e

Please sign in to comment.