Skip to content

Commit ca6a9f7

Browse files
authored
Merge branch 'dev' into refactor/dispute-resolver
2 parents bedfc49 + b5bd874 commit ca6a9f7

File tree

11 files changed

+1337
-1380
lines changed

11 files changed

+1337
-1380
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
},
7272
"alias": {
7373
"process": "process/browser.js",
74-
"buffer": "buffer",
75-
"@lifi/sdk": "@tractors/lifi-sdk-parcel"
74+
"buffer": "buffer"
7675
}
7776
}

web/global.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ declare module "styled-components" {
1717
//eslint-disable-next-line @typescript-eslint/no-empty-interface
1818
export interface DefaultTheme extends Theme {}
1919
}
20+
21+
declare module "chart.js" {
22+
interface TooltipPositionerMap {
23+
custom: TooltipPositionerFunction<ChartType>;
24+
}
25+
}

web/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@
7979
"@filebase/client": "^0.0.5",
8080
"@kleros/kleros-sdk": "workspace:^",
8181
"@kleros/ui-components-library": "^2.14.0",
82-
"@lifi/widget": "^2.10.1",
82+
"@lifi/wallet-management": "^3.0.3",
83+
"@lifi/widget": "^3.2.0",
8384
"@middy/core": "^5.3.2",
8485
"@middy/http-json-body-parser": "^5.3.2",
8586
"@sentry/react": "^7.93.0",
8687
"@sentry/tracing": "^7.93.0",
8788
"@supabase/supabase-js": "^2.39.3",
8889
"@tanstack/react-query": "^5.40.1",
89-
"@tractors/lifi-sdk-parcel": "^2.5.3",
9090
"@types/react-modal": "^3.16.3",
9191
"@web3modal/wagmi": "^4.1.10",
9292
"@yornaath/batshit": "^0.9.0",
@@ -102,9 +102,9 @@
102102
"moment": "^2.30.1",
103103
"overlayscrollbars": "^2.4.6",
104104
"overlayscrollbars-react": "^0.5.3",
105-
"react": "^18.2.0",
105+
"react": "^18.3.1",
106106
"react-chartjs-2": "^4.3.1",
107-
"react-dom": "^18.2.0",
107+
"react-dom": "^18.3.1",
108108
"react-error-boundary": "^3.1.4",
109109
"react-identicons": "^1.2.5",
110110
"react-is": "^18.2.0",
@@ -120,6 +120,6 @@
120120
"vanilla-jsoneditor": "^0.21.4",
121121
"viem": "^2.1.0",
122122
"vite": "^5.2.10",
123-
"wagmi": "^2.2.1"
123+
"wagmi": "^2.11.3"
124124
}
125125
}

web/src/components/ConnectWallet/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useCallback } from "react";
22

33
import { useWeb3Modal, useWeb3ModalState } from "@web3modal/wagmi/react";
4-
import { useAccount, useChainId, useSwitchChain } from "wagmi";
4+
import { useAccount, useSwitchChain } from "wagmi";
55

66
import { Button } from "@kleros/ui-components-library";
77

@@ -49,8 +49,8 @@ const ConnectButton: React.FC<{ className?: string }> = ({ className }) => {
4949
};
5050

5151
const ConnectWallet: React.FC<{ className?: string }> = ({ className }) => {
52-
const chainId = useChainId();
53-
const { isConnected } = useAccount();
52+
const { isConnected, chainId } = useAccount();
53+
5454
if (isConnected) {
5555
if (chainId !== DEFAULT_CHAIN) {
5656
return <SwitchChainButton {...{ className }} />;

web/src/layout/Header/DesktopHeader.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import styled, { css } from "styled-components";
33

44
import { useLocation } from "react-router-dom";
55
import { useToggle } from "react-use";
6+
import { useAccount } from "wagmi";
67

78
import KlerosSolutionsIcon from "svgs/menu-icons/kleros-solutions.svg";
89

910
import { useLockOverlayScroll } from "hooks/useLockOverlayScroll";
1011

12+
import { DEFAULT_CHAIN } from "consts/chains";
13+
1114
import { landscapeStyle } from "styles/landscapeStyle";
1215
import { responsiveSize } from "styles/responsiveSize";
1316

@@ -21,7 +24,6 @@ import Explore from "./navbar/Explore";
2124
import Menu from "./navbar/Menu";
2225
import Help from "./navbar/Menu/Help";
2326
import Settings from "./navbar/Menu/Settings";
24-
import { useAccount } from "wagmi";
2527

2628
const Container = styled.div`
2729
display: none;
@@ -73,13 +75,14 @@ const StyledKlerosSolutionsIcon = styled(KlerosSolutionsIcon)`
7375
fill: ${({ theme }) => theme.white} !important;
7476
`;
7577

76-
const ConnectWalletContainer = styled.div<{ isConnected: boolean }>`
78+
const ConnectWalletContainer = styled.div<{ isConnected: boolean; isDefaultChain: boolean }>`
7779
label {
7880
color: ${({ theme }) => theme.white};
7981
}
8082
81-
${({ isConnected }) =>
83+
${({ isConnected, isDefaultChain }) =>
8284
isConnected &&
85+
isDefaultChain &&
8386
css`
8487
cursor: pointer;
8588
& > * {
@@ -105,7 +108,8 @@ const DesktopHeader: React.FC = () => {
105108
const [isOnboardingMiniGuidesOpen, toggleIsOnboardingMiniGuidesOpen] = useToggle(false);
106109
const [initialTab, setInitialTab] = useState<number>(0);
107110
const location = useLocation();
108-
const { isConnected } = useAccount();
111+
const { isConnected, chainId } = useAccount();
112+
const isDefaultChain = chainId === DEFAULT_CHAIN;
109113

110114
const initializeFragmentURL = useCallback(() => {
111115
const hash = location.hash;
@@ -141,7 +145,10 @@ const DesktopHeader: React.FC = () => {
141145
</MiddleSide>
142146

143147
<RightSide>
144-
<ConnectWalletContainer isConnected={isConnected} onClick={isConnected ? toggleIsSettingsOpen : undefined}>
148+
<ConnectWalletContainer
149+
{...{ isConnected, isDefaultChain }}
150+
onClick={isConnected && isDefaultChain ? toggleIsSettingsOpen : undefined}
151+
>
145152
<ConnectWallet />
146153
</ConnectWalletContainer>
147154
<Menu {...{ toggleIsHelpOpen, toggleIsSettingsOpen }} />

web/src/layout/Header/navbar/Menu/Settings/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const Settings: React.FC<ISettings> = ({ toggleIsSettingsOpen, initialTab }) =>
9191
setCurrentTab(n);
9292
}}
9393
/>
94-
{currentTab === 0 ? <General /> : <NotificationSettings toggleIsSettingsOpen={toggleIsSettingsOpen} />}
94+
{currentTab === 0 ? <General /> : <NotificationSettings {...{ toggleIsSettingsOpen }} />}
9595
</Container>
9696
);
9797
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React, { useRef, type FC, type PropsWithChildren } from "react";
2+
3+
import { useSyncWagmiConfig } from "@lifi/wallet-management";
4+
import { useAvailableChains } from "@lifi/widget";
5+
import { injected, walletConnect } from "@wagmi/connectors";
6+
import { createWeb3Modal } from "@web3modal/wagmi";
7+
import { createClient, http } from "viem";
8+
import { arbitrum, arbitrumSepolia, mainnet } from "viem/chains";
9+
import type { Config } from "wagmi";
10+
import { createConfig, WagmiProvider } from "wagmi";
11+
12+
import { isProductionDeployment } from "consts/index";
13+
14+
import { lightTheme } from "styles/themes";
15+
16+
const projectId = import.meta.env.WALLETCONNECT_PROJECT_ID;
17+
18+
const connectors = [injected(), walletConnect({ projectId })];
19+
20+
export const WalletProvider: FC<PropsWithChildren> = ({ children }) => {
21+
const { chains } = useAvailableChains();
22+
const wagmi = useRef<Config>();
23+
24+
if (!wagmi.current) {
25+
wagmi.current = createConfig({
26+
chains: [mainnet],
27+
client({ chain }) {
28+
return createClient({ chain, transport: http() });
29+
},
30+
ssr: true,
31+
});
32+
}
33+
34+
useSyncWagmiConfig(wagmi.current, connectors, chains);
35+
36+
createWeb3Modal({
37+
wagmiConfig: wagmi.current,
38+
projectId,
39+
defaultChain: isProductionDeployment() ? arbitrum : arbitrumSepolia,
40+
allowUnsupportedChain: true,
41+
themeVariables: {
42+
"--w3m-color-mix": lightTheme.primaryPurple,
43+
"--w3m-color-mix-strength": 20,
44+
},
45+
});
46+
return (
47+
<WagmiProvider config={wagmi.current} reconnectOnMount={false}>
48+
{children}
49+
</WagmiProvider>
50+
);
51+
};

web/src/pages/GetPnk/Widget.tsx

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { LiFiWidget, WidgetConfig } from "@lifi/widget";
55

66
import { responsiveSize } from "styles/responsiveSize";
77

8+
import { WalletProvider } from "./WalletProvider";
9+
810
const WidgetContainer = styled.div`
911
width: 100%;
1012
> div {
@@ -19,18 +21,18 @@ const getWidgetConfig = (theme: Theme): WidgetConfig => ({
1921
toChain: 42161,
2022
fromToken: "0x93ED3FBe21207Ec2E8f2d3c3de6e058Cb73Bc04d",
2123
toToken: "0x330bD769382cFc6d50175903434CCC8D206DCAE5",
22-
containerStyle: {
23-
border: `1px solid ${theme.stroke}`,
24-
borderRadius: "3px",
25-
background: theme.whiteBackground,
26-
width: responsiveSize(350, 500),
27-
maxWidth: "600px",
28-
height: "fit-content",
29-
maxHeight: "none",
30-
minWidth: "300px",
31-
},
3224
hiddenUI: ["appearance", "language"],
3325
theme: {
26+
container: {
27+
border: `1px solid ${theme.stroke}`,
28+
borderRadius: "3px",
29+
background: theme.whiteBackground,
30+
width: responsiveSize(350, 500),
31+
maxWidth: "600px",
32+
height: "fit-content",
33+
maxHeight: "none",
34+
minWidth: "300px",
35+
},
3436
palette: {
3537
primary: {
3638
main: theme.primaryBlue,
@@ -40,7 +42,7 @@ const getWidgetConfig = (theme: Theme): WidgetConfig => ({
4042
},
4143
background: {
4244
paper: theme.whiteBackground, // bg color for cards
43-
default: theme.whiteBackground, // bg color container
45+
default: theme.lightBackground, // bg color container
4446
},
4547
grey: {
4648
300: theme.stroke, // border light theme
@@ -50,6 +52,21 @@ const getWidgetConfig = (theme: Theme): WidgetConfig => ({
5052
primary: theme.primaryText,
5153
secondary: theme.secondaryText,
5254
},
55+
common: {
56+
white: theme.primaryText,
57+
},
58+
warning: {
59+
main: theme.warning,
60+
},
61+
error: {
62+
main: theme.error,
63+
},
64+
info: {
65+
main: theme.primaryBlue,
66+
},
67+
success: {
68+
main: theme.success,
69+
},
5370
},
5471
shape: {
5572
borderRadius: 3,
@@ -68,8 +85,10 @@ export const Widget = () => {
6885
const widgetConfig = useMemo(() => getWidgetConfig(theme), [theme]);
6986

7087
return (
71-
<WidgetContainer>
72-
<LiFiWidget config={widgetConfig} integrator="Kleros" />
73-
</WidgetContainer>
88+
<WalletProvider>
89+
<WidgetContainer>
90+
<LiFiWidget config={widgetConfig} integrator="Kleros" />
91+
</WidgetContainer>
92+
</WalletProvider>
7493
);
7594
};

web/src/pages/Home/CourtOverview/Chart.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useMemo, useState } from "react";
22
import styled from "styled-components";
33

4+
import { Tooltip } from "chart.js";
45
import { formatUnits } from "viem";
56

67
import { DropdownSelect } from "@kleros/ui-components-library";
@@ -101,4 +102,23 @@ const Chart: React.FC = () => {
101102
);
102103
};
103104

105+
// custom positioner for tooltip, we need dynamic top positioning, which is not available by default.
106+
Tooltip.positioners.custom = function (elements) {
107+
const tooltip = this;
108+
const height = tooltip.chart.chartArea.height;
109+
const width = tooltip.chart.chartArea.width;
110+
111+
const x = elements[0]?.element.x;
112+
const y = elements[0]?.element.y;
113+
const isAtTop = height > y + tooltip.height;
114+
const isAtEnd = width < x + tooltip.width;
115+
116+
return {
117+
x: elements[0]?.element.x,
118+
y: elements[0]?.element.y,
119+
xAlign: isAtTop ? (isAtEnd ? "right" : "left") : "center",
120+
yAlign: isAtTop ? "center" : "bottom",
121+
};
122+
};
123+
104124
export default Chart;

web/src/pages/Home/CourtOverview/TimeSeriesChart.tsx

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import React from "react";
22
import styled, { useTheme } from "styled-components";
33

4-
import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, TimeScale, Tooltip } from "chart.js";
4+
import {
5+
Chart as ChartJS,
6+
CategoryScale,
7+
LinearScale,
8+
PointElement,
9+
LineElement,
10+
TimeScale,
11+
Tooltip,
12+
ScriptableContext,
13+
} from "chart.js";
514
import { Line } from "react-chartjs-2";
615
import "chartjs-adapter-moment";
716

@@ -51,6 +60,7 @@ const TimeSeriesChart: React.FC<ITimeSeriesChart> = ({ data }) => {
5160
},
5261
plugins: {
5362
tooltip: {
63+
position: "custom",
5464
backgroundColor: theme.whiteBackground,
5565
titleColor: theme.primaryText,
5666
borderColor: theme.stroke,
@@ -74,18 +84,47 @@ const TimeSeriesChart: React.FC<ITimeSeriesChart> = ({ data }) => {
7484
datasets: [
7585
{
7686
data,
77-
borderColor: theme.primaryBlue,
87+
// borderColor: theme.primaryBlue,
7888
stepped: true,
7989
cubicInterpolationMode: "monotone",
90+
borderColor: (context: ScriptableContext<"line">) => {
91+
const ctx = context.chart.ctx;
92+
const gradient = ctx.createLinearGradient(0, 0, 0, 200);
93+
gradient.addColorStop(0, theme.primaryBlue);
94+
gradient.addColorStop(1, theme.secondaryPurple);
95+
return gradient;
96+
},
8097
},
8198
],
8299
},
83100
options,
84101
}}
102+
plugins={[
103+
{
104+
id: "line-draw",
105+
afterDatasetsDraw: (chart) => {
106+
if (chart.tooltip?._active?.length) {
107+
const x = chart.tooltip._active[0].element.x;
108+
const y = chart.tooltip._active[0].element.y;
109+
const yAxis = chart.scales.y;
110+
111+
const ctx = chart.ctx;
112+
ctx.save();
113+
ctx.beginPath();
114+
ctx.moveTo(x, y);
115+
ctx.lineTo(x, yAxis.bottom);
116+
ctx.lineWidth = 1;
117+
ctx.strokeStyle = theme.secondaryPurple;
118+
ctx.setLineDash([4, 4]);
119+
ctx.stroke();
120+
ctx.restore();
121+
}
122+
},
123+
},
124+
]}
85125
/>
86126
}
87127
</LineContainer>
88128
);
89129
};
90-
91130
export default TimeSeriesChart;

0 commit comments

Comments
 (0)