Skip to content

Commit e80c005

Browse files
authored
Upgrade packages and dependencies (#14)
* ⬆️ upgrade wagmi, viem and connectkit * ⬆️ upgrade node engine version * 🚧 update rpc url from infura
1 parent 8728f13 commit e80c005

File tree

5 files changed

+1577
-799
lines changed

5 files changed

+1577
-799
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ FROM chef as dep_cacher
1313
COPY --from=dep_planner /siwe-oidc/recipe.json recipe.json
1414
RUN cargo chef cook --release --recipe-path recipe.json
1515

16-
FROM node:18.17.1-alpine3.18 as node_builder
16+
FROM node:18.20.0-alpine3.18 as node_builder
1717

1818
# Reference https://github.com/mhart/alpine-node/issues/27#issuecomment-880663905
1919
RUN apk add --no-cache --virtual .build-deps alpine-sdk python3

js/ui/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
99
},
1010
"dependencies": {
11+
"@tanstack/react-query": "5.51.1",
1112
"buffer": "6.0.3",
12-
"connectkit": "1.5.3",
13+
"connectkit": "1.8.2",
1314
"ethers": "6.6.1",
1415
"js-cookie": "3.0.5",
1516
"process": "0.11.10",
1617
"react": "18.2.0",
1718
"react-dom": "18.2.0",
1819
"siwe": "2.1.4",
1920
"usehooks-ts": "3.1.0",
20-
"viem": "1.1.7",
21-
"wagmi": "1.3.0"
21+
"viem": "2.x",
22+
"wagmi": "2.x"
2223
},
2324
"devDependencies": {
2425
"@babel/core": "7.22.5",
@@ -61,6 +62,6 @@
6162
"webpack-dev-server": "4.6.0"
6263
},
6364
"engines": {
64-
"node": ">=18.17.1"
65+
"node": ">=18.18.1"
6566
}
6667
}

js/ui/src/App.tsx

Lines changed: 82 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React from "react";
2+
import Cookies from "js-cookie";
23
import { ConnectKitButton, ConnectKitProvider } from "connectkit";
34
import { SiweMessage } from "siwe";
4-
import { useAccount, useDisconnect } from "wagmi";
5-
import Cookies from "js-cookie";
5+
import { useAccount, useChainId, useDisconnect, useSignMessage } from "wagmi";
6+
import { useCountdown } from "usehooks-ts";
7+
68
import devfolioLogoFull from "./assets/devfolio-logo-full.svg";
79
import connectWallet from "./assets/connect-wallet.svg";
810
import stepCheck from "./assets/step-check.svg";
911
import loader from "./assets/loader.svg";
10-
import { useCountdown } from "usehooks-ts";
1112

1213
type ACTION_TYPE = "signin" | "signup" | "connect";
1314
type STEP_STAGE = "complete" | "incomplete";
@@ -20,6 +21,8 @@ const oidc_nonce = params.get("oidc_nonce") ?? "";
2021
const client_id = params.get("client_id") ?? "";
2122
const action = (params.get("action") as ACTION_TYPE | undefined) ?? "signin";
2223

24+
const COUNTDOWN_IN_SECONDS = 3;
25+
2326
const TITLE: Record<ACTION_TYPE, string> = {
2427
signin: "Sign in with Ethereum",
2528
signup: "Sign up with Ethereum",
@@ -106,41 +109,99 @@ const Step = ({
106109
};
107110

108111
function App() {
112+
let siweSessionTimeout: NodeJS.Timeout;
113+
let redirectTimeout: NodeJS.Timeout;
114+
109115
const account = useAccount();
110116
const { disconnect } = useDisconnect();
117+
const chainId = useChainId();
111118

112-
const [isVerifyingAddress, setIsVerifyingAddress] =
113-
React.useState<boolean>(false);
114-
const [activeStepNumber, setActiveStepNumber] = React.useState<number>(1);
119+
const { signMessage: wagmiSignMessage } = useSignMessage({
120+
mutation: {
121+
onSuccess: (signature) => onVerifyAddressSuccess(signature),
122+
},
123+
});
115124

116125
const [count, { startCountdown }] = useCountdown({
117-
countStart: 3,
126+
countStart: COUNTDOWN_IN_SECONDS,
118127
intervalMs: 1000,
119128
});
120129

121-
const onWalletConnectSuccess = () => {
122-
setActiveStepNumber(2);
123-
};
130+
const [localSession, setLocalSession] = React.useState<{
131+
message: SiweMessage;
132+
raw: string;
133+
signature?: string;
134+
} | null>(null);
135+
136+
const [isVerifyingAddress, setIsVerifyingAddress] =
137+
React.useState<boolean>(false);
138+
139+
const [activeStepNumber, setActiveStepNumber] = React.useState<number>(1);
140+
141+
const expirationTime = React.useMemo(() => {
142+
return new Date(
143+
new Date().getTime() + 2 * 24 * 60 * 60 * 1000, // 48h
144+
);
145+
}, []);
146+
147+
// Clear all the timeout before closing the tab/app
148+
React.useEffect(() => {
149+
return () => {
150+
clearTimeout(siweSessionTimeout);
151+
clearTimeout(redirectTimeout);
152+
};
153+
// eslint-disable-next-line react-hooks/exhaustive-deps
154+
}, []);
155+
156+
const onVerifyAddressSuccess = (signature?: string) => {
157+
if (
158+
!localSession?.message ||
159+
!localSession?.raw ||
160+
typeof signature !== "string" ||
161+
signature?.length === 0
162+
)
163+
return;
124164

125-
const onVerifyAddressSuccess = () => {
126165
// Start countdown for redirect
127166
startCountdown();
128167
setIsVerifyingAddress(false);
129168

130169
setActiveStepNumber(3);
170+
171+
siweSessionTimeout = setTimeout(
172+
() => {
173+
Cookies.set(
174+
"siwe",
175+
JSON.stringify({
176+
...localSession,
177+
signature,
178+
}),
179+
{
180+
expires: expirationTime,
181+
},
182+
);
183+
},
184+
(COUNTDOWN_IN_SECONDS - 2) * 1000,
185+
);
186+
187+
redirectTimeout = setTimeout(() => {
188+
window.location.replace(
189+
`/sign_in?redirect_uri=${encodeURI(redirect)}&state=${encodeURI(
190+
state,
191+
)}&client_id=${encodeURI(client_id)}${encodeURI(oidc_nonce)}`,
192+
);
193+
}, COUNTDOWN_IN_SECONDS * 1000);
194+
};
195+
196+
const onWalletConnectSuccess = () => {
197+
setActiveStepNumber(2);
131198
};
132199

133200
const handleSignInWithEthereum = async (e: React.MouseEvent) => {
134201
e.preventDefault();
135202
setIsVerifyingAddress(true);
136203
const address = account?.address;
137204
try {
138-
const expirationTime = new Date(
139-
new Date().getTime() + 2 * 24 * 60 * 60 * 1000, // 48h
140-
);
141-
142-
const chainId = await account.connector?.getChainId();
143-
144205
const signMessage = new SiweMessage({
145206
domain: window.location.host,
146207
address: address,
@@ -152,33 +213,18 @@ function App() {
152213
nonce,
153214
resources: [redirect],
154215
}).prepareMessage();
155-
const walletClient = await account.connector?.getWalletClient();
156216

157-
const signature = await walletClient?.signMessage({
217+
wagmiSignMessage({
158218
account: account.address,
159219
message: signMessage,
160220
});
161221

162222
const message = new SiweMessage(signMessage);
163-
const session = {
223+
224+
setLocalSession({
164225
message,
165226
raw: signMessage,
166-
signature,
167-
};
168-
169-
onVerifyAddressSuccess();
170-
171-
setTimeout(() => {
172-
Cookies.set("siwe", JSON.stringify(session), {
173-
expires: expirationTime,
174-
});
175-
176-
window.location.replace(
177-
`/sign_in?redirect_uri=${encodeURI(redirect)}&state=${encodeURI(
178-
state,
179-
)}&client_id=${encodeURI(client_id)}${encodeURI(oidc_nonce)}`,
180-
);
181-
}, 3000);
227+
});
182228

183229
return;
184230
} catch (e) {

js/ui/src/main.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
import React from "react";
22
import ReactDOM from "react-dom/client";
3-
import { WagmiConfig, createConfig, mainnet } from "wagmi";
3+
import { WagmiProvider, createConfig, fallback, http } from "wagmi";
44
import { getDefaultConfig } from "connectkit";
5+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
6+
import { mainnet } from "wagmi/chains";
7+
58
import App from "./App";
69
import "./index.css";
710

811
const config = createConfig(
912
getDefaultConfig({
10-
// Required API Keys
11-
infuraId: process.env.INFURA_ID,
12-
walletConnectProjectId: process.env.WALLET_CONNECT_ID ?? '',
13+
walletConnectProjectId: process.env.WALLET_CONNECT_ID ?? "",
1314
chains: [mainnet],
15+
transports: {
16+
[mainnet.id]: fallback([
17+
http(
18+
`https://mainnet.infura.io/v3/${process.env.INFURA_ID ?? ""}`,
19+
),
20+
http(), // public fallback
21+
]),
22+
},
1423

1524
// Required
1625
appName: "SIWE | Devfolio",
1726
appUrl: "https://devfolio.co", // your app's url
1827
appIcon: "https://siwe.devfolio.co/favicon.png", // your app's logo,no bigger than 1024x1024px (max. 1MB)
19-
autoConnect: false,
20-
})
28+
}),
2129
);
2230

31+
const queryClient = new QueryClient();
32+
2333
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
2434
<React.StrictMode>
25-
<WagmiConfig config={config}>
26-
<App />
27-
</WagmiConfig>
28-
</React.StrictMode>
35+
<WagmiProvider config={config}>
36+
<QueryClientProvider client={queryClient}>
37+
<App />
38+
</QueryClientProvider>
39+
</WagmiProvider>
40+
</React.StrictMode>,
2941
);

0 commit comments

Comments
 (0)