Skip to content

Commit 4ddce32

Browse files
committed
fixed build error
1 parent 9b33fab commit 4ddce32

File tree

5 files changed

+184
-435
lines changed

5 files changed

+184
-435
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@
3838
"@devprotocol/dev-kit": "8.6.0",
3939
"@devprotocol/util-ts": "4.0.0",
4040
"@wagmi/core": "^1.4.7",
41+
"@web3auth/base": "^7.1.0",
4142
"@web3auth/modal": "^7.1.1",
4243
"bignumber.js": "9.1.2",
43-
"ramda": "0.29.1"
44+
"ramda": "0.29.1",
45+
"type-fest": "^4.7.1"
4446
},
4547
"peerDependencies": {
4648
"@devprotocol/clubs-core": "^2.1.1",

src/components/ConnectButton.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script setup lang="ts">
22
import { whenDefined, type UndefinedOr, isNotError } from '@devprotocol/util-ts'
3-
import type { Web3Auth as IWeb3Auth, Web3AuthOptions } from '@web3auth/modal'
4-
import { Web3Auth } from '@web3auth/modal'
3+
import type { Web3Auth, Web3AuthOptions } from '@web3auth/modal'
54
import type { IProvider, UserInfo } from '@web3auth/base'
65
import { mainnet, polygon, polygonMumbai } from '@wagmi/core/chains'
76
import { computed, onMounted, ref, watch } from 'vue'
@@ -10,6 +9,7 @@ import { BrowserProvider } from 'ethers'
109
import Modal from './Modal.vue'
1110
import type { Web3AuthButtonOptions, Web3AuthButtonEnvs } from '../types'
1211
import ClubsLogo from '../assets/clubs--color.svg'
12+
import { load } from '../utils/load'
1313
1414
const props = defineProps<Web3AuthButtonOptions & Web3AuthButtonEnvs>()
1515
@@ -19,7 +19,7 @@ const loaded = ref<boolean>()
1919
const provider = ref<IProvider | null | undefined>()
2020
const showModal = ref(false)
2121
const userInfo = ref<Partial<UserInfo>>()
22-
let web3auth: UndefinedOr<IWeb3Auth>
22+
let web3auth: UndefinedOr<Web3Auth>
2323
let connectionPool: UndefinedOr<typeof Connection>
2424
2525
const truncatedAddress = computed(() => {
@@ -68,7 +68,13 @@ const logout = async () => {
6868
6969
onMounted(async () => {
7070
console.log({ chainConfig })
71-
web3auth = new Web3Auth({
71+
72+
const [{ connection }] = await Promise.all([
73+
import('@devprotocol/clubs-core/connection'),
74+
load('//cdn.jsdelivr.net/npm/buffer@6'),
75+
load('//cdn.jsdelivr.net/npm/@web3auth/modal'),
76+
])
77+
web3auth = new window.Modal.Web3Auth({
7278
clientId: props.web3authClientId,
7379
web3AuthNetwork: props.web3authNetwork,
7480
chainConfig,
@@ -81,8 +87,6 @@ onMounted(async () => {
8187
await web3auth.initModal()
8288
loaded.value = true
8389
84-
const { connection } = await import('@devprotocol/clubs-core/connection')
85-
8690
// @ts-ignore
8791
connection().account.subscribe((_account) => {
8892
account.value = _account

src/env.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* eslint-disable functional/type-declaration-immutability */
22
/// <reference types="astro/client" />
33

4+
import type { Web3Auth } from '@web3auth/modal'
5+
import type { Constructor } from 'type-fest'
6+
47
interface ImportMetaEnv {
58
readonly PUBLIC_INFURA_KEY: string
69
readonly PUBLIC_WEB3AUTH_CLIENT_ID: string
@@ -14,3 +17,11 @@ declare module '*.astro' {
1417
import type { AstroComponentFactory } from 'astro/dist/runtime/server'
1518
export default InstanceType<AstroComponentFactory>
1619
}
20+
21+
declare global {
22+
interface Window {
23+
Modal: {
24+
Web3Auth: Constructor<Web3Auth>
25+
}
26+
}
27+
}

src/utils/load.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable functional/no-return-void */
2+
/* eslint-disable functional/immutable-data */
3+
/* eslint-disable functional/no-expression-statements */
4+
5+
export const load = async (src: string): Promise<true> => {
6+
const id = `__load_${window.btoa(src)}__`
7+
8+
const exists = Boolean(document.getElementById(id))
9+
10+
console.log({ id, exists })
11+
12+
return exists
13+
? true
14+
: new Promise((resolve) => {
15+
const script = document.createElement('script')
16+
17+
script.id = id
18+
script.src = src
19+
document.body.append(script)
20+
script.onload = () => resolve(true)
21+
})
22+
}

0 commit comments

Comments
 (0)