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

feat: Convert to Side Panel View #2498

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions _raw/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,35 @@ if (navigator?.usb) {
console.log('USB device disconnected', device);
});
}

chrome.sidePanel
.setPanelBehavior({ openPanelOnActionClick: true })
.catch((err) => console.error(err));

/**
* Function to send active tab info to the React app
* @param tabId {number}
*/
const sendActiveTabInfo = (tabId) => {
chrome.tabs.get(tabId, (tab) => {
if (tab) {
chrome.windows.get(tab.windowId, (window) => {
if (window.type === 'normal') {
chrome.runtime.sendMessage({ type: 'TAB_UPDATED', tab });
}
})
}
});
};

// Listen for tab activation
chrome.tabs.onActivated.addListener((activeInfo) => {
sendActiveTabInfo(activeInfo.tabId);
});

// Listen for tab URL updates
chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
if (changeInfo.status === 'complete') {
sendActiveTabInfo(tabId);
}
});
10 changes: 7 additions & 3 deletions src/manifest/mv3/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
"48": "images/icon-48.png",
"128": "images/icon-128.png"
},
"default_title": "Rabby",
"default_popup": "popup.html"
"default_title": "Rabby"
},
"side_panel": {
"default_path": "popup.html"
},
"author": "https://rabby.io/",
"background": {
Expand Down Expand Up @@ -62,10 +64,12 @@
"storage",
"unlimitedStorage",
"alarms",
"tabs",
"activeTab",
"notifications",
"offscreen",
"contextMenus"
"contextMenus",
"sidePanel"
],
"host_permissions": [
"<all_urls>"
Expand Down
2 changes: 1 addition & 1 deletion src/ui/component/AccountSelectDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const AccountSelectDrawer = ({

return (
<Drawer
height={440}
height="60%"
className="account-select is-support-darkmode"
visible={visible}
placement="bottom"
Expand Down
4 changes: 2 additions & 2 deletions src/ui/component/ChainSelector/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface ChainSelectorModalProps {
hideTestnetTab?: boolean;
hideMainnetTab?: boolean;
showRPCStatus?: boolean;
height?: number;
height?: string | number;
zIndex?: number;
}

Expand Down Expand Up @@ -138,7 +138,7 @@ const ChainSelectorModal = ({
hideTestnetTab = false,
hideMainnetTab = false,
showRPCStatus = false,
height = 494,
height = '70%',
zIndex,
}: ChainSelectorModalProps) => {
const handleCancel = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/component/ChainSelector/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
.chain-selector__modal.chain-selector__modal {
.ant-drawer-content-wrapper {
max-height: calc(100vh - 40px);
height: 494px !important;
//height: 494px !important;
}
header {
padding-top: 8px;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/component/TokenSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const TokenSelector = ({
return (
<Drawer
className="token-selector custom-popup is-support-darkmode"
height="580px"
height="75%"
placement="bottom"
visible={visible}
onClose={onCancel}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/popup.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html translate="no" class="notranslate overflow-hidden w-[400px] h-[599px]">
<html translate="no" class="notranslate overflow-hidden">

<head>
<meta charset="UTF-8" />
Expand All @@ -24,7 +24,7 @@
</style>
</head>

<body class="h-full w-[400px] h-[599px]">
<body class="h-full w-full">
<div id="root" class="h-full overflow-x-hidden"></div>
</body>

Expand Down
2 changes: 1 addition & 1 deletion src/ui/utils/WalletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const useCommonPopupViewState = () => {
>();
const [visible, setVisible] = useState(false);
const [title, setTitle] = useState<React.ReactNode>('Sign');
const [height, setHeight] = useState(360);
const [height, setHeight] = useState<string | number>(360);
const [className, setClassName] = useState<'isConnectView' | undefined>();
const [account, setAccount] = useState<{
address: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const ApprovalPopupContainer: React.FC<Props> = ({
}
}, [status]);

const lastNormalHeight = React.useRef(0);
const lastNormalHeight = React.useRef<string | number>(0);

React.useEffect(() => {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/Bridge/Component/BridgeHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export const BridgeTxHistory = ({
<Popup
visible={visible}
title={t('page.bridge.history')}
height={494}
height="70%"
onClose={onClose}
closable
bodyStyle={{
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/Bridge/Component/BridgeTokenPair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const TokenPairDrawer = (
return (
<Drawer
className="token-selector custom-popup is-support-darkmode"
height={440}
height="60%"
placement="bottom"
{...props}
>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/CommonPopup/AssetList/AssetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const AssetList = ({
const { isShowTestnet, selectedTab, onTabChange } = useSwitchNetTab();

React.useEffect(() => {
setHeight(488);
setHeight('65%');
}, []);

React.useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export const AddCustomTokenPopup = ({ visible, onClose, onConfirm }: Props) => {
<Popup
visible={visible}
closable={false}
height={494}
height="70%"
onClose={onClose}
className="add-custom-token-popup"
push={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export const AddCustomTestnetTokenPopup = ({
<Popup
visible={visible}
closable={false}
height={494}
height="70%"
onClose={onClose}
className="add-custom-token-popup"
push={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export const CustomTestnetAssetListContainer: React.FC<Props> = ({
setIsShowAddTestnetModal(false);
refreshAsync();
}}
height={488}
height="65%"
maskStyle={
isDarkTheme
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const CustomTestnetTokenDetailPopup = ({
<Popup
visible={visible}
closable={true}
height={494}
height="70%"
onClose={onClose}
className="custom-testnet-token-detail-popup"
push={false}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/CommonPopup/AssetList/TokenLowValueItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const TokenLowValueItem: React.FC<Props> = ({ className, list }) => {
})}
</div>
}
height={494}
height="70%"
visible={visible}
closable
push={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function SpecialTokenListPopup({

return (
<Popup
height={494}
height="70%"
visible={visible}
closable
push={false}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/CustomRPC/components/EditRPCModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const EditRPCModal = ({

return (
<Popup
height={440}
height="60%"
visible={visible}
onCancel={onCancel}
bodyStyle={{
Expand Down
4 changes: 2 additions & 2 deletions src/ui/views/CustomTestnet/components/EditTestnetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const EditCustomTestnetModal = ({
onConfirm(values: TestnetChain): void;
onChange?: (values: Partial<TestnetChainBase>) => void;
zIndex?: number;
height?: number;
height?: string | number;
maskStyle?: React.CSSProperties;
ctx?: {
ga?: {
Expand Down Expand Up @@ -127,7 +127,7 @@ export const EditCustomTestnetModal = ({

return (
<Popup
height={height || 520}
height={height}
visible={visible}
onCancel={onCancel}
bodyStyle={{
Expand Down
114 changes: 66 additions & 48 deletions src/ui/views/Dashboard/components/BalanceView/CurveView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import dayjs from 'dayjs';
import React from 'react';
import { useMemo, useState, useRef, useEffect } from 'react';
import { AreaChart, YAxis, Area, XAxis, Tooltip } from 'recharts';
import {
AreaChart,
YAxis,
Area,
XAxis,
Tooltip,
ResponsiveContainer,
} from 'recharts';
import styled, { createGlobalStyle } from 'styled-components';

export type CurvePoint = {
Expand Down Expand Up @@ -53,67 +60,78 @@ export const CurveThumbnail = ({
}, [data]);
const divRef = useRef<HTMLDivElement>(null);
const [height, setHeight] = useState(92);
const [width, setWidth] = useState<number>();

useEffect(() => {
if (divRef.current) {
setHeight(divRef.current.clientHeight);
}
}, []);
useEffect(() => {
if (divRef.current) {
setWidth(divRef.current.clientWidth);
}
}, [divRef.current?.getBoundingClientRect()]);

const isEmpty = !data;

return (
<CurveWrapper ref={divRef} className={className}>
<CurveGlobalStyle />
{isEmpty ? null : (
<AreaChart
data={data?.list}
width={380}
height={height}
style={{ position: 'absolute', left: 0, cursor: 'pointer' }}
margin={{ top: 5, right: 0, left: 0, bottom: 5 }}
onMouseMove={(val) => {
if (val?.activePayload) {
onHover(val.activePayload[0].payload);
}
}}
onMouseLeave={() => onHover(undefined)}
>
<defs>
<linearGradient id="curveThumbnail" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stopColor={color} stopOpacity={0.2} />
<stop offset="100%" stopColor={color} stopOpacity={0} />
</linearGradient>
</defs>
<XAxis
dataKey="timestamp"
hide
type="number"
domain={['dataMin', 'dataMax']}
/>
<YAxis
hide
domain={[(dataMin) => dataMin * 0.98, (dataMax) => dataMax * 1.005]}
/>
{isHover && (
<Tooltip
cursor={{ strokeDasharray: '2 2', strokeWidth: 0.6 }}
content={({ label }) => {
return <div>{dayjs(label * 1000).format('HH:mm')}</div>;
}}
<ResponsiveContainer>
<AreaChart
data={data?.list}
width={width}
height={height}
style={{ position: 'absolute', left: 0, cursor: 'pointer' }}
margin={{ top: 5, right: 0, left: 0, bottom: 5 }}
onMouseMove={(val) => {
if (val?.activePayload) {
onHover(val.activePayload[0].payload);
}
}}
onMouseLeave={() => onHover(undefined)}
>
<defs>
<linearGradient id="curveThumbnail" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stopColor={color} stopOpacity={0.2} />
<stop offset="100%" stopColor={color} stopOpacity={0} />
</linearGradient>
</defs>
<XAxis
dataKey="timestamp"
hide
type="number"
domain={['dataMin', 'dataMax']}
/>
<YAxis
hide
domain={[
(dataMin) => dataMin * 0.98,
(dataMax) => dataMax * 1.005,
]}
/>
{isHover && (
<Tooltip
cursor={{ strokeDasharray: '2 2', strokeWidth: 0.6 }}
content={({ label }) => {
return <div>{dayjs(label * 1000).format('HH:mm')}</div>;
}}
/>
)}
<Area
type="linear"
dataKey="value"
stroke={color}
strokeOpacity={isHover ? 1 : 0.7}
strokeWidth={2}
fill="url(#curveThumbnail)"
animationDuration={0}
fillOpacity={0.8}
/>
)}
<Area
type="linear"
dataKey="value"
stroke={color}
strokeOpacity={isHover ? 1 : 0.7}
strokeWidth={2}
fill="url(#curveThumbnail)"
animationDuration={0}
fillOpacity={0.8}
/>
</AreaChart>
</AreaChart>
</ResponsiveContainer>
)}
</CurveWrapper>
);
Expand Down
Loading