@1001-digital/components 1.0.0 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1001-digital/components",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "*.css"
@@ -1,6 +1,8 @@
1
1
  <template>
2
- <Toasts />
3
- <ConfirmDialog />
2
+ <Toasts>
3
+ <ConfirmDialog />
4
+ <slot />
5
+ </Toasts>
4
6
  </template>
5
7
 
6
8
  <script setup lang="ts">
@@ -3,6 +3,8 @@
3
3
  :duration="duration"
4
4
  :swipe-direction="swipeDirection"
5
5
  >
6
+ <slot />
7
+
6
8
  <ToastRoot
7
9
  v-for="toast in toasts"
8
10
  :key="toast.id"
@@ -17,6 +17,7 @@
17
17
  v-model:open="dialogOpen"
18
18
  class="evm-profile"
19
19
  title="Account"
20
+ compat
20
21
  >
21
22
  <div class="profile-header">
22
23
  <div
@@ -26,7 +27,10 @@
26
27
  "
27
28
  />
28
29
  <div class="avatar-wrapper">
29
- <EvmAvatar :address="address" large />
30
+ <EvmAvatar
31
+ :address="address"
32
+ large
33
+ />
30
34
  </div>
31
35
  </div>
32
36
 
@@ -12,6 +12,7 @@
12
12
  title="Switch Network"
13
13
  v-model:open="dialogOpen"
14
14
  @closed="onClosed"
15
+ compat
15
16
  >
16
17
  <Alert
17
18
  v-if="errorMessage"
@@ -94,9 +95,10 @@ const switchTo = async (chain: Chain) => {
94
95
  dialogOpen.value = false
95
96
  } catch (e: unknown) {
96
97
  const message = e instanceof Error ? e.message : 'Failed to switch network.'
97
- errorMessage.value = message.includes('rejected') || message.includes('denied')
98
- ? 'Network switch cancelled.'
99
- : 'Failed to switch network. Please try again.'
98
+ errorMessage.value =
99
+ message.includes('rejected') || message.includes('denied')
100
+ ? 'Network switch cancelled.'
101
+ : 'Failed to switch network. Please try again.'
100
102
  emit('error', { message: errorMessage.value })
101
103
  } finally {
102
104
  switching.value = false
@@ -1,5 +1,7 @@
1
+ import { ref, computed, watchEffect, toValue, type MaybeRefOrGetter, type Ref } from 'vue'
1
2
  import { getPublicClient } from '@wagmi/core'
2
- import type { Config } from '@wagmi/vue'
3
+ import { useConfig, type Config } from '@wagmi/vue'
4
+ import { useEvmConfig } from '../config'
3
5
  import {
4
6
  ensCache,
5
7
  fetchEnsFromIndexer,
@@ -15,17 +17,6 @@ interface UseEnsOptions {
15
17
  mode?: MaybeRefOrGetter<EnsMode | undefined>
16
18
  }
17
19
 
18
- interface EnsRuntimeConfig {
19
- ens?: { indexer1?: string; indexer2?: string; indexer3?: string }
20
- }
21
-
22
- function getIndexerUrls(config: EnsRuntimeConfig): string[] {
23
- if (!config.ens) return []
24
- return [config.ens.indexer1, config.ens.indexer2, config.ens.indexer3].filter(
25
- Boolean,
26
- ) as string[]
27
- }
28
-
29
20
  async function resolve(
30
21
  identifier: string,
31
22
  strategies: EnsMode[],
@@ -59,36 +50,45 @@ function useEnsBase(
59
50
  chainKeys: string[],
60
51
  options: UseEnsOptions = {},
61
52
  ) {
62
- const { $wagmi } = useNuxtApp()
63
- const appConfig = useAppConfig()
64
- const runtimeConfig = useRuntimeConfig()
53
+ const config = useConfig()
54
+ const evmConfig = useEvmConfig()
65
55
 
66
56
  const mode = computed<EnsMode>(
67
- () => toValue(options.mode) || appConfig.evm?.ens?.mode || 'indexer',
68
- )
69
- const indexerUrls = computed(() =>
70
- getIndexerUrls(runtimeConfig.public.evm as EnsRuntimeConfig),
57
+ () => toValue(options.mode) || evmConfig.ens?.mode || 'indexer',
71
58
  )
59
+ const indexerUrls = computed(() => evmConfig.ens?.indexerUrls || [])
72
60
  const cacheKey = computed(() => `ens-${tier}-${toValue(identifier)}`)
73
61
 
74
- return useAsyncData(
75
- cacheKey.value,
76
- async () => {
77
- const id = toValue(identifier)
78
- if (!id) return null
62
+ const data: Ref<EnsProfile | null | undefined> = ref(
63
+ ensCache.get(cacheKey.value) ?? undefined,
64
+ )
79
65
 
80
- const strategies: EnsMode[] =
81
- mode.value === 'indexer' ? ['indexer', 'chain'] : ['chain', 'indexer']
66
+ watchEffect(async () => {
67
+ const id = toValue(identifier)
68
+ if (!id) {
69
+ data.value = null
70
+ return
71
+ }
82
72
 
83
- return ensCache.fetch(cacheKey.value, () =>
84
- resolve(id, strategies, indexerUrls.value, $wagmi as Config, chainKeys),
73
+ const cached = ensCache.get(cacheKey.value)
74
+ if (cached) {
75
+ data.value = cached
76
+ return
77
+ }
78
+
79
+ const strategies: EnsMode[] =
80
+ mode.value === 'indexer' ? ['indexer', 'chain'] : ['chain', 'indexer']
81
+
82
+ try {
83
+ data.value = await ensCache.fetch(cacheKey.value, () =>
84
+ resolve(id, strategies, indexerUrls.value, config, chainKeys),
85
85
  )
86
- },
87
- {
88
- watch: [() => toValue(identifier)],
89
- getCachedData: () => ensCache.get(cacheKey.value) ?? undefined,
90
- },
91
- )
86
+ } catch {
87
+ data.value = null
88
+ }
89
+ })
90
+
91
+ return { data }
92
92
  }
93
93
 
94
94
  export const useEns = (
@@ -1,11 +1,12 @@
1
+ import { useEvmConfig } from '../config'
1
2
  import { resolveUri } from '../utils/uri'
2
3
 
3
4
  export const useResolveUri = () => {
4
- const appConfig = useAppConfig()
5
+ const evmConfig = useEvmConfig()
5
6
 
6
7
  return (uri?: string) =>
7
8
  resolveUri(uri, {
8
- ipfsGateway: appConfig.evm?.ipfsGateway,
9
- arweaveGateway: appConfig.evm?.arweaveGateway,
9
+ ipfsGateway: evmConfig.ipfsGateway,
10
+ arweaveGateway: evmConfig.arweaveGateway,
10
11
  })
11
12
  }
package/src/evm/config.ts CHANGED
@@ -13,6 +13,8 @@ export interface EvmConfig {
13
13
  mode?: 'indexer' | 'chain'
14
14
  indexerUrls?: string[]
15
15
  }
16
+ ipfsGateway?: string
17
+ arweaveGateway?: string
16
18
  baseURL?: string
17
19
  walletConnectProjectId?: string
18
20
  }
@@ -49,7 +49,9 @@ export async function fetchEnsFromIndexer(
49
49
 
50
50
  for (const url of urls) {
51
51
  try {
52
- return await $fetch<EnsProfile>(`${url}/${identifier}`)
52
+ const res = await fetch(`${url}/${identifier}`)
53
+ if (!res.ok) throw new Error(`Indexer error: ${res.status}`)
54
+ return (await res.json()) as EnsProfile
53
55
  } catch (err) {
54
56
  lastError = err as Error
55
57
  }