@1001-digital/layers.evm 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +1 -3
- package/.playground/app/app.vue +1 -0
- package/.playground/app/pages/index.vue +1 -2
- package/.playground/nuxt.config.ts +3 -1
- package/AGENTS.md +2 -2
- package/README.md +1 -1
- package/app/composables/base.ts +1 -5
- package/app/composables/chainId.ts +6 -42
- package/app/plugins/wagmi.ts +40 -3
- package/app/utils/addresses.ts +1 -4
- package/app/utils/chains.ts +1 -13
- package/app/utils/format-eth.ts +1 -12
- package/nuxt.config.ts +33 -0
- package/package.json +5 -6
- package/app/components/EvmAccount.client.vue +0 -26
- package/app/components/EvmConnect.client.vue +0 -238
- package/app/components/EvmConnectorQR.client.vue +0 -108
- package/app/components/EvmMetaMaskQR.client.vue +0 -13
- package/app/components/EvmTransactionFlow.vue +0 -293
- package/app/components/EvmWalletConnectQR.client.vue +0 -13
- package/app/composables/clipboard.ts +0 -26
- package/app/composables/ens.ts +0 -88
- package/app/composables/gasPrice.ts +0 -36
- package/app/composables/helpers.ts +0 -1
- package/app/composables/priceFeed.ts +0 -103
- package/app/plugins/price-feed.client.ts +0 -7
- package/app/utils/cache.ts +0 -59
- package/app/utils/ens.ts +0 -98
- package/app/utils/price.ts +0 -15
package/.playground/app/app.vue
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url'
|
|
2
2
|
|
|
3
3
|
const layerDir = fileURLToPath(new URL('..', import.meta.url))
|
|
4
|
+
const componentsDir = fileURLToPath(new URL('../../components/src', import.meta.url))
|
|
4
5
|
|
|
5
6
|
export default defineNuxtConfig({
|
|
6
7
|
extends: ['@1001-digital/layers.base', '..'],
|
|
@@ -9,11 +10,12 @@ export default defineNuxtConfig({
|
|
|
9
10
|
config: {
|
|
10
11
|
// Use the generated ESLint config for lint root project as well
|
|
11
12
|
rootDir: layerDir,
|
|
12
|
-
}
|
|
13
|
+
},
|
|
13
14
|
},
|
|
14
15
|
hooks: {
|
|
15
16
|
'vite:serverCreated': (server) => {
|
|
16
17
|
server.watcher.add(layerDir)
|
|
18
|
+
server.watcher.add(componentsDir)
|
|
17
19
|
},
|
|
18
20
|
},
|
|
19
21
|
})
|
package/AGENTS.md
CHANGED
|
@@ -18,6 +18,7 @@ Nuxt layer for building dAPPs (Ethereum-powered applications). Extends `@1001-di
|
|
|
18
18
|
## Wagmi Configuration
|
|
19
19
|
|
|
20
20
|
Uses modern wagmi 0.4.x patterns:
|
|
21
|
+
|
|
21
22
|
- `useConnection` (not deprecated `useAccount`)
|
|
22
23
|
- `useConnectionEffect` (not deprecated `useAccountEffect`)
|
|
23
24
|
- `useSwitchConnection` (not deprecated `useSwitchAccount`)
|
|
@@ -29,7 +30,7 @@ Connectors: injected, coinbaseWallet, metaMask, walletConnect
|
|
|
29
30
|
## Components
|
|
30
31
|
|
|
31
32
|
- `EvmConnect.client.vue` - Wallet connection button with modal
|
|
32
|
-
- `EvmAccount.client.vue` - Address display
|
|
33
|
+
- `EvmAccount.client.vue` - Address display
|
|
33
34
|
- `EvmTransactionFlow.vue` - Guided transaction execution flow
|
|
34
35
|
- `EvmConnectorQR.client.vue` - Base QR code renderer
|
|
35
36
|
- `EvmWalletConnectQR.client.vue` - WalletConnect QR wrapper
|
|
@@ -42,7 +43,6 @@ Connectors: injected, coinbaseWallet, metaMask, walletConnect
|
|
|
42
43
|
- `useBlockExplorer(key?)` - Get block explorer URL for a named chain
|
|
43
44
|
- `useEnsureChainIdCheck()` - Validate/switch chain before transactions
|
|
44
45
|
- `useBaseURL()` - Get base URL with trailing slash
|
|
45
|
-
- `useClipboard()` - Copy text to clipboard with copied state
|
|
46
46
|
|
|
47
47
|
## Utilities
|
|
48
48
|
|
package/README.md
CHANGED
package/app/composables/base.ts
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const getDefaultChainKey = () => useAppConfig().evm?.defaultChain || 'mainnet'
|
|
9
|
-
|
|
10
|
-
export const useChainConfig = (key?: string) => {
|
|
11
|
-
const appConfig = useAppConfig()
|
|
12
|
-
const resolvedKey = key || getDefaultChainKey()
|
|
13
|
-
const chains = appConfig.evm?.chains as Record<string, ChainConfig> | undefined
|
|
14
|
-
const chain = chains?.[resolvedKey]
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
id: chain?.id ?? 1,
|
|
18
|
-
blockExplorer: chain?.blockExplorer ?? 'https://etherscan.io',
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const useMainChainId = () => useChainConfig().id
|
|
23
|
-
|
|
24
|
-
export const useBlockExplorer = (key?: string) => useChainConfig(key).blockExplorer
|
|
25
|
-
|
|
26
|
-
export const useEnsureChainIdCheck = () => {
|
|
27
|
-
const chainId = useMainChainId()
|
|
28
|
-
const { switchChain } = useSwitchChain()
|
|
29
|
-
const { chainId: currentChainId } = useConnection()
|
|
30
|
-
|
|
31
|
-
return async () => {
|
|
32
|
-
if (chainId !== currentChainId.value) {
|
|
33
|
-
switchChain({ chainId })
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (chainId === currentChainId.value) {
|
|
37
|
-
return true
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return false
|
|
41
|
-
}
|
|
42
|
-
}
|
|
1
|
+
export {
|
|
2
|
+
useChainConfig,
|
|
3
|
+
useMainChainId,
|
|
4
|
+
useBlockExplorer,
|
|
5
|
+
useEnsureChainIdCheck,
|
|
6
|
+
} from '@1001-digital/components'
|
package/app/plugins/wagmi.ts
CHANGED
|
@@ -9,14 +9,25 @@ import {
|
|
|
9
9
|
type Config,
|
|
10
10
|
type CreateConnectorFn,
|
|
11
11
|
} from '@wagmi/vue'
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
coinbaseWallet,
|
|
14
|
+
injected,
|
|
15
|
+
metaMask,
|
|
16
|
+
walletConnect,
|
|
17
|
+
} from '@wagmi/vue/connectors'
|
|
13
18
|
import type { Chain, Transport } from 'viem'
|
|
19
|
+
import {
|
|
20
|
+
EvmConfigKey,
|
|
21
|
+
resolveChain,
|
|
22
|
+
type EvmConfig,
|
|
23
|
+
} from '@1001-digital/components'
|
|
14
24
|
|
|
15
25
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
16
26
|
const appConfig = useAppConfig()
|
|
17
27
|
const runtimeConfig = nuxtApp.$config.public.evm as {
|
|
18
28
|
walletConnectProjectId: string
|
|
19
|
-
chains: Record<string, { rpc1?: string
|
|
29
|
+
chains: Record<string, { rpc1?: string; rpc2?: string; rpc3?: string }>
|
|
30
|
+
ens: { indexer1?: string; indexer2?: string; indexer3?: string }
|
|
20
31
|
}
|
|
21
32
|
|
|
22
33
|
const title = appConfig.evm?.title || 'EVM Layer'
|
|
@@ -78,7 +89,33 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
78
89
|
transports,
|
|
79
90
|
})
|
|
80
91
|
|
|
81
|
-
|
|
92
|
+
// Build EvmConfig from Nuxt app/runtime config
|
|
93
|
+
const indexerUrls = [
|
|
94
|
+
runtimeConfig.ens?.indexer1,
|
|
95
|
+
runtimeConfig.ens?.indexer2,
|
|
96
|
+
runtimeConfig.ens?.indexer3,
|
|
97
|
+
].filter(Boolean) as string[]
|
|
98
|
+
|
|
99
|
+
const evmConfig: EvmConfig = {
|
|
100
|
+
title,
|
|
101
|
+
defaultChain: appConfig.evm?.defaultChain || 'mainnet',
|
|
102
|
+
chains: Object.fromEntries(
|
|
103
|
+
Object.entries(chainEntries).map(([key, entry]) => [
|
|
104
|
+
key,
|
|
105
|
+
{ id: entry.id!, blockExplorer: entry.blockExplorer },
|
|
106
|
+
]),
|
|
107
|
+
),
|
|
108
|
+
ens: {
|
|
109
|
+
mode: appConfig.evm?.ens?.mode || 'indexer',
|
|
110
|
+
indexerUrls,
|
|
111
|
+
},
|
|
112
|
+
baseURL: nuxtApp.$config.app.baseURL,
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
nuxtApp.vueApp
|
|
116
|
+
.use(WagmiPlugin, { config: wagmiConfig })
|
|
117
|
+
.use(VueQueryPlugin, {})
|
|
118
|
+
.provide(EvmConfigKey, evmConfig)
|
|
82
119
|
|
|
83
120
|
return {
|
|
84
121
|
provide: {
|
package/app/utils/addresses.ts
CHANGED
package/app/utils/chains.ts
CHANGED
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { mainnet, sepolia, holesky, optimism, arbitrum, base, polygon, localhost } from 'viem/chains'
|
|
3
|
-
|
|
4
|
-
const KNOWN: Chain[] = [mainnet, sepolia, holesky, optimism, arbitrum, base, polygon, localhost]
|
|
5
|
-
const byId = new Map<number, Chain>(KNOWN.map(c => [c.id, c]))
|
|
6
|
-
|
|
7
|
-
export const resolveChain = (id: number): Chain =>
|
|
8
|
-
byId.get(id) ?? defineChain({
|
|
9
|
-
id,
|
|
10
|
-
name: `Chain ${id}`,
|
|
11
|
-
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
|
|
12
|
-
rpcUrls: { default: { http: [] } },
|
|
13
|
-
})
|
|
1
|
+
export { resolveChain } from '@1001-digital/components'
|
package/app/utils/format-eth.ts
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
const numberValue = typeof value === 'string' ? parseFloat(value) : value
|
|
3
|
-
|
|
4
|
-
if (isNaN(numberValue)) {
|
|
5
|
-
throw new Error('Invalid number input')
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return new Intl.NumberFormat('en-US', {
|
|
9
|
-
minimumFractionDigits: 0,
|
|
10
|
-
maximumFractionDigits: maxDecimals,
|
|
11
|
-
}).format(numberValue)
|
|
12
|
-
}
|
|
1
|
+
export { formatETH } from '@1001-digital/components'
|
package/nuxt.config.ts
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url'
|
|
2
|
+
|
|
3
|
+
const componentsDir = fileURLToPath(
|
|
4
|
+
new URL('../components/src/evm/components', import.meta.url),
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
const clientOnlyComponents = [
|
|
8
|
+
'EvmAccount',
|
|
9
|
+
'EvmConnect',
|
|
10
|
+
'EvmConnectorQR',
|
|
11
|
+
'EvmMetaMaskQR',
|
|
12
|
+
'EvmWalletConnectQR',
|
|
13
|
+
]
|
|
14
|
+
|
|
1
15
|
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
2
16
|
export default defineNuxtConfig({
|
|
3
17
|
extends: ['@1001-digital/layers.base'],
|
|
4
18
|
|
|
5
19
|
modules: ['@wagmi/vue/nuxt'],
|
|
6
20
|
|
|
21
|
+
hooks: {
|
|
22
|
+
'components:dirs': (dirs) => {
|
|
23
|
+
dirs.push({
|
|
24
|
+
path: componentsDir,
|
|
25
|
+
pathPrefix: false,
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
'components:extend': (components) => {
|
|
29
|
+
for (const c of components) {
|
|
30
|
+
if (clientOnlyComponents.includes(c.pascalName)) {
|
|
31
|
+
c.mode = 'client'
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
|
|
7
37
|
ssr: process.env.NUXT_SSR !== 'false',
|
|
8
38
|
|
|
9
39
|
runtimeConfig: {
|
|
@@ -23,6 +53,9 @@ export default defineNuxtConfig({
|
|
|
23
53
|
},
|
|
24
54
|
|
|
25
55
|
vite: {
|
|
56
|
+
resolve: {
|
|
57
|
+
dedupe: ['@wagmi/vue', '@wagmi/core', 'viem'],
|
|
58
|
+
},
|
|
26
59
|
optimizeDeps: {
|
|
27
60
|
include: [
|
|
28
61
|
'@1001-digital/layers.evm > @metamask/sdk',
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1001-digital/layers.evm",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.8",
|
|
5
5
|
"main": "./nuxt.config.ts",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@nuxt/eslint": "latest",
|
|
@@ -10,20 +10,19 @@
|
|
|
10
10
|
"nuxt": "^4.3.0",
|
|
11
11
|
"typescript": "^5.9.3",
|
|
12
12
|
"vue": "latest",
|
|
13
|
-
"@1001-digital/layers.base": "^0.0.
|
|
13
|
+
"@1001-digital/layers.base": "^0.0.32"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@1001-digital/layers.base": "^0.0.
|
|
16
|
+
"@1001-digital/layers.base": "^0.0.32"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@types/qrcode": "^1.5.6",
|
|
20
19
|
"@metamask/sdk": "~0.34.0",
|
|
21
20
|
"@tanstack/vue-query": "^5.92.9",
|
|
22
21
|
"@wagmi/core": "^3.3.2",
|
|
23
22
|
"@wagmi/vue": "^0.4.15",
|
|
24
23
|
"@walletconnect/ethereum-provider": "~2.23.4",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
24
|
+
"viem": "~2.45.1",
|
|
25
|
+
"@1001-digital/components": "^0.0.1"
|
|
27
26
|
},
|
|
28
27
|
"scripts": {
|
|
29
28
|
"dev": "nuxi dev .playground",
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<slot :display="display" :is-current="isCurrent">
|
|
3
|
-
<span>{{ display }}</span>
|
|
4
|
-
</slot>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script setup lang="ts">
|
|
8
|
-
import type { Address } from 'viem'
|
|
9
|
-
import { useConnection } from '@wagmi/vue'
|
|
10
|
-
|
|
11
|
-
const props = defineProps<{
|
|
12
|
-
address?: Address
|
|
13
|
-
mode?: 'indexer' | 'chain'
|
|
14
|
-
}>()
|
|
15
|
-
const address = computed(() => props.address)
|
|
16
|
-
|
|
17
|
-
const { address: currentAddress } = useConnection()
|
|
18
|
-
|
|
19
|
-
const isCurrent = computed<boolean>(
|
|
20
|
-
() => currentAddress.value?.toLowerCase() === address.value?.toLowerCase(),
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
const { data: profile } = useEns(address, { mode: computed(() => props.mode) })
|
|
24
|
-
|
|
25
|
-
const display = computed<string>(() => profile.value?.ens || shortAddress(address.value!))
|
|
26
|
-
</script>
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<Button
|
|
3
|
-
v-if="showConnect"
|
|
4
|
-
@click="chooseModalOpen = true"
|
|
5
|
-
:class="className"
|
|
6
|
-
>
|
|
7
|
-
<slot>Connect Wallet</slot>
|
|
8
|
-
</Button>
|
|
9
|
-
<slot
|
|
10
|
-
v-else
|
|
11
|
-
name="connected"
|
|
12
|
-
:address="address"
|
|
13
|
-
>
|
|
14
|
-
<EvmAccount :address="address" />
|
|
15
|
-
</slot>
|
|
16
|
-
|
|
17
|
-
<Dialog
|
|
18
|
-
v-if="showConnect"
|
|
19
|
-
title="Connect Wallet"
|
|
20
|
-
v-model:open="chooseModalOpen"
|
|
21
|
-
@closed="onModalClosed"
|
|
22
|
-
>
|
|
23
|
-
<Alert
|
|
24
|
-
v-if="errorMessage"
|
|
25
|
-
type="error"
|
|
26
|
-
>
|
|
27
|
-
{{ errorMessage }}
|
|
28
|
-
</Alert>
|
|
29
|
-
<EvmWalletConnectQR
|
|
30
|
-
v-if="walletConnectUri"
|
|
31
|
-
:uri="walletConnectUri"
|
|
32
|
-
/>
|
|
33
|
-
<EvmMetaMaskQR
|
|
34
|
-
v-else-if="metaMaskUri"
|
|
35
|
-
:uri="metaMaskUri"
|
|
36
|
-
/>
|
|
37
|
-
<template v-else-if="isConnecting">
|
|
38
|
-
<Loading
|
|
39
|
-
txt="Waiting for wallet confirmation..."
|
|
40
|
-
spinner
|
|
41
|
-
stacked
|
|
42
|
-
/>
|
|
43
|
-
</template>
|
|
44
|
-
<div
|
|
45
|
-
v-else
|
|
46
|
-
class="wallet-options"
|
|
47
|
-
>
|
|
48
|
-
<Button
|
|
49
|
-
v-for="connector in shownConnectors"
|
|
50
|
-
:key="connector.uid"
|
|
51
|
-
@click="() => login(connector)"
|
|
52
|
-
class="choose-connector"
|
|
53
|
-
>
|
|
54
|
-
<img
|
|
55
|
-
v-if="ICONS[connector.name]"
|
|
56
|
-
:src="
|
|
57
|
-
connector.icon || `${base}icons/wallets/${ICONS[connector.name]}`
|
|
58
|
-
"
|
|
59
|
-
:alt="connector.name"
|
|
60
|
-
/>
|
|
61
|
-
<div
|
|
62
|
-
v-else
|
|
63
|
-
class="default-wallet-icon"
|
|
64
|
-
>
|
|
65
|
-
<Icon type="wallet" />
|
|
66
|
-
</div>
|
|
67
|
-
<span>{{ connector.name }}</span>
|
|
68
|
-
</Button>
|
|
69
|
-
<Button
|
|
70
|
-
to="https://ethereum.org/wallets/"
|
|
71
|
-
target="_blank"
|
|
72
|
-
class="link muted small"
|
|
73
|
-
>
|
|
74
|
-
<Icon type="help" />
|
|
75
|
-
<span>New to wallets?</span>
|
|
76
|
-
</Button>
|
|
77
|
-
</div>
|
|
78
|
-
</Dialog>
|
|
79
|
-
</template>
|
|
80
|
-
|
|
81
|
-
<script setup lang="ts">
|
|
82
|
-
import type { Connector } from '@wagmi/vue'
|
|
83
|
-
import { useConnection, useConnect, useChainId } from '@wagmi/vue'
|
|
84
|
-
|
|
85
|
-
const ICONS: Record<string, string> = {
|
|
86
|
-
'Coinbase Wallet': 'coinbase.svg',
|
|
87
|
-
MetaMask: 'metamask.svg',
|
|
88
|
-
Phantom: 'phantom.svg',
|
|
89
|
-
'Rabby Wallet': 'rabby.svg',
|
|
90
|
-
Rainbow: 'rainbow.svg',
|
|
91
|
-
WalletConnect: 'walletconnect.svg',
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const PRIORITY: Record<string, number> = {
|
|
95
|
-
WalletConnect: 20,
|
|
96
|
-
'Coinbase Wallet': 10,
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
defineProps<{
|
|
100
|
-
className?: string
|
|
101
|
-
}>()
|
|
102
|
-
const emit = defineEmits<{
|
|
103
|
-
connected: [{ address: `0x${string}` | undefined }]
|
|
104
|
-
disconnected: []
|
|
105
|
-
}>()
|
|
106
|
-
const base = useBaseURL()
|
|
107
|
-
|
|
108
|
-
const chainId = useChainId()
|
|
109
|
-
const { connectors, connectAsync } = useConnect()
|
|
110
|
-
const { address, isConnected } = useConnection()
|
|
111
|
-
|
|
112
|
-
const showConnect = computed(() => !isConnected.value)
|
|
113
|
-
const shownConnectors = computed(() => {
|
|
114
|
-
const unique = Array.from(
|
|
115
|
-
new Map(
|
|
116
|
-
connectors?.map((connector) => [connector.name, connector]),
|
|
117
|
-
).values(),
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
const filtered =
|
|
121
|
-
unique.length > 1 ? unique.filter((c) => c.id !== 'injected') : unique
|
|
122
|
-
|
|
123
|
-
return filtered.sort((a, b) => {
|
|
124
|
-
const priorityA = PRIORITY[a.name] ?? 5
|
|
125
|
-
const priorityB = PRIORITY[b.name] ?? 5
|
|
126
|
-
return priorityA - priorityB
|
|
127
|
-
})
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
const chooseModalOpen = ref(false)
|
|
131
|
-
const errorMessage = ref('')
|
|
132
|
-
const isConnecting = ref(false)
|
|
133
|
-
const walletConnectUri = ref('')
|
|
134
|
-
const metaMaskUri = ref('')
|
|
135
|
-
|
|
136
|
-
const login = async (connector: Connector) => {
|
|
137
|
-
errorMessage.value = ''
|
|
138
|
-
isConnecting.value = true
|
|
139
|
-
walletConnectUri.value = ''
|
|
140
|
-
metaMaskUri.value = ''
|
|
141
|
-
|
|
142
|
-
const handleMessage = (event: { type: string; data?: unknown }) => {
|
|
143
|
-
if (event.type === 'display_uri' && typeof event.data === 'string') {
|
|
144
|
-
if (connector.id === 'walletConnect') {
|
|
145
|
-
walletConnectUri.value = event.data
|
|
146
|
-
} else if (connector.id === 'metaMaskSDK') {
|
|
147
|
-
metaMaskUri.value = event.data
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (connector.id === 'walletConnect' || connector.id === 'metaMaskSDK') {
|
|
153
|
-
connector.emitter.on('message', handleMessage)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
try {
|
|
157
|
-
await connectAsync({ connector, chainId: chainId.value })
|
|
158
|
-
|
|
159
|
-
setTimeout(() => {
|
|
160
|
-
chooseModalOpen.value = false
|
|
161
|
-
isConnecting.value = false
|
|
162
|
-
walletConnectUri.value = ''
|
|
163
|
-
metaMaskUri.value = ''
|
|
164
|
-
}, 100)
|
|
165
|
-
} catch (error: unknown) {
|
|
166
|
-
isConnecting.value = false
|
|
167
|
-
walletConnectUri.value = ''
|
|
168
|
-
metaMaskUri.value = ''
|
|
169
|
-
|
|
170
|
-
const errorMsg = error instanceof Error ? error.message : ''
|
|
171
|
-
if (
|
|
172
|
-
errorMsg.includes('User rejected') ||
|
|
173
|
-
errorMsg.includes('rejected') ||
|
|
174
|
-
errorMsg.includes('denied')
|
|
175
|
-
) {
|
|
176
|
-
errorMessage.value = 'Connection cancelled. Please try again.'
|
|
177
|
-
} else {
|
|
178
|
-
errorMessage.value = 'Failed to connect. Please try again.'
|
|
179
|
-
}
|
|
180
|
-
console.error('Wallet connection error:', error)
|
|
181
|
-
} finally {
|
|
182
|
-
if (connector.id === 'walletConnect' || connector.id === 'metaMaskSDK') {
|
|
183
|
-
connector.emitter.off('message', handleMessage)
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const onModalClosed = () => {
|
|
189
|
-
errorMessage.value = ''
|
|
190
|
-
isConnecting.value = false
|
|
191
|
-
walletConnectUri.value = ''
|
|
192
|
-
metaMaskUri.value = ''
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const check = () =>
|
|
196
|
-
isConnected.value
|
|
197
|
-
? emit('connected', { address: address.value })
|
|
198
|
-
: emit('disconnected')
|
|
199
|
-
watch(isConnected, () => check())
|
|
200
|
-
onMounted(() => check())
|
|
201
|
-
</script>
|
|
202
|
-
|
|
203
|
-
<style scoped>
|
|
204
|
-
.wallet-options {
|
|
205
|
-
display: grid;
|
|
206
|
-
gap: var(--spacer);
|
|
207
|
-
|
|
208
|
-
button.choose-connector {
|
|
209
|
-
width: 100%;
|
|
210
|
-
inline-size: auto;
|
|
211
|
-
justify-content: flex-start;
|
|
212
|
-
|
|
213
|
-
img,
|
|
214
|
-
.default-wallet-icon {
|
|
215
|
-
margin: -1rem 0 -1rem -0.6rem;
|
|
216
|
-
width: var(--size-5);
|
|
217
|
-
height: var(--size-5);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
.default-wallet-icon {
|
|
221
|
-
display: flex;
|
|
222
|
-
align-items: center;
|
|
223
|
-
justify-content: center;
|
|
224
|
-
background: var(--gray-z-2);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
span:last-child {
|
|
228
|
-
border-left: var(--border);
|
|
229
|
-
padding-left: var(--spacer-sm);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
.link.muted {
|
|
235
|
-
justify-self: center;
|
|
236
|
-
font-size: var(--font-xs);
|
|
237
|
-
}
|
|
238
|
-
</style>
|