Skip to content

Commit c556544

Browse files
committed
fix: production build lazyload walletconnect
split from other deploy PR
1 parent 20a0477 commit c556544

File tree

2 files changed

+56
-21
lines changed

2 files changed

+56
-21
lines changed

packages/auth-server/app.vue

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,7 @@
55
</template>
66

77
<script lang="ts" setup>
8-
import { createAppKit } from "@reown/appkit/vue";
9-
10-
const { defaultChain } = useClientStore();
11-
const { metadata, projectId, wagmiAdapter } = useAppKit();
12-
13-
createAppKit({
14-
adapters: [wagmiAdapter],
15-
networks: [defaultChain],
16-
projectId,
17-
metadata,
18-
});
19-
20-
// BigInt polyfill
8+
// BigInt polyfill for JSON serialization
219
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2210
(BigInt.prototype as any).toJSON = function () {
2311
return this.toString();
Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,75 @@
1+
import { createAppKit } from "@reown/appkit/vue";
12
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
23

4+
// Track if AppKit has been initialized
5+
let appKitInitialized = false;
6+
let wagmiAdapterInstance: WagmiAdapter | null = null;
7+
38
export const useAppKit = () => {
49
const runtimeConfig = useRuntimeConfig();
510
const { defaultChain } = useClientStore();
611

712
const projectId = runtimeConfig.public.appKitProjectId;
13+
const origin = typeof window !== "undefined" ? window.location.origin : "https://auth.zksync.dev";
14+
815
const metadata = {
916
name: "ZKsync SSO Auth Server",
1017
description: "ZKsync SSO Auth Server",
11-
url: window.location.origin,
12-
icons: [new URL("/icon-512.png", window.location.origin).toString()],
18+
url: origin,
19+
icons: [`${origin}/icon-512.png`],
1320
};
1421

15-
const wagmiAdapter = new WagmiAdapter({
16-
networks: [defaultChain],
17-
projectId,
18-
});
22+
// Create plain chain object to avoid Viem Proxy issues
23+
const plainChain = {
24+
id: defaultChain.id,
25+
name: defaultChain.name,
26+
nativeCurrency: {
27+
name: defaultChain.nativeCurrency.name,
28+
symbol: defaultChain.nativeCurrency.symbol,
29+
decimals: defaultChain.nativeCurrency.decimals,
30+
},
31+
rpcUrls: {
32+
default: {
33+
http: [...defaultChain.rpcUrls.default.http],
34+
},
35+
},
36+
blockExplorers: defaultChain.blockExplorers
37+
? {
38+
default: {
39+
name: defaultChain.blockExplorers.default.name,
40+
url: defaultChain.blockExplorers.default.url,
41+
},
42+
}
43+
: undefined,
44+
};
45+
46+
// Lazy initialization - only create AppKit when first used
47+
if (!appKitInitialized && typeof window !== "undefined") {
48+
try {
49+
wagmiAdapterInstance = new WagmiAdapter({
50+
networks: [plainChain],
51+
projectId,
52+
});
53+
54+
createAppKit({
55+
adapters: [wagmiAdapterInstance],
56+
networks: [plainChain],
57+
projectId,
58+
metadata,
59+
});
60+
61+
appKitInitialized = true;
62+
} catch (error) {
63+
console.warn("Failed to initialize AppKit:", error);
64+
}
65+
}
1966

20-
const wagmiConfig = wagmiAdapter.wagmiConfig;
67+
const wagmiConfig = wagmiAdapterInstance?.wagmiConfig;
2168

2269
return {
2370
metadata,
2471
projectId,
25-
wagmiAdapter,
72+
wagmiAdapter: wagmiAdapterInstance,
2673
wagmiConfig,
2774
};
2875
};

0 commit comments

Comments
 (0)