Skip to content

Commit b5bd874

Browse files
authored
Merge pull request #1658 from kleros/chore/update-lifi-widget-to-v3
Chore/update lifi widget to v3
2 parents 5f3d237 + 0bd343a commit b5bd874

File tree

6 files changed

+1256
-1371
lines changed

6 files changed

+1256
-1371
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/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 }} />;
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
};

0 commit comments

Comments
 (0)