@1001-digital/components 0.0.5 → 1.0.1
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 +2 -2
- package/src/evm/composables/ens.ts +34 -34
- package/src/evm/composables/uri.ts +4 -3
- package/src/evm/config.ts +2 -0
- package/src/evm/utils/ens.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1001-digital/components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"*.css"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@wagmi/vue": ">=0.5.0",
|
|
18
18
|
"viem": ">=2.0.0",
|
|
19
19
|
"vue": "^3.5.0",
|
|
20
|
-
"@1001-digital/styles": "^0.0
|
|
20
|
+
"@1001-digital/styles": "^1.0.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependenciesMeta": {
|
|
23
23
|
"@wagmi/core": {
|
|
@@ -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
|
|
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
|
|
63
|
-
const
|
|
64
|
-
const runtimeConfig = useRuntimeConfig()
|
|
53
|
+
const config = useConfig()
|
|
54
|
+
const evmConfig = useEvmConfig()
|
|
65
55
|
|
|
66
56
|
const mode = computed<EnsMode>(
|
|
67
|
-
() => toValue(options.mode) ||
|
|
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
|
-
|
|
75
|
-
cacheKey.value,
|
|
76
|
-
|
|
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
|
-
|
|
81
|
-
|
|
66
|
+
watchEffect(async () => {
|
|
67
|
+
const id = toValue(identifier)
|
|
68
|
+
if (!id) {
|
|
69
|
+
data.value = null
|
|
70
|
+
return
|
|
71
|
+
}
|
|
82
72
|
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
89
|
-
|
|
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
|
|
5
|
+
const evmConfig = useEvmConfig()
|
|
5
6
|
|
|
6
7
|
return (uri?: string) =>
|
|
7
8
|
resolveUri(uri, {
|
|
8
|
-
ipfsGateway:
|
|
9
|
-
arweaveGateway:
|
|
9
|
+
ipfsGateway: evmConfig.ipfsGateway,
|
|
10
|
+
arweaveGateway: evmConfig.arweaveGateway,
|
|
10
11
|
})
|
|
11
12
|
}
|
package/src/evm/config.ts
CHANGED
package/src/evm/utils/ens.ts
CHANGED
|
@@ -49,7 +49,9 @@ export async function fetchEnsFromIndexer(
|
|
|
49
49
|
|
|
50
50
|
for (const url of urls) {
|
|
51
51
|
try {
|
|
52
|
-
|
|
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
|
}
|